contestId
int64 0
1.01k
| index
stringclasses 57
values | name
stringlengths 2
58
| type
stringclasses 2
values | rating
int64 0
3.5k
| tags
sequencelengths 0
11
| title
stringclasses 522
values | time-limit
stringclasses 8
values | memory-limit
stringclasses 8
values | problem-description
stringlengths 0
7.15k
| input-specification
stringlengths 0
2.05k
| output-specification
stringlengths 0
1.5k
| demo-input
sequencelengths 0
7
| demo-output
sequencelengths 0
7
| note
stringlengths 0
5.24k
| points
float64 0
425k
| test_cases
listlengths 0
402
| creationTimeSeconds
int64 1.37B
1.7B
| relativeTimeSeconds
int64 8
2.15B
| programmingLanguage
stringclasses 3
values | verdict
stringclasses 14
values | testset
stringclasses 12
values | passedTestCount
int64 0
1k
| timeConsumedMillis
int64 0
15k
| memoryConsumedBytes
int64 0
805M
| code
stringlengths 3
65.5k
| prompt
stringlengths 262
8.2k
| response
stringlengths 17
65.5k
| score
float64 -1
3.99
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
998 | B | Cutting | PROGRAMMING | 1,200 | [
"dp",
"greedy",
"sortings"
] | null | null | There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. | First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers | Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. | [
"6 4\n1 2 5 10 15 20\n",
"4 10\n1 3 2 4\n",
"6 100\n1 2 3 4 5 6\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | 1,000 | [
{
"input": "6 4\n1 2 5 10 15 20",
"output": "1"
},
{
"input": "4 10\n1 3 2 4",
"output": "0"
},
{
"input": "6 100\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "2 100\n13 78",
"output": "0"
},
{
"input": "10 1\n56 56 98 2 11 64 97 41 95 53",
"output": "0"
},
{
"input": "10 100\n94 65 24 47 29 98 20 65 6 17",
"output": "2"
},
{
"input": "100 1\n35 6 19 84 49 64 36 91 50 65 21 86 20 89 10 52 50 24 98 74 11 48 58 98 51 85 1 29 44 83 9 97 68 41 83 57 1 57 46 42 87 2 32 50 3 57 17 77 22 100 36 27 3 34 55 8 90 61 34 20 15 39 43 46 60 60 14 23 4 22 75 51 98 23 69 22 99 57 63 30 79 7 16 8 34 84 13 47 93 40 48 25 93 1 80 6 82 93 6 21",
"output": "0"
},
{
"input": "100 10\n3 20 3 29 90 69 2 30 70 28 71 99 22 99 34 70 87 48 3 92 71 61 26 90 14 38 51 81 16 33 49 71 14 52 50 95 65 16 80 57 87 47 29 14 40 31 74 15 87 76 71 61 30 91 44 10 87 48 84 12 77 51 25 68 49 38 79 8 7 9 39 19 48 40 15 53 29 4 60 86 76 84 6 37 45 71 46 38 80 68 94 71 64 72 41 51 71 60 79 7",
"output": "2"
},
{
"input": "100 100\n60 83 82 16 17 7 89 6 83 100 85 41 72 44 23 28 64 84 3 23 33 52 93 30 81 38 67 25 26 97 94 78 41 74 74 17 53 51 54 17 20 81 95 76 42 16 16 56 74 69 30 9 82 91 32 13 47 45 97 40 56 57 27 28 84 98 91 5 61 20 3 43 42 26 83 40 34 100 5 63 62 61 72 5 32 58 93 79 7 18 50 43 17 24 77 73 87 74 98 2",
"output": "11"
},
{
"input": "100 100\n70 54 10 72 81 84 56 15 27 19 43 100 49 44 52 33 63 40 95 17 58 2 51 39 22 18 82 1 16 99 32 29 24 94 9 98 5 37 47 14 42 73 41 31 79 64 12 6 53 26 68 67 89 13 90 4 21 93 46 74 75 88 66 57 23 7 25 48 92 62 30 8 50 61 38 87 71 34 97 28 80 11 60 91 3 35 86 96 36 20 59 65 83 45 76 77 78 69 85 55",
"output": "3"
},
{
"input": "100 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "10 10\n94 32 87 13 4 22 85 81 18 95",
"output": "1"
},
{
"input": "10 50\n40 40 9 3 64 96 67 19 21 30",
"output": "1"
},
{
"input": "100 50\n13 31 29 86 46 10 2 87 94 2 28 31 29 15 64 3 94 71 37 76 9 91 89 38 12 46 53 33 58 11 98 4 37 72 30 52 6 86 40 98 28 6 34 80 61 47 45 69 100 47 91 64 87 41 67 58 88 75 13 81 36 58 66 29 10 27 54 83 44 15 11 33 49 36 61 18 89 26 87 1 99 19 57 21 55 84 20 74 14 43 15 51 2 76 22 92 43 14 72 77",
"output": "3"
},
{
"input": "100 1\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30",
"output": "0"
},
{
"input": "100 10\n19 55 91 50 31 23 60 84 38 1 22 51 27 76 28 98 11 44 61 63 15 93 52 3 66 16 53 36 18 62 35 85 78 37 73 64 87 74 46 26 82 69 49 33 83 89 56 67 71 25 39 94 96 17 21 6 47 68 34 42 57 81 13 10 54 2 48 80 20 77 4 5 59 30 90 95 45 75 8 88 24 41 40 14 97 32 7 9 65 70 100 99 72 58 92 29 79 12 86 43",
"output": "0"
},
{
"input": "100 50\n2 4 82 12 47 63 52 91 87 45 53 1 17 25 64 50 9 13 22 54 21 30 43 24 38 33 68 11 41 78 99 23 28 18 58 67 79 10 71 56 49 61 26 29 59 20 90 74 5 75 89 8 39 95 72 42 66 98 44 32 88 35 92 3 97 55 65 51 77 27 81 76 84 69 73 85 19 46 62 100 60 37 7 36 57 6 14 83 40 48 16 70 96 15 31 93 80 86 94 34",
"output": "1"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "1"
},
{
"input": "100 10\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "10"
},
{
"input": "100 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100",
"output": "49"
},
{
"input": "100 30\n2 1 2 2 2 2 1 1 1 2 1 1 2 2 1 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 2 2 2 1 1 2 1 2 2 2 1 1 1 1 1 2 1 1 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1 2 1 1 2",
"output": "11"
},
{
"input": "100 80\n1 1 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 1 1 2 2 2 2 1 2 2 1 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 2 2 2 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 2 2 2 1 2 2 1 2",
"output": "12"
},
{
"input": "100 30\n100 99 100 99 99 100 100 99 100 99 99 100 100 100 99 99 99 100 99 99 99 99 100 99 99 100 100 99 100 99 99 99 100 99 100 100 99 100 100 100 100 100 99 99 100 99 99 100 99 100 99 99 100 100 99 100 99 99 100 99 100 100 100 100 99 99 99 100 99 100 99 100 100 100 99 100 100 100 99 100 99 99 100 100 100 100 99 99 99 100 99 100 100 99 99 99 100 100 99 99",
"output": "14"
},
{
"input": "100 80\n99 100 100 100 99 99 99 99 100 99 99 99 99 99 99 99 99 100 100 99 99 99 99 99 100 99 100 99 100 100 100 100 100 99 100 100 99 99 100 100 100 100 100 99 100 99 100 99 99 99 100 99 99 99 99 99 99 99 99 100 99 100 100 99 99 99 99 100 100 100 99 100 100 100 100 100 99 100 100 100 100 100 100 100 100 99 99 99 99 100 99 100 100 100 100 100 99 100 99 100",
"output": "4"
},
{
"input": "100 30\n100 100 39 39 39 100 100 39 39 100 39 39 100 39 100 39 100 100 100 100 100 39 100 100 100 39 39 39 100 39 100 100 39 39 100 39 39 39 100 100 39 100 39 100 39 39 100 100 39 100 39 100 39 39 39 100 39 100 39 39 39 100 39 39 100 100 39 39 39 100 100 39 39 39 100 100 100 100 39 100 100 100 39 39 100 39 100 100 39 100 39 100 39 39 100 39 39 100 100 100",
"output": "5"
},
{
"input": "100 80\n39 100 39 100 100 100 100 39 39 100 100 39 39 100 39 39 39 39 100 39 39 39 39 100 100 100 100 39 100 39 39 100 100 39 39 100 39 100 39 100 100 39 39 100 39 39 39 100 39 100 39 100 100 100 100 100 100 100 39 100 39 100 100 100 39 39 39 39 39 100 100 100 39 100 100 100 100 39 100 100 39 39 100 39 39 39 100 39 100 39 39 100 100 39 100 39 39 39 100 39",
"output": "6"
},
{
"input": "4 1\n1 2 3 4",
"output": "1"
},
{
"input": "4 1\n1 2 1 2",
"output": "1"
},
{
"input": "4 4\n1 2 6 7",
"output": "1"
},
{
"input": "4 8\n1 2 10 11",
"output": "1"
},
{
"input": "6 2\n1 2 3 4 5 6",
"output": "2"
},
{
"input": "6 1\n1 2 1 2 1 2",
"output": "1"
},
{
"input": "6 4\n1 2 4 5 7 8",
"output": "2"
},
{
"input": "6 3\n1 2 5 10 15 20",
"output": "1"
}
] | 1,601,402,468 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 514 | 10,752,000 | import math
from decimal import *
import random
mod = int(1e9)+7
n,k = map(int, input().split())
arr = list(map(int, input().split()))
odd, even = 0,0
pos = []
for i in range(n-1):
if(arr[i]%2==0):
even+=1
elif(arr[i]%2==1):
odd+=1
if(odd==even):
pos.append(abs(arr[i+1]-arr[i]))
pos = sorted(pos)
ans= 0
if(pos):
while(k-pos[ans] >=0):
k-=pos[ans]
ans+=1
if(ans==len(pos)):
break
print(ans)
| Title: Cutting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers.
There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers.
Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements.
The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins.
Input Specification:
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have.
Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers
Output Specification:
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
Demo Input:
['6 4\n1 2 5 10 15 20\n', '4 10\n1 3 2 4\n', '6 100\n1 2 3 4 5 6\n']
Demo Output:
['1\n', '0\n', '2\n']
Note:
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins.
In the second sample it is not possible to make even one cut even with unlimited number of bitcoins.
In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. | ```python
import math
from decimal import *
import random
mod = int(1e9)+7
n,k = map(int, input().split())
arr = list(map(int, input().split()))
odd, even = 0,0
pos = []
for i in range(n-1):
if(arr[i]%2==0):
even+=1
elif(arr[i]%2==1):
odd+=1
if(odd==even):
pos.append(abs(arr[i+1]-arr[i]))
pos = sorted(pos)
ans= 0
if(pos):
while(k-pos[ans] >=0):
k-=pos[ans]
ans+=1
if(ans==len(pos)):
break
print(ans)
``` | 3 |
|
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000). | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input": "0 -100 0 100",
"output": "200 -100 200 100"
},
{
"input": "27 -74 27 74",
"output": "175 -74 175 74"
},
{
"input": "0 1 2 3",
"output": "0 3 2 1"
},
{
"input": "-100 100 100 -100",
"output": "-100 -100 100 100"
},
{
"input": "-100 -100 -100 100",
"output": "100 -100 100 100"
},
{
"input": "100 100 100 -100",
"output": "300 100 300 -100"
},
{
"input": "100 -100 -100 -100",
"output": "100 100 -100 100"
},
{
"input": "-100 100 100 100",
"output": "-100 300 100 300"
},
{
"input": "0 1 0 0",
"output": "1 1 1 0"
},
{
"input": "1 1 0 0",
"output": "1 0 0 1"
},
{
"input": "0 0 1 0",
"output": "0 1 1 1"
},
{
"input": "1 0 0 1",
"output": "1 1 0 0"
},
{
"input": "1 0 1 1",
"output": "2 0 2 1"
},
{
"input": "1 1 0 1",
"output": "1 2 0 2"
},
{
"input": "15 -9 80 -9",
"output": "15 56 80 56"
},
{
"input": "51 -36 18 83",
"output": "-1"
},
{
"input": "69 -22 60 16",
"output": "-1"
},
{
"input": "-68 -78 -45 -55",
"output": "-68 -55 -45 -78"
},
{
"input": "68 -92 8 -32",
"output": "68 -32 8 -92"
},
{
"input": "95 -83 -39 -6",
"output": "-1"
},
{
"input": "54 94 53 -65",
"output": "-1"
},
{
"input": "-92 15 84 15",
"output": "-92 191 84 191"
},
{
"input": "67 77 -11 -1",
"output": "67 -1 -11 77"
},
{
"input": "91 -40 30 21",
"output": "91 21 30 -40"
},
{
"input": "66 -64 -25 -64",
"output": "66 27 -25 27"
},
{
"input": "-42 84 -67 59",
"output": "-42 59 -67 84"
},
{
"input": "73 47 -5 -77",
"output": "-1"
},
{
"input": "6 85 -54 -84",
"output": "-1"
},
{
"input": "-58 -55 40 43",
"output": "-58 43 40 -55"
},
{
"input": "56 22 48 70",
"output": "-1"
},
{
"input": "-17 -32 76 -32",
"output": "-17 61 76 61"
},
{
"input": "0 2 2 0",
"output": "0 0 2 2"
},
{
"input": "0 0 -1 1",
"output": "0 1 -1 0"
},
{
"input": "0 2 1 1",
"output": "0 1 1 2"
},
{
"input": "0 0 1 -1",
"output": "0 -1 1 0"
},
{
"input": "-1 2 -2 3",
"output": "-1 3 -2 2"
},
{
"input": "0 1 1 0",
"output": "0 0 1 1"
},
{
"input": "1 2 2 1",
"output": "1 1 2 2"
},
{
"input": "4 1 2 1",
"output": "4 3 2 3"
},
{
"input": "70 0 0 10",
"output": "-1"
},
{
"input": "2 3 4 1",
"output": "2 1 4 3"
},
{
"input": "1 3 3 1",
"output": "1 1 3 3"
},
{
"input": "-3 3 0 0",
"output": "-3 0 0 3"
},
{
"input": "2 8 7 3",
"output": "2 3 7 8"
},
{
"input": "1 2 2 3",
"output": "1 3 2 2"
},
{
"input": "0 3 3 0",
"output": "0 0 3 3"
},
{
"input": "0 0 -3 3",
"output": "0 3 -3 0"
},
{
"input": "0 2 1 2",
"output": "0 3 1 3"
},
{
"input": "1 1 2 0",
"output": "1 0 2 1"
},
{
"input": "0 0 5 0",
"output": "0 5 5 5"
},
{
"input": "3 4 7 8",
"output": "3 8 7 4"
},
{
"input": "0 5 5 0",
"output": "0 0 5 5"
},
{
"input": "5 6 8 3",
"output": "5 3 8 6"
},
{
"input": "2 2 1 1",
"output": "2 1 1 2"
},
{
"input": "0 1 3 1",
"output": "0 4 3 4"
},
{
"input": "2 4 5 4",
"output": "2 7 5 7"
},
{
"input": "0 5 1 5",
"output": "0 6 1 6"
},
{
"input": "4 0 0 4",
"output": "4 4 0 0"
},
{
"input": "0 1 1 8",
"output": "-1"
},
{
"input": "2 3 3 4",
"output": "2 4 3 3"
},
{
"input": "1 0 2 1",
"output": "1 1 2 0"
},
{
"input": "0 0 2 14",
"output": "-1"
},
{
"input": "0 0 4 3",
"output": "-1"
},
{
"input": "3 5 5 3",
"output": "3 3 5 5"
},
{
"input": "-1 1 1 -1",
"output": "-1 -1 1 1"
},
{
"input": "0 0 2 0",
"output": "0 2 2 2"
},
{
"input": "0 0 1 7",
"output": "-1"
},
{
"input": "1 2 3 2",
"output": "1 4 3 4"
},
{
"input": "1 12 3 10",
"output": "1 10 3 12"
}
] | 1,698,862,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 31 | 0 | x1,y1,x2,y2=map(int,input().split())
if x1 != x2 and y1 != y2 and abs(x1-x2) != abs(y1-y2):
print(-1)
elif x1 ==x2:
print(x1+abs(y1-y2),y1,x2+abs(y1-y2),y2)
elif y1==y2:
print(x1 , abs(y1 - y2)+y1, x2 ,abs(y1 - y2)+ y2)
else:
print(x1,y2,x2,y1) | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.
Input Specification:
The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct.
Output Specification:
If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000).
Demo Input:
['0 0 0 1\n', '0 0 1 1\n', '0 0 1 2\n']
Demo Output:
['1 0 1 1\n', '0 1 1 0\n', '-1\n']
Note:
none | ```python
x1,y1,x2,y2=map(int,input().split())
if x1 != x2 and y1 != y2 and abs(x1-x2) != abs(y1-y2):
print(-1)
elif x1 ==x2:
print(x1+abs(y1-y2),y1,x2+abs(y1-y2),y2)
elif y1==y2:
print(x1 , abs(y1 - y2)+y1, x2 ,abs(y1 - y2)+ y2)
else:
print(x1,y2,x2,y1)
``` | 0 |
|
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring.
String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*.
Help the bear cope with the given problem. | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11). | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output": "4419"
},
{
"input": "bear",
"output": "1"
},
{
"input": "a",
"output": "0"
},
{
"input": "be",
"output": "0"
}
] | 1,503,282,772 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | s = input()
ind = [i for (i, _) in enumerate(s) if s.startswith('bear', i)]
L = len(s)
r, z = 0, 0
for e in ind:
for _ in range(z, e + 1):
z = e + 1
r += L - (e + 3)
print(r) | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string "bear" as a substring.
String *x*(*i*,<=*j*) contains string "bear", if there is such index *k* (*i*<=≤<=*k*<=≤<=*j*<=-<=3), that *s**k*<==<=*b*, *s**k*<=+<=1<==<=*e*, *s**k*<=+<=2<==<=*a*, *s**k*<=+<=3<==<=*r*.
Help the bear cope with the given problem.
Input Specification:
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['bearbtear\n', 'bearaabearc\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11), (6, 10), (6, 11), (7, 10), (7, 11). | ```python
s = input()
ind = [i for (i, _) in enumerate(s) if s.startswith('bear', i)]
L = len(s)
r, z = 0, 0
for e in ind:
for _ in range(z, e + 1):
z = e + 1
r += L - (e + 3)
print(r)
``` | 3 |
|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 1,688,359,741 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | a = list(map(int, input().split()))
total_drink = a[1] * a[2]
total_slice = a[3] * a[4]
total_salt = a[5] // a[7]
print(min(total_drink//a[6], total_slice, total_salt) // a[0]) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
Input Specification:
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Output Specification:
Print a single integer — the number of toasts each friend can make.
Demo Input:
['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | ```python
a = list(map(int, input().split()))
total_drink = a[1] * a[2]
total_slice = a[3] * a[4]
total_salt = a[5] // a[7]
print(min(total_drink//a[6], total_slice, total_salt) // a[0])
``` | 3 |
|
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"output": "Second"
},
{
"input": "1 1 1 1",
"output": "Second"
},
{
"input": "50 50 50 50",
"output": "Second"
},
{
"input": "50 49 1 2",
"output": "First"
},
{
"input": "50 48 3 1",
"output": "First"
},
{
"input": "48 50 12 11",
"output": "Second"
},
{
"input": "49 50 11 12",
"output": "Second"
},
{
"input": "49 49 4 1",
"output": "Second"
},
{
"input": "49 49 3 3",
"output": "Second"
},
{
"input": "1 50 1 50",
"output": "Second"
},
{
"input": "1 50 50 50",
"output": "Second"
},
{
"input": "50 1 1 1",
"output": "First"
},
{
"input": "50 1 1 50",
"output": "First"
},
{
"input": "32 31 10 9",
"output": "First"
},
{
"input": "32 4 17 3",
"output": "First"
}
] | 1,689,084,546 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n_balls,m_ball,n_moves,m_moves=map(int,input().split)
if(n_balls + n_moves >= m_ball+m_moves):
print("First")
else:
print("Second")
| Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.
Input Specification:
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output Specification:
Output "First" if the first player wins and "Second" otherwise.
Demo Input:
['2 2 1 2\n', '2 1 1 1\n']
Demo Output:
['Second\n', 'First\n']
Note:
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | ```python
n_balls,m_ball,n_moves,m_moves=map(int,input().split)
if(n_balls + n_moves >= m_ball+m_moves):
print("First")
else:
print("Second")
``` | -1 |
|
704 | A | Thor | PROGRAMMING | 1,600 | [
"brute force",
"data structures",
"implementation"
] | null | null | Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are about to happen (in chronological order). They are of three types:
1. Application *x* generates a notification (this new notification is unread). 1. Thor reads all notifications generated so far by application *x* (he may re-read some notifications). 1. Thor reads the first *t* notifications generated by phone applications (notifications generated in first *t* events of the first type). It's guaranteed that there were at least *t* events of the first type before this event. Please note that he doesn't read first *t* unread notifications, he just reads the very first *t* notifications generated on his phone and he may re-read some of them in this operation.
Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone. | The first line of input contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=300<=000) — the number of applications and the number of events to happen.
The next *q* lines contain the events. The *i*-th of these lines starts with an integer *type**i* — type of the *i*-th event. If *type**i*<==<=1 or *type**i*<==<=2 then it is followed by an integer *x**i*. Otherwise it is followed by an integer *t**i* (1<=≤<=*type**i*<=≤<=3,<=1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*t**i*<=≤<=*q*). | Print the number of unread notifications after each event. | [
"3 4\n1 3\n1 1\n1 2\n2 3\n",
"4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n"
] | [
"1\n2\n3\n2\n",
"1\n2\n3\n0\n1\n2\n"
] | In the first sample:
1. Application 3 generates a notification (there is 1 unread notification). 1. Application 1 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
1. Application 2 generates a notification (there is 1 unread notification). 1. Application 4 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left. 1. Application 3 generates a notification (there is 1 unread notification). 1. Application 3 generates a notification (there are 2 unread notifications). | 500 | [
{
"input": "3 4\n1 3\n1 1\n1 2\n2 3",
"output": "1\n2\n3\n2"
},
{
"input": "4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3",
"output": "1\n2\n3\n0\n1\n2"
},
{
"input": "10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n1 10\n3 8\n2 8\n1 6\n1 3\n1 9\n1 6\n1 3\n1 8\n1 1\n1 6\n1 10\n2 1\n2 10\n1 10\n1 1\n1 10\n1 6\n1 2\n1 8\n1 3\n1 4\n1 9\n1 5\n1 5\n2 2\n2 4\n1 7\n1 1\n2 4\n1 9\n1 1\n1 7\n1 8\n3 33\n1 10\n2 2\n1 3\n1 10\n1 6\n3 32\n2 3\n1 5\n2 10\n2 2\n2 4\n2 3\n3 16\n1 3\n2 2\n1 1\n3 18\n2 2\n2 5\n1 5\n1 9\n2 4\n1 3\n1 4\n1 3\n1 6\n1 10\n2 2\n1 7\n1 7\n2 8\n1 1\n3 1\n1 8\n1 10\n1 7\n1 8",
"output": "0\n1\n2\n2\n3\n4\n5\n4\n5\n3\n4\n5\n6\n7\n2\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n9\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n17\n16\n17\n18\n18\n19\n20\n21\n22\n3\n4\n4\n5\n6\n7\n7\n6\n7\n5\n5\n5\n5\n5\n6\n6\n7\n7\n7\n6\n7\n8\n8\n9\n10\n11\n12\n13\n13\n14\n15\n14\n15\n15\n16\n17\n18\n19"
},
{
"input": "300000 1\n1 300000",
"output": "1"
}
] | 1,674,580,275 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | from collections import defaultdict
n, q = map(int, input().split())
apps = defaultdict(list)
queue = []
num_unread = 0
num_read = 0
for _ in range(q):
event_type, app_number = map(int, input().split())
if event_type == 1:
apps[app_number].append(False)
queue.append([app_number, len(apps[app_number]) - 1])
num_unread += 1
elif event_type == 2:
for i in range(len(apps[app_number])):
unread = len(list(filter(lambda x: x == False, apps[app_number])))
apps[app_number] = [True] * len(apps[app_number])
num_unread -= unread
num_read += unread
elif event_type == 3:
num_notifs_to_read = app_number
for i in range(num_read - 1, num_notifs_to_read - num_read):
app_num, idx = queue[i]
if not apps[app_num][idx]:
apps[app_num][idx] = True
num_unread -= 1
num_read += 1
print(num_unread) | Title: Thor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are *n* applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).
*q* events are about to happen (in chronological order). They are of three types:
1. Application *x* generates a notification (this new notification is unread). 1. Thor reads all notifications generated so far by application *x* (he may re-read some notifications). 1. Thor reads the first *t* notifications generated by phone applications (notifications generated in first *t* events of the first type). It's guaranteed that there were at least *t* events of the first type before this event. Please note that he doesn't read first *t* unread notifications, he just reads the very first *t* notifications generated on his phone and he may re-read some of them in this operation.
Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.
Input Specification:
The first line of input contains two integers *n* and *q* (1<=≤<=*n*,<=*q*<=≤<=300<=000) — the number of applications and the number of events to happen.
The next *q* lines contain the events. The *i*-th of these lines starts with an integer *type**i* — type of the *i*-th event. If *type**i*<==<=1 or *type**i*<==<=2 then it is followed by an integer *x**i*. Otherwise it is followed by an integer *t**i* (1<=≤<=*type**i*<=≤<=3,<=1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*t**i*<=≤<=*q*).
Output Specification:
Print the number of unread notifications after each event.
Demo Input:
['3 4\n1 3\n1 1\n1 2\n2 3\n', '4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n']
Demo Output:
['1\n2\n3\n2\n', '1\n2\n3\n0\n1\n2\n']
Note:
In the first sample:
1. Application 3 generates a notification (there is 1 unread notification). 1. Application 1 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads the notification generated by application 3, there are 2 unread notifications left.
In the second sample test:
1. Application 2 generates a notification (there is 1 unread notification). 1. Application 4 generates a notification (there are 2 unread notifications). 1. Application 2 generates a notification (there are 3 unread notifications). 1. Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left. 1. Application 3 generates a notification (there is 1 unread notification). 1. Application 3 generates a notification (there are 2 unread notifications). | ```python
from collections import defaultdict
n, q = map(int, input().split())
apps = defaultdict(list)
queue = []
num_unread = 0
num_read = 0
for _ in range(q):
event_type, app_number = map(int, input().split())
if event_type == 1:
apps[app_number].append(False)
queue.append([app_number, len(apps[app_number]) - 1])
num_unread += 1
elif event_type == 2:
for i in range(len(apps[app_number])):
unread = len(list(filter(lambda x: x == False, apps[app_number])))
apps[app_number] = [True] * len(apps[app_number])
num_unread -= unread
num_read += unread
elif event_type == 3:
num_notifs_to_read = app_number
for i in range(num_read - 1, num_notifs_to_read - num_read):
app_num, idx = queue[i]
if not apps[app_num][idx]:
apps[app_num][idx] = True
num_unread -= 1
num_read += 1
print(num_unread)
``` | 0 |
|
715 | B | Complete The Graph | PROGRAMMING | 2,300 | [
"binary search",
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices *s* and *t* in the resulting graph is exactly *L*. Can you help him? | The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=≤<=*n*<=≤<=1000,<=<=1<=≤<=*m*<=≤<=10<=000,<=<=1<=≤<=*L*<=≤<=109,<=<=0<=≤<=*s*,<=*t*<=≤<=*n*<=-<=1,<=<=*s*<=≠<=*t*) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, *m* lines describing the edges of the graph follow. *i*-th of them contains three integers, *u**i*,<=*v**i*,<=*w**i* (0<=≤<=*u**i*,<=*v**i*<=≤<=*n*<=-<=1,<=<=*u**i*<=≠<=*v**i*,<=<=0<=≤<=*w**i*<=≤<=109). *u**i* and *v**i* denote the endpoints of the edge and *w**i* denotes its weight. If *w**i* is equal to 0 then the weight of the corresponding edge was erased.
It is guaranteed that there is at most one edge between any pair of vertices. | Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u**i*, *v**i* and *w**i*, denoting an edge between vertices *u**i* and *v**i* of weight *w**i*. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018.
The order of the edges in the output doesn't matter. The length of the shortest path between *s* and *t* must be equal to *L*.
If there are multiple solutions, print any of them. | [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n"
] | [
"YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"YES\n0 1 123456789\n",
"NO\n"
] | Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789.
In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO". | 1,000 | [
{
"input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4",
"output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4"
},
{
"input": "2 1 123456789 0 1\n0 1 0",
"output": "YES\n0 1 123456789"
},
{
"input": "2 1 999999999 1 0\n0 1 1000000000",
"output": "NO"
},
{
"input": "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6",
"output": "NO"
},
{
"input": "100 1 123456 99 0\n0 99 123456",
"output": "YES\n0 99 123456"
},
{
"input": "1000 1 5 999 0\n0 999 0",
"output": "YES\n0 999 5"
},
{
"input": "1000 1 1000000000 998 0\n0 999 0",
"output": "NO"
},
{
"input": "4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12",
"output": "NO"
},
{
"input": "4 4 13 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12",
"output": "YES\n1 3 13\n2 3 1000000000000000000\n2 0 1000000000000000000\n1 0 12"
},
{
"input": "4 4 2 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 0",
"output": "NO"
},
{
"input": "4 4 8 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 6",
"output": "YES\n1 3 13\n2 3 1\n2 0 1\n1 0 6"
},
{
"input": "5 6 1000000000 0 4\n0 1 1\n2 0 2\n3 0 3\n4 1 0\n4 2 0\n3 4 0",
"output": "YES\n0 1 1\n2 0 2\n3 0 3\n4 1 999999999\n4 2 1000000000000000000\n3 4 1000000000000000000"
},
{
"input": "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61",
"output": "YES\n0 1 1\n1 2 199\n2 3 318\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61"
},
{
"input": "7 9 319 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61",
"output": "YES\n0 1 1\n1 2 198\n2 3 317\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61"
},
{
"input": "7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1",
"output": "YES\n0 1 1\n1 2 999999996\n2 3 999999997\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1"
},
{
"input": "5 5 2 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "YES\n0 1 1\n1 2 1\n0 4 1000000000000000000\n4 3 1000000000000000000\n3 2 1000000000000000000"
},
{
"input": "5 5 1 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "NO"
},
{
"input": "5 5 3 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0",
"output": "NO"
},
{
"input": "8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6 1\n6 0 1\n5 7 0\n7 0 0",
"output": "YES\n1 2 1\n2 4 1\n1 3 1000000000000000000\n3 4 1000000000000000000\n4 5 6\n5 6 1\n6 0 1\n5 7 1000000000000000000\n7 0 1000000000000000000"
},
{
"input": "4 5 7 0 3\n0 1 0\n1 2 3\n2 3 0\n0 2 5\n1 3 5",
"output": "YES\n0 1 2\n1 2 3\n2 3 3\n0 2 5\n1 3 5"
}
] | 1,684,655,110 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 179 | 280 | 13,824,000 | import heapq
import random
import sys
from math import inf
from types import GeneratorType
RANDOM = random.randint(1, 10 ** 9)
class FastIO:
def __init__(self):
return
@staticmethod
def read_str():
return sys.stdin.readline()
def read_int(self):
return int(self.read_str())
def read_float(self):
return float(self.read_str())
def read_ints(self):
return map(int, self.read_str().split())
def read_floats(self):
return map(float, self.read_str().split())
def read_ints_minus_one(self):
return map(lambda x: int(x) - 1, self.read_str().split())
def read_list_ints(self):
return list(map(int, self.read_str().split()))
def read_list_floats(self):
return list(map(float, self.read_str().split()))
def read_list_ints_minus_one(self):
return list(map(lambda x: int(x) - 1, self.read_str().split()))
def read_list_strs(self):
return self.read_str().split()
def read_list_str(self):
return list(self.read_str())
@staticmethod
def st(x):
return print(x)
@staticmethod
def lst(x):
return print(*x)
@staticmethod
def round_5(f):
res = int(f)
if f - res >= 0.5:
res += 1
return res
@staticmethod
def max(a, b):
return a if a > b else b
@staticmethod
def min(a, b):
return a if a < b else b
@staticmethod
def bootstrap(f, queue=[]):
def wrappedfunc(*args, **kwargs):
if queue:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if isinstance(to, GeneratorType):
queue.append(to)
to = next(to)
else:
queue.pop()
if not queue:
break
to = queue[-1].send(to)
return to
return wrappedfunc
def ask(self, lst):
self.lst(lst)
sys.stdout.flush()
res = self.read_int()
return res
@staticmethod
def accumulate(nums):
n = len(nums)
pre = [0] * (n + 1)
for i in range(n):
pre[i + 1] = pre[i] + nums[i]
return pre
class Wrapper(int):
# 用来规避 py 哈希碰撞的问题和进行加速
def __init__(self, x):
int.__init__(x)
# 原理是异或一个随机种子
def __hash__(self):
# 也可以将数组排序后进行哈希计数
return super(Wrapper, self).__hash__() ^ RANDOM
class Solution:
def __init__(self):
return
@staticmethod
def main(ac=FastIO()):
n, m, target, source, destination = ac.read_ints()
edges = []
dct = [[] for _ in range(n)]
book = [0] * m
for ind in range(m):
i, j, w = ac.read_list_ints()
if w == 0:
w = 1
book[ind] = 1
edges.append([i, j, w])
dct[i].append([ind, j])
dct[j].append([ind, i])
# 第一遍最短路计算最小情况下的距离
dis0 = [inf] * n
stack = [[0, source]]
dis0[source] = 0
while stack:
d, i = heapq.heappop(stack)
if dis0[i] < d:
continue
for ind, j in dct[i]:
dj = edges[ind][2] + d
if dj < dis0[j]:
dis0[j] = dj
heapq.heappush(stack, [dj, j])
if dis0[destination] > target:
ac.st("NO")
return
# 第二遍最短路
dis1 = [inf] * n
stack = [[0, source]]
dis1[source] = 0
while stack:
d, i = heapq.heappop(stack)
if dis1[i] < d:
continue
for ind, j in dct[i]:
if book[ind]:
# 假设 (i, j) 是最短路上的边
if (edges[ind][2] + dis1[i]) + (dis0[destination] - dis0[j]) < target:
# 此时还有一些增长空间即(当前到达 j 的距离)加上(剩余 j 到 destination)的距离仍旧小于 target
x = target - (edges[ind][2] + dis1[i]) - (dis0[destination] - dis0[j])
edges[ind][2] += x
book[ind] = 0
dj = edges[ind][2] + d
if dj < dis1[j]:
dis1[j] = dj
heapq.heappush(stack, [dj, j])
if dis1[destination] == target:
ac.st("YES")
for e in edges:
ac.lst(e)
else:
ac.st("NO")
return
Solution().main()
| Title: Complete The Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices *s* and *t* in the resulting graph is exactly *L*. Can you help him?
Input Specification:
The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=≤<=*n*<=≤<=1000,<=<=1<=≤<=*m*<=≤<=10<=000,<=<=1<=≤<=*L*<=≤<=109,<=<=0<=≤<=*s*,<=*t*<=≤<=*n*<=-<=1,<=<=*s*<=≠<=*t*) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, *m* lines describing the edges of the graph follow. *i*-th of them contains three integers, *u**i*,<=*v**i*,<=*w**i* (0<=≤<=*u**i*,<=*v**i*<=≤<=*n*<=-<=1,<=<=*u**i*<=≠<=*v**i*,<=<=0<=≤<=*w**i*<=≤<=109). *u**i* and *v**i* denote the endpoints of the edge and *w**i* denotes its weight. If *w**i* is equal to 0 then the weight of the corresponding edge was erased.
It is guaranteed that there is at most one edge between any pair of vertices.
Output Specification:
Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u**i*, *v**i* and *w**i*, denoting an edge between vertices *u**i* and *v**i* of weight *w**i*. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018.
The order of the edges in the output doesn't matter. The length of the shortest path between *s* and *t* must be equal to *L*.
If there are multiple solutions, print any of them.
Demo Input:
['5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n', '2 1 123456789 0 1\n0 1 0\n', '2 1 999999999 1 0\n0 1 1000000000\n']
Demo Output:
['YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n', 'YES\n0 1 123456789\n', 'NO\n']
Note:
Here's how the graph in the first sample case looks like :
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789.
In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO". | ```python
import heapq
import random
import sys
from math import inf
from types import GeneratorType
RANDOM = random.randint(1, 10 ** 9)
class FastIO:
def __init__(self):
return
@staticmethod
def read_str():
return sys.stdin.readline()
def read_int(self):
return int(self.read_str())
def read_float(self):
return float(self.read_str())
def read_ints(self):
return map(int, self.read_str().split())
def read_floats(self):
return map(float, self.read_str().split())
def read_ints_minus_one(self):
return map(lambda x: int(x) - 1, self.read_str().split())
def read_list_ints(self):
return list(map(int, self.read_str().split()))
def read_list_floats(self):
return list(map(float, self.read_str().split()))
def read_list_ints_minus_one(self):
return list(map(lambda x: int(x) - 1, self.read_str().split()))
def read_list_strs(self):
return self.read_str().split()
def read_list_str(self):
return list(self.read_str())
@staticmethod
def st(x):
return print(x)
@staticmethod
def lst(x):
return print(*x)
@staticmethod
def round_5(f):
res = int(f)
if f - res >= 0.5:
res += 1
return res
@staticmethod
def max(a, b):
return a if a > b else b
@staticmethod
def min(a, b):
return a if a < b else b
@staticmethod
def bootstrap(f, queue=[]):
def wrappedfunc(*args, **kwargs):
if queue:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if isinstance(to, GeneratorType):
queue.append(to)
to = next(to)
else:
queue.pop()
if not queue:
break
to = queue[-1].send(to)
return to
return wrappedfunc
def ask(self, lst):
self.lst(lst)
sys.stdout.flush()
res = self.read_int()
return res
@staticmethod
def accumulate(nums):
n = len(nums)
pre = [0] * (n + 1)
for i in range(n):
pre[i + 1] = pre[i] + nums[i]
return pre
class Wrapper(int):
# 用来规避 py 哈希碰撞的问题和进行加速
def __init__(self, x):
int.__init__(x)
# 原理是异或一个随机种子
def __hash__(self):
# 也可以将数组排序后进行哈希计数
return super(Wrapper, self).__hash__() ^ RANDOM
class Solution:
def __init__(self):
return
@staticmethod
def main(ac=FastIO()):
n, m, target, source, destination = ac.read_ints()
edges = []
dct = [[] for _ in range(n)]
book = [0] * m
for ind in range(m):
i, j, w = ac.read_list_ints()
if w == 0:
w = 1
book[ind] = 1
edges.append([i, j, w])
dct[i].append([ind, j])
dct[j].append([ind, i])
# 第一遍最短路计算最小情况下的距离
dis0 = [inf] * n
stack = [[0, source]]
dis0[source] = 0
while stack:
d, i = heapq.heappop(stack)
if dis0[i] < d:
continue
for ind, j in dct[i]:
dj = edges[ind][2] + d
if dj < dis0[j]:
dis0[j] = dj
heapq.heappush(stack, [dj, j])
if dis0[destination] > target:
ac.st("NO")
return
# 第二遍最短路
dis1 = [inf] * n
stack = [[0, source]]
dis1[source] = 0
while stack:
d, i = heapq.heappop(stack)
if dis1[i] < d:
continue
for ind, j in dct[i]:
if book[ind]:
# 假设 (i, j) 是最短路上的边
if (edges[ind][2] + dis1[i]) + (dis0[destination] - dis0[j]) < target:
# 此时还有一些增长空间即(当前到达 j 的距离)加上(剩余 j 到 destination)的距离仍旧小于 target
x = target - (edges[ind][2] + dis1[i]) - (dis0[destination] - dis0[j])
edges[ind][2] += x
book[ind] = 0
dj = edges[ind][2] + d
if dj < dis1[j]:
dis1[j] = dj
heapq.heappush(stack, [dj, j])
if dis1[destination] == target:
ac.st("YES")
for e in edges:
ac.lst(e)
else:
ac.st("NO")
return
Solution().main()
``` | 3 |
|
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
"output": "9"
},
{
"input": "10\n10 5 8 9 5 6 8 7 2 8",
"output": "46"
},
{
"input": "10\n1 1 1 1 1 1 2 3 4 4",
"output": "14"
},
{
"input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4",
"output": "296"
},
{
"input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2",
"output": "313"
},
{
"input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9",
"output": "298"
},
{
"input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5",
"output": "312"
},
{
"input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2",
"output": "287"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8",
"output": "380"
},
{
"input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2",
"output": "265"
},
{
"input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9",
"output": "328"
},
{
"input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9",
"output": "324"
},
{
"input": "10\n7 4 5 3 9 1 10 3 4 5",
"output": "34"
},
{
"input": "10\n8 9 6 5 6 4 10 9 1 4",
"output": "39"
},
{
"input": "10\n1 7 1 4 9 10 8 2 9 9",
"output": "40"
},
{
"input": "1\n100000",
"output": "100000"
}
] | 1,668,564,048 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 31 | 0 | N=int(input())
B=[int(x) for x in input().split()]
ma=max(B)
D=[0]*(ma+2)
for i in range(N):
D[B[i]]+=1
E=[]
MAX=0
for j in range(len(D)):
if D[j]==0:
E.append(j)
for u in range(len(E)-1):
if E[u+1]-E[u]==2:
MAX=MAX+B[E[u]+1]*(E[u]+1)
if E[u+1]-E[u]>2:
Z1=0
Z2=0
for j in range(E[u]+2,E[u+1],2):
Z1+=D[j]*j
for k in range(E[u]+1,E[u+1],2):
Z2+=D[k]*k
MAX=MAX+max(Z1,Z2)
print(MAX) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player.
Alex is a perfectionist, so he decided to get as many points as possible. Help him.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a single integer — the maximum number of points that Alex can earn.
Demo Input:
['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n']
Demo Output:
['2\n', '4\n', '10\n']
Note:
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | ```python
N=int(input())
B=[int(x) for x in input().split()]
ma=max(B)
D=[0]*(ma+2)
for i in range(N):
D[B[i]]+=1
E=[]
MAX=0
for j in range(len(D)):
if D[j]==0:
E.append(j)
for u in range(len(E)-1):
if E[u+1]-E[u]==2:
MAX=MAX+B[E[u]+1]*(E[u]+1)
if E[u+1]-E[u]>2:
Z1=0
Z2=0
for j in range(E[u]+2,E[u+1],2):
Z1+=D[j]*j
for k in range(E[u]+1,E[u+1],2):
Z2+=D[k]*k
MAX=MAX+max(Z1,Z2)
print(MAX)
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,611,599,396 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | def checkHello(str1):
if len(str1)<=5:
print("NO")
else:
str2 = "helloo"
j = 0
for i in str1:
if i == str2[j] and j<=5:
j+=1
if j >= 4:
print("YES")
else:
print("NO")
str1 = input()
checkHello(str1) | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
def checkHello(str1):
if len(str1)<=5:
print("NO")
else:
str2 = "helloo"
j = 0
for i in str1:
if i == str2[j] and j<=5:
j+=1
if j >= 4:
print("YES")
else:
print("NO")
str1 = input()
checkHello(str1)
``` | -1 |
667 | A | Pouring Rain | PROGRAMMING | 1,100 | [
"geometry",
"math"
] | null | null | A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter. | The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. | If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. | [
"1 2 3 100\n",
"1 1 1 1\n"
] | [
"NO\n",
"YES\n3.659792366325\n"
] | In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | 500 | [
{
"input": "1 2 3 100",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "YES\n3.659792366325"
},
{
"input": "48 7946 7992 72",
"output": "NO"
},
{
"input": "72 6791 8546 46",
"output": "NO"
},
{
"input": "100 5635 9099 23",
"output": "NO"
},
{
"input": "20 287 3845 5",
"output": "YES\n39.646277165210"
},
{
"input": "48 6428 9807 83",
"output": "NO"
},
{
"input": "72 5272 4552 64",
"output": "NO"
},
{
"input": "100 4117 5106 34",
"output": "NO"
},
{
"input": "20 2961 9852 15",
"output": "YES\n180.991437129723"
},
{
"input": "48 1805 3109 93",
"output": "NO"
},
{
"input": "72 8534 7042 65",
"output": "NO"
},
{
"input": "1 47 80 68",
"output": "YES\n1.388102806810"
},
{
"input": "4 495 8813 1",
"output": "YES\n0.706823517575"
},
{
"input": "5 2797 5925 9",
"output": "YES\n9.553973511669"
},
{
"input": "1 8324 4362 23",
"output": "YES\n1.505007106354"
},
{
"input": "6 1976 8455 3",
"output": "YES\n6.674898722265"
},
{
"input": "7 2644 8080 5",
"output": "YES\n12.900417790197"
},
{
"input": "3 4183 5491 98",
"output": "YES\n6.162185601824"
},
{
"input": "2 8591 320 101",
"output": "YES\n9999.259991757254"
},
{
"input": "10000 10000 10000 10000",
"output": "NO"
},
{
"input": "2 5000 12 3",
"output": "YES\n6099.653943875812"
},
{
"input": "10 1000 100 1",
"output": "YES\n3659.792366325487"
}
] | 1,578,216,171 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 140 | 0 | from math import pi
X = list(map(int, input().split()))
RainPouring = X[-1] * (X[0] / 2) ** 2 * pi
if RainPouring >= X[-2]: print("NO");exit()
X[-2] -= RainPouring
Volume = X[1] * (X[0] / 2) ** 2 * pi
print("YES", Volume / X[-2], sep='\n')
# Caption: With the help of ARPA
| Title: Pouring Rain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do.
Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation.
Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom.
You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously.
Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds.
Note one milliliter equals to one cubic centimeter.
Input Specification:
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where:
- *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
Output Specification:
If it is impossible to make the cup empty, print "NO" (without quotes).
Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
Demo Input:
['1 2 3 100\n', '1 1 1 1\n']
Demo Output:
['NO\n', 'YES\n3.659792366325\n']
Note:
In the first example the water fills the cup faster than you can drink from it.
In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds. | ```python
from math import pi
X = list(map(int, input().split()))
RainPouring = X[-1] * (X[0] / 2) ** 2 * pi
if RainPouring >= X[-2]: print("NO");exit()
X[-2] -= RainPouring
Volume = X[1] * (X[0] / 2) ** 2 * pi
print("YES", Volume / X[-2], sep='\n')
# Caption: With the help of ARPA
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 0 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo",
"output": "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo"
},
{
"input": "10\nogooggoggo",
"output": "***oggoggo"
},
{
"input": "20\nooggooogooogooogooog",
"output": "ooggoo***o***o***oog"
},
{
"input": "30\ngoggogoooggooggggoggoggoogoggo",
"output": "gogg***ooggooggggoggoggo***ggo"
},
{
"input": "40\nogggogooggoogoogggogooogogggoogggooggooo",
"output": "oggg***oggo***oggg***o***gggoogggooggooo"
},
{
"input": "50\noggggogoogggggggoogogggoooggooogoggogooogogggogooo",
"output": "ogggg***ogggggggo***gggoooggoo***gg***o***ggg***oo"
},
{
"input": "60\nggoooogoggogooogogooggoogggggogogogggggogggogooogogogggogooo",
"output": "ggooo***gg***o***oggooggggg***gggggoggg***o***ggg***oo"
},
{
"input": "70\ngogoooggggoggoggggggoggggoogooogogggggooogggogoogoogoggogggoggogoooooo",
"output": "g***ooggggoggoggggggoggggo***o***gggggoooggg*********ggogggogg***ooooo"
},
{
"input": "80\nooogoggoooggogogoggooooogoogogooogoggggogggggogoogggooogooooooggoggoggoggogoooog",
"output": "oo***ggooogg***ggoooo******o***ggggoggggg***ogggoo***oooooggoggoggogg***ooog"
},
{
"input": "90\nooogoggggooogoggggoooogggggooggoggoggooooooogggoggogggooggggoooooogoooogooggoooogggggooooo",
"output": "oo***ggggoo***ggggoooogggggooggoggoggooooooogggoggogggooggggooooo***oo***oggoooogggggooooo"
},
{
"input": "100\ngooogoggooggggoggoggooooggogoogggoogogggoogogoggogogogoggogggggogggggoogggooogogoggoooggogoooooogogg",
"output": "goo***ggooggggoggoggoooogg***ogggo***gggo***gg***ggogggggogggggoogggoo***ggooogg***oooo***gg"
},
{
"input": "100\ngoogoogggogoooooggoogooogoogoogogoooooogooogooggggoogoggogooogogogoogogooooggoggogoooogooooooggogogo",
"output": "go***oggg***ooooggo***o*********oooo***o***oggggo***gg***o******oooggogg***oo***ooooogg***"
},
{
"input": "100\ngoogoggggogggoooggoogoogogooggoggooggggggogogggogogggoogogggoogoggoggogooogogoooogooggggogggogggoooo",
"output": "go***ggggogggoooggo******oggoggoogggggg***ggg***gggo***gggo***ggogg***o***oo***oggggogggogggoooo"
},
{
"input": "100\nogogogogogoggogogogogogogoggogogogoogoggoggooggoggogoogoooogogoogggogogogogogoggogogogogogogogogogoe",
"output": "***gg***gg******ggoggooggogg******oo***oggg***gg***e"
},
{
"input": "5\nogoga",
"output": "***ga"
},
{
"input": "1\no",
"output": "o"
},
{
"input": "100\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogog",
"output": "***g"
},
{
"input": "99\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo",
"output": "***"
},
{
"input": "5\nggggg",
"output": "ggggg"
},
{
"input": "6\ngoogoo",
"output": "go***o"
},
{
"input": "7\nooogooo",
"output": "oo***oo"
},
{
"input": "8\ngggggggg",
"output": "gggggggg"
},
{
"input": "9\nogggogggg",
"output": "ogggogggg"
},
{
"input": "10\nogogoggogo",
"output": "***gg***"
},
{
"input": "11\noooggooggog",
"output": "oooggooggog"
},
{
"input": "12\nogggooooggog",
"output": "ogggooooggog"
},
{
"input": "13\nogoggogogooog",
"output": "***gg***oog"
},
{
"input": "15\nggooogoooggoggg",
"output": "ggoo***ooggoggg"
},
{
"input": "14\noogooooggooggo",
"output": "o***oooggooggo"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "1\ng",
"output": "g"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "46\nsdfkogogogogergergogogergerogogogogoergoegogog",
"output": "sdfk***gergerg***gerger***ergoeg***g"
},
{
"input": "86\ngdfggogogodfogogdofgoodfogodgodgfogoogdodhbofgobgbgfogoogdfogogogogogoogggsgfosogodgon",
"output": "gdfgg***df***gdofgoodf***dgodgf***ogdodhbofgobgbgf***ogdf***ogggsgfos***dgon"
},
{
"input": "83\nergegergoogogogerogoerorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgtogooggsdgogoog",
"output": "ergegergo***ger***erorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgt***oggsdg***og"
},
{
"input": "2\nog",
"output": "og"
},
{
"input": "4\nogog",
"output": "***g"
},
{
"input": "4\nogoo",
"output": "***o"
},
{
"input": "29\naaaogogogogogogogogogogogobbb",
"output": "aaa***bbb"
},
{
"input": "11\nogogogogogo",
"output": "***"
},
{
"input": "9\nogogogogo",
"output": "***"
},
{
"input": "3\nogo",
"output": "***"
},
{
"input": "15\nogogogogogogogo",
"output": "***"
},
{
"input": "25\nogogogogogogogogogogogogo",
"output": "***"
}
] | 1,616,274,381 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 93 | 819,200 | import re
def solve(s):
return re.sub(r'ogo(?:go)*','***',s)
def main() :
n = input()
s = input()
# arr = list(map(int, input().split(' ')))
# arr = []
# for _ in range(4):
# i = input()
# arr.append(i)
print(solve(s))
main()
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters.
Output Specification:
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
Demo Input:
['7\naogogob\n', '13\nogogmgogogogo\n', '9\nogoogoogo\n']
Demo Output:
['a***b\n', '***gmg***\n', '*********\n']
Note:
The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | ```python
import re
def solve(s):
return re.sub(r'ogo(?:go)*','***',s)
def main() :
n = input()
s = input()
# arr = list(map(int, input().split(' ')))
# arr = []
# for _ in range(4):
# i = input()
# arr.append(i)
print(solve(s))
main()
``` | 3 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,697,553,499 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 92 | 0 | n = input()
a = b = c = 0
for i in range(0, len(n), 2):
if n[i] == '1':
a += 1
elif n[i] == '2':
b += 1
else:
c += 1
d = "1+" * a + "2+" * b + "3+" * c
print(d[:-1])
| Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
n = input()
a = b = c = 0
for i in range(0, len(n), 2):
if n[i] == '1':
a += 1
elif n[i] == '2':
b += 1
else:
c += 1
d = "1+" * a + "2+" * b + "3+" * c
print(d[:-1])
``` | 3 |
|
869 | B | The Eternal Immortality | PROGRAMMING | 1,100 | [
"math"
] | null | null | Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. | The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). | Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. | [
"2 4\n",
"0 10\n",
"107 109\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. | 1,000 | [
{
"input": "2 4",
"output": "2"
},
{
"input": "0 10",
"output": "0"
},
{
"input": "107 109",
"output": "2"
},
{
"input": "10 13",
"output": "6"
},
{
"input": "998244355 998244359",
"output": "4"
},
{
"input": "999999999000000000 1000000000000000000",
"output": "0"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "3 15",
"output": "0"
},
{
"input": "24 26",
"output": "0"
},
{
"input": "14 60",
"output": "0"
},
{
"input": "11 79",
"output": "0"
},
{
"input": "1230 1232",
"output": "2"
},
{
"input": "2633 2634",
"output": "4"
},
{
"input": "535 536",
"output": "6"
},
{
"input": "344319135 396746843",
"output": "0"
},
{
"input": "696667767 696667767",
"output": "1"
},
{
"input": "419530302 610096911",
"output": "0"
},
{
"input": "238965115 821731161",
"output": "0"
},
{
"input": "414626436 728903812",
"output": "0"
},
{
"input": "274410639 293308324",
"output": "0"
},
{
"input": "650636673091305697 650636673091305702",
"output": "0"
},
{
"input": "651240548333620923 651240548333620924",
"output": "4"
},
{
"input": "500000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "999999999999999999 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1"
},
{
"input": "0 4",
"output": "4"
},
{
"input": "50000000062000007 50000000062000011",
"output": "0"
},
{
"input": "0 0",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "0 2",
"output": "2"
},
{
"input": "10000000000012 10000000000015",
"output": "0"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "12 23",
"output": "0"
},
{
"input": "0 11",
"output": "0"
},
{
"input": "11111234567890 11111234567898",
"output": "0"
},
{
"input": "0 3",
"output": "6"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999999999999999997 999999999999999999",
"output": "2"
},
{
"input": "4 5",
"output": "5"
},
{
"input": "0 1",
"output": "1"
},
{
"input": "101 1002",
"output": "0"
},
{
"input": "0 100000000000000001",
"output": "0"
},
{
"input": "99999999999999997 99999999999999999",
"output": "2"
},
{
"input": "14 15",
"output": "5"
},
{
"input": "8 19",
"output": "0"
},
{
"input": "12 22",
"output": "0"
},
{
"input": "999999999999996 999999999999999",
"output": "4"
},
{
"input": "1 3",
"output": "6"
},
{
"input": "124 125",
"output": "5"
},
{
"input": "11 32",
"output": "0"
},
{
"input": "0 5",
"output": "0"
},
{
"input": "0 999999",
"output": "0"
},
{
"input": "151151151515 151151151526",
"output": "0"
},
{
"input": "6 107",
"output": "0"
},
{
"input": "5 16",
"output": "0"
},
{
"input": "7 16",
"output": "0"
},
{
"input": "6 19",
"output": "0"
},
{
"input": "11113111111111 13111111111111",
"output": "0"
},
{
"input": "1 1000",
"output": "0"
},
{
"input": "24 25",
"output": "5"
},
{
"input": "0 100000000000",
"output": "0"
},
{
"input": "1 22",
"output": "0"
},
{
"input": "999999999999999996 999999999999999999",
"output": "4"
}
] | 1,509,827,945 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 |
a=input("firs number")
b=input("second number")
a=int(a)
b=int(b)
sum1=1
sum2=1
if (a>b):
print (0)
else:
for i in range(1,a+1):
sum1*=i
sum2=sum1
for j in range(a+1,b+1):
sum2*=j
end=(sum2/sum1)%10
print(end)
| Title: The Eternal Immortality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Even if the world is full of counterfeits, I still regard it as wonderful.
Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this.
The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1.
Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer.
As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge.
Input Specification:
The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018).
Output Specification:
Output one line containing a single decimal digit — the last digit of the value that interests Koyomi.
Demo Input:
['2 4\n', '0 10\n', '107 109\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/99c47ca8b182f097e38094d12f0c06ce0b081b76.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2;
In the second example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9642ef11a23e7c5a3f3c2b1255c1b1b3533802a4.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 0;
In the third example, the last digit of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/844938cef52ee264c183246d2a9df05cca94dc60.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2. | ```python
a=input("firs number")
b=input("second number")
a=int(a)
b=int(b)
sum1=1
sum2=1
if (a>b):
print (0)
else:
for i in range(1,a+1):
sum1*=i
sum2=sum1
for j in range(a+1,b+1):
sum2*=j
end=(sum2/sum1)%10
print(end)
``` | -1 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,577,158,604 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | x = input()
a = x.find('h')
b = x.find('e', a+1, len(x))
c = x.find('l', b+1, len(x))
d = x.find('l', c+1, len(x))
e = x.find('o', d+1, len(x))
print(a, b, c, d, e)
print('YES' if e > d > c > b > a else 'NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
x = input()
a = x.find('h')
b = x.find('e', a+1, len(x))
c = x.find('l', b+1, len(x))
d = x.find('l', c+1, len(x))
e = x.find('o', d+1, len(x))
print(a, b, c, d, e)
print('YES' if e > d > c > b > a else 'NO')
``` | 0 |
389 | A | Fox and Number Game | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). | Output a single integer — the required minimal sum. | [
"2\n1 2\n",
"3\n2 4 6\n",
"2\n12 18\n",
"5\n45 12 27 30 18\n"
] | [
"2\n",
"6\n",
"12\n",
"15\n"
] | In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n2 4 6",
"output": "6"
},
{
"input": "2\n12 18",
"output": "12"
},
{
"input": "5\n45 12 27 30 18",
"output": "15"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n100 100",
"output": "200"
},
{
"input": "2\n87 58",
"output": "58"
},
{
"input": "39\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52",
"output": "2028"
},
{
"input": "59\n96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96 96",
"output": "5664"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "10000"
},
{
"input": "100\n70 70 77 42 98 84 56 91 35 21 7 70 77 77 56 63 14 84 56 14 77 77 63 70 14 7 28 91 63 49 21 84 98 56 77 98 98 84 98 14 7 56 49 28 91 98 7 56 14 91 14 98 49 28 98 14 98 98 14 70 35 28 63 28 49 63 63 56 91 98 35 42 42 35 63 35 42 14 63 21 77 56 42 77 35 91 56 21 28 84 56 70 70 91 98 70 84 63 21 98",
"output": "700"
},
{
"input": "39\n63 21 21 42 21 63 21 84 42 21 84 63 42 63 84 84 84 42 42 84 21 63 42 63 42 42 63 42 42 63 84 42 21 84 21 63 42 21 42",
"output": "819"
},
{
"input": "59\n70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70",
"output": "4130"
},
{
"input": "87\n44 88 88 88 88 66 88 22 22 88 88 44 88 22 22 22 88 88 88 88 66 22 88 88 88 88 66 66 44 88 44 44 66 22 88 88 22 44 66 44 88 66 66 22 22 22 22 88 22 22 44 66 88 22 22 88 66 66 88 22 66 88 66 88 66 44 88 44 22 44 44 22 44 88 44 44 44 44 22 88 88 88 66 66 88 44 22",
"output": "1914"
},
{
"input": "15\n63 63 63 63 63 63 63 63 63 63 63 63 63 63 63",
"output": "945"
},
{
"input": "39\n63 77 21 14 14 35 21 21 70 42 21 70 28 77 28 77 7 42 63 7 98 49 98 84 35 70 70 91 14 42 98 7 42 7 98 42 56 35 91",
"output": "273"
},
{
"input": "18\n18 18 18 36 36 36 54 72 54 36 72 54 36 36 36 36 18 36",
"output": "324"
},
{
"input": "46\n71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71 71",
"output": "3266"
},
{
"input": "70\n66 11 66 11 44 11 44 99 55 22 88 11 11 22 55 44 22 77 44 77 77 22 44 55 88 11 99 99 88 22 77 77 66 11 11 66 99 55 55 44 66 44 77 44 44 55 33 55 44 88 77 77 22 66 33 44 11 22 55 44 22 66 77 33 33 44 44 44 22 33",
"output": "770"
},
{
"input": "10\n60 12 96 48 60 24 60 36 60 60",
"output": "120"
},
{
"input": "20\n51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51 51",
"output": "1020"
},
{
"input": "50\n58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58 58",
"output": "2900"
},
{
"input": "98\n70 60 100 30 70 20 30 50 50 30 90 40 30 40 60 80 60 60 80 50 10 80 20 10 20 10 50 70 30 80 30 50 60 90 90 100 60 30 90 20 30 60 90 80 60 60 10 90 10 50 40 40 80 90 100 40 70 40 30 50 60 50 60 30 40 20 90 60 20 20 20 70 60 70 50 100 90 50 20 40 80 60 10 60 50 40 40 10 50 10 40 10 80 100 100 90 10 90",
"output": "980"
},
{
"input": "100\n82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82 82",
"output": "8200"
},
{
"input": "100\n11 87 77 93 3 54 21 93 9 71 37 23 69 85 74 3 48 99 51 31 56 19 21 96 39 6 4 4 29 69 100 42 1 22 81 53 48 49 81 61 10 7 40 61 7 71 51 59 79 44 50 35 95 80 83 8 98 40 18 94 84 49 52 74 66 69 39 37 100 44 38 62 2 80 46 31 35 53 5 60 21 49 63 55 20 53 80 53 66 34 23 92 77 50 86 63 65 24 12 70",
"output": "100"
},
{
"input": "2\n100 1",
"output": "2"
},
{
"input": "2\n18 30",
"output": "12"
},
{
"input": "2\n3 5",
"output": "2"
},
{
"input": "2\n1 10",
"output": "2"
},
{
"input": "2\n8 5",
"output": "2"
},
{
"input": "5\n2 3 5 8 18",
"output": "5"
},
{
"input": "5\n2 4 1 6 8",
"output": "5"
},
{
"input": "3\n12 10 5",
"output": "3"
},
{
"input": "3\n6 10 15",
"output": "3"
}
] | 1,618,359,395 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 0 | n = int(input())
x = [int(x) for x in input().split()]
for i in range(101):
x.sort()
if x[-1] > x[-2]:
a = x[-1]
x.pop()
x.append(a-x[-1])
print(sum(x)) | Title: Fox and Number Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a game with numbers now.
Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible.
Please help Ciel to find this minimal sum.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output Specification:
Output a single integer — the required minimal sum.
Demo Input:
['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n']
Demo Output:
['2\n', '6\n', '12\n', '15\n']
Note:
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. | ```python
n = int(input())
x = [int(x) for x in input().split()]
for i in range(101):
x.sort()
if x[-1] > x[-2]:
a = x[-1]
x.pop()
x.append(a-x[-1])
print(sum(x))
``` | 0 |
|
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once. | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once. | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "169"
},
{
"input": "50 14\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "1 1\na",
"output": "1"
},
{
"input": "50 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "1"
},
{
"input": "50 2\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "-1"
},
{
"input": "13 13\nuwgmkyqeiaocs",
"output": "169"
},
{
"input": "13 13\nhzdxpbfvrltnj",
"output": "182"
},
{
"input": "1 1\nn",
"output": "14"
},
{
"input": "10 8\nsmzeblyjqw",
"output": "113"
},
{
"input": "20 20\ntzmvhskkyugkuuxpvtbh",
"output": "-1"
},
{
"input": "30 15\nwjzolzzkfulwgioksfxmcxmnnjtoav",
"output": "-1"
},
{
"input": "40 30\nxumfrflllrrgswehqtsskefixhcxjrxbjmrpsshv",
"output": "-1"
},
{
"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz",
"output": "-1"
},
{
"input": "10 7\niuiukrxcml",
"output": "99"
},
{
"input": "38 2\nvjzarfykmrsrvwbwfwldsulhxtykmjbnwmdufa",
"output": "5"
},
{
"input": "12 6\nfwseyrarkwcd",
"output": "61"
},
{
"input": "2 2\nac",
"output": "4"
},
{
"input": "1 1\nc",
"output": "3"
},
{
"input": "2 2\nad",
"output": "5"
},
{
"input": "2 1\nac",
"output": "1"
},
{
"input": "4 3\nadjz",
"output": "15"
},
{
"input": "3 3\naoz",
"output": "42"
},
{
"input": "3 1\nzzz",
"output": "26"
},
{
"input": "2 1\nxz",
"output": "24"
},
{
"input": "5 1\naaddd",
"output": "1"
}
] | 1,532,703,933 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | M = lambda: list(map(int,input().split()))
n, k = M()
# s = sorted(set(input()))
j=[]
for code in map(ord, sorted(set(input()))):
j.append(code-96)
h=0
sm=0
cnt=0
for i in j:
if i!=h:
sm+=i
cnt+=1
h=i+1
if cnt==k:
break
if cnt>1:
print(sm)
else:
print(-1) | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The rocket must contain exactly $k$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.
For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $26$ tons.
Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.
Input Specification:
The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.
Output Specification:
Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.
Demo Input:
['5 3\nxyabd\n', '7 4\nproblem\n', '2 2\nab\n', '12 1\nabaabbaaabbb\n']
Demo Output:
['29', '34', '-1', '1']
Note:
In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight is $2+5+12+15=34$.
In the third example, $n=k=2$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1. | ```python
M = lambda: list(map(int,input().split()))
n, k = M()
# s = sorted(set(input()))
j=[]
for code in map(ord, sorted(set(input()))):
j.append(code-96)
h=0
sm=0
cnt=0
for i in j:
if i!=h:
sm+=i
cnt+=1
h=i+1
if cnt==k:
break
if cnt>1:
print(sm)
else:
print(-1)
``` | 0 |
|
991 | B | Getting an A | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo. | The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. | Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. | [
"3\n4 4 4\n",
"4\n5 4 5 5\n",
"4\n5 3 3 5\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | 1,000 | [
{
"input": "3\n4 4 4",
"output": "2"
},
{
"input": "4\n5 4 5 5",
"output": "0"
},
{
"input": "4\n5 3 3 5",
"output": "1"
},
{
"input": "1\n5",
"output": "0"
},
{
"input": "4\n3 2 5 4",
"output": "2"
},
{
"input": "5\n5 4 3 2 5",
"output": "2"
},
{
"input": "8\n5 4 2 5 5 2 5 5",
"output": "1"
},
{
"input": "5\n5 5 2 5 5",
"output": "1"
},
{
"input": "6\n5 5 5 5 5 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "5"
},
{
"input": "100\n3 2 4 3 3 3 4 2 3 5 5 2 5 2 3 2 4 4 4 5 5 4 2 5 4 3 2 5 3 4 3 4 2 4 5 4 2 4 3 4 5 2 5 3 3 4 2 2 4 4 4 5 4 3 3 3 2 5 2 2 2 3 5 4 3 2 4 5 5 5 2 2 4 2 3 3 3 5 3 2 2 4 5 5 4 5 5 4 2 3 2 2 2 2 5 3 5 2 3 4",
"output": "40"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "4\n3 2 5 5",
"output": "1"
},
{
"input": "6\n4 3 3 3 3 4",
"output": "4"
},
{
"input": "8\n3 3 5 3 3 3 5 5",
"output": "3"
},
{
"input": "10\n2 4 5 5 5 5 2 3 3 2",
"output": "3"
},
{
"input": "20\n5 2 5 2 2 2 2 2 5 2 2 5 2 5 5 2 2 5 2 2",
"output": "10"
},
{
"input": "25\n4 4 4 4 3 4 3 3 3 3 3 4 4 3 4 4 4 4 4 3 3 3 4 3 4",
"output": "13"
},
{
"input": "30\n4 2 4 2 4 2 2 4 4 4 4 2 4 4 4 2 2 2 2 4 2 4 4 4 2 4 2 4 2 2",
"output": "15"
},
{
"input": "52\n5 3 4 4 4 3 5 3 4 5 3 4 4 3 5 5 4 3 3 3 4 5 4 4 5 3 5 3 5 4 5 5 4 3 4 5 3 4 3 3 4 4 4 3 5 3 4 5 3 5 4 5",
"output": "14"
},
{
"input": "77\n5 3 2 3 2 3 2 3 5 2 2 3 3 3 3 5 3 3 2 2 2 5 5 5 5 3 2 2 5 2 3 2 2 5 2 5 3 3 2 2 5 5 2 3 3 2 3 3 3 2 5 5 2 2 3 3 5 5 2 2 5 5 3 3 5 5 2 2 5 2 2 5 5 5 2 5 2",
"output": "33"
},
{
"input": "55\n3 4 2 3 3 2 4 4 3 3 4 2 4 4 3 3 2 3 2 2 3 3 2 3 2 3 2 4 4 3 2 3 2 3 3 2 2 4 2 4 4 3 4 3 2 4 3 2 4 2 2 3 2 3 4",
"output": "34"
},
{
"input": "66\n5 4 5 5 4 4 4 4 4 2 5 5 2 4 2 2 2 5 4 4 4 4 5 2 2 5 5 2 2 4 4 2 4 2 2 5 2 5 4 5 4 5 4 4 2 5 2 4 4 4 2 2 5 5 5 5 4 4 4 4 4 2 4 5 5 5",
"output": "16"
},
{
"input": "99\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "83"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "84"
},
{
"input": "99\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "75"
},
{
"input": "99\n2 2 3 3 3 3 3 2 2 3 2 3 2 3 2 2 3 2 3 2 3 3 3 3 2 2 2 2 3 2 3 3 3 3 3 2 3 3 3 3 2 3 2 3 3 3 2 3 2 3 3 3 3 2 2 3 2 3 2 3 2 3 2 2 2 3 3 2 3 2 2 2 2 2 2 2 2 3 3 3 3 2 3 2 3 3 2 3 2 3 2 3 3 2 2 2 3 2 3",
"output": "75"
},
{
"input": "100\n3 2 3 3 2 2 3 2 2 3 3 2 3 2 2 2 2 2 3 2 2 2 3 2 3 3 2 2 3 2 2 2 2 3 2 3 3 2 2 3 2 2 3 2 3 2 2 3 2 3 2 2 3 2 2 3 3 3 3 3 2 2 3 2 3 3 2 2 3 2 2 2 3 2 2 3 3 2 2 3 3 3 3 2 3 2 2 2 3 3 2 2 3 2 2 2 2 3 2 2",
"output": "75"
},
{
"input": "99\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "50"
},
{
"input": "99\n2 2 2 2 4 2 2 2 2 4 4 4 4 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 4 2 2 2 4 4 2 2 2 2 4 4 4 2 2 2 4 4 2 4 2 4 2 2 4 2 4 4 4 4 4 2 2 4 4 4 2 2 2 2 4 2 4 2 2 2 2 2 2 4 4 2 4 2 2 4 2 2 2 2 2 4 2 4 2 2 4 4 4",
"output": "54"
},
{
"input": "100\n4 2 4 4 2 4 2 2 4 4 4 4 4 4 4 4 4 2 4 4 2 2 4 4 2 2 4 4 2 2 2 4 4 2 4 4 2 4 2 2 4 4 2 4 2 4 4 4 2 2 2 2 2 2 2 4 2 2 2 4 4 4 2 2 2 2 4 2 2 2 2 2 2 2 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 4 4 4 4 2 4 2 2 4",
"output": "50"
},
{
"input": "99\n4 3 4 4 4 4 4 3 4 3 3 4 3 3 4 4 3 3 3 4 3 4 3 3 4 3 3 3 3 4 3 4 4 3 4 4 3 3 4 4 4 3 3 3 4 4 3 3 4 3 4 3 4 3 4 3 3 3 3 4 3 4 4 4 4 4 4 3 4 4 3 3 3 3 3 3 3 3 4 3 3 3 4 4 4 4 4 4 3 3 3 3 4 4 4 3 3 4 3",
"output": "51"
},
{
"input": "100\n3 3 4 4 4 4 4 3 4 4 3 3 3 3 4 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 3 3 3 3 3 3 3 3 4 3 4 3 3 4 3 3 3 4 4 3 4 4 3 3 4 4 4 4 4 4 3 4 4 3 4 3 3 3 4 4 3 3 4 4 3 4 4 4 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 4 3 3 4",
"output": "51"
},
{
"input": "99\n3 3 4 4 4 2 4 4 3 2 3 4 4 4 2 2 2 3 2 4 4 2 4 3 2 2 2 4 2 3 4 3 4 2 3 3 4 2 3 3 2 3 4 4 3 2 4 3 4 3 3 3 3 3 4 4 3 3 4 4 2 4 3 4 3 2 3 3 3 4 4 2 4 4 2 3 4 2 3 3 3 4 2 2 3 2 4 3 2 3 3 2 3 4 2 3 3 2 3",
"output": "58"
},
{
"input": "100\n2 2 4 2 2 3 2 3 4 4 3 3 4 4 4 2 3 2 2 3 4 2 3 2 4 3 4 2 3 3 3 2 4 3 3 2 2 3 2 4 4 2 4 3 4 4 3 3 3 2 4 2 2 2 2 2 2 3 2 3 2 3 4 4 4 2 2 3 4 4 3 4 3 3 2 3 3 3 4 3 2 3 3 2 4 2 3 3 4 4 3 3 4 3 4 3 3 4 3 3",
"output": "61"
},
{
"input": "99\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "99\n2 2 2 2 2 5 2 2 5 2 5 2 5 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 2 5 5 2 5 2 2 5 2 5 2 2 5 5 2 2 2 2 5 5 2 2 2 5 2 2 5 2 2 2 2 2 5 5 5 5 2 2 5 2 5 2 2 2 2 2 5 2 2 5 5 2 2 2 2 2 5 5 2 2 5 5 2 2 2 2 5 5 5 2 5",
"output": "48"
},
{
"input": "100\n5 5 2 2 2 2 2 2 5 5 2 5 2 2 2 2 5 2 5 2 5 5 2 5 5 2 2 2 2 2 2 5 2 2 2 5 2 2 5 2 2 5 5 5 2 5 5 5 5 5 5 2 2 5 2 2 5 5 5 5 5 2 5 2 5 2 2 2 5 2 5 2 5 5 2 5 5 2 2 5 2 5 5 2 5 2 2 5 2 2 2 5 2 2 2 2 5 5 2 5",
"output": "38"
},
{
"input": "99\n5 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 3 3 3 3 3 5 3 3 3 5 5 3 5 5 3 3 5 5 5 3 5 3 3 3 3 5 3 3 5 5 3 5 5 5 3 5 3 5 3 5 5 5 5 3 3 3 5 3 5 3 3 3 5 5 5 5 5 3 5 5 3 3 5 5 3 5 5 3 5 5 3 3 5 5 5 3 3 3 5 3 3 3",
"output": "32"
},
{
"input": "100\n3 3 3 5 3 3 3 3 3 3 5 5 5 5 3 3 3 3 5 3 3 3 3 3 5 3 5 3 3 5 5 5 5 5 5 3 3 5 3 3 5 3 5 5 5 3 5 3 3 3 3 3 3 3 3 3 3 3 5 5 3 5 3 5 5 3 5 3 3 5 3 5 5 5 5 3 5 3 3 3 5 5 5 3 3 3 5 3 5 5 5 3 3 3 5 3 5 5 3 5",
"output": "32"
},
{
"input": "99\n5 3 5 5 3 3 3 2 2 5 2 5 3 2 5 2 5 2 3 5 3 2 3 2 5 5 2 2 3 3 5 5 3 5 5 2 3 3 5 2 2 5 3 2 5 2 3 5 5 2 5 2 2 5 3 3 5 3 3 5 3 2 3 5 3 2 3 2 3 2 2 2 2 5 2 2 3 2 5 5 5 3 3 2 5 3 5 5 5 2 3 2 5 5 2 5 2 5 3",
"output": "39"
},
{
"input": "100\n3 5 3 3 5 5 3 3 2 5 5 3 3 3 2 2 3 2 5 3 2 2 3 3 3 3 2 5 3 2 3 3 5 2 2 2 3 2 3 5 5 3 2 5 2 2 5 5 3 5 5 5 2 2 5 5 3 3 2 2 2 5 3 3 2 2 3 5 3 2 3 5 5 3 2 3 5 5 3 3 2 3 5 2 5 5 5 5 5 5 3 5 3 2 3 3 2 5 2 2",
"output": "42"
},
{
"input": "99\n4 4 4 5 4 4 5 5 4 4 5 5 5 4 5 4 5 5 5 4 4 5 5 5 5 4 5 5 5 4 4 5 5 4 5 4 4 4 5 5 5 5 4 4 5 4 4 5 4 4 4 4 5 5 5 4 5 4 5 5 5 5 5 4 5 4 5 4 4 4 4 5 5 5 4 5 5 4 4 5 5 5 4 5 4 4 5 5 4 5 5 5 5 4 5 5 4 4 4",
"output": "0"
},
{
"input": "100\n4 4 5 5 5 5 5 5 4 4 5 5 4 4 5 5 4 5 4 4 4 4 4 4 4 4 5 5 5 5 5 4 4 4 4 4 5 4 4 5 4 4 4 5 5 5 4 5 5 5 5 5 5 4 4 4 4 4 4 5 5 4 5 4 4 5 4 4 4 4 5 5 4 5 5 4 4 4 5 5 5 5 4 5 5 5 4 4 5 5 5 4 5 4 5 4 4 5 5 4",
"output": "1"
},
{
"input": "99\n2 2 2 5 2 2 2 2 2 4 4 5 5 2 2 4 2 5 2 2 2 5 2 2 5 5 5 4 5 5 4 4 2 2 5 2 2 2 2 5 5 2 2 4 4 4 2 2 2 5 2 4 4 2 4 2 4 2 5 4 2 2 5 2 4 4 4 2 5 2 2 5 4 2 2 5 5 5 2 4 5 4 5 5 4 4 4 5 4 5 4 5 4 2 5 2 2 2 4",
"output": "37"
},
{
"input": "100\n4 4 5 2 2 5 4 5 2 2 2 4 2 5 4 4 2 2 4 5 2 4 2 5 5 4 2 4 4 2 2 5 4 2 5 4 5 2 5 2 4 2 5 4 5 2 2 2 5 2 5 2 5 2 2 4 4 5 5 5 5 5 5 5 4 2 2 2 4 2 2 4 5 5 4 5 4 2 2 2 2 4 2 2 5 5 4 2 2 5 4 5 5 5 4 5 5 5 2 2",
"output": "31"
},
{
"input": "99\n5 3 4 4 5 4 4 4 3 5 4 3 3 4 3 5 5 5 5 4 3 3 5 3 4 5 3 5 4 4 3 5 5 4 4 4 4 3 5 3 3 5 5 5 5 5 4 3 4 4 3 5 5 3 3 4 4 4 5 4 4 5 4 4 4 4 5 5 4 3 3 4 3 5 3 3 3 3 4 4 4 4 3 4 5 4 4 5 5 5 3 4 5 3 4 5 4 3 3",
"output": "24"
},
{
"input": "100\n5 4 4 4 5 5 5 4 5 4 4 3 3 4 4 4 5 4 5 5 3 5 5 4 5 5 5 4 4 5 3 5 3 5 3 3 5 4 4 5 5 4 5 5 3 4 5 4 4 3 4 4 3 3 5 4 5 4 5 3 4 5 3 4 5 4 3 5 4 5 4 4 4 3 4 5 3 4 3 5 3 4 4 4 3 4 4 5 3 3 4 4 5 5 4 3 4 4 3 5",
"output": "19"
},
{
"input": "99\n2 2 5 2 5 3 4 2 3 5 4 3 4 2 5 3 2 2 4 2 4 4 5 4 4 5 2 5 5 3 2 3 2 2 3 4 5 3 5 2 5 4 4 5 4 2 2 3 2 3 3 3 4 4 3 2 2 4 4 2 5 3 5 3 5 4 4 4 5 4 5 2 2 5 4 4 4 3 3 2 5 2 5 2 3 2 5 2 2 5 5 3 4 5 3 4 4 4 4",
"output": "37"
},
{
"input": "2\n5 2",
"output": "1"
},
{
"input": "5\n2 2 2 2 2",
"output": "5"
},
{
"input": "100\n2 3 2 2 2 3 2 3 3 3 3 3 2 3 3 2 2 3 3 2 3 2 3 2 3 4 4 4 3 3 3 3 3 4 4 3 3 4 3 2 3 4 3 3 3 3 2 3 4 3 4 3 3 2 4 4 2 4 4 3 3 3 3 4 3 2 3 4 3 4 4 4 4 4 3 2 2 3 4 2 4 4 4 2 2 4 2 2 3 2 2 4 4 3 4 2 3 3 2 2",
"output": "61"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "1"
},
{
"input": "100\n5 4 3 5 3 5 4 2 3 3 4 5 4 5 5 4 2 4 2 2 5 2 5 3 4 4 4 5 5 5 3 4 4 4 3 5 3 2 5 4 3 3 3 5 2 3 4 2 5 4 3 4 5 2 2 3 4 4 2 3 3 3 2 5 2 3 4 3 3 3 2 5 4 3 4 5 4 2 5 4 5 2 2 4 2 2 5 5 4 5 2 2 2 2 5 2 4 4 4 5",
"output": "35"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "20\n4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5",
"output": "1"
}
] | 1,628,446,478 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 77 | 6,963,200 | from sys import *
def main():
n = int(stdin.readline())
target = 4.5*n
currentTotal = 0
minimumRetakes = 0
listOfScores = [int(x) for x in stdin.readline().split()]
for x in listOfScores:
currentTotal+=x
listOfScores.sort()
while(currentTotal < target):
currentTotal+=(5-listOfScores[minimumRetakes])
minimumRetakes += 1
print(minimumRetakes)
if __name__ == '__main__':
main() | Title: Getting an A
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.
The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$.
This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo.
Help Vasya — calculate the minimum amount of lab works Vasya has to redo.
Input Specification:
The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$).
The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works.
Output Specification:
Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$.
Demo Input:
['3\n4 4 4\n', '4\n5 4 5 5\n', '4\n5 3 3 5\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first sample, it is enough to redo two lab works to make two $4$s into $5$s.
In the second sample, Vasya's average is already $4.75$ so he doesn't have to redo anything to get a $5$.
In the second sample Vasya has to redo one lab work to get rid of one of the $3$s, that will make the average exactly $4.5$ so the final grade would be $5$. | ```python
from sys import *
def main():
n = int(stdin.readline())
target = 4.5*n
currentTotal = 0
minimumRetakes = 0
listOfScores = [int(x) for x in stdin.readline().split()]
for x in listOfScores:
currentTotal+=x
listOfScores.sort()
while(currentTotal < target):
currentTotal+=(5-listOfScores[minimumRetakes])
minimumRetakes += 1
print(minimumRetakes)
if __name__ == '__main__':
main()
``` | 3 |
|
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer — the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1",
"output": "4"
},
{
"input": "0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0\n0 0 0 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n1 0 0 0 0",
"output": "4"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0",
"output": "2"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 1 0",
"output": "3"
}
] | 1,695,837,384 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | for i in range(int(input())):
ch1=input()
ch2=input()
ch3=input()
ch4=input()
ch5=input()
n=0
ch=ch3
if ("1" in ch1):
n+=2
ch=ch1
elif("1" in ch5):
n+=2
ch=ch5
elif("1" in ch4)
n+=1
ch=ch4
elif ("1" in ch2):
n+=1
ch=ch2
if(ch.find("1")==0)or(ch.find("1")==4):
n+=2
elif(ch.find("1")==1)or(ch.find("1")==3):
n+=1
print(n)
| Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=<<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=<<=5).
You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
Input Specification:
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Output Specification:
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
Demo Input:
['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
for i in range(int(input())):
ch1=input()
ch2=input()
ch3=input()
ch4=input()
ch5=input()
n=0
ch=ch3
if ("1" in ch1):
n+=2
ch=ch1
elif("1" in ch5):
n+=2
ch=ch5
elif("1" in ch4)
n+=1
ch=ch4
elif ("1" in ch2):
n+=1
ch=ch2
if(ch.find("1")==0)or(ch.find("1")==4):
n+=2
elif(ch.find("1")==1)or(ch.find("1")==3):
n+=1
print(n)
``` | -1 |
|
30 | A | Accounting | PROGRAMMING | 1,400 | [
"brute force",
"math"
] | A. Accounting | 2 | 256 | A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year).
King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation:
Surely, the king is not going to do this job by himself, and demands you to find such number *X*.
It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. | The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). | Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. | [
"2 18 2\n",
"-1 8 3\n",
"0 0 10\n",
"1 16 5\n"
] | [
"3",
"-2",
"5",
"No solution"
] | none | 500 | [
{
"input": "2 18 2",
"output": "3"
},
{
"input": "-1 8 3",
"output": "-2"
},
{
"input": "0 0 10",
"output": "5"
},
{
"input": "1 16 5",
"output": "No solution"
},
{
"input": "0 1 2",
"output": "No solution"
},
{
"input": "3 0 4",
"output": "0"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "-1 -1 5",
"output": "1"
},
{
"input": "-1 0 4",
"output": "0"
},
{
"input": "-7 0 1",
"output": "0"
},
{
"input": "-5 -5 3",
"output": "1"
},
{
"input": "-5 -5 9",
"output": "1"
},
{
"input": "-5 -5 6",
"output": "1"
},
{
"input": "-4 0 1",
"output": "0"
},
{
"input": "-5 0 3",
"output": "0"
},
{
"input": "-4 4 9",
"output": "-1"
},
{
"input": "10 0 6",
"output": "0"
},
{
"input": "-5 3 4",
"output": "No solution"
},
{
"input": "0 3 6",
"output": "No solution"
},
{
"input": "3 6 10",
"output": "No solution"
},
{
"input": "-3 7 5",
"output": "No solution"
},
{
"input": "-526 526 1",
"output": "-1"
},
{
"input": "-373 373 3",
"output": "-1"
},
{
"input": "-141 0 8",
"output": "0"
},
{
"input": "7 175 1",
"output": "25"
},
{
"input": "-5 -560 1",
"output": "112"
},
{
"input": "-1 -512 10",
"output": "No solution"
},
{
"input": "-3 -768 8",
"output": "2"
},
{
"input": "-3 -768 7",
"output": "No solution"
},
{
"input": "-3 -768 9",
"output": "No solution"
},
{
"input": "-3 -768 4",
"output": "4"
},
{
"input": "4 972 4",
"output": "No solution"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "4 972 6",
"output": "No solution"
},
{
"input": "4 972 1",
"output": "243"
},
{
"input": "4 972 2",
"output": "No solution"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1000 1",
"output": "1000"
},
{
"input": "1 961 2",
"output": "31"
},
{
"input": "1 1000 3",
"output": "10"
},
{
"input": "1 625 4",
"output": "5"
},
{
"input": "4 972 5",
"output": "3"
},
{
"input": "1 729 6",
"output": "3"
},
{
"input": "7 896 7",
"output": "2"
},
{
"input": "3 768 8",
"output": "2"
},
{
"input": "1 512 9",
"output": "2"
},
{
"input": "1 1 5",
"output": "1"
},
{
"input": "1 1 4",
"output": "1"
},
{
"input": "1 -1 1",
"output": "-1"
}
] | 1,680,580,362 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 92 | 0 | import sys
q,w,num = map(int,input().split())
for p in range(-1000,1001):
if q*(p**num)== w:
print(p)
sys.exit()
print("No solution") | Title: Accounting
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year).
King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation:
Surely, the king is not going to do this job by himself, and demands you to find such number *X*.
It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
Input Specification:
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output Specification:
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
Demo Input:
['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n']
Demo Output:
['3', '-2', '5', 'No solution']
Note:
none | ```python
import sys
q,w,num = map(int,input().split())
for p in range(-1000,1001):
if q*(p**num)== w:
print(p)
sys.exit()
print("No solution")
``` | 3.977 |
285 | A | Slightly Decreasing Permutations | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=<<=*n*), that *p**i*<=><=*p**i*<=+<=1.
You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. | The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient. | In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. | [
"5 2\n",
"3 0\n",
"3 2\n"
] | [
"1 5 2 4 3\n",
"1 2 3\n",
"3 2 1\n"
] | none | 500 | [
{
"input": "5 2",
"output": "1 5 2 4 3"
},
{
"input": "3 0",
"output": "1 2 3"
},
{
"input": "3 2",
"output": "3 2 1"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "2 0",
"output": "1 2"
},
{
"input": "2 1",
"output": "2 1"
},
{
"input": "10 4",
"output": "10 9 8 7 1 2 3 4 5 6"
},
{
"input": "56893 5084",
"output": "56893 56892 56891 56890 56889 56888 56887 56886 56885 56884 56883 56882 56881 56880 56879 56878 56877 56876 56875 56874 56873 56872 56871 56870 56869 56868 56867 56866 56865 56864 56863 56862 56861 56860 56859 56858 56857 56856 56855 56854 56853 56852 56851 56850 56849 56848 56847 56846 56845 56844 56843 56842 56841 56840 56839 56838 56837 56836 56835 56834 56833 56832 56831 56830 56829 56828 56827 56826 56825 56824 56823 56822 56821 56820 56819 56818 56817 56816 56815 56814 56813 56812 56811 56810 56809 5..."
},
{
"input": "6 3",
"output": "6 5 4 1 2 3"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "310 186",
"output": "310 309 308 307 306 305 304 303 302 301 300 299 298 297 296 295 294 293 292 291 290 289 288 287 286 285 284 283 282 281 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183..."
},
{
"input": "726 450",
"output": "726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599..."
},
{
"input": "438 418",
"output": "438 437 436 435 434 433 432 431 430 429 428 427 426 425 424 423 422 421 420 419 418 417 416 415 414 413 412 411 410 409 408 407 406 405 404 403 402 401 400 399 398 397 396 395 394 393 392 391 390 389 388 387 386 385 384 383 382 381 380 379 378 377 376 375 374 373 372 371 370 369 368 367 366 365 364 363 362 361 360 359 358 357 356 355 354 353 352 351 350 349 348 347 346 345 344 343 342 341 340 339 338 337 336 335 334 333 332 331 330 329 328 327 326 325 324 323 322 321 320 319 318 317 316 315 314 313 312 311..."
},
{
"input": "854 829",
"output": "854 853 852 851 850 849 848 847 846 845 844 843 842 841 840 839 838 837 836 835 834 833 832 831 830 829 828 827 826 825 824 823 822 821 820 819 818 817 816 815 814 813 812 811 810 809 808 807 806 805 804 803 802 801 800 799 798 797 796 795 794 793 792 791 790 789 788 787 786 785 784 783 782 781 780 779 778 777 776 775 774 773 772 771 770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727..."
},
{
"input": "214 167",
"output": "214 213 212 211 210 209 208 207 206 205 204 203 202 201 200 199 198 197 196 195 194 193 192 191 190 189 188 187 186 185 184 183 182 181 180 179 178 177 176 175 174 173 172 171 170 169 168 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 ..."
},
{
"input": "85705 56268",
"output": "85705 85704 85703 85702 85701 85700 85699 85698 85697 85696 85695 85694 85693 85692 85691 85690 85689 85688 85687 85686 85685 85684 85683 85682 85681 85680 85679 85678 85677 85676 85675 85674 85673 85672 85671 85670 85669 85668 85667 85666 85665 85664 85663 85662 85661 85660 85659 85658 85657 85656 85655 85654 85653 85652 85651 85650 85649 85648 85647 85646 85645 85644 85643 85642 85641 85640 85639 85638 85637 85636 85635 85634 85633 85632 85631 85630 85629 85628 85627 85626 85625 85624 85623 85622 85621 8..."
},
{
"input": "11417 4583",
"output": "11417 11416 11415 11414 11413 11412 11411 11410 11409 11408 11407 11406 11405 11404 11403 11402 11401 11400 11399 11398 11397 11396 11395 11394 11393 11392 11391 11390 11389 11388 11387 11386 11385 11384 11383 11382 11381 11380 11379 11378 11377 11376 11375 11374 11373 11372 11371 11370 11369 11368 11367 11366 11365 11364 11363 11362 11361 11360 11359 11358 11357 11356 11355 11354 11353 11352 11351 11350 11349 11348 11347 11346 11345 11344 11343 11342 11341 11340 11339 11338 11337 11336 11335 11334 11333 1..."
},
{
"input": "53481 20593",
"output": "53481 53480 53479 53478 53477 53476 53475 53474 53473 53472 53471 53470 53469 53468 53467 53466 53465 53464 53463 53462 53461 53460 53459 53458 53457 53456 53455 53454 53453 53452 53451 53450 53449 53448 53447 53446 53445 53444 53443 53442 53441 53440 53439 53438 53437 53436 53435 53434 53433 53432 53431 53430 53429 53428 53427 53426 53425 53424 53423 53422 53421 53420 53419 53418 53417 53416 53415 53414 53413 53412 53411 53410 53409 53408 53407 53406 53405 53404 53403 53402 53401 53400 53399 53398 53397 5..."
},
{
"input": "79193 77281",
"output": "79193 79192 79191 79190 79189 79188 79187 79186 79185 79184 79183 79182 79181 79180 79179 79178 79177 79176 79175 79174 79173 79172 79171 79170 79169 79168 79167 79166 79165 79164 79163 79162 79161 79160 79159 79158 79157 79156 79155 79154 79153 79152 79151 79150 79149 79148 79147 79146 79145 79144 79143 79142 79141 79140 79139 79138 79137 79136 79135 79134 79133 79132 79131 79130 79129 79128 79127 79126 79125 79124 79123 79122 79121 79120 79119 79118 79117 79116 79115 79114 79113 79112 79111 79110 79109 7..."
},
{
"input": "42607 42144",
"output": "42607 42606 42605 42604 42603 42602 42601 42600 42599 42598 42597 42596 42595 42594 42593 42592 42591 42590 42589 42588 42587 42586 42585 42584 42583 42582 42581 42580 42579 42578 42577 42576 42575 42574 42573 42572 42571 42570 42569 42568 42567 42566 42565 42564 42563 42562 42561 42560 42559 42558 42557 42556 42555 42554 42553 42552 42551 42550 42549 42548 42547 42546 42545 42544 42543 42542 42541 42540 42539 42538 42537 42536 42535 42534 42533 42532 42531 42530 42529 42528 42527 42526 42525 42524 42523 4..."
},
{
"input": "100000 0",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155..."
},
{
"input": "100000 99999",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "100000 53860",
"output": "100000 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990 99989 99988 99987 99986 99985 99984 99983 99982 99981 99980 99979 99978 99977 99976 99975 99974 99973 99972 99971 99970 99969 99968 99967 99966 99965 99964 99963 99962 99961 99960 99959 99958 99957 99956 99955 99954 99953 99952 99951 99950 99949 99948 99947 99946 99945 99944 99943 99942 99941 99940 99939 99938 99937 99936 99935 99934 99933 99932 99931 99930 99929 99928 99927 99926 99925 99924 99923 99922 99921 99920 99919 99918 99917 99916 ..."
},
{
"input": "4 0",
"output": "1 2 3 4"
},
{
"input": "4 1",
"output": "4 1 2 3"
},
{
"input": "4 2",
"output": "4 3 1 2"
},
{
"input": "4 3",
"output": "4 3 2 1"
},
{
"input": "3 1",
"output": "3 1 2"
}
] | 1,683,263,419 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 186 | 9,728,000 | a, b = map(int, input().split())
m = []
j = 0
for i in range(a, 1, -1):
if j != b:
m.append(i)
j += 1
if j == b:
break
print(*m, end = ' ')
v = []
for i in range(1, a-b+1):
v.append(i)
print(*v)
| Title: Slightly Decreasing Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=<<=*n*), that *p**i*<=><=*p**i*<=+<=1.
You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*.
Input Specification:
The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=<<=*n*) — the permutation length and the decreasing coefficient.
Output Specification:
In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*.
If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.
Demo Input:
['5 2\n', '3 0\n', '3 2\n']
Demo Output:
['1 5 2 4 3\n', '1 2 3\n', '3 2 1\n']
Note:
none | ```python
a, b = map(int, input().split())
m = []
j = 0
for i in range(a, 1, -1):
if j != b:
m.append(i)
j += 1
if j == b:
break
print(*m, end = ' ')
v = []
for i in range(1, a-b+1):
v.append(i)
print(*v)
``` | 3 |
|
722 | A | Broken Clock | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39. | The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. | The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. | [
"24\n17:30\n",
"12\n17:30\n",
"24\n99:99\n"
] | [
"17:30\n",
"07:30\n",
"09:09\n"
] | none | 500 | [
{
"input": "24\n17:30",
"output": "17:30"
},
{
"input": "12\n17:30",
"output": "07:30"
},
{
"input": "24\n99:99",
"output": "09:09"
},
{
"input": "12\n05:54",
"output": "05:54"
},
{
"input": "12\n00:05",
"output": "01:05"
},
{
"input": "24\n23:80",
"output": "23:00"
},
{
"input": "24\n73:16",
"output": "03:16"
},
{
"input": "12\n03:77",
"output": "03:07"
},
{
"input": "12\n47:83",
"output": "07:03"
},
{
"input": "24\n23:88",
"output": "23:08"
},
{
"input": "24\n51:67",
"output": "01:07"
},
{
"input": "12\n10:33",
"output": "10:33"
},
{
"input": "12\n00:01",
"output": "01:01"
},
{
"input": "12\n07:74",
"output": "07:04"
},
{
"input": "12\n00:60",
"output": "01:00"
},
{
"input": "24\n08:32",
"output": "08:32"
},
{
"input": "24\n42:59",
"output": "02:59"
},
{
"input": "24\n19:87",
"output": "19:07"
},
{
"input": "24\n26:98",
"output": "06:08"
},
{
"input": "12\n12:91",
"output": "12:01"
},
{
"input": "12\n11:30",
"output": "11:30"
},
{
"input": "12\n90:32",
"output": "10:32"
},
{
"input": "12\n03:69",
"output": "03:09"
},
{
"input": "12\n33:83",
"output": "03:03"
},
{
"input": "24\n10:45",
"output": "10:45"
},
{
"input": "24\n65:12",
"output": "05:12"
},
{
"input": "24\n22:64",
"output": "22:04"
},
{
"input": "24\n48:91",
"output": "08:01"
},
{
"input": "12\n02:51",
"output": "02:51"
},
{
"input": "12\n40:11",
"output": "10:11"
},
{
"input": "12\n02:86",
"output": "02:06"
},
{
"input": "12\n99:96",
"output": "09:06"
},
{
"input": "24\n19:24",
"output": "19:24"
},
{
"input": "24\n55:49",
"output": "05:49"
},
{
"input": "24\n01:97",
"output": "01:07"
},
{
"input": "24\n39:68",
"output": "09:08"
},
{
"input": "24\n24:00",
"output": "04:00"
},
{
"input": "12\n91:00",
"output": "01:00"
},
{
"input": "24\n00:30",
"output": "00:30"
},
{
"input": "12\n13:20",
"output": "03:20"
},
{
"input": "12\n13:00",
"output": "03:00"
},
{
"input": "12\n42:35",
"output": "02:35"
},
{
"input": "12\n20:00",
"output": "10:00"
},
{
"input": "12\n21:00",
"output": "01:00"
},
{
"input": "24\n10:10",
"output": "10:10"
},
{
"input": "24\n30:40",
"output": "00:40"
},
{
"input": "24\n12:00",
"output": "12:00"
},
{
"input": "12\n10:60",
"output": "10:00"
},
{
"input": "24\n30:00",
"output": "00:00"
},
{
"input": "24\n34:00",
"output": "04:00"
},
{
"input": "12\n22:00",
"output": "02:00"
},
{
"input": "12\n20:20",
"output": "10:20"
}
] | 1,584,622,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 108 | 307,200 | def getHour(num, horas, minutos):
dezHoras = int(horas[0])
uniHoras = int(horas[1])
dezMin = int(minutos[0])
uniMin = int(minutos[1])
qtdHoras = 10 * int(dezHoras) + int(uniHoras)
qtdMin = 10 * int(dezMin) + int(uniMin)
if(num == 24 and qtdHoras > 23):
dezHoras = 0
if(num == 12 and qtdHoras > 12):
if(uniHoras != 0):
dezHoras = 0
else:
dezHoras = 1
elif(num == 12 and horas == 0):
dezHoras = 1
if(qtdMin > 59):
dezMin = 0
return "{}{}:{}{}".format(dezHoras, uniHoras, dezMin, uniMin)
num = int(input())
entrada = input().split(":")
horas = entrada[0]
minutos = entrada[1]
print(getHour(num, horas, minutos))
| Title: Broken Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken clock. Your goal is to change minimum number of digits in order to make clocks display the correct time in the given format.
For example, if 00:99 is displayed, it is enough to replace the second 9 with 3 in order to get 00:39 that is a correct time in 24-hours format. However, to make 00:99 correct in 12-hours format, one has to change at least two digits. Additionally to the first change one can replace the second 0 with 1 and obtain 01:39.
Input Specification:
The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes.
Output Specification:
The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them.
Demo Input:
['24\n17:30\n', '12\n17:30\n', '24\n99:99\n']
Demo Output:
['17:30\n', '07:30\n', '09:09\n']
Note:
none | ```python
def getHour(num, horas, minutos):
dezHoras = int(horas[0])
uniHoras = int(horas[1])
dezMin = int(minutos[0])
uniMin = int(minutos[1])
qtdHoras = 10 * int(dezHoras) + int(uniHoras)
qtdMin = 10 * int(dezMin) + int(uniMin)
if(num == 24 and qtdHoras > 23):
dezHoras = 0
if(num == 12 and qtdHoras > 12):
if(uniHoras != 0):
dezHoras = 0
else:
dezHoras = 1
elif(num == 12 and horas == 0):
dezHoras = 1
if(qtdMin > 59):
dezMin = 0
return "{}{}:{}{}".format(dezHoras, uniHoras, dezMin, uniMin)
num = int(input())
entrada = input().split(":")
horas = entrada[0]
minutos = entrada[1]
print(getHour(num, horas, minutos))
``` | 0 |
|
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above. | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
"input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543",
"output": "NO"
},
{
"input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869",
"output": "YES"
},
{
"input": "3\n408 410 409",
"output": "YES"
},
{
"input": "3\n903 902 904",
"output": "YES"
},
{
"input": "3\n399 400 398",
"output": "YES"
},
{
"input": "3\n450 448 449",
"output": "YES"
},
{
"input": "3\n390 389 388",
"output": "YES"
},
{
"input": "3\n438 439 440",
"output": "YES"
},
{
"input": "11\n488 688 490 94 564 615 641 170 489 517 669",
"output": "YES"
},
{
"input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954",
"output": "YES"
},
{
"input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318",
"output": "YES"
},
{
"input": "6\n10 79 306 334 304 305",
"output": "YES"
},
{
"input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365",
"output": "YES"
},
{
"input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73",
"output": "YES"
},
{
"input": "11\n325 325 324 324 324 325 325 324 324 324 324",
"output": "NO"
},
{
"input": "7\n517 517 518 517 518 518 518",
"output": "NO"
},
{
"input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710",
"output": "NO"
},
{
"input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29",
"output": "NO"
},
{
"input": "7\n880 880 514 536 881 881 879",
"output": "YES"
},
{
"input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375",
"output": "YES"
},
{
"input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404",
"output": "YES"
},
{
"input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987",
"output": "YES"
},
{
"input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116",
"output": "NO"
},
{
"input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995",
"output": "NO"
},
{
"input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22",
"output": "YES"
},
{
"input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952",
"output": "YES"
},
{
"input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "3\n500 999 1000",
"output": "NO"
},
{
"input": "10\n101 102 104 105 107 109 110 112 113 115",
"output": "NO"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "3\n1000 999 998",
"output": "YES"
},
{
"input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456",
"output": "NO"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3",
"output": "YES"
},
{
"input": "3\n999 999 1000",
"output": "NO"
},
{
"input": "9\n2 4 5 13 25 100 200 300 400",
"output": "NO"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n998 999 1000",
"output": "YES"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 2 2 4",
"output": "NO"
},
{
"input": "4\n4 3 4 5",
"output": "YES"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "NO"
},
{
"input": "3\n2 3 2",
"output": "NO"
},
{
"input": "5\n10 5 6 3 2",
"output": "NO"
},
{
"input": "3\n1 2 1",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "4\n998 999 1000 1000",
"output": "YES"
},
{
"input": "5\n2 3 9 9 4",
"output": "YES"
},
{
"input": "4\n1 2 4 4",
"output": "NO"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "7\n1 2 2 2 4 5 6",
"output": "YES"
},
{
"input": "5\n1 3 10 3 10",
"output": "NO"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "4\n1000 1000 999 998",
"output": "YES"
},
{
"input": "3\n5 3 7",
"output": "NO"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "YES"
},
{
"input": "9\n6 6 6 5 5 5 4 4 4",
"output": "YES"
},
{
"input": "7\n5 6 6 6 7 7 7",
"output": "YES"
},
{
"input": "5\n2 3 3 3 4",
"output": "YES"
},
{
"input": "5\n2 1 2 1 3",
"output": "YES"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "3\n1000 1000 1000",
"output": "NO"
},
{
"input": "5\n1 100 2 100 3",
"output": "YES"
},
{
"input": "5\n5 4 6 5 5",
"output": "YES"
},
{
"input": "12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "5\n9 9 1 2 3",
"output": "YES"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "YES"
},
{
"input": "7\n1 1 1 1 2 3 3",
"output": "YES"
},
{
"input": "3\n13 13 13",
"output": "NO"
},
{
"input": "3\n42 42 42",
"output": "NO"
},
{
"input": "8\n1 1 1 1 2 2 2 2",
"output": "NO"
},
{
"input": "6\n1 1 1 1 2 3",
"output": "YES"
},
{
"input": "6\n1 1 2 2 6 6",
"output": "NO"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "NO"
},
{
"input": "9\n1 2 3 1 2 3 1 2 3",
"output": "YES"
},
{
"input": "4\n1 2 1 100",
"output": "NO"
},
{
"input": "5\n1 1 2 2 3",
"output": "YES"
}
] | 1,458,694,381 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 62 | 5,120,000 | #http://codeforces.com/contest/653/problem/A
import sys
len_input = input()
seq_input = input().split()
#seq_input = '18 55 16 17'.split()
# seq_input = '40 41 43 44 44 44'.split()
# seq_input = '5 972 3 4 1 4 970 971'.split()
# seq_input = ''.split()
# seq_input = '998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543'.split()
seq = sorted([int(x) for x in seq_input])
seq_red = sorted([int(x) for x in list(set(seq))])
# print(seq)
# print(seq_red)
if len(seq_red) < 3:
print('NO') #less than two distinct options
sys.exit()
seq_sub = [seq_red[i] - seq_red[i+2] for i in range(len(seq_red)-2)]
seq_truth = [1 if abs(x) < 3 else 0 for x in seq_sub]
seq_sum = sum(seq_truth)
if seq_sum == 0:
print('NO') #all values are too far apart
elif seq_sum > 0:
print('YES') | Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above.
Input Specification:
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Output Specification:
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
Demo Input:
['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | ```python
#http://codeforces.com/contest/653/problem/A
import sys
len_input = input()
seq_input = input().split()
#seq_input = '18 55 16 17'.split()
# seq_input = '40 41 43 44 44 44'.split()
# seq_input = '5 972 3 4 1 4 970 971'.split()
# seq_input = ''.split()
# seq_input = '998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543'.split()
seq = sorted([int(x) for x in seq_input])
seq_red = sorted([int(x) for x in list(set(seq))])
# print(seq)
# print(seq_red)
if len(seq_red) < 3:
print('NO') #less than two distinct options
sys.exit()
seq_sub = [seq_red[i] - seq_red[i+2] for i in range(len(seq_red)-2)]
seq_truth = [1 if abs(x) < 3 else 0 for x in seq_sub]
seq_sum = sum(seq_truth)
if seq_sum == 0:
print('NO') #all values are too far apart
elif seq_sum > 0:
print('YES')
``` | 3 |
|
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 1,579,274,871 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 109 | 0 | s=input()
s=s[::-1]
s=str(int(s))
if s==s[::-1]:
print('YES')
else:
print('NO') | Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number.
Input Specification:
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Output Specification:
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
Demo Input:
['131\n', '320\n', '2010200\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
s=input()
s=s[::-1]
s=str(int(s))
if s==s[::-1]:
print('YES')
else:
print('NO')
``` | 3 |
|
382 | C | Arithmetic Progression | PROGRAMMING | 1,700 | [
"implementation",
"sortings"
] | null | null | Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills:
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has *n* cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting *n*<=+<=1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled. | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108. | If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples). | [
"3\n4 1 7\n",
"1\n10\n",
"4\n1 3 5 9\n",
"4\n4 3 4 5\n",
"2\n2 4\n"
] | [
"2\n-2 10\n",
"-1\n",
"1\n7\n",
"0\n",
"3\n0 3 6\n"
] | none | 1,500 | [
{
"input": "3\n4 1 7",
"output": "2\n-2 10"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "4\n1 3 5 9",
"output": "1\n7"
},
{
"input": "4\n4 3 4 5",
"output": "0"
},
{
"input": "2\n2 4",
"output": "3\n0 3 6"
},
{
"input": "4\n1 3 4 5",
"output": "1\n2"
},
{
"input": "2\n3 3",
"output": "1\n3"
},
{
"input": "2\n13 2",
"output": "2\n-9 24"
},
{
"input": "5\n2 2 2 2 2",
"output": "1\n2"
},
{
"input": "6\n11 1 7 9 5 13",
"output": "1\n3"
},
{
"input": "2\n100000000 1",
"output": "2\n-99999998 199999999"
},
{
"input": "5\n2 3 1 4 6",
"output": "1\n5"
},
{
"input": "5\n1 2 2 3 4",
"output": "0"
},
{
"input": "3\n1 4 2",
"output": "1\n3"
},
{
"input": "3\n8 8 8",
"output": "1\n8"
},
{
"input": "5\n2 2 2 2 3",
"output": "0"
},
{
"input": "1\n100000000",
"output": "-1"
},
{
"input": "20\n27 6 3 18 54 33 9 15 39 12 57 48 21 51 60 30 24 36 42 45",
"output": "2\n0 63"
},
{
"input": "40\n100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000",
"output": "1\n100000000"
},
{
"input": "49\n81787 163451 104059 89211 96635 133755 148603 141179 159739 122619 123 144891 70651 11259 63227 3835 44667 37243 100347 26107 137467 18683 156027 59515 22395 40955 111483 52091 7547 85499 107771 178299 115195 152315 74363 126331 33531 130043 14971 48379 167163 182011 170875 78075 174587 55803 66939 29819 118907",
"output": "1\n92923"
},
{
"input": "9\n1 2 3 3 4 4 5 5 6",
"output": "0"
},
{
"input": "7\n1 1 2 3 4 5 6",
"output": "0"
},
{
"input": "2\n4 1",
"output": "2\n-2 7"
},
{
"input": "2\n2 100000000",
"output": "3\n-99999996 50000001 199999998"
},
{
"input": "8\n1 2 3 4 11 12 13 14",
"output": "0"
},
{
"input": "7\n5 40 45 50 55 60 65",
"output": "0"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "2\n1 1",
"output": "1\n1"
},
{
"input": "2\n100000000 2",
"output": "3\n-99999996 50000001 199999998"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "5\n1 3 5 9 13",
"output": "0"
},
{
"input": "5\n1 2 4 8 16",
"output": "0"
},
{
"input": "3\n2 2 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 8",
"output": "0"
},
{
"input": "3\n1 3 4",
"output": "1\n2"
},
{
"input": "5\n1 2 4 6 7",
"output": "0"
},
{
"input": "4\n1 5 9 11",
"output": "0"
},
{
"input": "4\n3 4 5 9",
"output": "0"
},
{
"input": "4\n1 5 6 8",
"output": "0"
},
{
"input": "4\n2 6 8 12",
"output": "0"
},
{
"input": "5\n1 2 3 5 7",
"output": "0"
},
{
"input": "6\n1 2 3 4 6 8",
"output": "0"
}
] | 1,575,650,336 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n = int(input())
list_numbers = list(map(int,input().split()))
list_numbers.sort()
def ap(list_numbers,n):
if n == 1:
return -1
if n == 2:
if (list_numbers[0] + list_numbers[1])%2 == 0:
x = int((list_numbers[0] + list_numbers[1])/2)
y = list_numbers[1] - list_numbers[0]
print(3)
print( str(x) + " "+ str(list_numbers[0] - y) + " " + str(list_numbers[1] + y ))
else :
y = list_numbers[1] - list_numbers[0]
print(2)
print( str(list_numbers[0] - y) + " " + str(list_numbers[1] + y))
i = 0
i_to_use = 0
previous_num = 0
difference = " "
difference_2 = " "
if n > 2:
if list_numbers[2] - list_numbers[1] < list_numbers[1] - list_numbers[0] :
list_numbers.reverse()
for j in list_numbers:
if i == 0:
previous_num = j
i += 1
else:
if difference == " ":
difference = j - previous_num
previous_num = j
i += 1
else:
if difference != j - previous_num:
if difference_2 == " ":
difference_2 = j - previous_num
i_to_use = i
i += 1
continue
else:
if difference_2 != j - previous_num:
print(0)
break
else:
i += 1
continue
if difference_2 == " ":
print(2)
print(str(list_numbers[0] - difference) + " " + str(list_numbers[1] + difference))
else:
if difference_2 * 2 == difference:
print(1)
print(list_numbers[i_to_use - 1] + difference_2)
else:
print(0)
else :
for j in list_numbers :
if i == 0:
previous_num = j
i +=1
else :
if difference == " ":
difference = j - previous_num
previous_num = j
i += 1
else :
if difference != j - previous_num :
if difference_2 == " ":
difference_2 = j - previous_num
i_to_use = i
i += 1
continue
else :
if difference_2 != j - previous_num :
print(0)
break
else :
i += 1
continue
else :
previous_num = j
i +=1
if difference_2 == " ":
print(2)
print(str(list_numbers[0] - difference) + " " + str(list_numbers[-1] + difference))
else :
if difference_2 == difference *2 :
print(1)
print(list_numbers[i_to_use-1] + difference)
else:
print(0)
ap(list_numbers,n) | Title: Arithmetic Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Everybody knows what an arithmetic progression is. Let us remind you just in case that an arithmetic progression is such sequence of numbers *a*1,<=*a*2,<=...,<=*a**n* of length *n*, that the following condition fulfills:
For example, sequences [1, 5], [10], [5, 4, 3] are arithmetic progressions and sequences [1, 3, 2], [1, 2, 4] are not.
Alexander has *n* cards containing integers. Arthur wants to give Alexander exactly one more card with a number so that he could use the resulting *n*<=+<=1 cards to make an arithmetic progression (Alexander has to use all of his cards).
Arthur has already bought a card but he hasn't written a number on it. Help him, print all integers that you can write on a card so that the described condition fulfilled.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards. The next line contains the sequence of integers — the numbers on Alexander's cards. The numbers are positive integers, each of them doesn't exceed 108.
Output Specification:
If Arthur can write infinitely many distinct integers on the card, print on a single line -1.
Otherwise, print on the first line the number of integers that suit you. In the second line, print the numbers in the increasing order. Note that the numbers in the answer can exceed 108 or even be negative (see test samples).
Demo Input:
['3\n4 1 7\n', '1\n10\n', '4\n1 3 5 9\n', '4\n4 3 4 5\n', '2\n2 4\n']
Demo Output:
['2\n-2 10\n', '-1\n', '1\n7\n', '0\n', '3\n0 3 6\n']
Note:
none | ```python
n = int(input())
list_numbers = list(map(int,input().split()))
list_numbers.sort()
def ap(list_numbers,n):
if n == 1:
return -1
if n == 2:
if (list_numbers[0] + list_numbers[1])%2 == 0:
x = int((list_numbers[0] + list_numbers[1])/2)
y = list_numbers[1] - list_numbers[0]
print(3)
print( str(x) + " "+ str(list_numbers[0] - y) + " " + str(list_numbers[1] + y ))
else :
y = list_numbers[1] - list_numbers[0]
print(2)
print( str(list_numbers[0] - y) + " " + str(list_numbers[1] + y))
i = 0
i_to_use = 0
previous_num = 0
difference = " "
difference_2 = " "
if n > 2:
if list_numbers[2] - list_numbers[1] < list_numbers[1] - list_numbers[0] :
list_numbers.reverse()
for j in list_numbers:
if i == 0:
previous_num = j
i += 1
else:
if difference == " ":
difference = j - previous_num
previous_num = j
i += 1
else:
if difference != j - previous_num:
if difference_2 == " ":
difference_2 = j - previous_num
i_to_use = i
i += 1
continue
else:
if difference_2 != j - previous_num:
print(0)
break
else:
i += 1
continue
if difference_2 == " ":
print(2)
print(str(list_numbers[0] - difference) + " " + str(list_numbers[1] + difference))
else:
if difference_2 * 2 == difference:
print(1)
print(list_numbers[i_to_use - 1] + difference_2)
else:
print(0)
else :
for j in list_numbers :
if i == 0:
previous_num = j
i +=1
else :
if difference == " ":
difference = j - previous_num
previous_num = j
i += 1
else :
if difference != j - previous_num :
if difference_2 == " ":
difference_2 = j - previous_num
i_to_use = i
i += 1
continue
else :
if difference_2 != j - previous_num :
print(0)
break
else :
i += 1
continue
else :
previous_num = j
i +=1
if difference_2 == " ":
print(2)
print(str(list_numbers[0] - difference) + " " + str(list_numbers[-1] + difference))
else :
if difference_2 == difference *2 :
print(1)
print(list_numbers[i_to_use-1] + difference)
else:
print(0)
ap(list_numbers,n)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. | The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. | Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. | [
"hellno\n",
"abacaba\n",
"asdfasdf\n"
] | [
"hell no \n",
"abacaba \n",
"asd fasd f \n"
] | none | 0 | [
{
"input": "hellno",
"output": "hell no "
},
{
"input": "abacaba",
"output": "abacaba "
},
{
"input": "asdfasdf",
"output": "asd fasd f "
},
{
"input": "ooo",
"output": "ooo "
},
{
"input": "moyaoborona",
"output": "moyaoborona "
},
{
"input": "jxegxxx",
"output": "jxegx xx "
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz "
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te "
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz "
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf "
},
{
"input": "mvjajoyeg",
"output": "mv jajoyeg "
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q "
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef "
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j "
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p "
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d "
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r "
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu "
},
{
"input": "a",
"output": "a "
},
{
"input": "b",
"output": "b "
},
{
"input": "aa",
"output": "aa "
},
{
"input": "ab",
"output": "ab "
},
{
"input": "ba",
"output": "ba "
},
{
"input": "bb",
"output": "bb "
},
{
"input": "aaa",
"output": "aaa "
},
{
"input": "aab",
"output": "aab "
},
{
"input": "aba",
"output": "aba "
},
{
"input": "abb",
"output": "abb "
},
{
"input": "baa",
"output": "baa "
},
{
"input": "bab",
"output": "bab "
},
{
"input": "bba",
"output": "bba "
},
{
"input": "bbb",
"output": "bbb "
},
{
"input": "bbc",
"output": "bb c "
},
{
"input": "bcb",
"output": "bc b "
},
{
"input": "cbb",
"output": "cb b "
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc "
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b "
},
{
"input": "helllllooooo",
"output": "helllllooooo "
},
{
"input": "bbbzxxx",
"output": "bbb zx xx "
},
{
"input": "ffff",
"output": "ffff "
},
{
"input": "cdddddddddddddddddd",
"output": "cd ddddddddddddddddd "
},
{
"input": "bbbc",
"output": "bbb c "
},
{
"input": "lll",
"output": "lll "
},
{
"input": "bbbbb",
"output": "bbbbb "
},
{
"input": "llll",
"output": "llll "
},
{
"input": "bbbbbbccc",
"output": "bbbbbb ccc "
},
{
"input": "lllllb",
"output": "lllll b "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "lllll",
"output": "lllll "
},
{
"input": "bbbbbbbbbc",
"output": "bbbbbbbbb c "
},
{
"input": "helllllno",
"output": "helllll no "
},
{
"input": "nnnnnnnnnnnn",
"output": "nnnnnnnnnnnn "
},
{
"input": "bbbbbccc",
"output": "bbbbb ccc "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "nnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz",
"output": "zzzzzzzzzzzzzzzzzzzzzzz "
},
{
"input": "hhhh",
"output": "hhhh "
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn "
},
{
"input": "zzzzzzzzzz",
"output": "zzzzzzzzzz "
},
{
"input": "dddd",
"output": "dddd "
},
{
"input": "heffffffgggggghhhhhh",
"output": "heffffff gggggg hhhhhh "
},
{
"input": "bcddd",
"output": "bc ddd "
},
{
"input": "x",
"output": "x "
},
{
"input": "nnn",
"output": "nnn "
},
{
"input": "xxxxxxxx",
"output": "xxxxxxxx "
},
{
"input": "cclcc",
"output": "cc lc c "
},
{
"input": "tttttttttttttt",
"output": "tttttttttttttt "
},
{
"input": "xxxxxxx",
"output": "xxxxxxx "
},
{
"input": "ccccb",
"output": "cccc b "
},
{
"input": "bcecccc",
"output": "bcecccc "
},
{
"input": "jjja",
"output": "jjja "
},
{
"input": "zzz",
"output": "zzz "
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz",
"output": "xxxxxxxxx zzzzzzzzzzzz "
},
{
"input": "alllewww",
"output": "alllewww "
},
{
"input": "bbbbbbbbb",
"output": "bbbbbbbbb "
},
{
"input": "jjj",
"output": "jjj "
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb "
},
{
"input": "kkkkkkkkkklllllllllllllll",
"output": "kkkkkkkkkk lllllllllllllll "
},
{
"input": "helllllllllllo",
"output": "helllllllllllo "
},
{
"input": "ttttsttttt",
"output": "tttt st tttt "
},
{
"input": "tttttttsssssss",
"output": "ttttttt sssssss "
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss "
},
{
"input": "xxxxx",
"output": "xxxxx "
},
{
"input": "bbbhbbb",
"output": "bbb hb bb "
},
{
"input": "bbbbbbbb",
"output": "bbbbbbbb "
}
] | 1,508,382,498 | 5,898 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,529,600 | # -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
"""
created by shhuan at 2017/10/19 10:54
"""
s = input()
ans = ""
VOL = {'a', 'e', 'i', 'o', 'u'}
i = 0
while i < len(s):
v = s[i]
if v not in VOL:
j = i + 1
while j < len(s) and s[j] not in VOL:
j += 1
t = s[i:j]
if len(set(t)) == 1:
ans += t
else:
for k in range(i, j):
ans += s[k]
if k%2 != 0:
ans += ' '
i = j - 1
else:
ans += v
i += 1
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
- the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; - the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
Input Specification:
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
Output Specification:
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
Demo Input:
['hellno\n', 'abacaba\n', 'asdfasdf\n']
Demo Output:
['hell no \n', 'abacaba \n', 'asd fasd f \n']
Note:
none | ```python
# -*- coding: utf-8 -*-
import math
import collections
import bisect
import heapq
import time
import random
import itertools
"""
created by shhuan at 2017/10/19 10:54
"""
s = input()
ans = ""
VOL = {'a', 'e', 'i', 'o', 'u'}
i = 0
while i < len(s):
v = s[i]
if v not in VOL:
j = i + 1
while j < len(s) and s[j] not in VOL:
j += 1
t = s[i:j]
if len(set(t)) == 1:
ans += t
else:
for k in range(i, j):
ans += s[k]
if k%2 != 0:
ans += ' '
i = j - 1
else:
ans += v
i += 1
print(ans)
``` | 0 |
|
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "1 1 1 1 1 1",
"output": "Elephant"
},
{
"input": "9 9 9 9 9 9",
"output": "Elephant"
},
{
"input": "1 8 9 1 1 1",
"output": "Bear"
},
{
"input": "9 9 9 1 9 9",
"output": "Bear"
},
{
"input": "1 2 3 8 9 7",
"output": "Alien"
},
{
"input": "5 5 5 6 6 6",
"output": "Alien"
},
{
"input": "1 1 2 2 3 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 2",
"output": "Bear"
},
{
"input": "2 2 3 3 4 4",
"output": "Alien"
},
{
"input": "4 4 4 4 4 5",
"output": "Bear"
},
{
"input": "1 1 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 2 5 5 5 5",
"output": "Bear"
},
{
"input": "4 4 2 2 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 1 2",
"output": "Bear"
},
{
"input": "2 2 4 4 4 4",
"output": "Elephant"
},
{
"input": "4 4 4 4 4 3",
"output": "Bear"
},
{
"input": "4 4 5 6 7 8",
"output": "Alien"
},
{
"input": "4 4 4 4 2 2",
"output": "Elephant"
},
{
"input": "1 1 1 1 2 2",
"output": "Elephant"
},
{
"input": "1 1 3 3 3 5",
"output": "Alien"
},
{
"input": "1 2 2 3 3 3",
"output": "Alien"
},
{
"input": "1 2 2 2 2 2",
"output": "Bear"
},
{
"input": "1 3 3 3 4 5",
"output": "Alien"
},
{
"input": "5 1 1 1 1 1",
"output": "Bear"
}
] | 1,412,091,275 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 0 |
sticks = input().split()
four = False
two = False
for stick in sticks:
if sticks.count(stick) >= 4:
four = True
if sticks.count(stick) == 2 or sticks.count(stick) == 6:
two = True
if four:
if two:
print("Elephant")
else:
print("Bear")
else:
print("Alien") | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
- Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input Specification:
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output Specification:
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Demo Input:
['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n']
Demo Output:
['Bear', 'Elephant', 'Alien']
Note:
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | ```python
sticks = input().split()
four = False
two = False
for stick in sticks:
if sticks.count(stick) >= 4:
four = True
if sticks.count(stick) == 2 or sticks.count(stick) == 6:
two = True
if four:
if two:
print("Elephant")
else:
print("Bear")
else:
print("Alien")
``` | 3 |
|
1,007 | A | Reorder the Array | PROGRAMMING | 1,300 | [
"combinatorics",
"data structures",
"math",
"sortings",
"two pointers"
] | null | null | You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. | Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. | [
"7\n10 1 1 1 5 5 3\n",
"5\n1 1 1 1 1\n"
] | [
"4\n",
"0\n"
] | In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | 500 | [
{
"input": "7\n10 1 1 1 5 5 3",
"output": "4"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000",
"output": "3"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "7\n3 5 2 2 5 2 4",
"output": "4"
},
{
"input": "5\n1 5 4 2 3",
"output": "4"
}
] | 1,600,774,192 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(l.index(min(l)))
| Title: Reorder the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20>10$, $40>20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
Input Specification:
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array.
Output Specification:
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
Demo Input:
['7\n10 1 1 1 5 5 3\n', '5\n1 1 1 1 1\n']
Demo Output:
['4\n', '0\n']
Note:
In the first sample, one of the best permutations is $[1, 5, 5, 3, 10, 1, 1]$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0. | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
print(l.index(min(l)))
``` | 0 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,694,139,163 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 62 | 0 | c = 0
for room in range(int(input())):
p, q = map(int, input().split())
if p + 2 <= q:
c += 1
else:
c += 0
print(c)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
c = 0
for room in range(int(input())):
p, q = map(int, input().split())
if p + 2 <= q:
c += 1
else:
c += 0
print(c)
``` | 3 |
|
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},
{
"input": "lwzjp\ninjit",
"output": "-1"
},
{
"input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm",
"output": "eodnlemiicdedmkcgavqbnqmm"
},
{
"input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs",
"output": "-1"
},
{
"input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf",
"output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf"
},
{
"input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen",
"output": "-1"
},
{
"input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb",
"output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb"
},
{
"input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym",
"output": "-1"
},
{
"input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib",
"output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib"
},
{
"input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew",
"output": "-1"
},
{
"input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv",
"output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv"
},
{
"input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns",
"output": "-1"
},
{
"input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf",
"output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf"
},
{
"input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp",
"output": "-1"
},
{
"input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp",
"output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp"
},
{
"input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej",
"output": "-1"
},
{
"input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe",
"output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe"
},
{
"input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang",
"output": "-1"
},
{
"input": "ftfr\nftfr",
"output": "ftfr"
},
{
"input": "ftr\nftr",
"output": "ftr"
},
{
"input": "shftr\nshftr",
"output": "shftr"
},
{
"input": "vkvkkv\nvkvkkv",
"output": "vkvkkv"
},
{
"input": "ftrd\nftrd",
"output": "ftrd"
},
{
"input": "fztr\nfztr",
"output": "fztr"
},
{
"input": "frtr\nfrtr",
"output": "frtr"
},
{
"input": "shdftr\nshdftr",
"output": "shdftr"
},
{
"input": "zzz\nzzz",
"output": "zzz"
},
{
"input": "shtr\nshtr",
"output": "shtr"
},
{
"input": "aaaaa\nzzzzz",
"output": "-1"
},
{
"input": "efr\nefr",
"output": "efr"
}
] | 1,492,358,199 | 1,299 | Python 3 | OK | TESTS | 35 | 62 | 5,529,600 | x = [i for i in input()]
y = [i for i in input()]
z = []
possible = True
for i in range(len(x)):
if x[i] == y[i]:
z.append('z')
elif x[i] > y[i]:
z.append(y[i])
else:
possible = False
break
if possible:
print("".join(z))
else:
print(-1)
| Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
Input Specification:
The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
Output Specification:
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
Demo Input:
['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n']
Demo Output:
['ba\n', 'xiyez\n', '-1\n']
Note:
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | ```python
x = [i for i in input()]
y = [i for i in input()]
z = []
possible = True
for i in range(len(x)):
if x[i] == y[i]:
z.append('z')
elif x[i] > y[i]:
z.append(y[i])
else:
possible = False
break
if possible:
print("".join(z))
else:
print(-1)
``` | 3 |
|
520 | A | Pangram | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters. | Output "YES", if the string is a pangram and "NO" otherwise. | [
"12\ntoosmallword\n",
"35\nTheQuickBrownFoxJumpsOverTheLazyDog\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "12\ntoosmallword",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog",
"output": "YES"
},
{
"input": "1\na",
"output": "NO"
},
{
"input": "26\nqwertyuiopasdfghjklzxcvbnm",
"output": "YES"
},
{
"input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "YES"
},
{
"input": "48\nthereisasyetinsufficientdataforameaningfulanswer",
"output": "NO"
},
{
"input": "30\nToBeOrNotToBeThatIsTheQuestion",
"output": "NO"
},
{
"input": "30\njackdawslovemybigsphinxofquarz",
"output": "NO"
},
{
"input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY",
"output": "YES"
},
{
"input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx",
"output": "YES"
},
{
"input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ",
"output": "YES"
},
{
"input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ",
"output": "YES"
},
{
"input": "25\nnxYTzLFwzNolAumjgcAboyxAj",
"output": "NO"
},
{
"input": "26\npRWdodGdxUESvcScPGbUoooZsC",
"output": "NO"
},
{
"input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj",
"output": "NO"
},
{
"input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa",
"output": "YES"
},
{
"input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK",
"output": "NO"
},
{
"input": "26\nvCUFRKElZOnjmXGylWQaHDiPst",
"output": "NO"
},
{
"input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY",
"output": "NO"
},
{
"input": "26\npGiFluRteQwkaVoPszJyNBChxM",
"output": "NO"
},
{
"input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY",
"output": "NO"
},
{
"input": "26\nLndjgvAEuICHKxPwqYztosrmBN",
"output": "NO"
},
{
"input": "26\nMdaXJrCipnOZLykfqHWEStevbU",
"output": "NO"
},
{
"input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba",
"output": "NO"
},
{
"input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo",
"output": "NO"
},
{
"input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa",
"output": "NO"
},
{
"input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO",
"output": "NO"
},
{
"input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe",
"output": "NO"
},
{
"input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG",
"output": "NO"
},
{
"input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF",
"output": "NO"
},
{
"input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu",
"output": "NO"
},
{
"input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf",
"output": "NO"
},
{
"input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE",
"output": "NO"
},
{
"input": "26\nDqspXZJTuONYieKgaHLMBwfVSC",
"output": "NO"
},
{
"input": "26\necOyUkqNljFHRVXtIpWabGMLDz",
"output": "NO"
},
{
"input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI",
"output": "NO"
},
{
"input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA",
"output": "NO"
},
{
"input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz",
"output": "NO"
},
{
"input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ",
"output": "NO"
},
{
"input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF",
"output": "NO"
},
{
"input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB",
"output": "NO"
},
{
"input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg",
"output": "NO"
},
{
"input": "26\nmnbvcxxlkjhgfdsapoiuytrewq",
"output": "NO"
},
{
"input": "26\naAbcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl",
"output": "NO"
},
{
"input": "25\nabcdefghijklmnopqrstuvwxy",
"output": "NO"
},
{
"input": "26\nabcdefhijklmnopqrstVxyzABC",
"output": "NO"
},
{
"input": "25\nqwertyuiopasdfghjklxcvbnm",
"output": "NO"
},
{
"input": "34\nTheQuickBrownFoxJumpsOverTheLayDog",
"output": "NO"
},
{
"input": "26\nabcdefghigklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxyA",
"output": "NO"
},
{
"input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM",
"output": "NO"
},
{
"input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog",
"output": "NO"
},
{
"input": "25\nbcdefghijklmnopqrstuvwxyz",
"output": "NO"
},
{
"input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa",
"output": "NO"
},
{
"input": "26\nabcdefghiklmnopqrstvxyzABC",
"output": "NO"
},
{
"input": "26\nabcdefghijklmnopqrstuvwxzZ",
"output": "NO"
},
{
"input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY",
"output": "NO"
}
] | 1,696,487,119 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n=int(input())
s=input()
res=[0]*27
for i in range(len(s)):
res[ord(s[i])-ord('a')+1] += 1
for i in range(1,len(res)):
if res[i] == 0:
print('False')
break
else:
print('True')
| Title: Pangram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output Specification:
Output "YES", if the string is a pangram and "NO" otherwise.
Demo Input:
['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
n=int(input())
s=input()
res=[0]*27
for i in range(len(s)):
res[ord(s[i])-ord('a')+1] += 1
for i in range(1,len(res)):
if res[i] == 0:
print('False')
break
else:
print('True')
``` | 0 |
|
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
{
"input": "1 1000\n1 1000",
"output": "1001"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2"
},
{
"input": "2 7\n6 3\n1 5",
"output": "9"
},
{
"input": "2 100\n99 2\n1 10",
"output": "101"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "6"
},
{
"input": "3 7\n1 6\n5 5\n6 1",
"output": "10"
},
{
"input": "2 100\n4 100\n7 99",
"output": "106"
},
{
"input": "2 10\n9 3\n1 4",
"output": "12"
},
{
"input": "2 5\n4 4\n5 4",
"output": "9"
},
{
"input": "2 10\n9 10\n6 11",
"output": "19"
},
{
"input": "2 100\n99 9\n1 10",
"output": "108"
},
{
"input": "2 7\n3 5\n7 4",
"output": "11"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9",
"output": "12"
},
{
"input": "2 1000\n1 2\n1000 1",
"output": "1001"
},
{
"input": "2 20\n1 1\n2 2",
"output": "20"
},
{
"input": "2 20\n10 10\n19 9",
"output": "28"
}
] | 1,577,116,208 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | n,s=map(int,input().split())
p=[[0,0] for i in range (0,n)]
for i in range (0,n):
p[i][1],p[i][0]=map(int,input().split())
p=sorted(p)
print(p[n-1][0]+p[n-1][1])
| Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input Specification:
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Output Specification:
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Demo Input:
['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n']
Demo Output:
['11\n', '79\n']
Note:
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | ```python
n,s=map(int,input().split())
p=[[0,0] for i in range (0,n)]
for i in range (0,n):
p[i][1],p[i][0]=map(int,input().split())
p=sorted(p)
print(p[n-1][0]+p[n-1][1])
``` | 0 |
|
743 | E | Vladik and cards | PROGRAMMING | 2,200 | [
"binary search",
"bitmasks",
"brute force",
"dp"
] | null | null | Vladik was bored on his way home and decided to play the following game. He took *n* cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
- the number of occurrences of each number from 1 to 8 in the subsequence doesn't differ by more then 1 from the number of occurrences of any other number. Formally, if there are *c**k* cards with number *k* on them in the subsequence, than for all pairs of integers the condition |*c**i*<=-<=*c**j*|<=≤<=1 must hold. - if there is at least one card with number *x* on it in the subsequence, then all cards with number *x* in this subsequence must form a continuous segment in it (but not necessarily a continuous segment in the original sequence). For example, the subsequence [1,<=1,<=2,<=2] satisfies this condition while the subsequence [1,<=2,<=2,<=1] doesn't. Note that [1,<=1,<=2,<=2] doesn't satisfy the first condition.
Please help Vladik to find the length of the longest subsequence that satisfies both conditions. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards in Vladik's sequence.
The second line contains the sequence of *n* positive integers not exceeding 8 — the description of Vladik's sequence. | Print single integer — the length of the longest subsequence of Vladik's sequence that satisfies both conditions. | [
"3\n1 1 1\n",
"8\n8 7 6 5 4 3 2 1\n",
"24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\n"
] | [
"1",
"8",
"17"
] | In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition. | 2,500 | [
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "8\n8 7 6 5 4 3 2 1",
"output": "8"
},
{
"input": "24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8",
"output": "17"
},
{
"input": "1\n8",
"output": "1"
},
{
"input": "2\n5 4",
"output": "2"
},
{
"input": "3\n3 3 2",
"output": "2"
},
{
"input": "18\n3 6 6 8 8 1 1 4 4 3 3 5 5 7 7 2 2 3",
"output": "16"
},
{
"input": "5\n2 6 1 2 6",
"output": "3"
},
{
"input": "6\n4 3 1 6 7 4",
"output": "5"
},
{
"input": "7\n8 8 2 6 1 8 5",
"output": "5"
},
{
"input": "8\n2 8 4 7 5 3 6 1",
"output": "8"
},
{
"input": "8\n8 6 3 6 7 5 5 3",
"output": "5"
},
{
"input": "15\n5 2 2 7 5 2 6 4 3 8 1 8 4 2 7",
"output": "9"
},
{
"input": "15\n8 8 1 6 2 2 4 5 4 2 4 8 2 5 2",
"output": "6"
},
{
"input": "16\n8 2 1 5 7 6 2 5 4 4 8 2 2 6 3 8",
"output": "10"
},
{
"input": "16\n2 2 8 8 5 5 3 3 7 7 1 1 6 6 4 4",
"output": "16"
},
{
"input": "18\n4 3 3 3 7 7 5 2 1 1 3 3 6 1 2 4 1 8",
"output": "11"
},
{
"input": "30\n5 5 4 8 6 6 7 7 8 2 2 2 1 4 4 4 8 8 6 3 5 7 7 3 7 1 6 1 1 8",
"output": "19"
},
{
"input": "30\n1 7 2 2 2 3 1 1 1 3 7 3 7 3 7 7 1 7 6 6 6 5 5 5 4 4 4 8 8 8",
"output": "24"
},
{
"input": "120\n6 7 8 5 2 8 5 4 6 4 3 2 5 6 5 7 5 7 1 7 4 6 4 1 4 1 1 7 6 7 3 7 4 7 4 6 4 7 6 6 6 5 5 7 3 5 3 7 2 2 4 2 5 6 8 4 1 2 2 8 3 3 2 5 6 4 3 6 2 4 1 4 2 8 8 3 7 6 4 7 2 7 3 3 8 8 6 8 7 7 6 8 3 2 5 2 6 5 7 5 7 5 3 2 6 2 6 5 7 8 7 7 2 6 5 4 2 3 1 8",
"output": "34"
},
{
"input": "120\n5 4 1 4 1 7 7 1 1 1 8 2 3 3 6 3 6 2 7 3 7 3 2 8 1 6 6 1 8 3 4 6 4 7 5 8 1 4 3 5 7 6 1 5 8 5 8 5 6 5 7 4 3 4 5 2 6 3 2 4 4 4 4 7 4 5 2 7 2 6 2 2 7 2 4 7 2 1 6 4 2 8 6 2 3 4 4 8 1 6 7 6 2 7 5 6 7 6 2 3 7 8 5 2 7 7 7 7 2 7 8 8 7 5 5 6 8 8 8 3",
"output": "46"
},
{
"input": "120\n6 6 6 6 3 6 6 6 6 6 6 8 2 8 8 8 8 8 4 8 8 8 8 2 1 6 1 3 1 1 1 1 1 5 1 1 1 5 2 1 7 7 7 1 7 7 3 7 7 7 7 7 7 3 7 5 6 2 1 5 4 5 4 5 5 5 6 4 5 5 5 3 5 5 4 2 4 3 2 4 4 4 4 7 4 2 4 4 3 8 4 3 3 4 7 3 3 3 3 3 3 3 3 2 2 2 1 2 7 1 2 2 2 6 2 8 2 2 3 2",
"output": "84"
},
{
"input": "120\n8 8 8 8 8 8 8 8 8 8 8 8 1 8 8 4 6 4 4 4 4 4 4 4 4 3 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6 6 6 6 6 3 3 3 3 3 3 3 3 3 3 3 3 3 3 7 7 7 7 7 8 7 7 7 7 7 7 4 7 7 7 3 5 5 5 1 5 5 5 5 5 5 5 5 5 5 5 5 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "113"
},
{
"input": "120\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "120"
}
] | 1,675,524,759 | 4,359 | PyPy 3 | OK | TESTS | 41 | 233 | 24,780,800 | import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return (m + 1) * u + v
n = int(input())
a = list(map(int, input().split()))
m = 8
x = [[] for _ in range(m)]
for i in range(n):
x[a[i] - 1].append(i)
s = 0
for y in x:
s += min(len(y), 1)
if s < m:
ans = s
print(ans)
exit()
pow2 = [1]
for _ in range(m):
pow2.append(2 * pow2[-1])
pm = pow2[m]
inf = pow(10, 9) + 1
ans = 8
ok = 1
for c in range(1, n // 8 + 3):
dp = [inf] * ((m + 1) * pm)
dp[0] = -1
for i in range(pm):
for j in range(m):
u = f(i, j)
if dp[u] == inf:
break
dpu = dp[u]
for k in range(m):
if i & pow2[k]:
continue
l = i ^ pow2[k]
xk = x[k]
z = bisect.bisect_left(xk, dpu) + c
for y in range(2):
if y + z - 1 < len(xk):
v = f(l, j + y)
dp[v] = min(dp[v], xk[y + z - 1])
for i in range(1, m + 1):
if dp[f(pm - 1, i)] == inf:
ok = 0
break
ans += 1
if not ok:
break
print(ans) | Title: Vladik and cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vladik was bored on his way home and decided to play the following game. He took *n* cards and put them in a row in front of himself. Every card has a positive integer number not exceeding 8 written on it. He decided to find the longest subsequence of cards which satisfies the following conditions:
- the number of occurrences of each number from 1 to 8 in the subsequence doesn't differ by more then 1 from the number of occurrences of any other number. Formally, if there are *c**k* cards with number *k* on them in the subsequence, than for all pairs of integers the condition |*c**i*<=-<=*c**j*|<=≤<=1 must hold. - if there is at least one card with number *x* on it in the subsequence, then all cards with number *x* in this subsequence must form a continuous segment in it (but not necessarily a continuous segment in the original sequence). For example, the subsequence [1,<=1,<=2,<=2] satisfies this condition while the subsequence [1,<=2,<=2,<=1] doesn't. Note that [1,<=1,<=2,<=2] doesn't satisfy the first condition.
Please help Vladik to find the length of the longest subsequence that satisfies both conditions.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards in Vladik's sequence.
The second line contains the sequence of *n* positive integers not exceeding 8 — the description of Vladik's sequence.
Output Specification:
Print single integer — the length of the longest subsequence of Vladik's sequence that satisfies both conditions.
Demo Input:
['3\n1 1 1\n', '8\n8 7 6 5 4 3 2 1\n', '24\n1 8 1 2 8 2 3 8 3 4 8 4 5 8 5 6 8 6 7 8 7 8 8 8\n']
Demo Output:
['1', '8', '17']
Note:
In the first sample all the numbers written on the cards are equal, so you can't take more than one card, otherwise you'll violate the first condition. | ```python
import bisect
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return (m + 1) * u + v
n = int(input())
a = list(map(int, input().split()))
m = 8
x = [[] for _ in range(m)]
for i in range(n):
x[a[i] - 1].append(i)
s = 0
for y in x:
s += min(len(y), 1)
if s < m:
ans = s
print(ans)
exit()
pow2 = [1]
for _ in range(m):
pow2.append(2 * pow2[-1])
pm = pow2[m]
inf = pow(10, 9) + 1
ans = 8
ok = 1
for c in range(1, n // 8 + 3):
dp = [inf] * ((m + 1) * pm)
dp[0] = -1
for i in range(pm):
for j in range(m):
u = f(i, j)
if dp[u] == inf:
break
dpu = dp[u]
for k in range(m):
if i & pow2[k]:
continue
l = i ^ pow2[k]
xk = x[k]
z = bisect.bisect_left(xk, dpu) + c
for y in range(2):
if y + z - 1 < len(xk):
v = f(l, j + y)
dp[v] = min(dp[v], xk[y + z - 1])
for i in range(1, m + 1):
if dp[f(pm - 1, i)] == inf:
ok = 0
break
ans += 1
if not ok:
break
print(ans)
``` | 3 |
|
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3",
"output": "16"
},
{
"input": "10\n2 3 0 1 3 1 2 2 1 0",
"output": "3"
},
{
"input": "45\n3 3 2 3 2 3 3 3 0 3 3 3 3 3 3 3 1 3 2 3 2 3 2 2 2 3 2 3 3 3 3 3 1 2 3 3 2 2 2 3 3 3 3 1 3",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "2\n3 3",
"output": "0"
},
{
"input": "3\n3 3 3",
"output": "0"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "2\n0 2",
"output": "1"
},
{
"input": "10\n2 2 3 3 3 3 2 1 3 2",
"output": "2"
},
{
"input": "15\n0 1 0 0 0 2 0 1 0 0 0 2 0 0 0",
"output": "11"
},
{
"input": "15\n1 3 2 2 2 3 3 3 3 2 3 2 2 1 1",
"output": "4"
},
{
"input": "15\n3 1 3 2 3 2 2 2 3 3 3 3 2 3 2",
"output": "3"
},
{
"input": "20\n0 2 0 1 0 0 0 1 2 0 1 1 1 0 1 1 0 1 1 0",
"output": "12"
},
{
"input": "20\n2 3 2 3 3 3 3 2 0 3 1 1 2 3 0 3 2 3 0 3",
"output": "5"
},
{
"input": "20\n3 3 3 3 2 3 3 2 1 3 3 2 2 2 3 2 2 2 2 2",
"output": "4"
},
{
"input": "25\n0 0 1 0 0 1 0 0 1 0 0 1 0 2 0 0 2 0 0 1 0 2 0 1 1",
"output": "16"
},
{
"input": "25\n1 3 3 2 2 3 3 3 3 3 1 2 2 3 2 0 2 1 0 1 3 2 2 3 3",
"output": "5"
},
{
"input": "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3",
"output": "3"
},
{
"input": "30\n0 0 1 0 1 0 1 1 0 0 0 0 0 0 1 0 0 1 1 0 0 2 0 0 1 1 2 0 0 0",
"output": "22"
},
{
"input": "30\n1 1 3 2 2 0 3 2 3 3 1 2 0 1 1 2 3 3 2 3 1 3 2 3 0 2 0 3 3 2",
"output": "9"
},
{
"input": "30\n1 2 3 2 2 3 3 3 3 3 3 3 3 3 3 1 2 2 3 2 3 3 3 2 1 3 3 3 1 3",
"output": "2"
},
{
"input": "35\n0 1 1 0 0 2 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 2 1 0 2 2 1 0 1 0 1 1 1 0 0",
"output": "21"
},
{
"input": "35\n2 2 0 3 2 2 0 3 3 1 1 3 3 1 2 2 0 2 2 2 2 3 1 0 2 1 3 2 2 3 2 3 3 1 2",
"output": "11"
},
{
"input": "35\n1 2 2 3 3 3 3 3 2 2 3 3 2 3 3 2 3 2 3 3 2 2 2 3 3 2 3 3 3 1 3 3 2 2 2",
"output": "7"
},
{
"input": "40\n2 0 1 1 0 0 0 0 2 0 1 1 1 0 0 1 0 0 0 0 0 2 0 0 0 2 1 1 1 3 0 0 0 0 0 0 0 1 1 0",
"output": "28"
},
{
"input": "40\n2 2 3 2 0 2 3 2 1 2 3 0 2 3 2 1 1 3 1 1 0 2 3 1 3 3 1 1 3 3 2 2 1 3 3 3 2 3 3 1",
"output": "10"
},
{
"input": "40\n1 3 2 3 3 2 3 3 2 2 3 1 2 1 2 2 3 1 2 2 1 2 2 2 1 2 2 3 2 3 2 3 2 3 3 3 1 3 2 3",
"output": "8"
},
{
"input": "45\n2 1 0 0 0 2 1 0 1 0 0 2 2 1 1 0 0 2 0 0 0 0 0 0 1 0 0 2 0 0 1 1 0 0 1 0 0 1 1 2 0 0 2 0 2",
"output": "29"
},
{
"input": "45\n3 3 2 3 3 3 2 2 3 2 3 1 3 2 3 2 2 1 1 3 2 3 2 1 3 1 2 3 2 2 0 3 3 2 3 2 3 2 3 2 0 3 1 1 3",
"output": "8"
},
{
"input": "50\n3 0 0 0 2 0 0 0 0 0 0 0 2 1 0 2 0 1 0 1 3 0 2 1 1 0 0 1 1 0 0 1 2 1 1 2 1 1 0 0 0 0 0 0 0 1 2 2 0 0",
"output": "32"
},
{
"input": "50\n3 3 3 3 1 0 3 3 0 2 3 1 1 1 3 2 3 3 3 3 3 1 0 1 2 2 3 3 2 3 0 0 0 2 1 0 1 2 2 2 2 0 2 2 2 1 2 3 3 2",
"output": "16"
},
{
"input": "50\n3 2 3 1 2 1 2 3 3 2 3 3 2 1 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 2 3 3 3 3 2 3 1 2 3 3 2 3 3 1 2 2 1 1 3 3",
"output": "7"
},
{
"input": "55\n0 0 1 1 0 1 0 0 1 0 1 0 0 0 2 0 0 1 0 0 0 1 0 0 0 0 3 1 0 0 0 1 0 0 0 0 2 0 0 0 2 0 2 1 0 0 0 0 0 0 0 0 2 0 0",
"output": "40"
},
{
"input": "55\n3 0 3 3 3 2 0 2 3 0 3 2 3 3 0 3 3 1 3 3 1 2 3 2 0 3 3 2 1 2 3 2 3 0 3 2 2 1 2 3 2 2 1 3 2 2 3 1 3 2 2 3 3 2 2",
"output": "13"
},
{
"input": "55\n3 3 1 3 2 3 2 3 2 2 3 3 3 3 3 1 1 3 3 2 3 2 3 2 0 1 3 3 3 3 2 3 2 3 1 1 2 2 2 3 3 3 3 3 2 2 2 3 2 3 3 3 3 1 3",
"output": "7"
},
{
"input": "60\n0 1 0 0 0 0 0 0 0 2 1 1 3 0 0 0 0 0 1 0 1 1 0 0 0 3 0 1 0 1 0 2 0 0 0 0 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0",
"output": "44"
},
{
"input": "60\n3 2 1 3 2 2 3 3 3 1 1 3 2 2 3 3 1 3 2 2 3 3 2 2 2 2 0 2 2 3 2 3 0 3 3 3 2 3 3 0 1 3 2 1 3 1 1 2 1 3 1 1 2 2 1 3 3 3 2 2",
"output": "15"
},
{
"input": "60\n3 2 2 3 2 3 2 3 3 2 3 2 3 3 2 3 3 3 3 3 3 2 3 3 1 2 3 3 3 2 1 3 3 1 3 1 3 0 3 3 3 2 3 2 3 2 3 3 1 1 2 3 3 3 3 2 1 3 2 3",
"output": "8"
},
{
"input": "65\n1 0 2 1 1 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 2 0 2 1 0 2 1 0 1 0 1 1 0 1 1 1 2 1 0 1 0 0 0 0 1 2 2 1 0 0 1 2 1 2 0 2 0 0 0 1 1",
"output": "35"
},
{
"input": "65\n2 2 2 3 0 2 1 2 3 3 1 3 1 2 1 3 2 3 2 2 2 1 2 0 3 1 3 1 1 3 1 3 3 3 3 3 1 3 0 3 1 3 1 2 2 3 2 0 3 1 3 2 1 2 2 2 3 3 2 3 3 3 2 2 3",
"output": "13"
},
{
"input": "65\n3 2 3 3 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 2 3 2 2 3 3 3 3 3 2 2 2 3 3 2 3 3 2 3 3 3 3 2 3 3 3 2 2 3 3 3 3 3 3 2 2 3 3 2 3 3 1 3 3 3 3",
"output": "6"
},
{
"input": "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1",
"output": "43"
},
{
"input": "70\n2 3 3 3 1 3 3 1 2 1 1 2 2 3 0 2 3 3 1 3 3 2 2 3 3 3 2 2 2 2 1 3 3 0 2 1 1 3 2 3 3 2 2 3 1 3 1 2 3 2 3 3 2 2 2 3 1 1 2 1 3 3 2 2 3 3 3 1 1 1",
"output": "16"
},
{
"input": "70\n3 3 2 2 1 2 1 2 2 2 2 2 3 3 2 3 3 3 3 2 2 2 2 3 3 3 1 3 3 3 2 3 3 3 3 2 3 3 1 3 1 3 2 3 3 2 3 3 3 2 3 2 3 3 1 2 3 3 2 2 2 3 2 3 3 3 3 3 3 1",
"output": "10"
},
{
"input": "75\n1 0 0 1 1 0 0 1 0 1 2 0 0 2 1 1 0 0 0 0 0 0 2 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 2 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 0",
"output": "51"
},
{
"input": "75\n1 3 3 3 1 1 3 2 3 3 1 3 3 3 2 1 3 2 2 3 1 1 1 1 1 1 2 3 3 3 3 3 3 2 3 3 3 3 3 2 3 3 2 2 2 1 2 3 3 2 2 3 0 1 1 3 3 0 0 1 1 3 2 3 3 3 3 1 2 2 3 3 3 3 1",
"output": "16"
},
{
"input": "75\n3 3 3 3 2 2 3 2 2 3 2 2 1 2 3 3 2 2 3 3 1 2 2 2 1 3 3 3 1 2 2 3 3 3 2 3 2 2 2 3 3 1 3 2 2 3 3 3 0 3 2 1 3 3 2 3 3 3 3 1 2 3 3 3 2 2 3 3 3 3 2 2 3 3 1",
"output": "11"
},
{
"input": "80\n0 0 0 0 2 0 1 1 1 1 1 0 0 0 0 2 0 0 1 0 0 0 0 1 1 0 2 2 1 1 0 1 0 1 0 1 1 1 0 1 2 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 2 2 0 1 1 0 0 0 0 0 0 0 0 1",
"output": "56"
},
{
"input": "80\n2 2 3 3 2 1 0 1 0 3 2 2 3 2 1 3 1 3 3 2 3 3 3 2 3 3 3 2 1 3 3 1 3 3 3 3 3 3 2 2 2 1 3 2 1 3 2 1 1 0 1 1 2 1 3 0 1 2 3 2 2 3 2 3 1 3 3 2 1 1 0 3 3 3 3 1 2 1 2 0",
"output": "17"
},
{
"input": "80\n2 3 3 2 2 2 3 3 2 3 3 3 3 3 2 3 2 3 2 3 3 3 3 3 3 3 3 3 2 3 1 3 2 3 3 0 3 1 2 3 3 1 2 3 2 3 3 2 3 3 3 3 3 2 2 3 0 3 3 3 3 3 2 2 3 2 3 3 3 3 3 2 3 2 3 3 3 3 2 3",
"output": "9"
},
{
"input": "85\n0 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 2 0 1 0 0 2 0 1 1 0 0 0 0 2 2 0 0 0 1 0 0 0 1 2 0 1 0 0 0 2 1 1 2 0 3 1 0 2 2 1 0 0 1 1 0 0 0 0 1 0 2 1 1 2 1 0 0 1 2 1 2 0 0 1 0 1 0",
"output": "54"
},
{
"input": "85\n2 3 1 3 2 3 1 3 3 2 1 2 1 2 2 3 2 2 3 2 0 3 3 2 1 2 2 2 3 3 2 3 3 3 2 1 1 3 1 3 2 2 2 3 3 2 3 2 3 1 1 3 2 3 1 3 3 2 3 3 2 2 3 0 1 1 2 2 2 2 1 2 3 1 3 3 1 3 2 2 3 2 3 3 3",
"output": "19"
},
{
"input": "85\n1 2 1 2 3 2 3 3 3 3 3 3 3 2 1 3 2 3 3 3 3 2 3 3 3 1 3 3 3 3 2 3 3 3 3 3 3 2 2 1 3 3 3 3 2 2 3 1 1 2 3 3 3 2 3 3 3 3 3 2 3 3 3 2 2 3 3 1 1 1 3 3 3 3 1 3 3 3 1 3 3 1 3 2 3",
"output": "9"
},
{
"input": "90\n2 0 1 0 0 0 0 0 0 1 1 2 0 0 0 0 0 0 0 2 2 0 2 0 0 2 1 0 2 0 1 0 1 0 0 1 2 2 0 0 1 0 0 1 0 1 0 2 0 1 1 1 0 1 1 0 1 0 2 0 1 0 1 0 0 0 1 0 0 1 2 0 0 0 1 0 0 2 2 0 0 0 0 0 1 3 1 1 0 1",
"output": "57"
},
{
"input": "90\n2 3 3 3 2 3 2 1 3 0 3 2 3 3 2 1 3 3 2 3 2 3 3 2 1 3 1 3 3 1 2 2 3 3 2 1 2 3 2 3 0 3 3 2 2 3 1 0 3 3 1 3 3 3 3 2 1 2 2 1 3 2 1 3 3 1 2 0 2 2 3 2 2 3 3 3 1 3 2 1 2 3 3 2 3 2 3 3 2 1",
"output": "17"
},
{
"input": "90\n2 3 2 3 2 2 3 3 2 3 2 1 2 3 3 3 2 3 2 3 3 2 3 3 3 1 3 3 1 3 2 3 2 2 1 3 3 3 3 3 3 3 3 3 3 2 3 2 3 2 1 3 3 3 3 2 2 3 3 3 3 3 3 3 3 3 3 3 3 2 2 3 3 3 3 1 3 2 3 3 3 2 2 3 2 3 2 1 3 2",
"output": "9"
},
{
"input": "95\n0 0 3 0 2 0 1 0 0 2 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 0 0 2 1 0 0 1 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 2 0 1 2 2 0 0 1 0 2 0 0 0 1 0 2 1 2 1 0 1 0 0 0 1 0 0 1 1 2 1 1 1 1 2 0 0 0 0 0 1 1 0 1",
"output": "61"
},
{
"input": "95\n2 3 3 2 1 1 3 3 3 2 3 3 3 2 3 2 3 3 3 2 3 2 2 3 3 2 1 2 3 3 3 1 3 0 3 3 1 3 3 1 0 1 3 3 3 0 2 1 3 3 3 3 0 1 3 2 3 3 2 1 3 1 2 1 1 2 3 0 3 3 2 1 3 2 1 3 3 3 2 2 3 2 3 3 3 2 1 3 3 3 2 3 3 1 2",
"output": "15"
},
{
"input": "95\n2 3 3 2 3 2 2 1 3 1 2 1 2 3 1 2 3 3 1 3 3 3 1 2 3 2 2 2 2 3 3 3 2 2 3 3 3 3 3 1 2 2 3 3 3 3 2 3 2 2 2 3 3 2 3 3 3 3 3 3 3 0 3 2 0 3 3 1 3 3 3 2 3 2 3 2 3 3 3 3 2 2 1 1 3 3 3 3 3 1 3 3 3 3 2",
"output": "14"
},
{
"input": "100\n1 0 2 0 0 0 0 2 0 0 0 1 0 1 0 0 1 0 1 2 0 1 1 0 0 1 0 1 1 0 0 0 2 0 1 0 0 2 0 0 0 0 0 1 1 1 0 0 1 0 2 0 0 0 0 1 0 1 0 1 0 1 0 1 2 2 0 0 2 0 1 0 1 0 1 0 0 0 1 0 0 2 1 1 1 0 0 1 0 0 0 2 0 0 2 1 1 0 0 2",
"output": "63"
},
{
"input": "100\n3 2 1 3 2 3 2 3 2 2 3 1 3 3 3 3 3 2 2 3 2 2 3 2 3 3 3 2 3 1 2 1 3 3 3 3 1 3 3 3 3 3 2 3 2 1 3 3 1 2 2 3 1 3 3 1 2 2 1 3 1 3 2 2 3 3 1 3 2 3 1 2 1 2 3 3 2 2 1 2 3 3 3 3 3 1 3 3 3 3 2 1 3 0 3 3 3 2 3 3",
"output": "15"
},
{
"input": "100\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "0"
},
{
"input": "100\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "49"
},
{
"input": "100\n2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "100"
},
{
"input": "2\n0 3",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 0",
"output": "1"
},
{
"input": "2\n2 1",
"output": "0"
},
{
"input": "2\n2 3",
"output": "0"
},
{
"input": "2\n3 0",
"output": "1"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "100\n3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0 3 0",
"output": "50"
}
] | 1,613,824,362 | 2,147,483,647 | Python 3 | OK | TESTS | 88 | 62 | 307,200 | n=int(input())
dp=[[0 for i in range(3)]for j in range(n+1)]
ar=tuple(map(str,input().split()))
for i in range(1,n+1):
x=ar[i-1]
dp[i][0]=min(dp[i-1])+1
if(x=='1' or x=='3'):
dp[i][1]=min(dp[i-1][0],dp[i-1][2])
else:
dp[i][1]=dp[i-1][1]+1
if(x=='2' or x=='3'):
dp[i][2]=min(dp[i-1][0],dp[i-1][1])
else:
dp[i][2]=dp[i-1][2]+1
print(min(dp[-1]))
| Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Output Specification:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days.
Demo Input:
['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day. | ```python
n=int(input())
dp=[[0 for i in range(3)]for j in range(n+1)]
ar=tuple(map(str,input().split()))
for i in range(1,n+1):
x=ar[i-1]
dp[i][0]=min(dp[i-1])+1
if(x=='1' or x=='3'):
dp[i][1]=min(dp[i-1][0],dp[i-1][2])
else:
dp[i][1]=dp[i-1][1]+1
if(x=='2' or x=='3'):
dp[i][2]=min(dp[i-1][0],dp[i-1][1])
else:
dp[i][2]=dp[i-1][2]+1
print(min(dp[-1]))
``` | 3 |
|
234 | B | Reading | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all *n* hours of the trip — *n* numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose *k* hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours. | The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour. | In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers *b**i* in an arbitrary order. | [
"5 3\n20 10 30 40 10\n",
"6 5\n90 20 35 40 60 100\n"
] | [
"20\n1 3 4 \n",
"35\n1 3 4 5 6 \n"
] | In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | 0 | [
{
"input": "5 3\n20 10 30 40 10",
"output": "20\n1 3 4 "
},
{
"input": "6 5\n90 20 35 40 60 100",
"output": "35\n1 3 4 5 6 "
},
{
"input": "100 7\n85 66 9 91 50 46 61 12 55 65 95 1 25 97 95 4 59 59 52 34 94 30 60 11 68 36 17 84 87 68 72 87 46 99 24 66 75 77 75 2 19 3 33 19 7 20 22 3 71 29 88 63 89 47 7 52 47 55 87 77 9 81 44 13 30 43 66 74 9 42 9 72 97 61 9 94 92 29 18 7 92 68 76 43 35 71 54 49 77 50 77 68 57 24 84 73 32 85 24 37",
"output": "94\n11 14 15 21 34 73 76 "
},
{
"input": "1 1\n10",
"output": "10\n1 "
},
{
"input": "1 1\n86",
"output": "86\n1 "
},
{
"input": "100 79\n83 83 83 83 83 94 94 83 83 83 83 90 83 99 83 91 83 83 83 83 83 83 83 83 83 83 83 91 83 83 83 83 83 96 83 83 83 91 83 83 92 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 83 98 83 83 91 97 83 83 83 83 83 83 83 92 83 83 83 83 83 83 83 93 83 83 91 83 83 83 83 83 83 83 83 83 83 83 96 83 83 83 83 83",
"output": "83\n6 7 12 14 16 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "20 3\n17 76 98 17 55 17 17 99 65 17 17 17 17 52 17 17 69 88 17 17",
"output": "88\n3 8 18 "
},
{
"input": "15 1\n0 78 24 24 61 60 0 65 52 57 97 51 56 13 10",
"output": "97\n11 "
},
{
"input": "50 50\n59 40 52 0 65 49 3 58 57 22 86 37 55 72 11 3 30 30 20 64 44 45 12 48 96 96 39 14 8 53 40 37 8 58 97 16 96 48 30 89 66 19 31 50 23 80 67 16 11 7",
"output": "0\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 "
},
{
"input": "60 8\n59 12 34 86 57 65 42 24 62 18 94 92 43 29 95 33 73 3 69 18 36 18 34 97 85 65 74 25 26 70 46 31 57 73 78 89 95 77 94 71 38 23 30 97 69 97 76 43 76 31 38 50 13 16 55 85 47 5 71 4",
"output": "92\n11 12 15 24 37 39 44 46 "
},
{
"input": "70 5\n76 16 20 60 5 96 32 50 35 9 79 42 38 35 72 45 98 33 55 0 86 92 49 87 22 79 35 27 69 35 89 29 31 43 88 1 48 95 3 92 82 97 53 80 79 0 78 58 37 38 45 9 5 38 53 49 71 7 91 3 75 17 76 44 77 31 78 91 59 91",
"output": "92\n6 17 38 40 42 "
},
{
"input": "12 3\n18 64 98 27 36 27 65 43 39 41 69 47",
"output": "65\n3 7 11 "
},
{
"input": "15 13\n6 78 78 78 78 20 78 78 8 3 78 18 32 56 78",
"output": "8\n2 3 4 5 6 7 8 9 11 12 13 14 15 "
},
{
"input": "17 4\n75 52 24 74 70 24 24 53 24 48 24 0 67 47 24 24 6",
"output": "67\n1 4 5 13 "
},
{
"input": "14 2\n31 18 78 90 96 2 90 27 86 9 94 98 94 34",
"output": "96\n5 12 "
},
{
"input": "100 56\n56 64 54 22 46 0 51 27 8 10 5 26 68 37 51 53 4 64 82 23 38 89 97 20 23 31 7 95 55 27 33 23 95 6 64 69 27 54 36 4 96 61 68 26 46 10 61 53 32 19 28 62 7 32 86 84 12 88 92 51 53 23 80 7 36 46 48 29 12 98 72 99 16 0 94 22 83 23 12 37 29 13 93 16 53 21 8 37 67 33 33 67 35 72 3 97 46 30 9 57",
"output": "33\n1 2 3 5 7 13 14 15 16 18 19 21 22 23 28 29 33 35 36 38 39 41 42 43 45 47 48 52 55 56 58 59 60 61 63 65 66 67 70 71 72 75 77 80 83 85 88 89 90 91 92 93 94 96 97 100 "
},
{
"input": "90 41\n43 24 4 69 54 87 33 34 9 77 87 66 66 0 71 43 42 10 78 48 26 40 8 61 80 38 76 63 7 47 99 69 77 43 29 74 86 93 39 28 99 98 11 27 43 58 50 61 1 79 45 17 23 13 10 98 41 28 19 98 87 51 26 28 88 60 42 25 19 3 29 18 0 56 84 27 43 92 93 97 25 90 13 90 75 52 99 6 66 87",
"output": "52\n4 5 6 10 11 12 13 15 19 24 25 27 28 31 32 33 36 37 38 41 42 46 48 50 56 60 61 65 66 74 75 78 79 80 82 84 85 86 87 89 90 "
},
{
"input": "100 71\n29 56 85 57 40 89 93 81 92 38 81 41 18 9 89 21 81 6 95 94 38 11 90 38 6 81 61 43 81 12 36 35 33 10 81 49 59 37 81 61 95 34 43 20 94 88 57 81 42 81 50 24 85 81 1 90 33 8 59 87 17 52 91 54 81 98 28 11 24 51 95 31 98 29 5 81 91 52 41 81 7 9 81 81 13 81 3 81 10 0 37 47 62 50 81 81 81 94 93 38",
"output": "35\n2 3 4 5 6 7 8 9 10 11 12 15 17 19 20 21 23 24 26 27 28 29 31 32 35 36 37 38 39 40 41 43 45 46 47 48 49 50 51 53 54 56 59 60 62 63 64 65 66 70 71 73 76 77 78 79 80 83 84 86 88 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100 55\n72 70 77 90 86 96 60 60 60 60 87 62 60 87 0 60 82 60 86 74 60 60 60 60 60 60 78 60 60 60 96 60 60 0 60 60 89 99 60 60 60 60 60 60 89 60 88 84 60 93 0 60 60 60 75 60 67 64 65 60 65 60 72 60 76 4 60 60 60 63 96 62 78 71 63 81 89 98 60 60 69 60 61 60 60 60 85 71 82 79 67 60 60 60 79 96 2 60 60 60",
"output": "60\n1 2 3 4 5 6 11 12 14 17 19 20 27 31 37 38 45 47 48 50 55 57 58 59 61 63 65 70 71 72 73 74 75 76 77 78 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 98 99 100 "
},
{
"input": "100 27\n25 87 25 25 77 78 25 73 91 25 25 70 84 25 61 75 82 25 25 25 25 65 25 25 82 63 93 25 93 75 25 25 25 89 98 25 25 72 70 25 72 25 25 25 70 25 25 98 90 25 25 25 25 25 91 25 78 71 63 69 25 25 25 63 25 25 75 94 25 25 25 25 25 97 25 78 66 87 25 89 25 25 73 85 25 91 72 25 25 80 25 70 25 96 25 25 25 25 25 25",
"output": "75\n2 5 6 9 13 16 17 25 27 29 30 34 35 48 49 55 57 67 68 74 76 78 80 84 86 90 94 "
},
{
"input": "100 99\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100 50\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "2\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 "
},
{
"input": "100 51\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 99 100 "
},
{
"input": "100 75\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "1\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "100 45\n1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2",
"output": "2\n12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 "
},
{
"input": "2 2\n2 2",
"output": "2\n1 2 "
},
{
"input": "2 1\n2 1",
"output": "2\n1 "
},
{
"input": "2 1\n1 2",
"output": "2\n2 "
},
{
"input": "3 1\n1 2 0",
"output": "2\n2 "
},
{
"input": "3 2\n0 0 0",
"output": "0\n2 3 "
},
{
"input": "3 3\n0 1 0",
"output": "0\n1 2 3 "
},
{
"input": "3 2\n99 100 99",
"output": "99\n2 3 "
},
{
"input": "1 1\n0",
"output": "0\n1 "
},
{
"input": "4 1\n100 100 0 100",
"output": "100\n4 "
},
{
"input": "4 2\n0 1 0 1",
"output": "1\n2 4 "
},
{
"input": "10 3\n0 1 2 3 0 1 2 3 0 1",
"output": "2\n4 7 8 "
},
{
"input": "10 9\n0 1 0 1 100 100 1 0 1 0",
"output": "0\n2 3 4 5 6 7 8 9 10 "
},
{
"input": "7 7\n1 0 0 0 0 0 0",
"output": "0\n1 2 3 4 5 6 7 "
},
{
"input": "7 6\n0 0 0 0 0 0 1",
"output": "0\n2 3 4 5 6 7 "
},
{
"input": "7 1\n12 33 12 88 10 0 3",
"output": "88\n4 "
},
{
"input": "7 1\n0 1 1 1 1 1 1",
"output": "1\n7 "
},
{
"input": "7 6\n1 1 1 1 1 1 0",
"output": "1\n1 2 3 4 5 6 "
},
{
"input": "7 2\n1 0 1 1 1 1 1",
"output": "1\n6 7 "
},
{
"input": "8 4\n1 1 1 1 0 0 0 0",
"output": "1\n1 2 3 4 "
},
{
"input": "7 5\n1 1 1 2 0 0 0",
"output": "0\n1 2 3 4 7 "
}
] | 1,620,612,761 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 6,963,200 | f = open("input.txt", "r")
list1 = f.readline().split()
list2 = f.readline().split()
f.close()
integer_map = map(int, list1)
integer_list1 = list(integer_map)
integer_map = map(int, list2)
num = list(integer_map)
A = int(list1[0])
B = int(list1[1])
input_list = []
final_list = []
for i in num:
input_list.append(int(i))
place = 0
for i in range(0, B):
max1 = 0
for j in range(0, A):
if input_list[j] >= max1:
max1 = input_list[j]
place = j
final_list.append(place +1)
input_list[place] = 0
final_list.sort()
output = ""
for i in final_list:
output += str(i) + " "
output2 = ''
for i in range(len(num)):
output2 += str(i) + " "
o = open("output.txt", "w")
if A > B:
o.write(max1)
o.write(output)
elif A == B:
o.write("0")
o.write(output2)
o.close()
| Title: Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya is going to the Olympics in the city Ntown by train. The boy wants to read the textbook to prepare for the Olympics. He counted that he needed *k* hours for this. He also found that the light in the train changes every hour. The light is measured on a scale from 0 to 100, where 0 is very dark, and 100 is very light.
Vasya has a train lighting schedule for all *n* hours of the trip — *n* numbers from 0 to 100 each (the light level in the first hour, the second hour and so on). During each of those hours he will either read the whole time, or not read at all. He wants to choose *k* hours to read a book, not necessarily consecutive, so that the minimum level of light among the selected hours were maximum. Vasya is very excited before the upcoming contest, help him choose reading hours.
Input Specification:
The first input line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*k*<=≤<=*n*) — the number of hours on the train and the number of hours to read, correspondingly. The second line contains *n* space-separated integers *a**i* (0<=≤<=*a**i*<=≤<=100), *a**i* is the light level at the *i*-th hour.
Output Specification:
In the first output line print the minimum light level Vasya will read at. In the second line print *k* distinct space-separated integers *b*1,<=*b*2,<=...,<=*b**k*, — the indexes of hours Vasya will read at (1<=≤<=*b**i*<=≤<=*n*). The hours are indexed starting from 1. If there are multiple optimal solutions, print any of them. Print the numbers *b**i* in an arbitrary order.
Demo Input:
['5 3\n20 10 30 40 10\n', '6 5\n90 20 35 40 60 100\n']
Demo Output:
['20\n1 3 4 \n', '35\n1 3 4 5 6 \n']
Note:
In the first sample Vasya should read at the first hour (light 20), third hour (light 30) and at the fourth hour (light 40). The minimum light Vasya will have to read at is 20. | ```python
f = open("input.txt", "r")
list1 = f.readline().split()
list2 = f.readline().split()
f.close()
integer_map = map(int, list1)
integer_list1 = list(integer_map)
integer_map = map(int, list2)
num = list(integer_map)
A = int(list1[0])
B = int(list1[1])
input_list = []
final_list = []
for i in num:
input_list.append(int(i))
place = 0
for i in range(0, B):
max1 = 0
for j in range(0, A):
if input_list[j] >= max1:
max1 = input_list[j]
place = j
final_list.append(place +1)
input_list[place] = 0
final_list.sort()
output = ""
for i in final_list:
output += str(i) + " "
output2 = ''
for i in range(len(num)):
output2 += str(i) + " "
o = open("output.txt", "w")
if A > B:
o.write(max1)
o.write(output)
elif A == B:
o.write("0")
o.write(output2)
o.close()
``` | -1 |
|
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"input": "1 1\n5",
"output": "1 1"
},
{
"input": "10 4\n1 1 2 2 3 3 4 4 4 4",
"output": "2 7"
},
{
"input": "4 2\n3 3 4 3",
"output": "2 3"
},
{
"input": "4 3\n4 4 4 2",
"output": "-1 -1"
},
{
"input": "10 5\n15 17 2 13 3 16 4 5 9 12",
"output": "1 5"
},
{
"input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148",
"output": "1 13"
},
{
"input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796",
"output": "-1 -1"
},
{
"input": "8 5\n1 2 1 1 2 3 4 5",
"output": "4 8"
},
{
"input": "7 3\n2 1 2 2 1 2 3",
"output": "5 7"
},
{
"input": "6 3\n1 3 1 1 4 5",
"output": "2 5"
},
{
"input": "5 3\n1 2 1 1 3",
"output": "2 5"
},
{
"input": "9 3\n1 2 1 2 1 2 2 3 1",
"output": "5 8"
},
{
"input": "4 3\n1 2 1 3",
"output": "2 4"
},
{
"input": "5 3\n1 3 1 3 4",
"output": "3 5"
},
{
"input": "6 3\n1 3 3 1 4 4",
"output": "3 5"
},
{
"input": "5 3\n1 2 1 2 3",
"output": "3 5"
},
{
"input": "8 4\n1 2 3 2 1 2 3 4",
"output": "5 8"
},
{
"input": "10 4\n1 2 3 1 2 3 4 3 2 1",
"output": "4 7"
},
{
"input": "10 3\n1 1 1 2 1 2 3 3 3 4",
"output": "5 7"
},
{
"input": "10 3\n1 1 2 1 2 2 3 4 5 6",
"output": "4 7"
}
] | 1,590,141,187 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 278 | 0 | n,k =map(int,input().split())
arr=list(map(int,input().split()))
b=0
start=0
count=0
for i in range(0,n):
a=[arr[i]]
p=1
length=1
for j in range(i+1,n):
if b!=0 and length==b:
break
if p==k :
b=len(a)
start=i
break
if arr[j] not in a:
p+=1
a.append(arr[j])
length+=1
if b!=0:
print(start+1,start+b)
else:
print(-1,-1) | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
Input Specification:
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
Demo Input:
['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n']
Demo Output:
['1 2\n', '2 5\n', '-1 -1\n']
Note:
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sample there is no segment with four distinct numbers. | ```python
n,k =map(int,input().split())
arr=list(map(int,input().split()))
b=0
start=0
count=0
for i in range(0,n):
a=[arr[i]]
p=1
length=1
for j in range(i+1,n):
if b!=0 and length==b:
break
if p==k :
b=len(a)
start=i
break
if arr[j] not in a:
p+=1
a.append(arr[j])
length+=1
if b!=0:
print(start+1,start+b)
else:
print(-1,-1)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up; - climb one area down; - jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x*<=+<=*k* of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous. | Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes). | [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n"
] | [
"YES\n",
"NO\n"
] | In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | 0 | [
{
"input": "7 3\n---X--X\n-X--XX-",
"output": "YES"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "10 1\n-X-X-X-X-X\nX-X-X-X-X-",
"output": "YES"
},
{
"input": "5 4\n-X---\n----X",
"output": "NO"
},
{
"input": "6 2\n--X--X\nXX-X-X",
"output": "YES"
},
{
"input": "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----",
"output": "YES"
},
{
"input": "1 1\n-\nX",
"output": "YES"
},
{
"input": "2 1\n-X\nX-",
"output": "YES"
},
{
"input": "2 1\n-X\n-X",
"output": "NO"
},
{
"input": "1 20\n-\n-",
"output": "YES"
},
{
"input": "1 100000\n-\n-",
"output": "YES"
},
{
"input": "5 2\n-----\nXXXXX",
"output": "YES"
},
{
"input": "5 1\n----X\n----X",
"output": "NO"
},
{
"input": "12 4\n----X---X--X\n-----X-----X",
"output": "YES"
},
{
"input": "12 2\n-X-X-X-X-X-X\nX---XXX--X-X",
"output": "NO"
},
{
"input": "10 8\n-XXXXXXXXX\nXXXXXXXXX-",
"output": "NO"
},
{
"input": "100 10\n-X------XXX--XXX-XXXXXX---XXX---X-XX--XXX----------XX-X-XXXX-X-X-XX-X-X--XXXXX---X--X--XXX-X--XXXXXX\n---X-XXXXXXX--X-XXX--X-XX--XX----XX-X----X-X-XX-X--X-XXXXXXX-XX-X---X--XX-X-XX--XXXXXXX-X--XX--X-XXX",
"output": "NO"
},
{
"input": "12 3\n--XX--XX-XXX\n----X---XXX-",
"output": "NO"
},
{
"input": "6 2\n--X-X-\nX--XX-",
"output": "NO"
},
{
"input": "25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--",
"output": "YES"
},
{
"input": "13 2\n---X---X--X-X\n--X---X-X--X-",
"output": "YES"
},
{
"input": "5 2\n---XX\n---X-",
"output": "YES"
},
{
"input": "101 1\n----------------------------------------------------------------------------------------------------X\n----------------------------------------------------------------------------------------------------X",
"output": "NO"
}
] | 1,683,467,107 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 29 | 2,000 | 62,976,000 | n , k = input().split(" ")
n = int(n)
k = int(k)
barisKiri = input()
barisKanan = input()
# buat adjacency mapping
mapping = {}
for I in range(n):
mapping['%d-Kiri' % (I)] = []
if I+1 < n and barisKiri[I+1] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kiri' % (I+1))
if I > 0 and barisKiri[I-1] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kiri' % (I-1))
if I + k < n and barisKanan[I+k] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kanan' % (I+k))
if I + k >= n:
mapping['%d-Kiri' % (I)].append('Gol')
for I in range(n):
mapping['%d-Kanan' % (I)] = []
if I+1 < n and barisKanan[I+1] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kanan' % (I+1))
if I > 0 and barisKanan[I-1] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kanan' % (I-1))
if I + k < n and barisKiri[I+k] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kiri' % (I+k))
if I + k >= n:
mapping['%d-Kanan' % (I)].append('Gol')
#print(mapping)
start = ['0-Kiri']
for tinggiAir in range(n):
#print(start)
if 'Gol' in start:
break
akhir = []
for I in start:
if int(I.split("-")[0]) >= tinggiAir:
akhir.extend(mapping[I])
start = list(set(akhir))
if 'Gol' in start:
print("YES")
else:
print("NO") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is *n* meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to *n* from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up; - climb one area down; - jump to the opposite wall. That gets the ninja to the area that is exactly *k* meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area *x* of one wall, then after the jump he is located at area *x*<=+<=*k* of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than *n*, then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of *n* characters. The *i*-th character represents the state of the *i*-th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
Output Specification:
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
Demo Input:
['7 3\n---X--X\n-X--XX-\n', '6 2\n--X-X-\nX--XX-\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon. | ```python
n , k = input().split(" ")
n = int(n)
k = int(k)
barisKiri = input()
barisKanan = input()
# buat adjacency mapping
mapping = {}
for I in range(n):
mapping['%d-Kiri' % (I)] = []
if I+1 < n and barisKiri[I+1] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kiri' % (I+1))
if I > 0 and barisKiri[I-1] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kiri' % (I-1))
if I + k < n and barisKanan[I+k] == '-' :
mapping['%d-Kiri' % (I)].append('%d-Kanan' % (I+k))
if I + k >= n:
mapping['%d-Kiri' % (I)].append('Gol')
for I in range(n):
mapping['%d-Kanan' % (I)] = []
if I+1 < n and barisKanan[I+1] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kanan' % (I+1))
if I > 0 and barisKanan[I-1] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kanan' % (I-1))
if I + k < n and barisKiri[I+k] == '-' :
mapping['%d-Kanan' % (I)].append('%d-Kiri' % (I+k))
if I + k >= n:
mapping['%d-Kanan' % (I)].append('Gol')
#print(mapping)
start = ['0-Kiri']
for tinggiAir in range(n):
#print(start)
if 'Gol' in start:
break
akhir = []
for I in start:
if int(I.split("-")[0]) >= tinggiAir:
akhir.extend(mapping[I])
start = list(set(akhir))
if 'Gol' in start:
print("YES")
else:
print("NO")
``` | 0 |
|
808 | B | Average Sleep Time | PROGRAMMING | 1,300 | [
"data structures",
"implementation",
"math"
] | null | null | It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks. | The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point. | [
"3 2\n3 4 7\n",
"1 1\n10\n",
"8 2\n1 2 4 100000 123 456 789 1\n"
] | [
"9.0000000000\n",
"10.0000000000\n",
"28964.2857142857\n"
] | In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | 0 | [
{
"input": "3 2\n3 4 7",
"output": "9.0000000000"
},
{
"input": "1 1\n10",
"output": "10.0000000000"
},
{
"input": "8 2\n1 2 4 100000 123 456 789 1",
"output": "28964.2857142857"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n100000",
"output": "100000.0000000000"
},
{
"input": "3 1\n1 2 3",
"output": "2.0000000000"
},
{
"input": "10 4\n11 3 5 20 12 7 9 2 2 20",
"output": "36.2857142857"
},
{
"input": "10 5\n15 9 3 2 17 10 9 18 4 19",
"output": "50.3333333333"
},
{
"input": "10 6\n19 3 20 16 14 10 1 13 7 3",
"output": "65.8000000000"
},
{
"input": "10 7\n8 16 2 13 15 9 5 13 9 2",
"output": "68.2500000000"
},
{
"input": "10 4\n127 1459 718 1183 880 1044 1857 1340 725 1496",
"output": "4574.4285714286"
},
{
"input": "10 5\n1384 1129 1780 1960 1567 1928 12 1523 1165 344",
"output": "6931.3333333333"
}
] | 1,621,438,302 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 77 | 0 | import math
n, k = map(int, input().split())
arr = [int(z) for z in input().split()]
if n == k:
print((f'{sum(arr):.6f}'))
exit()
res = 0
if k >= math.ceil(n/2):
for i in range(n-k+1):
res += arr[i] * (i+1)
#print(arr[i], i+1, res)
for i in range(n-k+1, 2* (n-k)):
res += arr[i] * (n-k+1)
#print(arr[i], n-k+1, res, 'bruh')
for i in range(2*(n-k), n):
res += arr[i] * (n-i)
#print(arr[i], n-i, res)
else:
for i in range(k - 1):
res += arr[i] * (i + 1)
res += arr[-(i + 1)] * (i + 1)
# print(arr[i], arr[-(i+1)], res)
for i in range(k - 1, n - k + 1):
res += arr[i] * (k)
# print(arr[i], k, res, 'bruh')
print(res/(n-k+1))
| Title: Average Sleep Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts *k* days!
When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last *n* days. So now he has a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the sleep time on the *i*-th day.
The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider *k* consecutive days as a week. So there will be *n*<=-<=*k*<=+<=1 weeks to take into consideration. For example, if *k*<==<=2, *n*<==<=3 and *a*<==<=[3,<=4,<=7], then the result is .
You should write a program which will calculate average sleep times of Polycarp over all weeks.
Input Specification:
The first line contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
Output Specification:
Output average sleeping time over all weeks.
The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=6. In particular, it is enough to output real number with at least 6 digits after the decimal point.
Demo Input:
['3 2\n3 4 7\n', '1 1\n10\n', '8 2\n1 2 4 100000 123 456 789 1\n']
Demo Output:
['9.0000000000\n', '10.0000000000\n', '28964.2857142857\n']
Note:
In the third example there are *n* - *k* + 1 = 7 weeks, so the answer is sums of all weeks divided by 7. | ```python
import math
n, k = map(int, input().split())
arr = [int(z) for z in input().split()]
if n == k:
print((f'{sum(arr):.6f}'))
exit()
res = 0
if k >= math.ceil(n/2):
for i in range(n-k+1):
res += arr[i] * (i+1)
#print(arr[i], i+1, res)
for i in range(n-k+1, 2* (n-k)):
res += arr[i] * (n-k+1)
#print(arr[i], n-k+1, res, 'bruh')
for i in range(2*(n-k), n):
res += arr[i] * (n-i)
#print(arr[i], n-i, res)
else:
for i in range(k - 1):
res += arr[i] * (i + 1)
res += arr[-(i + 1)] * (i + 1)
# print(arr[i], arr[-(i+1)], res)
for i in range(k - 1, n - k + 1):
res += arr[i] * (k)
# print(arr[i], k, res, 'bruh')
print(res/(n-k+1))
``` | 0 |
|
402 | C | Searching for Graph | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"graphs"
] | null | null | Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=+<=*p* edges.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
Your task is to find a *p*-interesting graph consisting of *n* vertices. | The first line contains a single integer *t* (1<=≤<=*t*<=≤<=5) — the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=≤<=*n*<=≤<=24; *p*<=≥<=0; ) — the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the required graph exists. | For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to *n*.
Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them. | [
"1\n6 0\n"
] | [
"1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"
] | none | 1,500 | [
{
"input": "1\n6 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6"
},
{
"input": "1\n5 0",
"output": "1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5"
},
{
"input": "5\n6 0\n5 0\n7 0\n8 0\n9 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6"
},
{
"input": "5\n6 1\n5 0\n7 1\n8 1\n9 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n4 5\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 5\n3 6\n3 7"
},
{
"input": "5\n24 0\n23 0\n22 0\n21 0\n24 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23..."
},
{
"input": "5\n24 1\n23 1\n22 1\n21 1\n20 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n..."
},
{
"input": "5\n20 0\n19 0\n18 0\n17 0\n16 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 1..."
},
{
"input": "5\n15 0\n14 0\n13 0\n12 0\n11 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n2 3..."
},
{
"input": "5\n10 0\n20 0\n24 0\n19 0\n17 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13..."
},
{
"input": "5\n24 0\n23 0\n24 1\n23 1\n22 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23..."
},
{
"input": "5\n24 0\n24 0\n24 0\n24 0\n24 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22..."
},
{
"input": "5\n23 0\n23 0\n23 0\n23 0\n23 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n3 4\n3 5\n..."
},
{
"input": "5\n19 1\n18 1\n17 1\n16 1\n15 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n2 3\n..."
},
{
"input": "5\n15 1\n14 1\n13 1\n12 1\n11 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n..."
},
{
"input": "5\n24 2\n24 1\n24 0\n23 0\n23 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n..."
},
{
"input": "5\n24 10\n23 50\n24 228\n24 200\n23 150",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2..."
},
{
"input": "5\n24 228\n24 228\n24 228\n24 228\n24 228",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
},
{
"input": "5\n20 1\n20 0\n19 0\n20 0\n20 0",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n3 4\n3 5\n3 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13..."
},
{
"input": "5\n21 1\n19 1\n18 1\n20 1\n17 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n..."
},
{
"input": "5\n10 1\n11 1\n12 1\n13 1\n14 1",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n3 4\n3 5\n3 6\n3 7\n1 2\n1 3\n1..."
},
{
"input": "1\n24 100",
"output": "1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n1 11\n1 12\n1 13\n1 14\n1 15\n1 16\n1 17\n1 18\n1 19\n1 20\n1 21\n1 22\n1 23\n1 24\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n2 13\n2 14\n2 15\n2 16\n2 17\n2 18\n2 19\n2 20\n2 21\n2 22\n2 23\n2 24\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n3 13\n3 14\n3 15\n3 16\n3 17\n3 18\n3 19\n3 20\n3 21\n3 22\n3 23\n3 24\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n4 11\n4 12\n4 13\n4 14\n4 15\n4 16\n4 17\n4 18\n4 19\n4 20\n4 21\n4 22\n4 23\n4 24\n5 6\n5 7\n5 8\n5 9\n5..."
}
] | 1,636,386,845 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 77 | 33,587,200 | def construct(n, p):
for i in range (2*n + p):
pos = i % n
# 1, ...
cycle = (i // n) + 1
neighbor = (pos + cycle) % n
# convert to 1-index
print(pos+1, neighbor+1)
for _ in range(int(input())):
n, p = [int(x) for x in input().split()]
construct(n,p)
| Title: Searching for Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call an undirected graph of *n* vertices *p*-interesting, if the following conditions fulfill:
- the graph contains exactly 2*n*<=+<=*p* edges; - the graph doesn't contain self-loops and multiple edges; - for any integer *k* (1<=≤<=*k*<=≤<=*n*), any subgraph consisting of *k* vertices contains at most 2*k*<=+<=*p* edges.
A subgraph of a graph is some set of the graph vertices and some set of the graph edges. At that, the set of edges must meet the condition: both ends of each edge from the set must belong to the chosen set of vertices.
Your task is to find a *p*-interesting graph consisting of *n* vertices.
Input Specification:
The first line contains a single integer *t* (1<=≤<=*t*<=≤<=5) — the number of tests in the input. Next *t* lines each contains two space-separated integers: *n*, *p* (5<=≤<=*n*<=≤<=24; *p*<=≥<=0; ) — the number of vertices in the graph and the interest value for the appropriate test.
It is guaranteed that the required graph exists.
Output Specification:
For each of the *t* tests print 2*n*<=+<=*p* lines containing the description of the edges of a *p*-interesting graph: the *i*-th line must contain two space-separated integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*) — two vertices, connected by an edge in the resulting graph. Consider the graph vertices numbered with integers from 1 to *n*.
Print the answers to the tests in the order the tests occur in the input. If there are multiple solutions, you can print any of them.
Demo Input:
['1\n6 0\n']
Demo Output:
['1 2\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n']
Note:
none | ```python
def construct(n, p):
for i in range (2*n + p):
pos = i % n
# 1, ...
cycle = (i // n) + 1
neighbor = (pos + cycle) % n
# convert to 1-index
print(pos+1, neighbor+1)
for _ in range(int(input())):
n, p = [int(x) for x in input().split()]
construct(n,p)
``` | 3 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,602,611,129 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | s = input()
word = "hello"
ans = 0
i = 0
for char in s:
if char == word[i]:
i += 1
if i == len(word):
ans = 1
break
if ans == 1:
print("YES")
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
s = input()
word = "hello"
ans = 0
i = 0
for char in s:
if char == word[i]:
i += 1
if i == len(word):
ans = 1
break
if ans == 1:
print("YES")
else:
print("NO")
``` | 3.9455 |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33",
"output": "NO"
},
{
"input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7",
"output": "NO"
},
{
"input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38",
"output": "NO"
},
{
"input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6",
"output": "YES"
},
{
"input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0",
"output": "YES"
},
{
"input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0",
"output": "YES"
},
{
"input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0",
"output": "YES"
},
{
"input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0",
"output": "YES"
},
{
"input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0",
"output": "YES"
},
{
"input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87",
"output": "YES"
},
{
"input": "3\n1 2 3\n3 2 1\n0 0 0",
"output": "NO"
},
{
"input": "2\n5 -23 12\n0 0 0",
"output": "NO"
},
{
"input": "1\n0 0 0",
"output": "YES"
},
{
"input": "1\n1 -2 0",
"output": "NO"
},
{
"input": "2\n-23 77 -86\n23 -77 86",
"output": "YES"
},
{
"input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82",
"output": "YES"
},
{
"input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0",
"output": "YES"
},
{
"input": "3\n96 49 -12\n2 -66 28\n-98 17 -16",
"output": "YES"
},
{
"input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0",
"output": "YES"
},
{
"input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53",
"output": "YES"
},
{
"input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1",
"output": "YES"
},
{
"input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0",
"output": "YES"
},
{
"input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0",
"output": "YES"
},
{
"input": "3\n0 2 -2\n1 -1 3\n-3 0 0",
"output": "NO"
}
] | 1,593,268,225 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 6,656,000 | t=int(input())
count=0
for i in range(t):
a,b,c=map(int,input().strip().split())
count=count+(a+b+c)
if(count==0):
print("YES")
else:
print("NO")
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Output Specification:
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
Demo Input:
['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n']
Demo Output:
['NO', 'YES']
Note:
none | ```python
t=int(input())
count=0
for i in range(t):
a,b,c=map(int,input().strip().split())
count=count+(a+b+c)
if(count==0):
print("YES")
else:
print("NO")
``` | 0 |
182 | E | Wooden Fence | PROGRAMMING | 1,800 | [
"dp"
] | null | null | Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to produce a board of this type that is a rectangular *a**i* by *b**i* block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length *l*, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
- there are no two successive boards of the same type - the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the *i*-th board in the fence is different from the *i*<=-<=1-th board's type; besides, the *i*-th board's length is equal to the *i*<=-<=1-th board's width (for all *i*, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length *l*.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109<=+<=7). | The first line contains two integers *n* and *l* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*l*<=≤<=3000) — the number of different board types and the fence length, correspondingly. Next *n* lines contain descriptions of board types: the *i*-th line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the sizes of the board of the *i*-th type. All numbers on the lines are separated by spaces. | Print a single integer — the sought number of variants modulo 1000000007 (109<=+<=7). | [
"2 3\n1 2\n2 3\n",
"1 2\n2 2\n",
"6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n"
] | [
"2\n",
"1\n",
"20\n"
] | In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
- As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3. - Use one board of the second type after you turn it. That makes its length equal 3, and width — 2. | 1,500 | [
{
"input": "2 3\n1 2\n2 3",
"output": "2"
},
{
"input": "1 2\n2 2",
"output": "1"
},
{
"input": "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1",
"output": "20"
},
{
"input": "4 3\n1 2\n1 1\n3 1\n2 2",
"output": "4"
},
{
"input": "4 6\n1 1\n1 2\n3 1\n5 10",
"output": "0"
},
{
"input": "5 10\n1 2\n2 3\n1 2\n3 1\n2 4",
"output": "50"
},
{
"input": "1 4\n4 1",
"output": "1"
},
{
"input": "1 3\n1 1",
"output": "0"
},
{
"input": "4 6\n2 1\n1 2\n2 1\n2 1",
"output": "216"
},
{
"input": "4 10\n4 5\n5 3\n1 4\n1 2",
"output": "2"
},
{
"input": "5 8\n3 1\n2 1\n2 3\n2 1\n3 1",
"output": "62"
},
{
"input": "10 11\n3 10\n10 2\n2 6\n7 6\n8 1\n2 3\n7 10\n8 2\n6 5\n2 5",
"output": "10"
},
{
"input": "8 20\n18 18\n14 15\n8 4\n5 9\n2 7\n9 2\n9 19\n2 11",
"output": "0"
},
{
"input": "6 7\n3 1\n2 1\n1 2\n4 5\n2 5\n2 1",
"output": "94"
},
{
"input": "7 4\n1 2\n2 2\n3 3\n3 3\n1 1\n3 3\n3 1",
"output": "9"
},
{
"input": "100 3000\n1 4\n2 1\n3 3\n1 1\n5 4\n4 1\n2 1\n5 4\n1 1\n3 3\n4 3\n3 4\n4 2\n2 4\n1 2\n3 4\n5 3\n1 4\n2 4\n4 5\n1 2\n5 2\n2 2\n3 2\n4 4\n1 4\n5 5\n3 4\n4 1\n3 3\n5 2\n3 3\n4 1\n1 5\n4 3\n5 3\n4 2\n3 3\n3 5\n5 1\n5 1\n3 3\n4 3\n1 3\n4 1\n2 3\n1 3\n1 2\n5 5\n5 2\n1 5\n4 2\n1 1\n1 1\n1 2\n4 4\n5 4\n2 5\n1 3\n5 3\n1 1\n3 5\n1 4\n5 2\n2 3\n1 3\n5 1\n3 4\n5 1\n5 3\n3 2\n2 4\n5 2\n2 5\n5 4\n2 4\n1 1\n2 1\n2 3\n4 4\n1 5\n2 2\n1 3\n3 1\n3 2\n5 2\n5 5\n2 5\n2 3\n3 2\n4 1\n2 3\n5 1\n4 2\n2 4\n2 1\n5 3\n5 4\n1 1\n2 3",
"output": "440706472"
},
{
"input": "20 20\n2 1\n1 1\n2 3\n2 1\n2 1\n3 3\n2 3\n1 2\n1 1\n1 1\n2 3\n2 3\n1 3\n2 2\n2 1\n3 2\n2 1\n1 1\n1 3\n3 3",
"output": "379149793"
},
{
"input": "13 10\n4 2\n1 3\n3 3\n2 2\n3 1\n3 4\n4 1\n1 3\n2 3\n1 3\n3 1\n3 3\n2 1",
"output": "4551"
},
{
"input": "10 50\n9 7\n2 2\n7 9\n10 9\n6 1\n8 10\n10 5\n7 5\n4 5\n8 1",
"output": "42"
},
{
"input": "10 30\n12 21\n2 8\n19 7\n7 1\n27 14\n13 3\n14 7\n19 26\n21 17\n17 30",
"output": "1"
},
{
"input": "10 5\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "65610"
},
{
"input": "100 2000\n2 2\n2 1\n2 2\n1 2\n1 2\n2 2\n1 2\n1 2\n2 2\n2 1\n1 1\n2 2\n2 2\n2 1\n2 2\n2 2\n1 1\n2 2\n1 2\n2 2\n1 1\n2 1\n2 1\n2 1\n1 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n1 2\n2 2\n1 2\n2 1\n2 2\n2 2\n1 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n2 1\n2 1\n1 1\n2 1\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 1\n1 2\n1 2\n2 1\n2 2\n1 2\n2 1\n2 2\n1 2\n2 1\n2 1\n2 2\n1 2\n2 2\n1 1\n2 2\n2 1\n2 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 1\n2 1\n2 1\n2 2\n2 1\n1 1\n2 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n1 2\n2 1\n2 2\n2 1\n1 1\n2 2",
"output": "842986379"
},
{
"input": "100 2000\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "370055910"
},
{
"input": "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2 1\n1 3\n1 3\n1 3\n1 1\n1 3\n3 1\n2 3\n1 3\n2 2\n2 1\n2 1\n2 3\n3 2\n1 2\n2 2\n1 3\n1 1\n1 3\n3 3\n1 3\n3 2\n1 3\n2 1\n2 3\n2 3\n2 3\n3 2\n1 2\n1 3\n2 3\n1 3\n2 1\n3 2\n3 3\n1 1\n3 1\n3 3\n1 3\n3 2\n3 2\n2 2\n1 3\n2 2\n3 2\n1 3\n2 2\n2 1\n3 2\n1 3\n3 2\n1 2\n2 2\n1 3\n1 1\n3 3\n2 2\n3 1\n3 3",
"output": "548967810"
},
{
"input": "100 2500\n3 1\n3 2\n3 2\n3 1\n1 1\n1 2\n3 3\n1 2\n1 2\n3 1\n3 3\n3 2\n1 3\n2 1\n2 3\n2 2\n1 3\n2 2\n2 2\n1 1\n2 3\n1 3\n1 2\n3 1\n2 3\n2 3\n3 1\n2 3\n2 3\n3 1\n1 1\n3 2\n2 3\n3 3\n3 2\n3 1\n3 2\n3 1\n2 1\n1 3\n2 2\n2 2\n3 2\n1 2\n3 1\n3 2\n3 1\n1 2\n3 1\n3 1\n3 1\n2 3\n1 3\n1 3\n2 2\n1 2\n3 3\n3 2\n3 2\n3 3\n3 3\n2 1\n1 2\n3 2\n1 2\n2 3\n1 2\n2 3\n2 3\n3 2\n3 1\n2 3\n1 2\n1 1\n1 1\n3 1\n2 3\n2 1\n2 3\n3 2\n1 1\n3 3\n1 3\n3 2\n3 2\n2 2\n2 2\n2 2\n1 1\n1 2\n1 2\n3 3\n1 1\n3 2\n1 2\n2 2\n3 3\n2 2\n1 2\n2 3",
"output": "563987225"
},
{
"input": "30 2800\n25 12\n43 10\n38 39\n14 8\n35 41\n19 11\n23 5\n28 2\n7 36\n9 36\n38 32\n28 29\n18 31\n22 6\n25 34\n43 25\n36 33\n14 24\n13 40\n1 1\n19 44\n37 18\n7 17\n18 14\n44 35\n15 37\n43 23\n34 29\n3 21\n31 47",
"output": "0"
},
{
"input": "50 100\n45 74\n41 31\n84 56\n14 8\n25 94\n71 76\n35 8\n66 67\n27 54\n67 91\n71 20\n71 91\n7 58\n13 34\n47 60\n68 32\n74 58\n78 55\n67 40\n22 67\n27 59\n2 2\n89 62\n90 60\n41 57\n66 24\n65 93\n55 8\n94 2\n82 81\n91 67\n63 68\n24 12\n95 49\n48 63\n30 23\n32 86\n10 98\n89 71\n73 35\n85 60\n22 46\n9 50\n79 75\n24 53\n48 17\n22 61\n26 49\n89 58\n77 56",
"output": "2"
},
{
"input": "40 700\n11 14\n4 14\n14 13\n12 9\n14 10\n3 9\n7 7\n5 15\n1 11\n5 7\n2 9\n7 5\n3 10\n5 14\n4 11\n13 6\n4 6\n3 9\n1 11\n8 13\n6 4\n12 10\n10 14\n8 2\n1 15\n13 13\n6 11\n7 2\n7 12\n8 7\n1 13\n13 7\n12 10\n1 7\n7 1\n4 4\n10 7\n1 4\n13 8\n13 10",
"output": "964762206"
},
{
"input": "60 900\n38 15\n10 1\n14 37\n13 1\n40 15\n31 26\n31 4\n12 5\n28 34\n37 7\n28 34\n11 30\n30 16\n27 18\n11 18\n17 6\n38 22\n31 37\n20 38\n21 23\n11 12\n24 35\n36 8\n13 13\n34 39\n20 15\n17 3\n23 17\n18 23\n26 18\n11 2\n18 30\n25 25\n32 40\n9 38\n37 39\n39 37\n5 10\n15 19\n14 21\n34 8\n7 36\n29 3\n11 21\n32 2\n21 40\n10 33\n36 39\n15 31\n38 16\n4 14\n6 16\n31 18\n15 23\n1 38\n32 24\n13 12\n15 15\n24 11\n24 27",
"output": "457432849"
},
{
"input": "50 2000\n12 1\n11 29\n7 4\n18 27\n25 17\n28 5\n1 17\n10 29\n10 21\n8 7\n23 4\n20 7\n8 24\n2 27\n13 13\n14 15\n19 15\n7 26\n24 13\n8 25\n7 11\n18 11\n19 1\n30 15\n3 24\n27 7\n24 25\n7 7\n14 23\n3 24\n25 10\n25 3\n4 11\n22 29\n27 28\n23 5\n3 6\n16 3\n30 18\n16 22\n24 7\n11 1\n10 23\n2 3\n27 28\n28 25\n20 21\n25 3\n10 3\n7 25",
"output": "771010208"
},
{
"input": "1 3000\n78 92",
"output": "0"
},
{
"input": "50 30\n9 35\n1 48\n17 43\n41 39\n28 7\n14 10\n3 45\n35 37\n31 27\n11 16\n40 8\n4 7\n15 33\n29 17\n41 45\n11 24\n6 8\n6 2\n2 42\n19 34\n7 36\n14 15\n26 2\n22 33\n15 22\n49 23\n10 41\n6 17\n21 11\n15 37\n49 26\n49 49\n15 29\n12 49\n22 13\n7 49\n25 32\n7 7\n31 37\n23 14\n5 37\n14 6\n44 21\n8 16\n22 7\n43 44\n36 44\n4 26\n22 46\n4 21",
"output": "12"
},
{
"input": "30 80\n27 10\n39 39\n87 45\n70 82\n20 50\n45 51\n67 31\n43 96\n87 26\n59 20\n42 22\n69 71\n10 30\n39 59\n42 100\n4 67\n21 55\n83 69\n33 81\n37 43\n57 12\n30 83\n34 12\n35 32\n11 12\n51 96\n100 68\n96 20\n50 61\n46 61",
"output": "1"
},
{
"input": "100 3000\n1 1\n3 3\n3 2\n1 1\n3 2\n1 3\n1 3\n1 1\n2 3\n2 3\n3 2\n1 3\n3 3\n1 1\n3 1\n2 3\n3 1\n2 1\n3 2\n3 2\n2 2\n1 2\n3 3\n3 3\n3 3\n3 3\n1 3\n3 2\n2 3\n3 2\n3 1\n1 1\n3 1\n1 3\n1 2\n2 1\n3 2\n2 3\n3 1\n3 2\n3 1\n2 1\n1 3\n1 1\n3 3\n2 2\n3 2\n3 3\n2 2\n2 3\n3 3\n2 3\n2 2\n3 3\n3 3\n1 1\n2 3\n1 1\n3 3\n3 3\n2 2\n1 2\n3 2\n3 3\n3 3\n3 3\n3 1\n1 2\n1 1\n1 1\n2 1\n1 2\n3 2\n2 3\n3 2\n1 1\n2 1\n2 2\n1 1\n1 2\n1 3\n2 2\n2 3\n2 1\n1 2\n3 1\n3 1\n3 3\n2 3\n1 1\n3 3\n2 2\n1 3\n3 1\n2 3\n2 2\n3 2\n1 1\n3 3\n3 2",
"output": "936413338"
},
{
"input": "100 3000\n3 3\n2 1\n3 3\n4 1\n2 4\n3 1\n3 4\n1 2\n3 4\n4 3\n2 2\n2 3\n4 2\n3 3\n1 3\n4 3\n3 1\n4 3\n2 2\n2 4\n2 2\n3 2\n2 1\n3 4\n1 1\n1 1\n1 2\n1 3\n2 4\n3 4\n2 4\n2 3\n3 1\n4 1\n1 3\n2 2\n3 2\n2 2\n3 3\n2 2\n4 4\n4 3\n1 3\n2 3\n1 3\n1 1\n2 3\n3 3\n4 2\n2 2\n1 1\n1 3\n4 4\n3 3\n4 2\n1 4\n4 4\n2 4\n1 3\n2 3\n1 3\n1 1\n4 4\n3 2\n2 1\n4 4\n2 1\n2 1\n2 3\n3 3\n2 4\n2 1\n4 1\n3 1\n2 3\n1 2\n1 1\n1 1\n2 2\n1 1\n4 1\n4 4\n3 2\n2 2\n1 4\n2 2\n4 3\n2 2\n4 1\n2 1\n4 2\n2 4\n2 1\n3 4\n4 2\n2 4\n3 4\n2 1\n1 1\n1 2",
"output": "822253206"
}
] | 1,680,289,086 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 498 | 4,710,400 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return 2 * n * u + v
n, l = map(int, input().split())
mod = pow(10, 9) + 7
a, b = [], []
for _ in range(n):
a0, b0 = map(int, input().split())
a.append(a0)
b.append(b0)
if a0 == b0:
a0, b0 = l + 1, l + 1
a.append(b0)
b.append(a0)
G = [[] for _ in range(2 * n)]
for i in range(2 * n):
for j in range(2 * n):
if i // 2 == j // 2:
continue
if b[i] == a[j]:
G[i].append(j)
m = 2 * n * (l + 1)
dp = [0] * m
for i in range(2 * n):
if a[i] <= l:
dp[f(a[i], i)] = 1
for i in range(1, l):
for j in range(2 * n):
u = f(i, j)
if not dp[u]:
continue
for k in G[j]:
if i + a[k] <= l:
dp[f(i + a[k], k)] += dp[u]
dp[f(i + a[k], k)] %= mod
ans = 0
for i in range(2 * n):
ans += dp[f(l, i)]
ans %= mod
print(ans) | Title: Wooden Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently bought some land and decided to surround it with a wooden fence.
He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to produce a board of this type that is a rectangular *a**i* by *b**i* block.
Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards.
Vasya is required to construct a fence of length *l*, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled:
- there are no two successive boards of the same type - the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one
In other words, the fence is considered beautiful, if the type of the *i*-th board in the fence is different from the *i*<=-<=1-th board's type; besides, the *i*-th board's length is equal to the *i*<=-<=1-th board's width (for all *i*, starting from 2).
Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length *l*.
Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers *n* and *l* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*l*<=≤<=3000) — the number of different board types and the fence length, correspondingly. Next *n* lines contain descriptions of board types: the *i*-th line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the sizes of the board of the *i*-th type. All numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the sought number of variants modulo 1000000007 (109<=+<=7).
Demo Input:
['2 3\n1 2\n2 3\n', '1 2\n2 2\n', '6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n']
Demo Output:
['2\n', '1\n', '20\n']
Note:
In the first sample there are exactly two variants of arranging a beautiful fence of length 3:
- As the first fence board use the board of the first type of length 1 and width 2. As the second board use board of the second type of length 2 and width 3. - Use one board of the second type after you turn it. That makes its length equal 3, and width — 2. | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def f(u, v):
return 2 * n * u + v
n, l = map(int, input().split())
mod = pow(10, 9) + 7
a, b = [], []
for _ in range(n):
a0, b0 = map(int, input().split())
a.append(a0)
b.append(b0)
if a0 == b0:
a0, b0 = l + 1, l + 1
a.append(b0)
b.append(a0)
G = [[] for _ in range(2 * n)]
for i in range(2 * n):
for j in range(2 * n):
if i // 2 == j // 2:
continue
if b[i] == a[j]:
G[i].append(j)
m = 2 * n * (l + 1)
dp = [0] * m
for i in range(2 * n):
if a[i] <= l:
dp[f(a[i], i)] = 1
for i in range(1, l):
for j in range(2 * n):
u = f(i, j)
if not dp[u]:
continue
for k in G[j]:
if i + a[k] <= l:
dp[f(i + a[k], k)] += dp[u]
dp[f(i + a[k], k)] %= mod
ans = 0
for i in range(2 * n):
ans += dp[f(l, i)]
ans %= mod
print(ans)
``` | 3 |
|
895 | A | Pizza Separation | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. | Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya. | [
"4\n90 90 90 90\n",
"3\n100 100 160\n",
"1\n360\n",
"4\n170 30 150 10\n"
] | [
"0\n",
"40\n",
"360\n",
"0\n"
] | In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | 500 | [
{
"input": "4\n90 90 90 90",
"output": "0"
},
{
"input": "3\n100 100 160",
"output": "40"
},
{
"input": "1\n360",
"output": "360"
},
{
"input": "4\n170 30 150 10",
"output": "0"
},
{
"input": "5\n10 10 10 10 320",
"output": "280"
},
{
"input": "8\n45 45 45 45 45 45 45 45",
"output": "0"
},
{
"input": "3\n120 120 120",
"output": "120"
},
{
"input": "5\n110 90 70 50 40",
"output": "40"
},
{
"input": "2\n170 190",
"output": "20"
},
{
"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10",
"output": "10"
},
{
"input": "5\n30 60 180 60 30",
"output": "0"
},
{
"input": "2\n359 1",
"output": "358"
},
{
"input": "5\n100 100 30 100 30",
"output": "40"
},
{
"input": "5\n36 34 35 11 244",
"output": "128"
},
{
"input": "5\n96 94 95 71 4",
"output": "18"
},
{
"input": "2\n85 275",
"output": "190"
},
{
"input": "3\n281 67 12",
"output": "202"
},
{
"input": "5\n211 113 25 9 2",
"output": "62"
},
{
"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1",
"output": "212"
},
{
"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "92"
},
{
"input": "50\n148 53 32 11 4 56 8 2 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 358",
"output": "356"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341",
"output": "322"
},
{
"input": "33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 328",
"output": "296"
},
{
"input": "70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291",
"output": "222"
},
{
"input": "130\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 231",
"output": "102"
},
{
"input": "200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161",
"output": "0"
},
{
"input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139",
"output": "0"
},
{
"input": "10\n8 3 11 4 1 10 10 1 8 304",
"output": "248"
},
{
"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283",
"output": "206"
},
{
"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275",
"output": "190"
},
{
"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280",
"output": "200"
},
{
"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275",
"output": "190"
},
{
"input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189",
"output": "18"
},
{
"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189",
"output": "18"
},
{
"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168",
"output": "0"
},
{
"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5",
"output": "0"
},
{
"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68",
"output": "0"
},
{
"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "6\n27 15 28 34 41 215",
"output": "70"
},
{
"input": "7\n41 38 41 31 22 41 146",
"output": "14"
},
{
"input": "8\n24 27 34 23 29 23 30 170",
"output": "20"
},
{
"input": "9\n11 11 20 20 33 32 35 26 172",
"output": "6"
},
{
"input": "10\n36 13 28 13 33 34 23 25 34 121",
"output": "0"
},
{
"input": "11\n19 37 13 41 37 15 32 12 19 35 100",
"output": "10"
},
{
"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41",
"output": "2"
},
{
"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28",
"output": "2"
},
{
"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44",
"output": "4"
},
{
"input": "3\n95 91 174",
"output": "12"
},
{
"input": "4\n82 75 78 125",
"output": "46"
},
{
"input": "6\n87 75 88 94 15 1",
"output": "4"
},
{
"input": "10\n27 52 58 64 45 64 1 19 2 28",
"output": "12"
},
{
"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1",
"output": "0"
},
{
"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3",
"output": "0"
},
{
"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1",
"output": "0"
},
{
"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2",
"output": "0"
},
{
"input": "5\n35 80 45 100 100",
"output": "40"
},
{
"input": "4\n90 179 90 1",
"output": "2"
},
{
"input": "5\n50 50 20 160 80",
"output": "0"
},
{
"input": "5\n30 175 30 5 120",
"output": "10"
},
{
"input": "4\n170 30 10 150",
"output": "20"
},
{
"input": "6\n90 30 90 30 90 30",
"output": "60"
},
{
"input": "4\n70 80 110 100",
"output": "20"
},
{
"input": "7\n35 45 70 100 10 10 90",
"output": "0"
},
{
"input": "6\n50 90 10 90 20 100",
"output": "20"
},
{
"input": "6\n10 155 162 1 26 6",
"output": "18"
},
{
"input": "7\n80 90 80 45 10 10 45",
"output": "20"
},
{
"input": "4\n18 36 162 144",
"output": "36"
},
{
"input": "5\n20 50 50 160 80",
"output": "40"
},
{
"input": "5\n10 30 140 20 160",
"output": "0"
},
{
"input": "6\n90 80 60 50 40 40",
"output": "20"
},
{
"input": "9\n40 20 20 20 20 20 20 40 160",
"output": "40"
},
{
"input": "4\n90 54 90 126",
"output": "72"
},
{
"input": "4\n150 170 30 10",
"output": "20"
},
{
"input": "8\n130 12 13 85 41 67 5 7",
"output": "26"
},
{
"input": "7\n70 170 20 10 30 30 30",
"output": "20"
},
{
"input": "8\n100 100 50 50 15 15 15 15",
"output": "40"
},
{
"input": "4\n100 70 80 110",
"output": "20"
},
{
"input": "5\n160 130 40 20 10",
"output": "20"
},
{
"input": "4\n20 149 151 40",
"output": "22"
},
{
"input": "4\n100 10 100 150",
"output": "60"
},
{
"input": "6\n19 64 105 168 1 3",
"output": "16"
},
{
"input": "8\n10 10 70 70 90 90 10 10",
"output": "0"
}
] | 1,511,860,530 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 420 | 6,348,800 | n=int(input())
a=[int (i) for i in input().split()]
min=361
for i in range(n):
for j in range(i, n):
if -min<sum(a[0:i])+sum(a[j:])-sum(a[i:j])<min:
min=sum(a[0:i])+sum(a[j:])-sum(a[i:j])
if min<0:
min*=-1
print(min) | Title: Pizza Separation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360) — the number of pieces into which the delivered pizza was cut.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360) — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Output Specification:
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
Demo Input:
['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n']
Demo Output:
['0\n', '40\n', '360\n', '0\n']
Note:
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. | ```python
n=int(input())
a=[int (i) for i in input().split()]
min=361
for i in range(n):
for j in range(i, n):
if -min<sum(a[0:i])+sum(a[j:])-sum(a[i:j])<min:
min=sum(a[0:i])+sum(a[j:])-sum(a[i:j])
if min<0:
min*=-1
print(min)
``` | 3 |
|
278 | A | Circle Line | PROGRAMMING | 800 | [
"implementation"
] | null | null | The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces. | Print a single number — the length of the shortest path between stations number *s* and *t*. | [
"4\n2 3 4 9\n1 3\n",
"4\n5 8 2 100\n4 1\n",
"3\n1 1 1\n3 1\n",
"3\n31 41 59\n1 1\n"
] | [
"5\n",
"15\n",
"1\n",
"0\n"
] | In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | 500 | [
{
"input": "4\n2 3 4 9\n1 3",
"output": "5"
},
{
"input": "4\n5 8 2 100\n4 1",
"output": "15"
},
{
"input": "3\n1 1 1\n3 1",
"output": "1"
},
{
"input": "3\n31 41 59\n1 1",
"output": "0"
},
{
"input": "5\n16 13 10 30 15\n4 2",
"output": "23"
},
{
"input": "6\n89 82 87 32 67 33\n4 4",
"output": "0"
},
{
"input": "7\n2 3 17 10 2 2 2\n4 2",
"output": "18"
},
{
"input": "3\n4 37 33\n3 3",
"output": "0"
},
{
"input": "8\n87 40 96 7 86 86 72 97\n6 8",
"output": "158"
},
{
"input": "10\n91 94 75 99 100 91 79 86 79 92\n2 8",
"output": "348"
},
{
"input": "19\n1 1 1 1 2 1 1 1 1 1 2 1 3 2 2 1 1 1 2\n7 7",
"output": "0"
},
{
"input": "34\n96 65 24 99 74 76 97 93 99 69 94 82 92 91 98 83 95 97 96 81 90 95 86 87 43 78 88 86 82 62 76 99 83 96\n21 16",
"output": "452"
},
{
"input": "50\n75 98 65 75 99 89 84 65 9 53 62 61 61 53 80 7 6 47 86 1 89 27 67 1 31 39 53 92 19 20 76 41 60 15 29 94 76 82 87 89 93 38 42 6 87 36 100 97 93 71\n2 6",
"output": "337"
},
{
"input": "99\n1 15 72 78 23 22 26 98 7 2 75 58 100 98 45 79 92 69 79 72 33 88 62 9 15 87 17 73 68 54 34 89 51 91 28 44 20 11 74 7 85 61 30 46 95 72 36 18 48 22 42 46 29 46 86 53 96 55 98 34 60 37 75 54 1 81 20 68 84 19 18 18 75 84 86 57 73 34 23 43 81 87 47 96 57 41 69 1 52 44 54 7 85 35 5 1 19 26 7\n4 64",
"output": "1740"
},
{
"input": "100\n33 63 21 27 49 82 86 93 43 55 4 72 89 85 5 34 80 7 23 13 21 49 22 73 89 65 81 25 6 92 82 66 58 88 48 96 1 1 16 48 67 96 84 63 87 76 20 100 36 4 31 41 35 62 55 76 74 70 68 41 4 16 39 81 2 41 34 73 66 57 41 89 78 93 68 96 87 47 92 60 40 58 81 12 19 74 56 83 56 61 83 97 26 92 62 52 39 57 89 95\n71 5",
"output": "2127"
},
{
"input": "100\n95 98 99 81 98 96 100 92 96 90 99 91 98 98 91 78 97 100 96 98 87 93 96 99 91 92 96 92 90 97 85 83 99 95 66 91 87 89 100 95 100 88 99 84 96 79 99 100 94 100 99 99 92 89 99 91 100 94 98 97 91 92 90 87 84 99 97 98 93 100 90 85 75 95 86 71 98 93 91 87 92 95 98 94 95 94 100 98 96 100 97 96 95 95 86 86 94 97 98 96\n67 57",
"output": "932"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 99 100 100 99 99 100 99 100 100 100 100 100 100 100 100 100 97 99 98 98 100 98 98 100 99 100 100 100 100 99 100 98 100 99 98 99 98 98 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 98 100 99 99 100 96 100 96 100 99 100 100 99 100 99 100 100 100 99 100 100 100 100 98 98 97 100 100 99 98\n16 6",
"output": "997"
},
{
"input": "100\n3 6 23 4 23 1 2 14 2 3 3 9 17 8 10 5 1 14 8 5 7 4 13 8 5 6 24 3 12 3 4 9 2 8 2 1 2 1 3 2 1 6 14 23 8 6 3 5 7 8 18 9 2 5 22 6 13 16 2 4 31 20 4 3 3 6 6 1 1 18 5 11 1 14 4 16 6 37 11 1 8 3 7 11 21 14 3 3 12 2 5 1 9 16 3 1 3 4 4 2\n98 24",
"output": "195"
},
{
"input": "100\n1 1 3 1 1 2 1 2 1 1 2 2 2 1 1 1 1 1 1 3 1 1 1 3 1 3 3 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 3 3 2 1 1 1 1 1 2 2 1 3 1 1 1 2 4 1 1 2 5 2 1 1 2 1 1 1 2 3 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 2 3 1 7 3 1 3 1 2 1 2 1\n49 10",
"output": "60"
},
{
"input": "100\n75 62 31 96 62 76 93 96 72 67 88 35 67 34 60 56 95 86 82 48 64 61 74 100 56 98 76 98 78 55 53 10 12 78 58 45 86 90 93 77 69 73 88 66 92 88 33 50 95 69 89 12 93 57 93 89 59 53 71 86 15 13 61 93 24 100 58 76 46 95 76 82 50 20 79 38 5 72 99 81 55 90 90 65 85 44 63 39 6 34 98 72 88 30 59 73 84 61 25 67\n86 25",
"output": "2523"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n1 51",
"output": "5000"
},
{
"input": "4\n1 1 1 1\n2 4",
"output": "2"
},
{
"input": "4\n1 1 2 1\n2 4",
"output": "2"
}
] | 1,547,180,761 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 248 | 0 | nb_elems = [int(x) for x in input().split()]
elems = [int(x) for x in input().split()]
src, tgt = [int(x) for x in input().split()]
mins = min(src, tgt)
maxs = max(src, tgt)
sums = sum(elems)
clockwise = sum(elems[mins-1:maxs-1])
aclocwise = sums - clockwise
print(min(clockwise, aclocwise))
| Title: Circle Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations:
- *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th station;- *d**n* is the distance between the *n*-th and the 1-st station.
The trains go along the circle line in both directions. Find the shortest distance between stations with numbers *s* and *t*.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≤<=*d**i*<=≤<=100) — the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≤<=*s*,<=*t*<=≤<=*n*) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same.
The numbers in the lines are separated by single spaces.
Output Specification:
Print a single number — the length of the shortest path between stations number *s* and *t*.
Demo Input:
['4\n2 3 4 9\n1 3\n', '4\n5 8 2 100\n4 1\n', '3\n1 1 1\n3 1\n', '3\n31 41 59\n1 1\n']
Demo Output:
['5\n', '15\n', '1\n', '0\n']
Note:
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.
In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.
In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.
In the fourth sample the numbers of stations are the same, so the shortest distance equals 0. | ```python
nb_elems = [int(x) for x in input().split()]
elems = [int(x) for x in input().split()]
src, tgt = [int(x) for x in input().split()]
mins = min(src, tgt)
maxs = max(src, tgt)
sums = sum(elems)
clockwise = sum(elems[mins-1:maxs-1])
aclocwise = sums - clockwise
print(min(clockwise, aclocwise))
``` | 3 |
|
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,698,000,279 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | n=int(input())
res=0
for i in range(n):
messi=input()
a,b,c=messi.split()
a=int(a)
b=int(b)
c=int(c)
s=a+b+c
if s>=2:
res=res+1
print(res)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
n=int(input())
res=0
for i in range(n):
messi=input()
a,b,c=messi.split()
a=int(a)
b=int(b)
c=int(c)
s=a+b+c
if s>=2:
res=res+1
print(res)
``` | 3 |
|
855 | B | Marvolo Gaunt's Ring | PROGRAMMING | 1,500 | [
"brute force",
"data structures",
"dp"
] | null | null | Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made.
Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. | First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. | [
"5 1 2 3\n1 2 3 4 5\n",
"5 1 2 -3\n-1 -2 -3 -4 -5\n"
] | [
"30\n",
"12\n"
] | In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | 1,000 | [
{
"input": "5 1 2 3\n1 2 3 4 5",
"output": "30"
},
{
"input": "5 1 2 -3\n-1 -2 -3 -4 -5",
"output": "12"
},
{
"input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777",
"output": "376059240645059046"
},
{
"input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876",
"output": "547306902373544674"
},
{
"input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162",
"output": "1876641179289775029"
},
{
"input": "1 0 0 0\n0",
"output": "0"
},
{
"input": "1 1000000000 1000000000 1000000000\n1000000000",
"output": "3000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 1000000000\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 -1000000000\n1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1000000000 1000000000 1000000000\n-1000000000 -1000000000 -1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 1 1\n-1",
"output": "-3"
},
{
"input": "1 -1 -1 -1\n1",
"output": "-3"
},
{
"input": "1 1000000000 1000000000 1000000000\n-1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 1 2 3\n-1",
"output": "-6"
},
{
"input": "3 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "2 -1000000000 -1000000000 -1000000000\n1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "3 1 1 1\n-1 -1 -1",
"output": "-3"
},
{
"input": "1 -1000000000 0 0\n1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -100 -100 -100\n100",
"output": "-30000"
},
{
"input": "5 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000",
"output": "-3000000000000000000"
},
{
"input": "1 999999999 999999999 999999999\n-999999999",
"output": "-2999999994000000003"
},
{
"input": "3 -1000000000 -1000000000 1\n1000000000 1000000000 1000000000",
"output": "-1999999999000000000"
},
{
"input": "3 -2 3 -2\n1 2 1",
"output": "2"
},
{
"input": "2 1 -1 1\n1 -1",
"output": "1"
},
{
"input": "1 -1000000000 1 -1000000000\n1000000000",
"output": "-1999999999000000000"
},
{
"input": "1 1000000000 1000000000 -1000000000\n-1000000000",
"output": "-1000000000000000000"
},
{
"input": "1 -1000000000 -1000000000 0\n1000000000",
"output": "-2000000000000000000"
}
] | 1,675,766,309 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 82 | 77 | 14,233,600 | def main():
n, p, q, r = map(int, input().split())
a = list(map(int, input().split()))
ans = -float('inf')
mx = -float('inf')
mx1 = -float('inf')
for i in range(n):
mx = max(mx, a[i] * p)
mx1 = max(mx1, mx + a[i] * q)
ans = max(ans, mx1 + a[i] * r)
print(ans)
if __name__ == '__main__':
main() | Title: Marvolo Gaunt's Ring
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made.
Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative.
Input Specification:
First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105).
Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*.
Demo Input:
['5 1 2 3\n1 2 3 4 5\n', '5 1 2 -3\n-1 -2 -3 -4 -5\n']
Demo Output:
['30\n', '12\n']
Note:
In the first sample case, we can take *i* = *j* = *k* = 5, thus making the answer as 1·5 + 2·5 + 3·5 = 30.
In second sample case, selecting *i* = *j* = 1 and *k* = 5 gives the answer 12. | ```python
def main():
n, p, q, r = map(int, input().split())
a = list(map(int, input().split()))
ans = -float('inf')
mx = -float('inf')
mx1 = -float('inf')
for i in range(n):
mx = max(mx, a[i] * p)
mx1 = max(mx1, mx + a[i] * q)
ans = max(ans, mx1 + a[i] * r)
print(ans)
if __name__ == '__main__':
main()
``` | 3 |
|
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggglgpep",
"output": "2"
},
{
"input": "iegdlraaidefgegiagrdfhihe",
"output": "2"
},
{
"input": "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg",
"output": "1"
},
{
"input": "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw",
"output": "2"
},
{
"input": "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbkvviwntdhqscvkmphnkkljizndnbjt",
"output": "3"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"output": "99"
},
{
"input": "ikiikiikikiiikkkkkikkkkiiiiikkiiikkiikiikkkkikkkikikkikiiikkikikiiikikkkiiikkkikkikkikkkkiiikkiiiiii",
"output": "10"
},
{
"input": "ovovhoovvhohhhvhhvhhvhovoohovhhoooooovohvooooohvvoooohvvovhhvhovhhvoovhvhvoovovvhooovhhooovohvhhovhv",
"output": "8"
},
{
"input": "ccwckkkycccccckwckwkwkwkkkkyycykcccycyckwywcckwykcycykkkwcycwwcykcwkwkwwykwkwcykywwwyyykckkyycckwcwk",
"output": "5"
},
{
"input": "ttketfkefktfztezzkzfkkeetkkfktftzktezekkeezkeeetteeteefetefkzzzetekfftkeffzkktffzkzzeftfeezfefzffeef",
"output": "4"
},
{
"input": "rtharczpfznrgdnkltchafduydgbgkdjqrmjqyfmpwjwphrtsjbmswkanjlprbnduaqbcjqxlxmkspkhkcnzbqwxonzxxdmoigti",
"output": "2"
},
{
"input": "fplrkfklvwdeiynbjgaypekambmbjfnoknlhczhkdmljicookdywdgpnlnqlpunnkebnikgcgcjefeqhknvlynmvjcegvcdgvvdb",
"output": "2"
},
{
"input": "txbciieycswqpniwvzipwlottivvnfsysgzvzxwbctcchfpvlbcjikdofhpvsknptpjdbxemtmjcimetkemdbettqnbvzzbdyxxb",
"output": "2"
},
{
"input": "fmubmfwefikoxtqvmaavwjxmoqltapexkqxcsztpezfcltqavuicefxovuswmqimuikoppgqpiapqutkczgcvxzutavkujxvpklv",
"output": "3"
},
{
"input": "ipsrjylhpkjvlzncfixipstwcicxqygqcfrawpzzvckoveyqhathglblhpkjvlzncfixipfajaqobtzvthmhgbuawoxoknirclxg",
"output": "15"
},
{
"input": "kcnjsntjzcbgzjscrsrjkrbytqsrptzspzctjrorsyggrtkcnjsntjzcbgzjscrsrjyqbrtpcgqirsrrjbbbrnyqstnrozcoztt",
"output": "20"
},
{
"input": "unhcfnrhsqetuerjqcetrhlsqgfnqfntvkgxsscquolxxroqgtchffyccetrhlsqgfnqfntvkgxsscquolxxroqgtchffhfqvx",
"output": "37"
},
{
"input": "kkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckkkkkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckckckkc",
"output": "46"
},
{
"input": "mlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydbrxdmlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydik",
"output": "47"
},
{
"input": "abcdefghijklmnopqrstuvwxyz",
"output": "0"
},
{
"input": "tttttbttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttmttttttt",
"output": "85"
},
{
"input": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffff",
"output": "61"
},
{
"input": "cccccccccccccccccccccccwcccccccccccccccccccccuccccccccccccccnccccccccccccccccccccccccccccccccccccccc",
"output": "38"
},
{
"input": "ffffffffffffffffffffffffffufffgfffffffffffffffffffffffffffffffffffffffgffffffftffffffgffffffffffffff",
"output": "38"
},
{
"input": "rrrrrrrrrrrrrrrrrrrlhbrrrrrrrrurrrrrrrfrrqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrewrrrrrrryrrxrrrrrrrrrrr",
"output": "33"
},
{
"input": "vyvvvvvvvvzvvvvvzvvvwvvvvrvvvvvvvvvvvvvvvrvvvvvvvvvpkvvpvgvvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvysvvvbvvvv",
"output": "17"
},
{
"input": "cbubbbbbbbbbbfbbbbbbbbjbobbbbbbbbbbibbubbbbjbbbnzgbbzbbfbbbbbbbbbbbfbpbbbbbbbbbbygbbbgbabbbbbbbhibbb",
"output": "12"
},
{
"input": "lrqrrrrrrrjrrrrrcdrrgrrmwvrrrrrrrrrxfzrmrmrryrrrurrrdrrrrrrrrrrererrrsrrrrrrrrrrrqrrrrcrrwjsrrlrrrrr",
"output": "10"
},
{
"input": "ssssusisisosscssssztzessssyspskjssvosiissussszsosssslsssdsssvssvsssslsssmsfjasjsssssowscsjsssszsspss",
"output": "8"
},
{
"input": "uukuuuumueuuuujuukgdhbztuuuubbguuocuozfaunqufjujuguyuuvkuuauubuubuucuvtjuuuuuusduduuuuuuuueunuuuuuzu",
"output": "7"
},
{
"input": "jpkkgwklngwqcfzmwkkpcwkkkkkekkkekkkdsykqwjkkkhkkkxdnukkkkkkmkqykkkxqklkskkrkkkkkqqjikkkkkkpknkkkkkoh",
"output": "7"
},
{
"input": "bmzbbfbbhqxwthtbbisbbbbbtbbfbbpbfbbpbkbjfbcbbbbzbbbdwmbbbrnvqdbbtbbuglrnbbbbvmbyblebbabibrevaxbbjbqb",
"output": "6"
},
{
"input": "qqqmqqqsbteqqopsuqiqumrqzpqnqgqeniqqkyqqyqqqpxzqeqqquhdqquhqqqfqjirqaqqaquxqoqqjqqqqbjbgqcqqqqicnkqc",
"output": "4"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaavaaaaaaauaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "44"
},
{
"input": "a",
"output": "0"
},
{
"input": "fg",
"output": "0"
},
{
"input": "yy",
"output": "1"
},
{
"input": "abcabcabc",
"output": "6"
},
{
"input": "qwerqwedqwes",
"output": "3"
}
] | 1,681,235,623 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | https://vjudge.net/contest/550830#rank
| Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Specification:
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
Output Specification:
Output one number — length of the longest substring that can be met in the string at least twice.
Demo Input:
['abcd\n', 'ababa\n', 'zzz\n']
Demo Output:
['0', '3', '2']
Note:
none | ```python
https://vjudge.net/contest/550830#rank
``` | -1 |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 17 21 10 11 100 23 10",
"output": "1"
},
{
"input": "52\n1 12 3 11 4 5 10 6 9 7 8 2",
"output": "6"
},
{
"input": "50\n2 2 3 4 5 4 4 5 7 3 2 7",
"output": "-1"
},
{
"input": "0\n55 81 28 48 99 20 67 95 6 19 10 93",
"output": "0"
},
{
"input": "93\n85 40 93 66 92 43 61 3 64 51 90 21",
"output": "1"
},
{
"input": "99\n36 34 22 0 0 0 52 12 0 0 33 47",
"output": "2"
},
{
"input": "99\n28 32 31 0 10 35 11 18 0 0 32 28",
"output": "3"
},
{
"input": "99\n19 17 0 1 18 11 29 9 29 22 0 8",
"output": "4"
},
{
"input": "76\n2 16 11 10 12 0 20 4 4 14 11 14",
"output": "5"
},
{
"input": "41\n2 1 7 7 4 2 4 4 9 3 10 0",
"output": "6"
},
{
"input": "47\n8 2 2 4 3 1 9 4 2 7 7 8",
"output": "7"
},
{
"input": "58\n6 11 7 0 5 6 3 9 4 9 5 1",
"output": "8"
},
{
"input": "32\n5 2 4 1 5 0 5 1 4 3 0 3",
"output": "9"
},
{
"input": "31\n6 1 0 4 4 5 1 0 5 3 2 0",
"output": "9"
},
{
"input": "35\n2 3 0 0 6 3 3 4 3 5 0 6",
"output": "9"
},
{
"input": "41\n3 1 3 4 3 6 6 1 4 4 0 6",
"output": "11"
},
{
"input": "97\n0 5 3 12 10 16 22 8 21 17 21 10",
"output": "5"
},
{
"input": "100\n21 21 0 0 4 13 0 26 0 0 0 15",
"output": "6"
},
{
"input": "100\n0 0 16 5 22 0 5 0 25 0 14 13",
"output": "7"
},
{
"input": "97\n17 0 10 0 0 0 18 0 14 23 15 0",
"output": "6"
},
{
"input": "100\n0 9 0 18 7 0 0 14 33 3 0 16",
"output": "7"
},
{
"input": "95\n5 2 13 0 15 18 17 0 6 11 0 8",
"output": "9"
},
{
"input": "94\n11 13 0 9 15 8 8 16 3 7 1 3",
"output": "11"
},
{
"input": "96\n8 4 12 15 8 0 4 10 6 6 12 11",
"output": "11"
},
{
"input": "100\n5 5 3 8 6 5 0 3 3 8 1 3",
"output": "-1"
},
{
"input": "100\n1 0 0 1 1 0 1 1 1 1 2 1",
"output": "-1"
},
{
"input": "100\n6 3 2 0 4 1 2 2 2 2 1 1",
"output": "-1"
},
{
"input": "0\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
},
{
"input": "0\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100",
"output": "1"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "12"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 2",
"output": "12"
},
{
"input": "15\n10 1 1 1 1 1 1 1 1 1 1 1",
"output": "6"
},
{
"input": "1\n0 0 0 0 0 0 0 0 0 0 0 0",
"output": "-1"
}
] | 1,695,726,047 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | k = int(input())
a = sorted(map(int, input().split()), reverse=True)
res = cur_height = 0
for i in a:
cur_height += i
if cur_height >= k:
break
res += 1
if cur_height >= k:
print(res)
else:
print(-1)
| Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters.
Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
Input Specification:
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Output Specification:
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
Demo Input:
['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all. | ```python
k = int(input())
a = sorted(map(int, input().split()), reverse=True)
res = cur_height = 0
for i in a:
cur_height += i
if cur_height >= k:
break
res += 1
if cur_height >= k:
print(res)
else:
print(-1)
``` | 0 |
|
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details. | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them. | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
},
{
"input": "1\nXO|OX",
"output": "NO"
},
{
"input": "1\nOO|OO",
"output": "YES\n++|OO"
},
{
"input": "4\nXO|XX\nXX|XO\nOX|XX\nXO|XO",
"output": "NO"
},
{
"input": "9\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|OO\nOX|OX\nOX|XO\nOX|OX",
"output": "YES\nOX|XO\nOX|XO\nXO|OX\nOX|OX\nXO|OX\nXX|++\nOX|OX\nOX|XO\nOX|OX"
},
{
"input": "61\nOX|XX\nOX|XX\nOX|XX\nXO|XO\nXX|XO\nXX|XX\nXX|XX\nOX|XX\nXO|XO\nOX|XO\nXO|OX\nXX|XX\nXX|XX\nOX|OX\nXX|OX\nOX|XO\nOX|XO\nXO|OX\nXO|XX\nOX|XX\nOX|XX\nXO|OX\nXO|XX\nXO|XX\nOX|XX\nXX|XX\nXX|XO\nXO|XX\nXX|XX\nXO|OX\nXX|XO\nXO|XX\nXO|XO\nXO|OX\nXX|OX\nXO|OX\nOX|XX\nXX|OX\nXX|XX\nOX|XO\nOX|XX\nXO|OX\nOX|XX\nOX|XX\nXO|XO\nXO|XX\nOX|XX\nXO|XO\nOX|XX\nXX|XX\nOX|XO\nXO|XO\nXO|XO\nOX|OX\nXX|OX\nXX|OX\nOX|XO\nOX|XX\nOX|OX\nXO|XX\nOX|XX",
"output": "NO"
},
{
"input": "1\nOO|XX",
"output": "YES\n++|XX"
},
{
"input": "10\nOO|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX",
"output": "YES\n++|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|XX"
},
{
"input": "10\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|OO",
"output": "YES\nXX|XX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXO|OX\nXX|++"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nOO|OX\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\n++|OX\nOX|XO"
},
{
"input": "6\nOO|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX",
"output": "YES\n++|XX\nXO|XX\nOX|OO\nXX|OX\nOO|XX\nOX|XX"
}
] | 1,635,760,692 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 4,505,600 | n = int(input())
a = []
checker = True
for i in range(n):
a.append(input().split('|'))
if a[i][0] == 'OO' and checker:
checker = False
a[i][0] = "++"
elif a[i][1] == "OO" and checker:
checker = False
a[i][1] = "++"
if checker:
print("NO")
else:
print("YES")
for i in range(n):
print(f"{a[i][0]}|{a[i][1]}")
| Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris are good friends. They insist to get a pair of neighbouring empty seats. Two seats are considered neighbouring if they are in the same row and in the same pair. Given the configuration of the bus, can you help ZS and Chris determine where they should sit?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and the last two of them denote the second pair of seats in the row.
Each character, except the walkway, equals to 'O' or to 'X'. 'O' denotes an empty seat, 'X' denotes an occupied seat. See the sample cases for more details.
Output Specification:
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by exactly two charaters (they should be equal to 'O' in the input and to '+' in the output).
If there is no pair of seats for Chris and ZS, print "NO" (without quotes) in a single line.
If there are multiple solutions, you may print any of them.
Demo Input:
['6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', '4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n', '5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n']
Demo Output:
['YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n', 'NO\n', 'YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n']
Note:
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | ```python
n = int(input())
a = []
checker = True
for i in range(n):
a.append(input().split('|'))
if a[i][0] == 'OO' and checker:
checker = False
a[i][0] = "++"
elif a[i][1] == "OO" and checker:
checker = False
a[i][1] = "++"
if checker:
print("NO")
else:
print("YES")
for i in range(n):
print(f"{a[i][0]}|{a[i][1]}")
``` | 3 |
|
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "480",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "49",
"output": "YES"
},
{
"input": "56",
"output": "YES"
},
{
"input": "124",
"output": "YES"
},
{
"input": "1000",
"output": "YES"
},
{
"input": "999",
"output": "NO"
},
{
"input": "298",
"output": "NO"
},
{
"input": "274",
"output": "NO"
},
{
"input": "998",
"output": "NO"
},
{
"input": "42",
"output": "YES"
},
{
"input": "788",
"output": "YES"
},
{
"input": "70",
"output": "YES"
},
{
"input": "444",
"output": "YES"
},
{
"input": "777",
"output": "YES"
},
{
"input": "799",
"output": "YES"
},
{
"input": "25",
"output": "NO"
},
{
"input": "882",
"output": "YES"
},
{
"input": "88",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "YES"
},
{
"input": "94",
"output": "YES"
},
{
"input": "477",
"output": "YES"
},
{
"input": "141",
"output": "YES"
}
] | 1,698,206,081 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,048,000 | solve()
def checkLucky(y):
x=str(y)
flag=True
luckyDigits=['4','7']
for char in x:
if char not in luckyDigits:
return False
return True
def solve():
x = input()
y = int(x)
flag = checkLucky(y)
if(flag):
print("YES")
else:
for i in range(4,y//2):
if checkLucky(i) and (y%i==0):
print("YES")
print("NO")
| Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
Output Specification:
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
Demo Input:
['47\n', '16\n', '78\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | ```python
solve()
def checkLucky(y):
x=str(y)
flag=True
luckyDigits=['4','7']
for char in x:
if char not in luckyDigits:
return False
return True
def solve():
x = input()
y = int(x)
flag = checkLucky(y)
if(flag):
print("YES")
else:
for i in range(4,y//2):
if checkLucky(i) and (y%i==0):
print("YES")
print("NO")
``` | -1 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn! | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | 0 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "ab\nbb",
"output": "NO"
},
{
"input": "zzaa\naazz",
"output": "YES"
},
{
"input": "azza\nzaaz",
"output": "YES"
},
{
"input": "abc\nabc",
"output": "YES"
},
{
"input": "abc\nacb",
"output": "NO"
},
{
"input": "azzz\nzzaz",
"output": "YES"
},
{
"input": "abcd\ndcab",
"output": "YES"
},
{
"input": "abcd\ncdab",
"output": "YES"
},
{
"input": "abcd\ndcba",
"output": "YES"
},
{
"input": "abcd\nacbd",
"output": "NO"
},
{
"input": "oloaxgddgujq\noloaxgujqddg",
"output": "YES"
},
{
"input": "uwzwdxfmosmqatyv\ndxfmzwwusomqvyta",
"output": "YES"
},
{
"input": "hagnzomowtledfdotnll\nledfdotnllomowthagnz",
"output": "YES"
},
{
"input": "snyaydaeobufdg\nsnyaydaeobufdg",
"output": "YES"
},
{
"input": "baaaaa\nabaaaa",
"output": "NO"
},
{
"input": "hhiisug\nmzdjwju",
"output": "NO"
},
{
"input": "bbbabbabaaab\naaaabbabbbbb",
"output": "NO"
},
{
"input": "bbaaab\naababb",
"output": "NO"
},
{
"input": "aabbaaaa\naaaaabab",
"output": "NO"
},
{
"input": "aab\naba",
"output": "NO"
},
{
"input": "abcddd\nbacddd",
"output": "NO"
},
{
"input": "qgiufelsfhanx\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "aabaababaaba\naababaaababa",
"output": "NO"
},
{
"input": "nocdqzdriyyil\naaaaaaaaaaaaa",
"output": "NO"
},
{
"input": "zdmctxl\nkojqhgw",
"output": "NO"
},
{
"input": "yhwepqwyhwepqwyhwepqweahnqtueahnqtueahnqtuyhwepqwyhwepqwyhwepqwyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtueahnqtueahnqtueahnqtueahnqtu\neahnqtueahnqtueahnqtuyhwepqweahnqtuyhwepqwyhwepqweahnqtuyhwepqweahnqtuyhwepqweahnqtueahnqtuyhwepqweahnqtueahnqtuyhwepqwyhwepqwyhwepqw",
"output": "NO"
},
{
"input": "abc\nbac",
"output": "NO"
},
{
"input": "ottceez\npcstdvz",
"output": "NO"
}
] | 1,672,116,154 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def solve(s,t):
if len(s)!=len(t):
return False
elif s==t:
return True
elif len(s)%2 and len(t)%2:
return False
else:
g,f=s[:len(s)//2],s[len(s)//2:]
x,y=t[:len(t)//2],t[len(t)//2:]
if f==x and g==y:
return True
elif f==x:
return solve(g,y)
elif g==y:
return solve(f,x)
else:
return solve(g,y) and solve(f,x)
s=input()
t=input()
if solve(s,t):
print("YES")
else:
print("NO") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size *b*1 and *b*2, then one of the following is correct: *a*1 is equivalent to *b*1, and *a*2 is equivalent to *b*2 1. *a*1 is equivalent to *b*2, and *a*2 is equivalent to *b*1
As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.
Gerald has already completed this home task. Now it's your turn!
Input Specification:
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Output Specification:
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
Demo Input:
['aaba\nabaa\n', 'aabb\nabab\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa". | ```python
def solve(s,t):
if len(s)!=len(t):
return False
elif s==t:
return True
elif len(s)%2 and len(t)%2:
return False
else:
g,f=s[:len(s)//2],s[len(s)//2:]
x,y=t[:len(t)//2],t[len(t)//2:]
if f==x and g==y:
return True
elif f==x:
return solve(g,y)
elif g==y:
return solve(f,x)
else:
return solve(g,y) and solve(f,x)
s=input()
t=input()
if solve(s,t):
print("YES")
else:
print("NO")
``` | 0 |
|
230 | B | T-primes | PROGRAMMING | 1,300 | [
"binary search",
"implementation",
"math",
"number theory"
] | null | null | We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not. | The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier. | Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't. | [
"3\n4 5 6\n"
] | [
"YES\nNO\nNO\n"
] | The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | 500 | [
{
"input": "3\n4 5 6",
"output": "YES\nNO\nNO"
},
{
"input": "2\n48 49",
"output": "NO\nYES"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO"
},
{
"input": "1\n36",
"output": "NO"
},
{
"input": "1\n999966000289",
"output": "YES"
},
{
"input": "1\n999993399999",
"output": "NO"
},
{
"input": "9\n111 121 131 111 121 131 111 121 131",
"output": "NO\nYES\nNO\nNO\nYES\nNO\nNO\nYES\nNO"
},
{
"input": "1\n1",
"output": "NO"
},
{
"input": "1\n10",
"output": "NO"
},
{
"input": "1\n976197352729",
"output": "NO"
},
{
"input": "1\n1000000000000",
"output": "NO"
},
{
"input": "1\n9",
"output": "YES"
},
{
"input": "6\n549755813888 847288609443 762939453125 678223072849 285311670611 137858491849",
"output": "NO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "3\n223092870 6469693230 200560490130",
"output": "NO\nNO\nNO"
},
{
"input": "2\n81 25",
"output": "NO\nYES"
},
{
"input": "1\n16",
"output": "NO"
},
{
"input": "22\n1 2 3 4 5 6 7 8 9 10 12752041 64 121 144 27550356289 124 24657 23756 135153365 25235235235 42351351 81",
"output": "NO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO"
},
{
"input": "1\n225",
"output": "NO"
},
{
"input": "1\n1521",
"output": "NO"
},
{
"input": "1\n81",
"output": "NO"
}
] | 1,697,042,737 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 32 | 2,000 | 14,745,600 | import copy
import math
def isprime_slow(n):
if n < 2:
return False
elif n == 2 or n == 3:
return True
elif n % 2 == 0:
return False
else:
i = 3
while i * i <= n:
if n % i == 0:
return False
i += 2
return True
def v(q, t):
ans = 0
while t % q == 0:
ans += 1
t //= q
return ans
def prime_factorize(n):
ret = []
p = 2
while p * p <= n:
if n % p == 0:
num = 0
while n % p == 0:
num += 1
n //= p
ret.append((p, num))
p += 1
if n != 1:
ret.append((n, 1))
return ret
def e(t):
s = 1
q_list = []
for q in range(2, t + 2):
if t % (q - 1) == 0 and isprime_slow(q):
s *= q ** (1 + v(q, t))
q_list.append(q)
return 2 * s, q_list
class JacobiSum(object):
def __init__(self, p, k, q):
self.p = p
self.k = k
self.q = q
self.m = (p - 1) * p ** (k - 1)
self.pk = p**k
self.coef = [0] * self.m
def one(self):
self.coef[0] = 1
for i in range(1, self.m):
self.coef[i] = 0
return self
def mul(self, jac):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(m):
for j in range(m):
if (i + j) % pk < m:
j_ret.coef[(i + j) % pk] += self.coef[i] * jac.coef[j]
else:
r = (i + j) % pk - self.p ** (self.k - 1)
while r >= 0:
j_ret.coef[r] -= self.coef[i] * jac.coef[j]
r -= self.p ** (self.k - 1)
return j_ret
def __mul__(self, right):
if type(right) is int:
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(self.m):
j_ret.coef[i] = self.coef[i] * right
return j_ret
else:
return self.mul(right)
def modpow(self, x, n):
j_ret = JacobiSum(self.p, self.k, self.q)
j_ret.coef[0] = 1
j_a = copy.deepcopy(self)
while x > 0:
if x % 2 == 1:
j_ret = (j_ret * j_a).mod(n)
j_a = j_a * j_a
j_a.mod(n)
x //= 2
return j_ret
def mod(self, n):
for i in range(self.m):
self.coef[i] %= n
return self
def sigma(self, x):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(m):
if (i * x) % pk < m:
j_ret.coef[(i * x) % pk] += self.coef[i]
else:
r = (i * x) % pk - self.p ** (self.k - 1)
while r >= 0:
j_ret.coef[r] -= self.coef[i]
r -= self.p ** (self.k - 1)
return j_ret
def sigma_inv(self, x):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(pk):
if i < m:
if (i * x) % pk < m:
j_ret.coef[i] += self.coef[(i * x) % pk]
else:
r = i - self.p ** (self.k - 1)
while r >= 0:
if (i * x) % pk < m:
j_ret.coef[r] -= self.coef[(i * x) % pk]
r -= self.p ** (self.k - 1)
return j_ret
def is_root_of_unity(self, N):
m = self.m
p = self.p
k = self.k
one = 0
for i in range(m):
if self.coef[i] == 1:
one += 1
h = i
elif self.coef[i] == 0:
continue
elif (self.coef[i] - (-1)) % N != 0:
return False, None
if one == 1:
return True, h
for i in range(m):
if self.coef[i] != 0:
break
r = i % (p ** (k - 1))
for i in range(m):
if i % (p ** (k - 1)) == r:
if (self.coef[i] - (-1)) % N != 0:
return False, None
else:
if self.coef[i] != 0:
return False, None
return True, (p - 1) * p ** (k - 1) + r
def smallest_primitive_root(q):
for r in range(2, q):
s = set({})
m = 1
for i in range(1, q):
m = (m * r) % q
s.add(m)
if len(s) == q - 1:
return r
return None
def calc_f(q):
g = smallest_primitive_root(q)
m = {}
for x in range(1, q - 1):
m[pow(g, x, q)] = x
f = {}
for x in range(1, q - 1):
f[x] = m[(1 - pow(g, x, q)) % q]
return f
def calc_J_ab(p, k, q, a, b):
j_ret = JacobiSum(p, k, q)
f = calc_f(q)
for x in range(1, q - 1):
pk = p**k
if (a * x + b * f[x]) % pk < j_ret.m:
j_ret.coef[(a * x + b * f[x]) % pk] += 1
else:
r = (a * x + b * f[x]) % pk - p ** (k - 1)
while r >= 0:
j_ret.coef[r] -= 1
r -= p ** (k - 1)
return j_ret
def calc_J(p, k, q):
return calc_J_ab(p, k, q, 1, 1)
def calc_J3(p, k, q):
j2q = calc_J(p, k, q)
j21 = calc_J_ab(p, k, q, 2, 1)
j_ret = j2q * j21
return j_ret
def calc_J2(p, k, q):
j31 = calc_J_ab(2, 3, q, 3, 1)
j_conv = JacobiSum(p, k, q)
for i in range(j31.m):
j_conv.coef[i * (p**k) // 8] = j31.coef[i]
j_ret = j_conv * j_conv
return j_ret
def APRtest_step4a(p, k, q, N):
J = calc_J(p, k, q)
s1 = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % p == 0:
continue
t = J.sigma_inv(x)
t = t.modpow(x, N)
s1 = s1 * t
s1.mod(N)
r = N % (p**k)
s2 = s1.modpow(N // (p**k), N)
J_alpha = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % p == 0:
continue
t = J.sigma_inv(x)
t = t.modpow((r * x) // (p**k), N)
J_alpha = J_alpha * t
J_alpha.mod(N)
S = (s2 * J_alpha).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4b(p, k, q, N):
J = calc_J3(p, k, q)
s1 = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % 8 not in [1, 3]:
continue
t = J.sigma_inv(x)
t = t.modpow(x, N)
s1 = s1 * t
s1.mod(N)
r = N % (p**k)
s2 = s1.modpow(N // (p**k), N)
J_alpha = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % 8 not in [1, 3]:
continue
t = J.sigma_inv(x)
t = t.modpow((r * x) // (p**k), N)
J_alpha = J_alpha * t
J_alpha.mod(N)
if N % 8 in [1, 3]:
S = (s2 * J_alpha).mod(N)
else:
J2_delta = calc_J2(p, k, q)
S = (s2 * J_alpha * J2_delta).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0 and (pow(q, (N - 1) // 2, N) + 1) % N == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4c(p, k, q, N):
J2q = calc_J(p, k, q)
s1 = (J2q * J2q * q).mod(N)
s2 = s1.modpow(N // 4, N)
if N % 4 == 1:
S = s2
elif N % 4 == 3:
S = (s2 * J2q * J2q).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0 and (pow(q, (N - 1) // 2, N) + 1) % N == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4d(p, k, q, N):
S2q = pow(-q, (N - 1) // 2, N)
if (S2q - 1) % N != 0 and (S2q + 1) % N != 0:
return False, None
else:
if (S2q + 1) % N == 0 and (N - 1) % 4 == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4(p, k, q, N):
if p >= 3:
result, l_p = APRtest_step4a(p, k, q, N)
elif p == 2 and k >= 3:
result, l_p = APRtest_step4b(p, k, q, N)
elif p == 2 and k == 2:
result, l_p = APRtest_step4c(p, k, q, N)
elif p == 2 and k == 1:
result, l_p = APRtest_step4d(p, k, q, N)
return result, l_p
def APRtest(N):
t_list = [
2,
12,
60,
180,
840,
1260,
1680,
2520,
5040,
15120,
55440,
110880,
720720,
1441440,
4324320,
24504480,
73513440,
]
if N <= 3:
return False
for t in t_list:
et, q_list = e(t)
if N < et * et:
break
else:
return False
g = math.gcd(t * et, N)
if g > 1:
return False
l = {}
fac_t = prime_factorize(t)
for p, k in fac_t:
if p >= 3 and pow(N, p - 1, p * p) != 1:
l[p] = 1
else:
l[p] = 0
for q in q_list:
if q == 2:
continue
fac = prime_factorize(q - 1)
for p, k in fac:
result, l_p = APRtest_step4(p, k, q, N)
if not result:
return False
elif l_p == 1:
l[p] = 1
for p, value in l.items():
if value == 0:
count = 0
i = 1
found = False
while count < 30:
q = p * i + 1
if N % q != 0 and isprime_slow(q) and (q not in q_list):
count += 1
k = v(p, q - 1)
result, l_p = APRtest_step4(p, k, q, N)
if not result:
return False
elif l_p == 1:
found = True
break
i += 1
if not found:
return False
r = 1
for t in range(t - 1):
r = (r * N) % et
if r != 1 and r != N and N % r == 0:
return False
return True
bsid = int(input())
chnd = list(map(int, input().split()))
for sgrv in chnd:
if math.sqrt(sgrv).is_integer():
fxbi = int(math.sqrt(sgrv))
if APRtest(fxbi) or fxbi == 2 or fxbi == 3:
print("YES")
else:
print("NO")
else:
print("NO")
| Title: T-primes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we'll call a positive integer *t* Т-prime, if *t* has exactly three distinct positive divisors.
You are given an array of *n* positive integers. For each of them determine whether it is Т-prime or not.
Input Specification:
The first line contains a single positive integer, *n* (1<=≤<=*n*<=≤<=105), showing how many numbers are in the array. The next line contains *n* space-separated integers *x**i* (1<=≤<=*x**i*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is advised to use the cin, cout streams or the %I64d specifier.
Output Specification:
Print *n* lines: the *i*-th line should contain "YES" (without the quotes), if number *x**i* is Т-prime, and "NO" (without the quotes), if it isn't.
Demo Input:
['3\n4 5 6\n']
Demo Output:
['YES\nNO\nNO\n']
Note:
The given test has three numbers. The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is "YES". The second number 5 has two divisors (1 and 5), and the third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is "NO". | ```python
import copy
import math
def isprime_slow(n):
if n < 2:
return False
elif n == 2 or n == 3:
return True
elif n % 2 == 0:
return False
else:
i = 3
while i * i <= n:
if n % i == 0:
return False
i += 2
return True
def v(q, t):
ans = 0
while t % q == 0:
ans += 1
t //= q
return ans
def prime_factorize(n):
ret = []
p = 2
while p * p <= n:
if n % p == 0:
num = 0
while n % p == 0:
num += 1
n //= p
ret.append((p, num))
p += 1
if n != 1:
ret.append((n, 1))
return ret
def e(t):
s = 1
q_list = []
for q in range(2, t + 2):
if t % (q - 1) == 0 and isprime_slow(q):
s *= q ** (1 + v(q, t))
q_list.append(q)
return 2 * s, q_list
class JacobiSum(object):
def __init__(self, p, k, q):
self.p = p
self.k = k
self.q = q
self.m = (p - 1) * p ** (k - 1)
self.pk = p**k
self.coef = [0] * self.m
def one(self):
self.coef[0] = 1
for i in range(1, self.m):
self.coef[i] = 0
return self
def mul(self, jac):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(m):
for j in range(m):
if (i + j) % pk < m:
j_ret.coef[(i + j) % pk] += self.coef[i] * jac.coef[j]
else:
r = (i + j) % pk - self.p ** (self.k - 1)
while r >= 0:
j_ret.coef[r] -= self.coef[i] * jac.coef[j]
r -= self.p ** (self.k - 1)
return j_ret
def __mul__(self, right):
if type(right) is int:
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(self.m):
j_ret.coef[i] = self.coef[i] * right
return j_ret
else:
return self.mul(right)
def modpow(self, x, n):
j_ret = JacobiSum(self.p, self.k, self.q)
j_ret.coef[0] = 1
j_a = copy.deepcopy(self)
while x > 0:
if x % 2 == 1:
j_ret = (j_ret * j_a).mod(n)
j_a = j_a * j_a
j_a.mod(n)
x //= 2
return j_ret
def mod(self, n):
for i in range(self.m):
self.coef[i] %= n
return self
def sigma(self, x):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(m):
if (i * x) % pk < m:
j_ret.coef[(i * x) % pk] += self.coef[i]
else:
r = (i * x) % pk - self.p ** (self.k - 1)
while r >= 0:
j_ret.coef[r] -= self.coef[i]
r -= self.p ** (self.k - 1)
return j_ret
def sigma_inv(self, x):
m = self.m
pk = self.pk
j_ret = JacobiSum(self.p, self.k, self.q)
for i in range(pk):
if i < m:
if (i * x) % pk < m:
j_ret.coef[i] += self.coef[(i * x) % pk]
else:
r = i - self.p ** (self.k - 1)
while r >= 0:
if (i * x) % pk < m:
j_ret.coef[r] -= self.coef[(i * x) % pk]
r -= self.p ** (self.k - 1)
return j_ret
def is_root_of_unity(self, N):
m = self.m
p = self.p
k = self.k
one = 0
for i in range(m):
if self.coef[i] == 1:
one += 1
h = i
elif self.coef[i] == 0:
continue
elif (self.coef[i] - (-1)) % N != 0:
return False, None
if one == 1:
return True, h
for i in range(m):
if self.coef[i] != 0:
break
r = i % (p ** (k - 1))
for i in range(m):
if i % (p ** (k - 1)) == r:
if (self.coef[i] - (-1)) % N != 0:
return False, None
else:
if self.coef[i] != 0:
return False, None
return True, (p - 1) * p ** (k - 1) + r
def smallest_primitive_root(q):
for r in range(2, q):
s = set({})
m = 1
for i in range(1, q):
m = (m * r) % q
s.add(m)
if len(s) == q - 1:
return r
return None
def calc_f(q):
g = smallest_primitive_root(q)
m = {}
for x in range(1, q - 1):
m[pow(g, x, q)] = x
f = {}
for x in range(1, q - 1):
f[x] = m[(1 - pow(g, x, q)) % q]
return f
def calc_J_ab(p, k, q, a, b):
j_ret = JacobiSum(p, k, q)
f = calc_f(q)
for x in range(1, q - 1):
pk = p**k
if (a * x + b * f[x]) % pk < j_ret.m:
j_ret.coef[(a * x + b * f[x]) % pk] += 1
else:
r = (a * x + b * f[x]) % pk - p ** (k - 1)
while r >= 0:
j_ret.coef[r] -= 1
r -= p ** (k - 1)
return j_ret
def calc_J(p, k, q):
return calc_J_ab(p, k, q, 1, 1)
def calc_J3(p, k, q):
j2q = calc_J(p, k, q)
j21 = calc_J_ab(p, k, q, 2, 1)
j_ret = j2q * j21
return j_ret
def calc_J2(p, k, q):
j31 = calc_J_ab(2, 3, q, 3, 1)
j_conv = JacobiSum(p, k, q)
for i in range(j31.m):
j_conv.coef[i * (p**k) // 8] = j31.coef[i]
j_ret = j_conv * j_conv
return j_ret
def APRtest_step4a(p, k, q, N):
J = calc_J(p, k, q)
s1 = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % p == 0:
continue
t = J.sigma_inv(x)
t = t.modpow(x, N)
s1 = s1 * t
s1.mod(N)
r = N % (p**k)
s2 = s1.modpow(N // (p**k), N)
J_alpha = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % p == 0:
continue
t = J.sigma_inv(x)
t = t.modpow((r * x) // (p**k), N)
J_alpha = J_alpha * t
J_alpha.mod(N)
S = (s2 * J_alpha).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4b(p, k, q, N):
J = calc_J3(p, k, q)
s1 = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % 8 not in [1, 3]:
continue
t = J.sigma_inv(x)
t = t.modpow(x, N)
s1 = s1 * t
s1.mod(N)
r = N % (p**k)
s2 = s1.modpow(N // (p**k), N)
J_alpha = JacobiSum(p, k, q).one()
for x in range(p**k):
if x % 8 not in [1, 3]:
continue
t = J.sigma_inv(x)
t = t.modpow((r * x) // (p**k), N)
J_alpha = J_alpha * t
J_alpha.mod(N)
if N % 8 in [1, 3]:
S = (s2 * J_alpha).mod(N)
else:
J2_delta = calc_J2(p, k, q)
S = (s2 * J_alpha * J2_delta).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0 and (pow(q, (N - 1) // 2, N) + 1) % N == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4c(p, k, q, N):
J2q = calc_J(p, k, q)
s1 = (J2q * J2q * q).mod(N)
s2 = s1.modpow(N // 4, N)
if N % 4 == 1:
S = s2
elif N % 4 == 3:
S = (s2 * J2q * J2q).mod(N)
exist, h = S.is_root_of_unity(N)
if not exist:
return False, None
else:
if h % p != 0 and (pow(q, (N - 1) // 2, N) + 1) % N == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4d(p, k, q, N):
S2q = pow(-q, (N - 1) // 2, N)
if (S2q - 1) % N != 0 and (S2q + 1) % N != 0:
return False, None
else:
if (S2q + 1) % N == 0 and (N - 1) % 4 == 0:
l_p = 1
else:
l_p = 0
return True, l_p
def APRtest_step4(p, k, q, N):
if p >= 3:
result, l_p = APRtest_step4a(p, k, q, N)
elif p == 2 and k >= 3:
result, l_p = APRtest_step4b(p, k, q, N)
elif p == 2 and k == 2:
result, l_p = APRtest_step4c(p, k, q, N)
elif p == 2 and k == 1:
result, l_p = APRtest_step4d(p, k, q, N)
return result, l_p
def APRtest(N):
t_list = [
2,
12,
60,
180,
840,
1260,
1680,
2520,
5040,
15120,
55440,
110880,
720720,
1441440,
4324320,
24504480,
73513440,
]
if N <= 3:
return False
for t in t_list:
et, q_list = e(t)
if N < et * et:
break
else:
return False
g = math.gcd(t * et, N)
if g > 1:
return False
l = {}
fac_t = prime_factorize(t)
for p, k in fac_t:
if p >= 3 and pow(N, p - 1, p * p) != 1:
l[p] = 1
else:
l[p] = 0
for q in q_list:
if q == 2:
continue
fac = prime_factorize(q - 1)
for p, k in fac:
result, l_p = APRtest_step4(p, k, q, N)
if not result:
return False
elif l_p == 1:
l[p] = 1
for p, value in l.items():
if value == 0:
count = 0
i = 1
found = False
while count < 30:
q = p * i + 1
if N % q != 0 and isprime_slow(q) and (q not in q_list):
count += 1
k = v(p, q - 1)
result, l_p = APRtest_step4(p, k, q, N)
if not result:
return False
elif l_p == 1:
found = True
break
i += 1
if not found:
return False
r = 1
for t in range(t - 1):
r = (r * N) % et
if r != 1 and r != N and N % r == 0:
return False
return True
bsid = int(input())
chnd = list(map(int, input().split()))
for sgrv in chnd:
if math.sqrt(sgrv).is_integer():
fxbi = int(math.sqrt(sgrv))
if APRtest(fxbi) or fxbi == 2 or fxbi == 3:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 |
|
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city. | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 2",
"output": "4"
},
{
"input": "2\n-1000000000 -1000000000\n1000000000 1000000000",
"output": "4000000000000000000"
},
{
"input": "2\n1000000000 -1000000000\n-1000000000 1000000000",
"output": "4000000000000000000"
},
{
"input": "5\n-851545463 -208880322\n-154983867 -781305244\n293363100 785256340\n833468900 -593065920\n-920692803 -637662144",
"output": "3077083280271860209"
},
{
"input": "10\n-260530833 169589238\n-681955770 -35391010\n223450511 24504262\n479795061 -26191863\n-291344265 21153856\n714700263 -328447419\n-858655942 161086142\n-270884153 462537328\n-501424901 977460517\n115284904 -151626824",
"output": "2475449747812002025"
},
{
"input": "10\n917139470 819990899\n-69828590 691215072\n-846815289 112372447\n560780737 -890423729\n243241705 284240970\n-47397355 -263709479\n759162072 709456353\n-330469400 -597545533\n436509256 728506920\n133368867 668789238",
"output": "3111536391798748081"
},
{
"input": "10\n-200157522 -824574736\n299208799 -287211553\n-160170880 148363130\n103709327 245344406\n482860382 547328085\n895537733 -545816336\n671947380 910981768\n-43209851 585461399\n-573679087 427675821\n151452830 27262384",
"output": "3012156378576702016"
},
{
"input": "2\n-2 -2\n-3 -3",
"output": "1"
},
{
"input": "2\n-1000 -1000\n-1100 -1100",
"output": "10000"
},
{
"input": "2\n-5 -5\n-4 -4",
"output": "1"
},
{
"input": "2\n-10 0\n-9 0",
"output": "1"
},
{
"input": "2\n-10 -10\n-20 -20",
"output": "100"
},
{
"input": "2\n-1000000 -1000000\n-100 -100",
"output": "999800010000"
},
{
"input": "2\n100000000 100000000\n200000000 200000000",
"output": "10000000000000000"
},
{
"input": "2\n-10 10\n-2 3",
"output": "64"
},
{
"input": "2\n-999999999 -999999999\n-999999991 -999999991",
"output": "64"
},
{
"input": "2\n-1000 -1000\n-999 -999",
"output": "1"
},
{
"input": "2\n-3 0\n-5 0",
"output": "4"
},
{
"input": "2\n999999999 999999999\n999999991 999999991",
"output": "64"
},
{
"input": "2\n100000012 100000012\n100000012 100000013",
"output": "1"
}
] | 1,599,149,720 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | n=int(input())
s=0
for i in range(n):
x,y=map(int,input().split())
if(max(x,y)>s):
s=max(x,y)
print(s**2) | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square.
Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.
Input Specification:
The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct.
Output Specification:
Print the minimum area of the city that can cover all the mines with valuable resources.
Demo Input:
['2\n0 0\n2 2\n', '2\n0 0\n0 3\n']
Demo Output:
['4\n', '9\n']
Note:
none | ```python
n=int(input())
s=0
for i in range(n):
x,y=map(int,input().split())
if(max(x,y)>s):
s=max(x,y)
print(s**2)
``` | 0 |
|
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. | Output one number — the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron",
"output": "256"
},
{
"input": "1\nTetrahedron",
"output": "4"
},
{
"input": "1\nCube",
"output": "6"
},
{
"input": "1\nOctahedron",
"output": "8"
},
{
"input": "1\nDodecahedron",
"output": "12"
},
{
"input": "1\nIcosahedron",
"output": "20"
},
{
"input": "28\nOctahedron\nDodecahedron\nOctahedron\nOctahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nDodecahedron\nDodecahedron\nCube\nDodecahedron\nCube\nTetrahedron\nCube\nCube\nTetrahedron\nDodecahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron\nDodecahedron\nIcosahedron\nDodecahedron\nDodecahedron\nIcosahedron\nIcosahedron",
"output": "340"
}
] | 1,674,567,841 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 295 | 10,444,800 | lists=[]
for _ in range(int(input())):
lists.append(input())
s=0
for i in lists:
if i=='Tetrahedron':
s+=4
elif i=='Cube':
s+=6
elif i=='Octahedron':
s+=8
elif i=='Dodecahedron':
s+=12
elif i=='Icosahedron':
s+=20
print(s) | Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron.
Output Specification:
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
Demo Input:
['4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n', '3\nDodecahedron\nOctahedron\nOctahedron\n']
Demo Output:
['42\n', '28\n']
Note:
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces. | ```python
lists=[]
for _ in range(int(input())):
lists.append(input())
s=0
for i in lists:
if i=='Tetrahedron':
s+=4
elif i=='Cube':
s+=6
elif i=='Octahedron':
s+=8
elif i=='Dodecahedron':
s+=12
elif i=='Icosahedron':
s+=20
print(s)
``` | 3 |
|
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922",
"output": "17"
},
{
"input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000",
"output": "3"
},
{
"input": "2\nRL\n0 1000000000",
"output": "500000000"
},
{
"input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082",
"output": "108"
},
{
"input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418",
"output": "88"
},
{
"input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668",
"output": "123"
},
{
"input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808",
"output": "10"
},
{
"input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970",
"output": "252"
},
{
"input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830",
"output": "48"
},
{
"input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720",
"output": "27"
},
{
"input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402",
"output": "59"
},
{
"input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626",
"output": "10"
},
{
"input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794",
"output": "7"
},
{
"input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18",
"output": "-1"
},
{
"input": "5\nLLLLL\n0 10 20 30 40",
"output": "-1"
},
{
"input": "6\nRRRRRR\n40 50 60 70 80 100",
"output": "-1"
},
{
"input": "1\nR\n0",
"output": "-1"
},
{
"input": "2\nRL\n2 1000000000",
"output": "499999999"
},
{
"input": "2\nRL\n0 400000",
"output": "200000"
},
{
"input": "2\nRL\n0 200002",
"output": "100001"
},
{
"input": "2\nRL\n2 20000000",
"output": "9999999"
},
{
"input": "4\nLLRL\n2 4 10 100",
"output": "45"
},
{
"input": "4\nRLRL\n2 10 12 14",
"output": "1"
},
{
"input": "2\nRL\n0 100000000",
"output": "50000000"
},
{
"input": "2\nRL\n2 600002",
"output": "300000"
},
{
"input": "1\nL\n0",
"output": "-1"
},
{
"input": "2\nRL\n0 600000",
"output": "300000"
},
{
"input": "5\nRRRRR\n0 2 4 6 8",
"output": "-1"
},
{
"input": "2\nRL\n2 200000000",
"output": "99999999"
},
{
"input": "2\nRL\n0 267382766",
"output": "133691383"
},
{
"input": "3\nRRL\n4 8 999999998",
"output": "499999995"
},
{
"input": "2\nRL\n0 2",
"output": "1"
},
{
"input": "2\nRL\n2 400002",
"output": "200000"
},
{
"input": "2\nLL\n2 4",
"output": "-1"
},
{
"input": "2\nLL\n0 2",
"output": "-1"
},
{
"input": "2\nRL\n0 100000",
"output": "50000"
},
{
"input": "2\nRL\n2 200000020",
"output": "100000009"
},
{
"input": "2\nRL\n2000000 4000000",
"output": "1000000"
},
{
"input": "2\nRL\n0 199998",
"output": "99999"
},
{
"input": "3\nLRR\n40 50 60",
"output": "-1"
},
{
"input": "2\nRL\n200 400400",
"output": "200100"
},
{
"input": "2\nRL\n2 400004",
"output": "200001"
},
{
"input": "2\nRL\n0 200000000",
"output": "100000000"
}
] | 1,643,022,038 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 202 | 16,384,000 | n = int(input())
s = input()
arr = list(map(int, input().split()))
ans = []
for i in range(n):
if(i == n-1):
break
if((s[i] == "R" and s[i+1] == "L")):
ans.append(arr[i+1]-arr[i])
for i in range(len(ans)):
ans[i] = int(ans[i]/2)
if not ans:
print(-1)
else:
print(min(ans)) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output Specification:
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Demo Input:
['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n']
Demo Output:
['1\n', '-1\n']
Note:
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | ```python
n = int(input())
s = input()
arr = list(map(int, input().split()))
ans = []
for i in range(n):
if(i == n-1):
break
if((s[i] == "R" and s[i+1] == "L")):
ans.append(arr[i+1]-arr[i])
for i in range(len(ans)):
ans[i] = int(ans[i]/2)
if not ans:
print(-1)
else:
print(min(ans))
``` | 3 |
|
587 | A | Duff and Weight Lifting | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps. | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values. | Print the minimum number of steps in a single line. | [
"5\n1 1 2 3 3\n",
"4\n0 1 2 3\n"
] | [
"2\n",
"4\n"
] | In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | 500 | [
{
"input": "5\n1 1 2 3 3",
"output": "2"
},
{
"input": "4\n0 1 2 3",
"output": "4"
},
{
"input": "1\n120287",
"output": "1"
},
{
"input": "2\n28288 0",
"output": "2"
},
{
"input": "2\n95745 95745",
"output": "1"
},
{
"input": "13\n92 194 580495 0 10855 41704 13 96429 33 213 0 92 140599",
"output": "11"
},
{
"input": "13\n688743 688743 1975 688743 688743 688743 688743 688743 688743 0 0 688743 688743",
"output": "4"
},
{
"input": "35\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "3"
},
{
"input": "35\n130212 3176 77075 8071 18 1369 7539 1683 80757 1847 0 1374 122 8524 4 2 21333 270264 4 9254 151921 0 1 33596 73002 54382 0 1 29233 75952 15 38892 1877 6167 4",
"output": "31"
},
{
"input": "35\n0 0 298 0 0 0 0 0 689063 65442 0 984598 2054 43668 0 369 0 2054 0 996220 0 16327 369 0 996220 0 0 0 4693 2054 348 0 118 0 0",
"output": "16"
},
{
"input": "100\n196 1681 196 0 61 93 196 196 196 196 196 0 0 96 18 1576 0 93 666463 18 93 1 1278 8939 93 196 196 1278 3 0 67416 869956 10 56489 196 745 39 783 196 8939 196 81 69634 4552 39 3 14 20 25 8 10 4 7302 0 19579 20 1140 15990 7302 0 19579 4142 11 1354 75252 93 311 1278 0 79475 10 75252 93 7302 0 81 408441 19579 10 39 19 37748 4364 31135 47700 105818 47700 10 4142 543356 3 30647 45917 60714 8939 18 22925 7302 93 75252",
"output": "59"
}
] | 1,451,741,224 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 30,822,400 | r = int(input())
c = 0
sum = 0
l = map(int, input().split())
for x in l:
sum += (2 ** x)
n = str(bin(sum))
for i in n:
if i == '1': c += 1
print(c) | Title: Duff and Weight Lifting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to minimize the number of steps.
Duff is a competitive programming fan. That's why in each step, she can only lift and throw away a sequence of weights 2*a*1,<=...,<=2*a**k* if and only if there exists a non-negative integer *x* such that 2*a*1<=+<=2*a*2<=+<=...<=+<=2*a**k*<==<=2*x*, i. e. the sum of those numbers is a power of two.
Duff is a competitive programming fan, but not a programmer. That's why she asked for your help. Help her minimize the number of steps.
Input Specification:
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights.
The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Output Specification:
Print the minimum number of steps in a single line.
Demo Input:
['5\n1 1 2 3 3\n', '4\n0 1 2 3\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two.
In the second sample case: The only optimal way is to throw away one weight in each step. It's not possible to do it in less than 4 steps because there's no subset of weights with more than one weight and sum equal to a power of two. | ```python
r = int(input())
c = 0
sum = 0
l = map(int, input().split())
for x in l:
sum += (2 ** x)
n = str(bin(sum))
for i in n:
if i == '1': c += 1
print(c)
``` | 0 |
|
946 | B | Weird Subtraction Process | PROGRAMMING | 1,100 | [
"math",
"number theory"
] | null | null | You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends. | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*. | Print two integers — the values of *a* and *b* after the end of the process. | [
"12 5\n",
"31 12\n"
] | [
"0 1\n",
"7 12\n"
] | Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | 0 | [
{
"input": "12 5",
"output": "0 1"
},
{
"input": "31 12",
"output": "7 12"
},
{
"input": "1000000000000000000 7",
"output": "8 7"
},
{
"input": "31960284556200 8515664064180",
"output": "14928956427840 8515664064180"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "1000000000000000000 1000000000000000000"
},
{
"input": "1 1000",
"output": "1 0"
},
{
"input": "1 1000000",
"output": "1 0"
},
{
"input": "1 1000000000000000",
"output": "1 0"
},
{
"input": "1 99999999999999999",
"output": "1 1"
},
{
"input": "1 4",
"output": "1 0"
},
{
"input": "1000000000000001 500000000000000",
"output": "1 0"
},
{
"input": "1 1000000000000000000",
"output": "1 0"
},
{
"input": "2 4",
"output": "2 0"
},
{
"input": "2 1",
"output": "0 1"
},
{
"input": "6 19",
"output": "6 7"
},
{
"input": "22 5",
"output": "0 1"
},
{
"input": "10000000000000000 100000000000000001",
"output": "0 1"
},
{
"input": "1 1000000000000",
"output": "1 0"
},
{
"input": "2 1000000000000000",
"output": "2 0"
},
{
"input": "2 10",
"output": "2 2"
},
{
"input": "51 100",
"output": "51 100"
},
{
"input": "3 1000000000000000000",
"output": "3 4"
},
{
"input": "1000000000000000000 3",
"output": "4 3"
},
{
"input": "1 10000000000000000",
"output": "1 0"
},
{
"input": "8796203 7556",
"output": "1019 1442"
},
{
"input": "5 22",
"output": "1 0"
},
{
"input": "1000000000000000000 1",
"output": "0 1"
},
{
"input": "1 100000000000",
"output": "1 0"
},
{
"input": "2 1000000000000",
"output": "2 0"
},
{
"input": "5 4567865432345678",
"output": "5 8"
},
{
"input": "576460752303423487 288230376151711743",
"output": "1 1"
},
{
"input": "499999999999999999 1000000000000000000",
"output": "3 2"
},
{
"input": "1 9999999999999",
"output": "1 1"
},
{
"input": "103 1000000000000000000",
"output": "103 196"
},
{
"input": "7 1",
"output": "1 1"
},
{
"input": "100000000000000001 10000000000000000",
"output": "1 0"
},
{
"input": "5 10",
"output": "5 0"
},
{
"input": "7 11",
"output": "7 11"
},
{
"input": "1 123456789123456",
"output": "1 0"
},
{
"input": "5000000000000 100000000000001",
"output": "0 1"
},
{
"input": "1000000000000000 1",
"output": "0 1"
},
{
"input": "1000000000000000000 499999999999999999",
"output": "2 3"
},
{
"input": "10 5",
"output": "0 5"
},
{
"input": "9 18917827189272",
"output": "9 0"
},
{
"input": "179 100000000000497000",
"output": "179 270"
},
{
"input": "5 100000000000001",
"output": "1 1"
},
{
"input": "5 20",
"output": "5 0"
},
{
"input": "100000001 50000000",
"output": "1 0"
},
{
"input": "345869461223138161 835002744095575440",
"output": "1 0"
},
{
"input": "8589934592 4294967296",
"output": "0 4294967296"
},
{
"input": "4 8",
"output": "4 0"
},
{
"input": "1 100000000000000000",
"output": "1 0"
},
{
"input": "1000000000000000000 333333333333333",
"output": "1000 1333"
},
{
"input": "25 12",
"output": "1 0"
},
{
"input": "24 54",
"output": "0 6"
},
{
"input": "6 12",
"output": "6 0"
},
{
"input": "129200000000305 547300000001292",
"output": "1 0"
},
{
"input": "1000000000000000000 49999999999999999",
"output": "20 39"
},
{
"input": "1 2",
"output": "1 0"
},
{
"input": "1 123456789876",
"output": "1 0"
},
{
"input": "2 3",
"output": "2 3"
},
{
"input": "1 3",
"output": "1 1"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "19 46",
"output": "3 2"
},
{
"input": "3 6",
"output": "3 0"
},
{
"input": "129 1000000000000000000",
"output": "1 0"
},
{
"input": "12 29",
"output": "0 1"
},
{
"input": "8589934592 2147483648",
"output": "0 2147483648"
},
{
"input": "2147483648 8589934592",
"output": "2147483648 0"
},
{
"input": "5 6",
"output": "5 6"
},
{
"input": "1000000000000000000 2",
"output": "0 2"
},
{
"input": "2 7",
"output": "2 3"
},
{
"input": "17174219820754872 61797504734333370",
"output": "17174219820754872 27449065092823626"
},
{
"input": "49 100",
"output": "1 0"
},
{
"input": "7 17",
"output": "1 1"
},
{
"input": "1000000000000000000 10000001",
"output": "0 1"
},
{
"input": "49999999999999999 2",
"output": "3 2"
},
{
"input": "49999999999999999 1",
"output": "1 1"
},
{
"input": "576460752303423487 2",
"output": "3 2"
},
{
"input": "19395 19395",
"output": "19395 19395"
},
{
"input": "19394 19394",
"output": "19394 19394"
}
] | 1,548,422,341 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | c,d=map(int,input().split())
for i in range(0,10000):
if (c == 0 or d == 0):
break
elif (c >= 2 * d):
c = c - 2 * d
elif (d >= 2 * c):
d = d - 2 * c
else:
break
print(c,d)
| Title: Weird Subtraction Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two variables *a* and *b*. Consider the following sequence of actions performed with these variables:
1. If *a*<==<=0 or *b*<==<=0, end the process. Otherwise, go to step 2;1. If *a*<=≥<=2·*b*, then set the value of *a* to *a*<=-<=2·*b*, and repeat step 1. Otherwise, go to step 3;1. If *b*<=≥<=2·*a*, then set the value of *b* to *b*<=-<=2·*a*, and repeat step 1. Otherwise, end the process.
Initially the values of *a* and *b* are positive integers, and so the process will be finite.
You have to determine the values of *a* and *b* after the process ends.
Input Specification:
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1018). *n* is the initial value of variable *a*, and *m* is the initial value of variable *b*.
Output Specification:
Print two integers — the values of *a* and *b* after the end of the process.
Demo Input:
['12 5\n', '31 12\n']
Demo Output:
['0 1\n', '7 12\n']
Note:
Explanations to the samples:
1. *a* = 12, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 5 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 2, *b* = 1 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 0, *b* = 1;1. *a* = 31, *b* = 12 <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> *a* = 7, *b* = 12. | ```python
c,d=map(int,input().split())
for i in range(0,10000):
if (c == 0 or d == 0):
break
elif (c >= 2 * d):
c = c - 2 * d
elif (d >= 2 * c):
d = d - 2 * c
else:
break
print(c,d)
``` | 0 |
|
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"input": "9000",
"output": "9012"
},
{
"input": "1111",
"output": "1203"
},
{
"input": "8999",
"output": "9012"
},
{
"input": "4572",
"output": "4573"
},
{
"input": "6666",
"output": "6701"
},
{
"input": "2001",
"output": "2013"
},
{
"input": "3000",
"output": "3012"
},
{
"input": "7712",
"output": "7801"
},
{
"input": "8088",
"output": "8091"
},
{
"input": "1594",
"output": "1596"
},
{
"input": "6016",
"output": "6017"
},
{
"input": "8800",
"output": "8901"
},
{
"input": "3331",
"output": "3401"
},
{
"input": "5090",
"output": "5091"
},
{
"input": "2342",
"output": "2345"
},
{
"input": "2334",
"output": "2340"
},
{
"input": "1123",
"output": "1203"
},
{
"input": "8989",
"output": "9012"
},
{
"input": "8977",
"output": "9012"
},
{
"input": "6869",
"output": "6870"
},
{
"input": "8999",
"output": "9012"
}
] | 1,692,465,847 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a=int(input())
for i in range(a+1,9999):
b=str(a)
if (b[0] != b[1] and b[0] != b[2] and b[0] != b[3] and b[1] != b[2]and b[1] != b[3]and b[2] != b[3]):
print(i)
break | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
Input Specification:
The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number.
Output Specification:
Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists.
Demo Input:
['1987\n', '2013\n']
Demo Output:
['2013\n', '2014\n']
Note:
none | ```python
a=int(input())
for i in range(a+1,9999):
b=str(a)
if (b[0] != b[1] and b[0] != b[2] and b[0] != b[3] and b[1] != b[2]and b[1] != b[3]and b[2] != b[3]):
print(i)
break
``` | 0 |
|
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. | The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it. | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "0"
},
{
"input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk",
"output": "1"
},
{
"input": "1 1\np",
"output": "0"
},
{
"input": "2 5\nacdmw\nefazb",
"output": "1"
},
{
"input": "5 2\ndz\nda\nsx\nyu\nzz",
"output": "0"
},
{
"input": "5 5\nxeljd\nwriac\nveief\nlcacf\nbqefn",
"output": "2"
},
{
"input": "5 5\nacnbx\nefacp\nlrefa\norqce\nzvbay",
"output": "3"
},
{
"input": "5 5\nbyjvu\nkmaca\nalefe\nwcacg\nrefez",
"output": "5"
},
{
"input": "5 5\npuxac\nbbaef\naccfa\nefaec\nligsr",
"output": "5"
},
{
"input": "37 4\nacjo\nefac\nacef\nefac\nwpef\nicac\naefe\ncfac\naece\ncfaf\nyqce\nmiaf\nirce\nycaf\naefc\ncfae\nrsnc\nbacz\nqefb\npdhs\nffac\nfaef\nacfd\nacmi\nefvm\nacaz\nefpn\nacao\nefer\nacap\nefec\nacaf\nefef\nacbj\nefac\nacef\nefoz",
"output": "49"
},
{
"input": "7 3\njac\naef\ncfa\naec\ncfq\ndig\nxyq",
"output": "5"
},
{
"input": "35 1\ny\na\nk\ng\ni\nd\nv\nn\nl\nx\nu\nx\nu\no\nd\nf\nk\nj\nr\nm\nq\ns\nc\nd\nc\nm\nv\nh\nn\ne\nl\nt\nz\ny\no",
"output": "0"
},
{
"input": "9 46\nuuexbaacesjclggslacermcbkxlcxhdgqtacdwfryxzuxc\naclrsaefakndbnzlkefenuphgcgoedhkaxefjtnkgfeaca\nefuqunpmfxdyyffyhvracozzrxlpekhtsrfhlilfmyhefg\numyacfzffvicqtdpiulefnwcojuwtfbvlxkfsiapdnzpqo\nactefvuxqptremlqjhdbdwacjxdxitxjktecvefacamjcz\neflarseklqrkayhosverpfefzirqigzlxezabhzeferkwm\nztpypwxyohtacsnnvoigqwcachtaceyxlkhfhgwbnfmklb\nfzpqeymhljiefctvqtbgcdjefkxefarbciyosmktmoziac\nbssxizyrzyhacszttwhrzspbfkgfcejybdjcpuczhrkqef",
"output": "20"
},
{
"input": "7 30\nmjfracgaacacctacrreyrlkacuacay\nrlacefacefeftaeftkacacaefcefev\nacefacefacraccfaeaefefecaeacaf\nefacefacefaefaecfcfacacaecfefa\nncefacefacecacfaeaecefefcaeace\nfafaceacuafaefadcfcafacaefcfea\nzsvefafukcecfarkaeaecefecailgu",
"output": "95"
},
{
"input": "2 2\nff\nee",
"output": "0"
},
{
"input": "2 2\nfa\ncc",
"output": "0"
},
{
"input": "2 2\nfa\naa",
"output": "0"
},
{
"input": "2 2\nfa\nea",
"output": "0"
},
{
"input": "2 2\nfa\ndd",
"output": "0"
},
{
"input": "2 2\nee\nff",
"output": "0"
},
{
"input": "2 2\ncc\ncf",
"output": "0"
},
{
"input": "2 2\naa\nae",
"output": "0"
},
{
"input": "2 2\nef\nac",
"output": "1"
},
{
"input": "2 2\nfe\nca",
"output": "1"
}
] | 1,433,600,468 | 4,868 | Python 3 | COMPILATION_ERROR | PRETESTS | 0 | 0 | 0 | n,m =[int(i) for i in input().split()]
a = []
for i in range(n):
a.append(input())
ans = 0
for i in range(n-1):
for j in range(m-1):
v = [a[i][j],a[i][j +1], a[i+1][j], a[i+1][j+1]]
v.sort()
if v == ['a',
'c','e','f']:
ans = ans + 1
print7888) | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face".
You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap.
Input Specification:
The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters.
Output Specification:
In the single line print the number of faces on the image.
Demo Input:
['4 4\nxxxx\nxfax\nxcex\nxxxx\n', '4 2\nxx\ncf\nae\nxx\n', '2 3\nfac\ncef\n', '1 4\nface\n']
Demo Output:
['1\n', '1\n', '2\n', '0\n']
Note:
In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In the fourth sample the image has no faces on it. | ```python
n,m =[int(i) for i in input().split()]
a = []
for i in range(n):
a.append(input())
ans = 0
for i in range(n-1):
for j in range(m-1):
v = [a[i][j],a[i][j +1], a[i+1][j], a[i+1][j+1]]
v.sort()
if v == ['a',
'c','e','f']:
ans = ans + 1
print7888)
``` | -1 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,688,879,356 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<stdio.h>
#include<string.h>
int main()
{
char word[6]="hello";
char s[100];
scanf("%s",s);
int l=strlen(s);
int a=0,count=0;
for(int i=0;i<l;i++)
{
if(s[i]==word[a])
{
a++;
count++;
}
}
if(count==5)
{
printf("YES");
}
else{
printf("NO");
}
return 0;
} | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
#include<stdio.h>
#include<string.h>
int main()
{
char word[6]="hello";
char s[100];
scanf("%s",s);
int l=strlen(s);
int a=0,count=0;
for(int i=0;i<l;i++)
{
if(s[i]==word[a])
{
a++;
count++;
}
}
if(count==5)
{
printf("YES");
}
else{
printf("NO");
}
return 0;
}
``` | -1 |
729 | A | Interview with Oleg | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 500 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input": "100\nggogogoooggogooggoggogggggogoogoggooooggooggoooggogoooggoggoogggoogoggogggoooggoggoggogggogoogggoooo",
"output": "gg***oogg***oggoggoggggg******ggooooggooggooogg***ooggoggoogggo***ggogggoooggoggoggoggg***ogggoooo"
},
{
"input": "10\nogooggoggo",
"output": "***oggoggo"
},
{
"input": "20\nooggooogooogooogooog",
"output": "ooggoo***o***o***oog"
},
{
"input": "30\ngoggogoooggooggggoggoggoogoggo",
"output": "gogg***ooggooggggoggoggo***ggo"
},
{
"input": "40\nogggogooggoogoogggogooogogggoogggooggooo",
"output": "oggg***oggo***oggg***o***gggoogggooggooo"
},
{
"input": "50\noggggogoogggggggoogogggoooggooogoggogooogogggogooo",
"output": "ogggg***ogggggggo***gggoooggoo***gg***o***ggg***oo"
},
{
"input": "60\nggoooogoggogooogogooggoogggggogogogggggogggogooogogogggogooo",
"output": "ggooo***gg***o***oggooggggg***gggggoggg***o***ggg***oo"
},
{
"input": "70\ngogoooggggoggoggggggoggggoogooogogggggooogggogoogoogoggogggoggogoooooo",
"output": "g***ooggggoggoggggggoggggo***o***gggggoooggg*********ggogggogg***ooooo"
},
{
"input": "80\nooogoggoooggogogoggooooogoogogooogoggggogggggogoogggooogooooooggoggoggoggogoooog",
"output": "oo***ggooogg***ggoooo******o***ggggoggggg***ogggoo***oooooggoggoggogg***ooog"
},
{
"input": "90\nooogoggggooogoggggoooogggggooggoggoggooooooogggoggogggooggggoooooogoooogooggoooogggggooooo",
"output": "oo***ggggoo***ggggoooogggggooggoggoggooooooogggoggogggooggggooooo***oo***oggoooogggggooooo"
},
{
"input": "100\ngooogoggooggggoggoggooooggogoogggoogogggoogogoggogogogoggogggggogggggoogggooogogoggoooggogoooooogogg",
"output": "goo***ggooggggoggoggoooogg***ogggo***gggo***gg***ggogggggogggggoogggoo***ggooogg***oooo***gg"
},
{
"input": "100\ngoogoogggogoooooggoogooogoogoogogoooooogooogooggggoogoggogooogogogoogogooooggoggogoooogooooooggogogo",
"output": "go***oggg***ooooggo***o*********oooo***o***oggggo***gg***o******oooggogg***oo***ooooogg***"
},
{
"input": "100\ngoogoggggogggoooggoogoogogooggoggooggggggogogggogogggoogogggoogoggoggogooogogoooogooggggogggogggoooo",
"output": "go***ggggogggoooggo******oggoggoogggggg***ggg***gggo***gggo***ggogg***o***oo***oggggogggogggoooo"
},
{
"input": "100\nogogogogogoggogogogogogogoggogogogoogoggoggooggoggogoogoooogogoogggogogogogogoggogogogogogogogogogoe",
"output": "***gg***gg******ggoggooggogg******oo***oggg***gg***e"
},
{
"input": "5\nogoga",
"output": "***ga"
},
{
"input": "1\no",
"output": "o"
},
{
"input": "100\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogog",
"output": "***g"
},
{
"input": "99\nogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogogo",
"output": "***"
},
{
"input": "5\nggggg",
"output": "ggggg"
},
{
"input": "6\ngoogoo",
"output": "go***o"
},
{
"input": "7\nooogooo",
"output": "oo***oo"
},
{
"input": "8\ngggggggg",
"output": "gggggggg"
},
{
"input": "9\nogggogggg",
"output": "ogggogggg"
},
{
"input": "10\nogogoggogo",
"output": "***gg***"
},
{
"input": "11\noooggooggog",
"output": "oooggooggog"
},
{
"input": "12\nogggooooggog",
"output": "ogggooooggog"
},
{
"input": "13\nogoggogogooog",
"output": "***gg***oog"
},
{
"input": "15\nggooogoooggoggg",
"output": "ggoo***ooggoggg"
},
{
"input": "14\noogooooggooggo",
"output": "o***oooggooggo"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "1\ng",
"output": "g"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "46\nsdfkogogogogergergogogergerogogogogoergoegogog",
"output": "sdfk***gergerg***gerger***ergoeg***g"
},
{
"input": "86\ngdfggogogodfogogdofgoodfogodgodgfogoogdodhbofgobgbgfogoogdfogogogogogoogggsgfosogodgon",
"output": "gdfgg***df***gdofgoodf***dgodgf***ogdodhbofgobgbgf***ogdf***ogggsgfos***dgon"
},
{
"input": "83\nergegergoogogogerogoerorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgtogooggsdgogoog",
"output": "ergegergo***ger***erorogroeorgefxcfgzdgawofqpwzxcvbnmsdfkfpweoriqgt***oggsdg***og"
},
{
"input": "2\nog",
"output": "og"
},
{
"input": "4\nogog",
"output": "***g"
},
{
"input": "4\nogoo",
"output": "***o"
},
{
"input": "29\naaaogogogogogogogogogogogobbb",
"output": "aaa***bbb"
},
{
"input": "11\nogogogogogo",
"output": "***"
},
{
"input": "9\nogogogogo",
"output": "***"
},
{
"input": "3\nogo",
"output": "***"
},
{
"input": "15\nogogogogogogogo",
"output": "***"
},
{
"input": "25\nogogogogogogogogogogogogo",
"output": "***"
}
] | 1,679,298,530 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 93 | 2,764,800 | import sys, io, os
import math
import bisect
import heapq
import string
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def WRITE(out):
return print('\n'.join(map(str, out)))
def WS(out):
return print(' '.join(map(str, out)))
def WNS(out):
return print(''.join(map(str, out)))
'''
n%4 == 0 and all_cnts <= n//4
'''
def solve():
n = II()
s = I().strip()
ans = []
l = 0
while l < n:
# print(l, s[l:])
if l+2 < n and s[l:l+3] == 'ogo':
l += 3
for i in range(l, n-1, 2):
if s[i:i+2] == 'go':
l = i+2
else:
break
ans.append('***')
else:
ans.append(s[l])
l += 1
WNS(ans)
solve() | Title: Interview with Oleg
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.
The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.
To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.
Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
Input Specification:
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters.
Output Specification:
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
Demo Input:
['7\naogogob\n', '13\nogogmgogogogo\n', '9\nogoogoogo\n']
Demo Output:
['a***b\n', '***gmg***\n', '*********\n']
Note:
The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | ```python
import sys, io, os
import math
import bisect
import heapq
import string
from collections import defaultdict,Counter,deque
input = sys.stdin.readline
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def WRITE(out):
return print('\n'.join(map(str, out)))
def WS(out):
return print(' '.join(map(str, out)))
def WNS(out):
return print(''.join(map(str, out)))
'''
n%4 == 0 and all_cnts <= n//4
'''
def solve():
n = II()
s = I().strip()
ans = []
l = 0
while l < n:
# print(l, s[l:])
if l+2 < n and s[l:l+3] == 'ogo':
l += 3
for i in range(l, n-1, 2):
if s[i:i+2] == 'go':
l = i+2
else:
break
ans.append('***')
else:
ans.append(s[l])
l += 1
WNS(ans)
solve()
``` | 3 |
|
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
{
"input": "789 101112 131415",
"output": "203802"
},
{
"input": "27485716 99999999 35182",
"output": "55041796"
},
{
"input": "1 293548 5",
"output": "12"
},
{
"input": "12059 259855 5874875",
"output": "543828"
},
{
"input": "46981 105809 585858",
"output": "305580"
},
{
"input": "9889 1221 2442",
"output": "7326"
},
{
"input": "100500 200600 300700",
"output": "601800"
},
{
"input": "318476 318476 318476",
"output": "955428"
},
{
"input": "23985 3353 75633",
"output": "54676"
},
{
"input": "120 1298 2222",
"output": "2836"
},
{
"input": "98437 23487 666672",
"output": "243848"
},
{
"input": "100000000 100000000 100000000",
"output": "300000000"
},
{
"input": "2 5 2",
"output": "8"
},
{
"input": "1 1000 1",
"output": "4"
},
{
"input": "1 100000000 1",
"output": "4"
}
] | 1,667,010,151 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | x = input().split()
d1 = int(a[0])
d2 = int(a[1])
d3 = int(a[2])
if d3 > d1 + d2:
b = d1 + d2 + d1 + d2
print(b)
else:
c = d1 + d2 + d3
print(c)
| Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house.
Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
Input Specification:
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Output Specification:
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
Demo Input:
['10 20 30\n', '1 1 5\n']
Demo Output:
['60\n', '4\n']
Note:
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. | ```python
x = input().split()
d1 = int(a[0])
d2 = int(a[1])
d3 = int(a[2])
if d3 > d1 + d2:
b = d1 + d2 + d1 + d2
print(b)
else:
c = d1 + d2 + d3
print(c)
``` | -1 |
|
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
"output": "1/6"
},
{
"input": "2 1",
"output": "5/6"
},
{
"input": "2 2",
"output": "5/6"
},
{
"input": "2 3",
"output": "2/3"
},
{
"input": "2 4",
"output": "1/2"
},
{
"input": "2 5",
"output": "1/3"
},
{
"input": "2 6",
"output": "1/6"
},
{
"input": "3 1",
"output": "2/3"
},
{
"input": "3 2",
"output": "2/3"
},
{
"input": "3 3",
"output": "2/3"
},
{
"input": "3 4",
"output": "1/2"
},
{
"input": "3 5",
"output": "1/3"
},
{
"input": "3 6",
"output": "1/6"
},
{
"input": "4 1",
"output": "1/2"
},
{
"input": "4 3",
"output": "1/2"
},
{
"input": "4 4",
"output": "1/2"
},
{
"input": "4 5",
"output": "1/3"
},
{
"input": "4 6",
"output": "1/6"
},
{
"input": "5 1",
"output": "1/3"
},
{
"input": "5 2",
"output": "1/3"
},
{
"input": "5 3",
"output": "1/3"
},
{
"input": "5 4",
"output": "1/3"
},
{
"input": "5 5",
"output": "1/3"
},
{
"input": "5 6",
"output": "1/6"
},
{
"input": "6 1",
"output": "1/6"
},
{
"input": "6 2",
"output": "1/6"
},
{
"input": "6 3",
"output": "1/6"
},
{
"input": "6 4",
"output": "1/6"
},
{
"input": "6 5",
"output": "1/6"
},
{
"input": "6 6",
"output": "1/6"
}
] | 1,586,515,707 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 216 | 0 | a,b = map(int,input().split())
v = max(a,b)
v = (6-v)+1
if(v==1):
print("1/6")
elif(v==2):
print("1/3")
elif(v==3):
print("1/2")
elif(v==4):
print("2/3")
elif(v==5):
print("5/6")
else:
print("1/1")
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.
But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.
Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.
It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
Input Specification:
The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.
Output Specification:
Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».
Demo Input:
['4 2\n']
Demo Output:
['1/2\n']
Note:
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | ```python
a,b = map(int,input().split())
v = max(a,b)
v = (6-v)+1
if(v==1):
print("1/6")
elif(v==2):
print("1/3")
elif(v==3):
print("1/2")
elif(v==4):
print("2/3")
elif(v==5):
print("5/6")
else:
print("1/1")
``` | 3.892 |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\n1 2 2 2 4 5 6 7 8 10",
"output": "376"
},
{
"input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002",
"output": "40204082"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "1\n1000000",
"output": "1000000"
},
{
"input": "10\n10 8 7 6 5 4 2 2 2 1",
"output": "376"
},
{
"input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821",
"output": "40204082"
},
{
"input": "10\n5 2 6 10 10 10 10 2 2 5",
"output": "485"
},
{
"input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255",
"output": "36742665"
},
{
"input": "10\n2 2 2 5 5 6 10 10 10 10",
"output": "485"
},
{
"input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 6 5 5 2 2 2",
"output": "485"
},
{
"input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496",
"output": "36742665"
},
{
"input": "10\n10 10 10 10 10 10 10 10 10 10",
"output": "640"
},
{
"input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000",
"output": "64000000"
},
{
"input": "1\n397870",
"output": "397870"
},
{
"input": "2\n1 2",
"output": "6"
},
{
"input": "2\n2 3",
"output": "10"
},
{
"input": "2\n1 1",
"output": "4"
}
] | 1,615,487,638 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 5,836,800 | # Collaborated with no one
lenArray = int(input())
array = list(map(int, input().split(" ")))
sum1 = 0
array.sort(reverse=True)
while(array!=[]):
for i in range(0, len(array)):
sum1+=array[i]
extra = array.pop()
if(array!=[]):
sum1+=extra
print(sum1)
| Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Output Specification:
Print a single integer — the largest possible score.
Demo Input:
['3\n3 1 5\n', '1\n10\n']
Demo Output:
['26\n', '10\n']
Note:
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions. | ```python
# Collaborated with no one
lenArray = int(input())
array = list(map(int, input().split(" ")))
sum1 = 0
array.sort(reverse=True)
while(array!=[]):
for i in range(0, len(array)):
sum1+=array[i]
extra = array.pop()
if(array!=[]):
sum1+=extra
print(sum1)
``` | 0 |
|
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.
Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value). | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach any city from any other by the roads. | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n1 47\n1 13\n1 46\n60 1\n1 6\n23 1\n20 1\n1 52\n2 1\n26 1\n1 59\n1 66\n10 1\n1 62\n1 68\n1 55\n50 1\n33 1\n44 1\n1 34\n1 35\n1 61\n14 1\n67 1\n49 1",
"output": "1.000000000000000"
},
{
"input": "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1",
"output": "1.500000000000000"
},
{
"input": "1",
"output": "0.000000000000000"
}
] | 1,683,132,363 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 716,800 | nodes_cnt = int(input())
neighbors_of = [set() for _ in range(nodes_cnt)]
for _ in range(nodes_cnt - 1):
c1, c2 = map(int, input().split())
c1 -= 1
c2 -= 1
neighbors_of[c1].add(c2)
neighbors_of[c2].add(c1)
total_distance = 0
total_path_cnt = 0
def dfs(node, cur_len, prev):
if len(neighbors_of[node]) == 1 and prev in neighbors_of[node]:
global total_distance, total_path_cnt
total_distance += cur_len
total_path_cnt += 1
for child in neighbors_of[node]:
if child == prev: continue
dfs(child, cur_len + 1, node)
dfs(0, 0, None)
print(total_distance / total_path_cnt)
| Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities.
Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value).
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach any city from any other by the roads.
Output Specification:
Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['4\n1 2\n1 3\n2 4\n', '5\n1 2\n1 3\n3 4\n2 5\n']
Demo Output:
['1.500000000000000\n', '2.000000000000000\n']
Note:
In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | ```python
nodes_cnt = int(input())
neighbors_of = [set() for _ in range(nodes_cnt)]
for _ in range(nodes_cnt - 1):
c1, c2 = map(int, input().split())
c1 -= 1
c2 -= 1
neighbors_of[c1].add(c2)
neighbors_of[c2].add(c1)
total_distance = 0
total_path_cnt = 0
def dfs(node, cur_len, prev):
if len(neighbors_of[node]) == 1 and prev in neighbors_of[node]:
global total_distance, total_path_cnt
total_distance += cur_len
total_path_cnt += 1
for child in neighbors_of[node]:
if child == prev: continue
dfs(child, cur_len + 1, node)
dfs(0, 0, None)
print(total_distance / total_path_cnt)
``` | -1 |
|
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},
{
"input": "lwzjp\ninjit",
"output": "-1"
},
{
"input": "epqnlxmiicdidyscjaxqznwur\neodnlemiicdedmkcgavqbnqmm",
"output": "eodnlemiicdedmkcgavqbnqmm"
},
{
"input": "qqdabbsxiibnnjgsgxllfvdqj\nuxmypqtwfdezewdxfgplannrs",
"output": "-1"
},
{
"input": "aanerbaqslfmqmuciqbxyznkevukvznpkmxlcorpmrenwxhzfgbmlfpxtkqpxdrmcqcmbf\naanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf",
"output": "aanebbaqkgfiimcciqbaoznkeqqkrgapdillccrfeienwbcvfgbmlfbimkqchcrmclcmbf"
},
{
"input": "mbyrkhjctrcrayisflptgfudwgrtegidhqicsjqafvdloritbjhciyxuwavxknezwwudnk\nvvixsutlbdewqoabqhpuerfkzrddcqptfwmxdlxwbvsaqfjoxztlddvwgflcteqbwaiaen",
"output": "-1"
},
{
"input": "eufycwztywhbjrpqobvknwfqmnboqcfdiahkagykeibbsqpljcghhmsgfmswwsanzyiwtvuirwmppfivtekaywkzskyydfvkjgxb\necfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb",
"output": "ecfwavookadbcilfobojnweqinbcpcfdiahkabwkeibbacpljcghhksgfajgmianfnivmhfifogpffiheegayfkxkkcmdfvihgdb"
},
{
"input": "qvpltcffyeghtbdhjyhfteojezyzziardduzrbwuxmzzkkoehfnxecafizxglboauhynfbawlfxenmykquyhrxswhjuovvogntok\nchvkcvzxptbcepdjfezcpuvtehewbnvqeoezlcnzhpfwujbmhafoeqmjhtwisnobauinkzyigrvahpuetkgpdjfgbzficsmuqnym",
"output": "-1"
},
{
"input": "nmuwjdihouqrnsuahimssnrbxdpwvxiyqtenahtrlshjkmnfuttnpqhgcagoptinnaptxaccptparldzrhpgbyrzedghudtsswxi\nnilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib",
"output": "nilhbdghosqnbebafimconrbvdodjsipqmekahhrllhjkemeketapfhgcagopfidnahtlaccpfpafedqicpcbvfgedghudhddwib"
},
{
"input": "dyxgwupoauwqtcfoyfjdotzirwztdfrueqiypxoqvkmhiehdppwtdoxrbfvtairdbuvlqohjflznggjpifhwjrshcrfbjtklpykx\ngzqlnoizhxolnditjdhlhptjsbczehicudoybzilwnshmywozwnwuipcgirgzldtvtowdsokfeafggwserzdazkxyddjttiopeew",
"output": "-1"
},
{
"input": "hbgwuqzougqzlxemvyjpeizjfwhgugrfnhbrlxkmkdalikfyunppwgdzmalbwewybnjzqsohwhjkdcyhhzmysflambvhpsjilsyv\nfbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv",
"output": "fbdjdqjojdafarakvcjpeipjfehgfgrfehbolxkmkdagikflunnpvadocalbkedibhbflmohnhjkdcthhaigsfjaibqhbcjelirv"
},
{
"input": "xnjjhjfuhgyxqhpzmvgbaohqarugdoaczcfecofltwemieyxolswkcwhlfagfrgmoiqrgftokbqwtxgxzweozzlikrvafiabivlk\npjfosalbsitcnqiazhmepfifjxvmazvdgffcnozmnqubhonwjldmpdsjagmamniylzjdbklcyrzivjyzgnogahobpkwpwpvraqns",
"output": "-1"
},
{
"input": "zrvzedssbsrfldqvjpgmsefrmsatspzoitwvymahiptphiystjlsauzquzqqbmljobdhijcpdvatorwmyojqgnezvzlgjibxepcf\npesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf",
"output": "pesoedmqbmffldqsjggmhefkadaesijointrkmahapaahiysfjdiaupqujngbjhjobdhiecadeatgjvelojjgnepvajgeibfepaf"
},
{
"input": "pdvkuwyzntzfqpblzmbynknyhlnqbxijuqaincviugxohcsrofozrrsategwkbwxcvkyzxhurokefpbdnmcfogfhsojayysqbrow\nbvxruombdrywlcjkrltyayaazwpauuhbtgwfzdrmfwwucgffucwelzvpsdgtapogchblzahsrfymjlaghkbmbssghrpxalkslcvp",
"output": "-1"
},
{
"input": "tgharsjyihroiiahwgbjezlxvlterxivdhtzjcqegzmtigqmrehvhiyjeywegxaseoyoacouijudbiruoghgxvxadwzgdxtnxlds\ntghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp",
"output": "tghaksjsdhkoiiahegbjexlfrctercipdhmvjbgegxdtggqdpbhvhiseehhegnaseoooacnsijubbirjnghgsvpadhaadrtimfdp"
},
{
"input": "jsinejpfwhzloulxndzvzftgogfdagrsscxmatldssqsgaknnbkcvhptebjjpkjhrjegrotzwcdosezkedzxeoyibmyzunkguoqj\nkfmvybobocdpipiripysioruqvloopvbggpjksgmwzyqwyxnesmvhsawnbbmntulspvsysfkjqwpvoelliopbaukyagedextzoej",
"output": "-1"
},
{
"input": "nttdcfceptruiomtmwzestrfchnqpgqeztpcvthzelfyggjgqadylzubpvbrlgndrcsursczpxlnoyoadxezncqalupfzmjeqihe\nkttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe",
"output": "kttdcfceohrjiaahmoldanpfchnfpgheqpdahqhxecfpbgigqadrkjubjfbrlgndbcgcgmcjpeleinaadretncqaiqpfkmjeqihe"
},
{
"input": "diuopwglduasnaxgduwslbzoyayoypzznqspljcyqehweydhlwifcvnjmaowuvyqfwynjghecqvxdvuquuwpvwrjljozocaxnktv\ntrdydprdzmjhgbhzytelrfjpgsebijicsigmwhynmcyjtqrvojcndodchzxfcvyqjxqzwibccdvsjqhsnectdjyrrhzkeamukang",
"output": "-1"
},
{
"input": "ftfr\nftfr",
"output": "ftfr"
},
{
"input": "ftr\nftr",
"output": "ftr"
},
{
"input": "shftr\nshftr",
"output": "shftr"
},
{
"input": "vkvkkv\nvkvkkv",
"output": "vkvkkv"
},
{
"input": "ftrd\nftrd",
"output": "ftrd"
},
{
"input": "fztr\nfztr",
"output": "fztr"
},
{
"input": "frtr\nfrtr",
"output": "frtr"
},
{
"input": "shdftr\nshdftr",
"output": "shdftr"
},
{
"input": "zzz\nzzz",
"output": "zzz"
},
{
"input": "shtr\nshtr",
"output": "shtr"
},
{
"input": "aaaaa\nzzzzz",
"output": "-1"
},
{
"input": "efr\nefr",
"output": "efr"
}
] | 1,492,358,665 | 1,765 | Python 3 | OK | TESTS | 35 | 62 | 5,529,600 | x=input()
y=input()
z=[]
boom=0
for i in range(len(x)):
if x[i]<y[i]:
boom+=1
elif x[i]==y[i]:
z.append("z")
else:
z.append(y[i])
if boom==0:
print("".join(z))
else:
print(-1) | Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2.
For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel".
You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists.
Input Specification:
The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100.
Output Specification:
If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters.
Demo Input:
['ab\naa\n', 'nzwzl\nniwel\n', 'ab\nba\n']
Demo Output:
['ba\n', 'xiyez\n', '-1\n']
Note:
The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | ```python
x=input()
y=input()
z=[]
boom=0
for i in range(len(x)):
if x[i]<y[i]:
boom+=1
elif x[i]==y[i]:
z.append("z")
else:
z.append(y[i])
if boom==0:
print("".join(z))
else:
print(-1)
``` | 3 |
|
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,601,034,669 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 0 | n, m = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ') if int(x) < 0]
a.sort()
print(-sum(a[:min(len(a), m)]))
| Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
n, m = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ') if int(x) < 0]
a.sort()
print(-sum(a[:min(len(a), m)]))
``` | 3.9455 |
991 | A | If at first you don't succeed... | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time? | The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$). | If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$. | [
"10 10 5 20\n",
"2 2 0 4\n",
"2 2 2 1\n"
] | [
"5",
"-1",
"-1"
] | The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | 500 | [
{
"input": "10 10 5 20",
"output": "5"
},
{
"input": "2 2 0 4",
"output": "-1"
},
{
"input": "2 2 2 1",
"output": "-1"
},
{
"input": "98 98 97 100",
"output": "1"
},
{
"input": "1 5 2 10",
"output": "-1"
},
{
"input": "5 1 2 10",
"output": "-1"
},
{
"input": "6 7 5 8",
"output": "-1"
},
{
"input": "6 7 5 9",
"output": "1"
},
{
"input": "6 7 5 7",
"output": "-1"
},
{
"input": "50 50 1 100",
"output": "1"
},
{
"input": "8 3 2 12",
"output": "3"
},
{
"input": "10 19 6 25",
"output": "2"
},
{
"input": "1 0 0 99",
"output": "98"
},
{
"input": "0 1 0 98",
"output": "97"
},
{
"input": "1 1 0 97",
"output": "95"
},
{
"input": "1 1 1 96",
"output": "95"
},
{
"input": "0 0 0 0",
"output": "-1"
},
{
"input": "100 0 0 0",
"output": "-1"
},
{
"input": "0 100 0 0",
"output": "-1"
},
{
"input": "100 100 0 0",
"output": "-1"
},
{
"input": "0 0 100 0",
"output": "-1"
},
{
"input": "100 0 100 0",
"output": "-1"
},
{
"input": "0 100 100 0",
"output": "-1"
},
{
"input": "100 100 100 0",
"output": "-1"
},
{
"input": "0 0 0 100",
"output": "100"
},
{
"input": "100 0 0 100",
"output": "-1"
},
{
"input": "0 100 0 100",
"output": "-1"
},
{
"input": "100 100 0 100",
"output": "-1"
},
{
"input": "0 0 100 100",
"output": "-1"
},
{
"input": "100 0 100 100",
"output": "-1"
},
{
"input": "0 100 100 100",
"output": "-1"
},
{
"input": "100 100 100 100",
"output": "-1"
},
{
"input": "10 45 7 52",
"output": "4"
},
{
"input": "38 1 1 68",
"output": "30"
},
{
"input": "8 45 2 67",
"output": "16"
},
{
"input": "36 36 18 65",
"output": "11"
},
{
"input": "10 30 8 59",
"output": "27"
},
{
"input": "38 20 12 49",
"output": "3"
},
{
"input": "8 19 4 38",
"output": "15"
},
{
"input": "36 21 17 72",
"output": "32"
},
{
"input": "14 12 12 89",
"output": "75"
},
{
"input": "38 6 1 44",
"output": "1"
},
{
"input": "13 4 6 82",
"output": "-1"
},
{
"input": "5 3 17 56",
"output": "-1"
},
{
"input": "38 5 29 90",
"output": "-1"
},
{
"input": "22 36 18 55",
"output": "15"
},
{
"input": "13 0 19 75",
"output": "-1"
},
{
"input": "62 65 10 89",
"output": "-1"
},
{
"input": "2 29 31 72",
"output": "-1"
},
{
"input": "1 31 19 55",
"output": "-1"
},
{
"input": "1 25 28 88",
"output": "-1"
},
{
"input": "34 32 28 33",
"output": "-1"
},
{
"input": "43 36 1 100",
"output": "22"
},
{
"input": "16 39 55 70",
"output": "-1"
},
{
"input": "2 3 0 91",
"output": "86"
},
{
"input": "55 29 12 48",
"output": "-1"
},
{
"input": "7 33 20 88",
"output": "-1"
},
{
"input": "40 38 27 99",
"output": "48"
},
{
"input": "18 28 14 84",
"output": "52"
},
{
"input": "34 25 25 92",
"output": "58"
},
{
"input": "4 24 5 76",
"output": "-1"
},
{
"input": "5 22 16 96",
"output": "-1"
},
{
"input": "1 1 0 4",
"output": "2"
},
{
"input": "5 5 3 1",
"output": "-1"
},
{
"input": "0 0 0 1",
"output": "1"
},
{
"input": "2 3 0 8",
"output": "3"
},
{
"input": "5 5 2 5",
"output": "-1"
},
{
"input": "1 2 1 3",
"output": "1"
},
{
"input": "3 0 0 4",
"output": "1"
},
{
"input": "0 0 0 5",
"output": "5"
},
{
"input": "5 5 0 3",
"output": "-1"
},
{
"input": "5 6 1 7",
"output": "-1"
},
{
"input": "10 10 10 11",
"output": "1"
},
{
"input": "0 0 0 10",
"output": "10"
},
{
"input": "5 15 5 30",
"output": "15"
},
{
"input": "3 2 0 7",
"output": "2"
}
] | 1,642,578,243 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 77 | 0 | a, b, c, n = map(int, input().split())
tmp = n - (a + b - c)
if tmp < 1 or a < c or b < c:
print(-1)
else:
print(tmp) | Title: If at first you don't succeed...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam.
Some of them celebrated in the BugDonalds restaurant, some of them — in the BeaverKing restaurant, the most successful ones were fast enough to celebrate in both of restaurants. Students which didn't pass the exam didn't celebrate in any of those restaurants and elected to stay home to prepare for their reexamination. However, this quickly bored Vasya and he started checking celebration photos on the Kilogramm. He found out that, in total, BugDonalds was visited by $A$ students, BeaverKing — by $B$ students and $C$ students visited both restaurants. Vasya also knows that there are $N$ students in his group.
Based on this info, Vasya wants to determine either if his data contradicts itself or, if it doesn't, how many students in his group didn't pass the exam. Can you help him so he won't waste his valuable preparation time?
Input Specification:
The first line contains four integers — $A$, $B$, $C$ and $N$ ($0 \leq A, B, C, N \leq 100$).
Output Specification:
If a distribution of $N$ students exists in which $A$ students visited BugDonalds, $B$ — BeaverKing, $C$ — both of the restaurants and at least one student is left home (it is known that Vasya didn't pass the exam and stayed at home), output one integer — amount of students (including Vasya) who did not pass the exam.
If such a distribution does not exist and Vasya made a mistake while determining the numbers $A$, $B$, $C$ or $N$ (as in samples 2 and 3), output $-1$.
Demo Input:
['10 10 5 20\n', '2 2 0 4\n', '2 2 2 1\n']
Demo Output:
['5', '-1', '-1']
Note:
The first sample describes following situation: $5$ only visited BugDonalds, $5$ students only visited BeaverKing, $5$ visited both of them and $5$ students (including Vasya) didn't pass the exam.
In the second sample $2$ students only visited BugDonalds and $2$ only visited BeaverKing, but that means all $4$ students in group passed the exam which contradicts the fact that Vasya didn't pass meaning that this situation is impossible.
The third sample describes a situation where $2$ students visited BugDonalds but the group has only $1$ which makes it clearly impossible. | ```python
a, b, c, n = map(int, input().split())
tmp = n - (a + b - c)
if tmp < 1 or a < c or b < c:
print(-1)
else:
print(tmp)
``` | 3 |
|
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero. | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3). | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
{
"input": "701",
"output": "116"
},
{
"input": "222",
"output": "39"
},
{
"input": "156",
"output": "28"
},
{
"input": "12343",
"output": "1778"
},
{
"input": "7984",
"output": "1178"
},
{
"input": "1000000",
"output": "128207"
},
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "11",
"output": "3"
},
{
"input": "77",
"output": "14"
},
{
"input": "216",
"output": "37"
},
{
"input": "1468",
"output": "233"
},
{
"input": "1995",
"output": "305"
},
{
"input": "11010",
"output": "1568"
},
{
"input": "47320",
"output": "6746"
},
{
"input": "258634",
"output": "35024"
}
] | 1,586,089,525 | 2,147,483,647 | PyPy 3 | OK | TESTS1 | 24 | 310 | 1,536,000 | n=int(input())
l=list(str(n))
n=int(n)
c=0
while n!=0:
m=max(list(str(n)))
n-=int(m)
c+=1
print(c) | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!"
Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero.
Input Specification:
The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3).
Output Specification:
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
Demo Input:
['24\n']
Demo Output:
['5']
Note:
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | ```python
n=int(input())
l=list(str(n))
n=int(n)
c=0
while n!=0:
m=max(list(str(n)))
n-=int(m)
c+=1
print(c)
``` | 3 |
|
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3",
"output": "1"
},
{
"input": "2 3 4",
"output": "1"
},
{
"input": "1000000000 1000000000 1",
"output": "1000000000000000000"
},
{
"input": "12 13 4",
"output": "12"
},
{
"input": "222 332 5",
"output": "3015"
},
{
"input": "1000 1000 10",
"output": "10000"
},
{
"input": "1001 1000 10",
"output": "10100"
},
{
"input": "100 10001 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 1000000000",
"output": "1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "4"
},
{
"input": "1000000000 1000000000 192",
"output": "27126743055556"
},
{
"input": "1000000000 987654321 1",
"output": "987654321000000000"
},
{
"input": "456784567 1000000000 51",
"output": "175618850864484"
},
{
"input": "39916800 134217728 40320",
"output": "3295710"
}
] | 1,678,467,992 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | str1 = input()
l = str1.split()
l = [int(i) for i in l]
s = 0
p = 1
while s<l[0]*l[1]:
s = s + l[2]*l[2]
p = p + 1
print(p) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
Input Specification:
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Output Specification:
Write the needed number of flagstones.
Demo Input:
['6 6 4\n']
Demo Output:
['4\n']
Note:
none | ```python
str1 = input()
l = str1.split()
l = [int(i) for i in l]
s = 0
p = 1
while s<l[0]*l[1]:
s = s + l[2]*l[2]
p = p + 1
print(p)
``` | 0 |
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,665,527,210 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 62 | 8,806,400 |
n=int(input())
l=list(map(int,input().split()))
maxi=l.count(max(l))
mini=l.count(min(l))
if n==1:
print(0)
else:
print(n - maxi - mini)
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
n=int(input())
l=list(map(int,input().split()))
maxi=l.count(max(l))
mini=l.count(min(l))
if n==1:
print(0)
else:
print(n - maxi - mini)
``` | 0 |
|
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. | Output the only number — answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"output": "10"
},
{
"input": "2 1\n2 1",
"output": "2"
},
{
"input": "2 2\n2 4\n1 4",
"output": "8"
},
{
"input": "2 3\n1 7\n1 2\n1 5",
"output": "12"
},
{
"input": "4 1\n2 2",
"output": "4"
},
{
"input": "4 2\n1 10\n4 4",
"output": "22"
},
{
"input": "4 3\n1 4\n6 4\n1 7",
"output": "19"
},
{
"input": "5 1\n10 5",
"output": "25"
},
{
"input": "5 2\n3 9\n2 2",
"output": "31"
},
{
"input": "5 5\n2 9\n3 1\n2 1\n1 8\n2 8",
"output": "42"
},
{
"input": "5 10\n1 3\n1 2\n1 9\n1 10\n1 1\n1 5\n1 10\n1 2\n1 3\n1 7",
"output": "41"
},
{
"input": "10 1\n9 4",
"output": "36"
},
{
"input": "10 2\n14 3\n1 3",
"output": "30"
},
{
"input": "10 7\n4 8\n1 10\n1 10\n1 2\n3 3\n1 3\n1 10",
"output": "71"
},
{
"input": "10 10\n1 8\n2 10\n1 9\n1 1\n1 9\n1 6\n1 4\n2 5\n1 2\n1 4",
"output": "70"
},
{
"input": "10 4\n1 5\n5 2\n1 9\n3 3",
"output": "33"
},
{
"input": "100 5\n78 6\n29 10\n3 6\n7 3\n2 4",
"output": "716"
},
{
"input": "1000 7\n102 10\n23 6\n79 4\n48 1\n34 10\n839 8\n38 4",
"output": "8218"
},
{
"input": "10000 10\n336 2\n2782 5\n430 10\n1893 7\n3989 10\n2593 8\n165 6\n1029 2\n2097 4\n178 10",
"output": "84715"
},
{
"input": "100000 3\n2975 2\n35046 4\n61979 9",
"output": "703945"
},
{
"input": "1000000 4\n314183 9\n304213 4\n16864 5\n641358 9",
"output": "8794569"
},
{
"input": "10000000 10\n360313 10\n416076 1\n435445 9\n940322 7\n1647581 7\n4356968 10\n3589256 2\n2967933 5\n2747504 7\n1151633 3",
"output": "85022733"
},
{
"input": "100000000 7\n32844337 7\n11210848 7\n47655987 1\n33900472 4\n9174763 2\n32228738 10\n29947408 5",
"output": "749254060"
},
{
"input": "200000000 10\n27953106 7\n43325979 4\n4709522 1\n10975786 4\n67786538 8\n48901838 7\n15606185 6\n2747583 1\n100000000 1\n633331 3",
"output": "1332923354"
},
{
"input": "200000000 9\n17463897 9\n79520463 1\n162407 4\n41017993 8\n71054118 4\n9447587 2\n5298038 9\n3674560 7\n20539314 5",
"output": "996523209"
},
{
"input": "200000000 8\n6312706 6\n2920548 2\n16843192 3\n1501141 2\n13394704 6\n10047725 10\n4547663 6\n54268518 6",
"output": "630991750"
},
{
"input": "200000000 7\n25621043 2\n21865270 1\n28833034 1\n22185073 5\n100000000 2\n13891017 9\n61298710 8",
"output": "931584598"
},
{
"input": "200000000 6\n7465600 6\n8453505 10\n4572014 8\n8899499 3\n86805622 10\n64439238 6",
"output": "1447294907"
},
{
"input": "200000000 5\n44608415 6\n100000000 9\n51483223 9\n44136047 1\n52718517 1",
"output": "1634907859"
},
{
"input": "200000000 4\n37758556 10\n100000000 6\n48268521 3\n20148178 10",
"output": "1305347138"
},
{
"input": "200000000 3\n65170000 7\n20790088 1\n74616133 4",
"output": "775444620"
},
{
"input": "200000000 2\n11823018 6\n100000000 9",
"output": "970938108"
},
{
"input": "200000000 1\n100000000 6",
"output": "600000000"
},
{
"input": "200000000 10\n12097724 9\n41745972 5\n26982098 9\n14916995 7\n21549986 7\n3786630 9\n8050858 7\n27994924 4\n18345001 5\n8435339 5",
"output": "1152034197"
},
{
"input": "200000000 10\n55649 8\n10980981 9\n3192542 8\n94994808 4\n3626106 1\n100000000 6\n5260110 9\n4121453 2\n15125061 4\n669569 6",
"output": "1095537357"
},
{
"input": "10 20\n1 7\n1 7\n1 8\n1 3\n1 10\n1 7\n1 7\n1 9\n1 3\n1 1\n1 2\n1 1\n1 3\n1 10\n1 9\n1 8\n1 8\n1 6\n1 7\n1 5",
"output": "83"
},
{
"input": "10000000 20\n4594 7\n520836 8\n294766 6\n298672 4\n142253 6\n450626 1\n1920034 9\n58282 4\n1043204 1\n683045 1\n1491746 5\n58420 4\n451217 2\n129423 4\n246113 5\n190612 8\n912923 6\n473153 6\n783733 6\n282411 10",
"output": "54980855"
},
{
"input": "200000000 20\n15450824 5\n839717 10\n260084 8\n1140850 8\n28744 6\n675318 3\n25161 2\n5487 3\n6537698 9\n100000000 5\n7646970 9\n16489 6\n24627 3\n1009409 5\n22455 1\n25488456 4\n484528 9\n32663641 3\n750968 4\n5152 6",
"output": "939368573"
},
{
"input": "200000000 20\n16896 2\n113 3\n277 2\n299 7\n69383562 2\n3929 8\n499366 4\n771846 5\n9 4\n1278173 7\n90 2\n54 7\n72199858 10\n17214 5\n3 10\n1981618 3\n3728 2\n141 8\n2013578 9\n51829246 5",
"output": "1158946383"
},
{
"input": "200000000 20\n983125 2\n7453215 9\n9193588 2\n11558049 7\n28666199 1\n34362244 1\n5241493 5\n15451270 4\n19945845 8\n6208681 3\n38300385 7\n6441209 8\n21046742 7\n577198 10\n3826434 8\n9764276 8\n6264675 7\n8567063 3\n3610303 4\n2908232 3",
"output": "1131379312"
},
{
"input": "10 15\n1 6\n2 6\n3 4\n1 3\n1 2\n1 5\n1 6\n1 2\n2 9\n1 10\n1 3\n1 7\n1 8\n1 2\n2 9",
"output": "79"
},
{
"input": "10000000 15\n111 5\n914124 3\n3 9\n177790 1\n2352 3\n32138 9\n104477 1\n1223 4\n18 6\n6655580 4\n57643 10\n94309 2\n37 1\n227002 10\n1733193 7",
"output": "45116295"
},
{
"input": "200000000 15\n7069868 1\n5567826 8\n2310059 10\n13539782 7\n38420939 4\n29911411 8\n52256316 1\n12265839 9\n2074265 1\n24896428 9\n72470695 5\n3236301 1\n3890243 2\n65168965 8\n65724 6",
"output": "1489289257"
},
{
"input": "200000000 15\n12044094 7\n2475138 10\n944451 7\n4854766 2\n3809145 10\n7727571 2\n43908937 6\n2745883 1\n427511 2\n100000000 5\n190914 6\n554889 3\n288798 4\n1848572 5\n893874 3",
"output": "961871671"
},
{
"input": "200000000 15\n6334191 7\n1927941 4\n5175933 10\n468389 1\n433043 10\n6863198 5\n7480646 4\n14774279 10\n2921129 8\n18325627 7\n6973152 9\n8277324 9\n21522856 2\n2058070 1\n2444742 4",
"output": "664376069"
}
] | 1,623,587,774 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | n,m=map(int,input().split())
l=[]
for i in range(m):
a,b=map(int,input().split())
l.append([b,a])
l.sort(reverse=True)
i=c=0
while n>0 and i<len(l):
if l[i][1]<n:
n-=l[i][1]
c+=l[i][0]*l[i][1]
i+=1
else:
# print(n)
d=n
n-=d
c+=l[i][0]*d
print(c) | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal.
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer.
Output Specification:
Output the only number — answer to the problem.
Demo Input:
['7 3\n5 10\n2 5\n3 6\n', '3 3\n1 3\n2 2\n3 1\n']
Demo Output:
['62\n', '7\n']
Note:
none | ```python
n,m=map(int,input().split())
l=[]
for i in range(m):
a,b=map(int,input().split())
l.append([b,a])
l.sort(reverse=True)
i=c=0
while n>0 and i<len(l):
if l[i][1]<n:
n-=l[i][1]
c+=l[i][0]*l[i][1]
i+=1
else:
# print(n)
d=n
n-=d
c+=l[i][0]*d
print(c)
``` | 3 |
449 | A | Jzzhu and Chocolate | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); - each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5<=×<=6 chocolate for 5 times.
Imagine Jzzhu have made *k* cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly *k* cuts? The area of a chocolate piece is the number of unit squares in it. | A single line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=109; 1<=≤<=*k*<=≤<=2·109). | Output a single integer representing the answer. If it is impossible to cut the big chocolate *k* times, print -1. | [
"3 4 1\n",
"6 4 2\n",
"2 3 4\n"
] | [
"6\n",
"8\n",
"-1\n"
] | In the first sample, Jzzhu can cut the chocolate following the picture below:
In the second sample the optimal division looks like this:
In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times. | 500 | [
{
"input": "3 4 1",
"output": "6"
},
{
"input": "6 4 2",
"output": "8"
},
{
"input": "2 3 4",
"output": "-1"
},
{
"input": "10 10 2",
"output": "30"
},
{
"input": "1000000000 1000000000 2000000000",
"output": "-1"
},
{
"input": "1000000000 1000000000 999999999",
"output": "1000000000"
},
{
"input": "1000000000 1000000000 1",
"output": "500000000000000000"
},
{
"input": "98283 999283848 23",
"output": "4092192268041"
},
{
"input": "6 4 5",
"output": "4"
},
{
"input": "6 4 6",
"output": "2"
},
{
"input": "482738478 493948384 502919283",
"output": "53"
},
{
"input": "1 1 1",
"output": "-1"
},
{
"input": "1 1 2",
"output": "-1"
},
{
"input": "1 1 1000000000",
"output": "-1"
},
{
"input": "1000000000 1000000000 123456",
"output": "8099000000000"
},
{
"input": "192837483 829387483 828374",
"output": "193030320483"
},
{
"input": "987283748 999283748 589766888",
"output": "999283748"
},
{
"input": "999999123 999999789 123456789",
"output": "7999998312"
},
{
"input": "999999789 999999123 52452444",
"output": "18999995991"
},
{
"input": "789789789 777888999 999999999",
"output": "3"
},
{
"input": "789529529 444524524 888524444",
"output": "4"
},
{
"input": "983748524 23 2",
"output": "7542072002"
},
{
"input": "999999999 1000000000 1",
"output": "499999999500000000"
},
{
"input": "1000000000 999999999 3",
"output": "249999999750000000"
},
{
"input": "12345 123456789 123456789",
"output": "6172"
},
{
"input": "98283 999283848 23",
"output": "4092192268041"
},
{
"input": "98723848 8238748 82838",
"output": "9812348868"
},
{
"input": "444444444 524444444 524",
"output": "443973777333804"
},
{
"input": "298238388 998888999 1000000000",
"output": "268"
},
{
"input": "599399444 599999994 897254524",
"output": "2"
},
{
"input": "999882937 982983748 999999888",
"output": "8404"
},
{
"input": "979882937 982983748 988254444",
"output": "185"
},
{
"input": "999872837 979283748 987837524",
"output": "979283748"
},
{
"input": "979283524 999872524 987524524",
"output": "979283524"
},
{
"input": "989872444 999283444 977999524",
"output": "999283444"
},
{
"input": "999872524 989283524 977999444",
"output": "999872524"
},
{
"input": "999524524 888524524 6",
"output": "126871721067257708"
},
{
"input": "888999999 999999444 7",
"output": "111124937645000070"
},
{
"input": "999888524 999995249 52424",
"output": "19071909388928"
},
{
"input": "999995244 999852424 52999",
"output": "18864910278060"
},
{
"input": "628145517 207579013 1361956",
"output": "95693924993"
},
{
"input": "186969586 883515281 376140463",
"output": "373939172"
},
{
"input": "98152103 326402540 762888636",
"output": "-1"
},
{
"input": "127860890 61402893 158176573",
"output": "2"
},
{
"input": "646139320 570870045 9580639",
"output": "38248293015"
},
{
"input": "61263305 484027667 178509023",
"output": "122526610"
},
{
"input": "940563716 558212775 841082556",
"output": "558212775"
},
{
"input": "496148000 579113529 26389630",
"output": "10424043522"
},
{
"input": "70301174 837151741 925801173",
"output": "-1"
},
{
"input": "902071051 285845006 656585276",
"output": "285845006"
},
{
"input": "9467291 727123763 403573724",
"output": "9467291"
},
{
"input": "899374334 631265401 296231663",
"output": "1893796203"
},
{
"input": "491747710 798571511 520690250",
"output": "491747710"
},
{
"input": "789204467 643215696 799313373",
"output": "63"
},
{
"input": "456517317 162733265 614608449",
"output": "1"
},
{
"input": "181457955 806956092 555253432",
"output": "181457955"
},
{
"input": "158398860 751354014 528156707",
"output": "158398860"
},
{
"input": "458000643 743974603 152040411",
"output": "2231923809"
},
{
"input": "882264705 164556874 37883251",
"output": "3784808102"
},
{
"input": "167035009 877444310 205461190",
"output": "668140036"
},
{
"input": "732553408 300206285 785986539",
"output": "5"
},
{
"input": "896205951 132099861 775142615",
"output": "132099861"
},
{
"input": "19344368 457641319 555144413",
"output": "-1"
},
{
"input": "909420688 506507264 590064714",
"output": "506507264"
},
{
"input": "793692317 55434271 489726670",
"output": "55434271"
},
{
"input": "537850353 901329639 210461043",
"output": "2151401412"
},
{
"input": "570497240 614794872 29523792",
"output": "11681102568"
},
{
"input": "904237002 706091348 905203770",
"output": "730"
},
{
"input": "307178253 337246325 118054687",
"output": "674492650"
},
{
"input": "644505509 896162464 150625750",
"output": "3584649856"
},
{
"input": "500000002 500000002 1000000000",
"output": "1"
},
{
"input": "6 6 9",
"output": "1"
},
{
"input": "6 7 2",
"output": "14"
},
{
"input": "1000000000 1000000000 1999999998",
"output": "1"
},
{
"input": "100 100 150",
"output": "1"
},
{
"input": "2 2 2",
"output": "1"
},
{
"input": "5 5 5",
"output": "2"
},
{
"input": "4 6 4",
"output": "4"
},
{
"input": "1000 1000 1000",
"output": "500"
},
{
"input": "5 4 3",
"output": "5"
},
{
"input": "6 7 1",
"output": "21"
},
{
"input": "6 7 5",
"output": "7"
},
{
"input": "6874 8974 3245",
"output": "17948"
},
{
"input": "1000000000 1000000000 220000000",
"output": "4000000000"
},
{
"input": "100 100 100",
"output": "50"
},
{
"input": "1000000000 10000000 10000000",
"output": "990000000"
},
{
"input": "7 8 9",
"output": "2"
},
{
"input": "4 5 6",
"output": "1"
},
{
"input": "4 6 3",
"output": "6"
},
{
"input": "10 10 11",
"output": "3"
},
{
"input": "1000000000 1000000000 999000111",
"output": "1000000000"
},
{
"input": "2 1 1",
"output": "1"
}
] | 1,680,618,479 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#include <cmath>
#include <chrono>
#include <numeric>
using namespace std;
#define fasterio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl "\n"
#define ll long long
#define testcase int t; cin>>t; for(int i=0;i<t;i++)
#define int long long
#define double long double
#define pb push_back
ll mod= 998244353;
ll N = 252000;
ll inf = 1e18;
void divisors(int n,vector<int> &v)
{
for(int i=1;i<=sqrt(n);i++)
{
if(i!=n/i&&n%i==0) {v.push_back(i);v.push_back(n/i);}
else v.push_back(i);
}
}
signed main()
{
#define int long long
fasterio
#ifndef ONLINE_JUDGE
freopen("error.txt", "w", stderr);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a,b,c;
vector<int> arra;
vector<int> arrb;
cin>>a>>b>>c;
divisors(a,arra);
divisors(b,arrb);
arra.push_back(0);
arrb.push_back(0);
sort(arra.begin(),arra.end());
sort(arrb.begin(),arrb.end());
auto x=lower_bound(arra.begin(),arra.end(),c)-arra.begin();
auto y=lower_bound(arrb.begin(),arrb.end(),c)-arrb.begin();
//cout<<x<<y<<endl;
int maxc=0;
int ind1=-1;
int ind2=-1;
int z=0;
for(int i=x;i>=0;i--)
{
if(arra[i]>c) continue;
else
{
z=lower_bound(arrb.begin(),arrb.end(),c-arra[i])-arrb.begin();
if(abs(arrb[z]-arra[i])>maxc&&z!=arrb.size()+1)
{
maxc=abs(arrb[z]-arra[i]);
ind1=i;
ind2=z;
}
}
}
if(ind1==-1||ind2==-1||ind1==arra.size()||ind2==arrb.size()) cout<<-1<<endl;
else
cout<<a*b/((arra[ind1]+1)*(arrb[ind2]+1))<<endl;
}
| Title: Jzzhu and Chocolate
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements:
- each cut should be straight (horizontal or vertical); - each cut should go along edges of unit squares (it is prohibited to divide any unit chocolate square with cut); - each cut should go inside the whole chocolate bar, and all cuts must be distinct.
The picture below shows a possible way to cut a 5<=×<=6 chocolate for 5 times.
Imagine Jzzhu have made *k* cuts and the big chocolate is splitted into several pieces. Consider the smallest (by area) piece of the chocolate, Jzzhu wants this piece to be as large as possible. What is the maximum possible area of smallest piece he can get with exactly *k* cuts? The area of a chocolate piece is the number of unit squares in it.
Input Specification:
A single line contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=109; 1<=≤<=*k*<=≤<=2·109).
Output Specification:
Output a single integer representing the answer. If it is impossible to cut the big chocolate *k* times, print -1.
Demo Input:
['3 4 1\n', '6 4 2\n', '2 3 4\n']
Demo Output:
['6\n', '8\n', '-1\n']
Note:
In the first sample, Jzzhu can cut the chocolate following the picture below:
In the second sample the optimal division looks like this:
In the third sample, it's impossible to cut a 2 × 3 chocolate 4 times. | ```python
#include <bits/stdc++.h>
#include <cmath>
#include <chrono>
#include <numeric>
using namespace std;
#define fasterio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl "\n"
#define ll long long
#define testcase int t; cin>>t; for(int i=0;i<t;i++)
#define int long long
#define double long double
#define pb push_back
ll mod= 998244353;
ll N = 252000;
ll inf = 1e18;
void divisors(int n,vector<int> &v)
{
for(int i=1;i<=sqrt(n);i++)
{
if(i!=n/i&&n%i==0) {v.push_back(i);v.push_back(n/i);}
else v.push_back(i);
}
}
signed main()
{
#define int long long
fasterio
#ifndef ONLINE_JUDGE
freopen("error.txt", "w", stderr);
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a,b,c;
vector<int> arra;
vector<int> arrb;
cin>>a>>b>>c;
divisors(a,arra);
divisors(b,arrb);
arra.push_back(0);
arrb.push_back(0);
sort(arra.begin(),arra.end());
sort(arrb.begin(),arrb.end());
auto x=lower_bound(arra.begin(),arra.end(),c)-arra.begin();
auto y=lower_bound(arrb.begin(),arrb.end(),c)-arrb.begin();
//cout<<x<<y<<endl;
int maxc=0;
int ind1=-1;
int ind2=-1;
int z=0;
for(int i=x;i>=0;i--)
{
if(arra[i]>c) continue;
else
{
z=lower_bound(arrb.begin(),arrb.end(),c-arra[i])-arrb.begin();
if(abs(arrb[z]-arra[i])>maxc&&z!=arrb.size()+1)
{
maxc=abs(arrb[z]-arra[i]);
ind1=i;
ind2=z;
}
}
}
if(ind1==-1||ind2==-1||ind1==arra.size()||ind2==arrb.size()) cout<<-1<<endl;
else
cout<<a*b/((arra[ind1]+1)*(arrb[ind2]+1))<<endl;
}
``` | -1 |
|
802 | M | April Fools' Problem (easy) | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.
However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools! | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2200). The second line contains *n* space-separated integers *a*1,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104). | Output one number. | [
"8 5\n1 1 1 1 1 1 1 1\n",
"10 3\n16 8 2 4 512 256 32 128 64 1\n",
"5 1\n20 10 50 30 46\n",
"6 6\n6 6 6 6 6 6\n",
"1 1\n100\n"
] | [
"5",
"7",
"10",
"36",
"100"
] | none | 0 | [
{
"input": "8 5\n1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "10 3\n16 8 2 4 512 256 32 128 64 1",
"output": "7"
},
{
"input": "5 1\n20 10 50 30 46",
"output": "10"
},
{
"input": "6 6\n6 6 6 6 6 6",
"output": "36"
},
{
"input": "1 1\n100",
"output": "100"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 5\n147 1917 5539 7159 5763 416 711 1412 6733 4402",
"output": "4603"
},
{
"input": "100 60\n1443 3849 6174 8249 696 8715 3461 9159 4468 2496 3044 2301 2437 7559 7235 7956 8959 2036 4399 9595 8664 9743 7688 3730 3705 1203 9332 7088 8563 3823 2794 8014 6951 1160 8616 970 9885 2421 6510 4885 5246 6146 8849 5141 8602 9486 7257 3300 8323 4797 4082 7135 80 9622 4543 6567 2747 5013 4626 9091 9028 9851 1654 7021 6843 3209 5350 3809 4697 4617 4450 81 5208 1877 2897 6115 3191 2878 9258 2849 8103 6678 8714 8024 80 9894 321 8074 6797 457 1348 8652 811 7215 4381 5000 7406 7899 9974 844",
"output": "206735"
}
] | 1,660,065,581 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 31 | 0 | a,b=map(int,input().split())
t=[int(i) for i in input().split()]
count=0
t.sort()
for i in range(b):count+=t[i]
print(count) | Title: April Fools' Problem (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers *n*, *k* and a sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also reads like a good criminal.
However I, Heidi, will have none of that. As my joke for today, I am removing the story from the statement and replacing it with these two unhelpful paragraphs. Now solve the problem, fools!
Input Specification:
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=2200). The second line contains *n* space-separated integers *a*1,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104).
Output Specification:
Output one number.
Demo Input:
['8 5\n1 1 1 1 1 1 1 1\n', '10 3\n16 8 2 4 512 256 32 128 64 1\n', '5 1\n20 10 50 30 46\n', '6 6\n6 6 6 6 6 6\n', '1 1\n100\n']
Demo Output:
['5', '7', '10', '36', '100']
Note:
none | ```python
a,b=map(int,input().split())
t=[int(i) for i in input().split()]
count=0
t.sort()
for i in range(b):count+=t[i]
print(count)
``` | 3 |
|
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation. | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
},
{
"input": "693\n970",
"output": "NO"
},
{
"input": "981\n1",
"output": "YES"
},
{
"input": "352\n276",
"output": "YES"
},
{
"input": "164\n691",
"output": "YES"
},
{
"input": "110036\n43",
"output": "YES"
},
{
"input": "100\n1000",
"output": "NO"
},
{
"input": "1000000000\n1000000000",
"output": "YES"
},
{
"input": "999999999\n999999999",
"output": "YES"
},
{
"input": "6\n4",
"output": "NO"
},
{
"input": "123456\n876543",
"output": "YES"
},
{
"input": "1234567\n9876543",
"output": "NO"
},
{
"input": "1111111\n1119111",
"output": "NO"
},
{
"input": "10502405\n40403403",
"output": "YES"
},
{
"input": "1\n1",
"output": "YES"
},
{
"input": "5\n4",
"output": "YES"
},
{
"input": "1\n6",
"output": "YES"
},
{
"input": "40\n17",
"output": "NO"
},
{
"input": "35\n81",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "2081\n7450",
"output": "NO"
},
{
"input": "84355694\n373629503",
"output": "NO"
},
{
"input": "885992048\n510468672",
"output": "NO"
},
{
"input": "540144752\n647307841",
"output": "NO"
},
{
"input": "341781108\n784147010",
"output": "NO"
},
{
"input": "960440938\n572334653",
"output": "NO"
},
{
"input": "657414510\n768771903",
"output": "NO"
},
{
"input": "501871728\n725074574",
"output": "NO"
},
{
"input": "968\n851",
"output": "YES"
},
{
"input": "943\n939",
"output": "YES"
},
{
"input": "347\n908",
"output": "NO"
},
{
"input": "611\n41",
"output": "YES"
},
{
"input": "737\n289",
"output": "NO"
},
{
"input": "168\n571",
"output": "YES"
},
{
"input": "868\n463",
"output": "YES"
},
{
"input": "815732007\n913882008",
"output": "NO"
},
{
"input": "459039901\n453033850",
"output": "NO"
},
{
"input": "975305404\n484601256",
"output": "NO"
}
] | 1,470,930,215 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | a=input()
b=input()
c=int(a)+int(b)
aa,bb,cc='','',''
for i in a: if i!='0': aa+=i
for i in b: if i!='0': bb+=i
for i in c: if i!='0': cc+=i
if int(aa)+int(bb)==int(cc): print("YES") else: print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c* is the sum of *a* and *b*. Now let's remove all zeros from this equation. Will the equation remain correct after removing all zeros?
For example if the equation is 101<=+<=102<==<=203, if we removed all zeros it will be 11<=+<=12<==<=23 which is still a correct equation.
But if the equation is 105<=+<=106<==<=211, if we removed all zeros it will be 15<=+<=16<==<=211 which is not a correct equation.
Input Specification:
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
Output Specification:
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
Demo Input:
['101\n102\n', '105\n106\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
a=input()
b=input()
c=int(a)+int(b)
aa,bb,cc='','',''
for i in a: if i!='0': aa+=i
for i in b: if i!='0': bb+=i
for i in c: if i!='0': cc+=i
if int(aa)+int(bb)==int(cc): print("YES") else: print("NO")
``` | -1 |
730 | H | Delete Them | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
- matches filenames "aabaa", "abba.", "a.ba9" and "a.ba."; - does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern. | The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — the total number of files and the number of files to be deleted.
The following *n* lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains *m* distinct integer numbers in ascending order *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*) — indices of files to be deleted. All files are indexed from 1 to *n* in order of their appearance in the input. | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | [
"3 2\nab\nac\ncd\n1 2\n",
"5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n",
"4 4\na\nb\nc\ndd\n1 2 3 4\n",
"6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n"
] | [
"Yes\na?\n",
"Yes\n?es?\n",
"No\n",
"Yes\n.???\n"
] | none | 0 | [
{
"input": "3 2\nab\nac\ncd\n1 2",
"output": "Yes\na?"
},
{
"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5",
"output": "Yes\n?es?"
},
{
"input": "4 4\na\nb\nc\ndd\n1 2 3 4",
"output": "No"
},
{
"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3",
"output": "Yes\n.???"
},
{
"input": "4 2\n.b\n.c\ndbt\ne.\n2 4",
"output": "No"
},
{
"input": "27 27\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n.\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27",
"output": "Yes\n?"
},
{
"input": "27 26\na\nb\nc\nd\nee\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n.\n1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27",
"output": "Yes\n?"
},
{
"input": "27 26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nkq\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz\n.\n1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27",
"output": "No"
},
{
"input": "1 1\nuevim.mrr\n1",
"output": "Yes\nuevim.mrr"
},
{
"input": "2 1\nkbfyvezmy\nsbfammwcy\n1",
"output": "Yes\nkbfyvezmy"
},
{
"input": "5 3\nlmljeqklg\nlclydkkxj\nuylscbk.g\neplpqakme\nablibhkfg\n1 3 5",
"output": "Yes\n??l???k?g"
},
{
"input": "5 4\nabacaba\naaaaaaa\naaaaaab\naaaaaac\naaaaaad\n2 3 4 5",
"output": "Yes\naaaaaa?"
},
{
"input": "5 4\nabacaba\naaaaaaa\nbaaaaab\ncaaaaac\ndaaaaad\n2 3 4 5",
"output": "Yes\n?aaaaa?"
},
{
"input": "5 5\nabacaba\naaaaaaa\nbaaaaab\ncaaaaac\ndaaaaad\n1 2 3 4 5",
"output": "Yes\n??a?a??"
},
{
"input": "5 3\nabacaba\naaaaaaa\nbaaaaab\ncaaaaac\ndaaaaad\n2 3 4",
"output": "No"
},
{
"input": "5 4\naaaaaaa\nbaaaaab\ncaaaaac\ndaaaaad\nabacaba\n1 2 3 4",
"output": "Yes\n?aaaaa?"
},
{
"input": "5 3\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeeeeee\n1 3 5",
"output": "No"
},
{
"input": "5 4\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeeeeee\n1 3 4 5",
"output": "No"
},
{
"input": "5 5\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeeeeee\n1 2 3 4 5",
"output": "Yes\n??????????"
},
{
"input": "5 4\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\neeeeeeeee\n1 2 3 4",
"output": "Yes\n??????????"
},
{
"input": "5 4\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\neeeeeeeee\ndddddddddd\n1 2 3 5",
"output": "Yes\n??????????"
},
{
"input": "5 4\naaaaaaaaaa\nbbbbbbbbbb\neeeeeeeee\ncccccccccc\ndddddddddd\n1 2 4 5",
"output": "Yes\n??????????"
},
{
"input": "5 4\naaaaaaaaaa\neeeeeeeee\nbbbbbbbbbb\ncccccccccc\ndddddddddd\n1 3 4 5",
"output": "Yes\n??????????"
},
{
"input": "5 4\neeeeeeeee\naaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddddd\n2 3 4 5",
"output": "Yes\n??????????"
},
{
"input": "2 1\na\nb\n1",
"output": "Yes\na"
},
{
"input": "2 1\na\nb\n2",
"output": "Yes\nb"
},
{
"input": "2 2\na\nb\n1 2",
"output": "Yes\n?"
},
{
"input": "2 1\naa\nb\n1",
"output": "Yes\naa"
},
{
"input": "2 1\naa\nb\n2",
"output": "Yes\nb"
},
{
"input": "2 2\naa\nb\n1 2",
"output": "No"
},
{
"input": "2 1\nb\naa\n1",
"output": "Yes\nb"
},
{
"input": "2 1\nb\naa\n2",
"output": "Yes\naa"
},
{
"input": "2 2\nb\naa\n1 2",
"output": "No"
},
{
"input": "2 1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac\n1",
"output": "Yes\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
}
] | 1,535,994,427 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 0 | def gpn(sf,ss):
#print('>>',sf,ss)
if len(sf)!=len(ss):
return 0,None,None
n=len(sf)
ts,b,tsl='',0,[]
for c in range(n):
if sf[c]==ss[c]:
b=1
ts+=sf[c]
tsl.append(c)
else:
ts+='?'
return b,ts,tsl
def gpnts(s,ts,tsl):
#print('>>',s,ts,tsl)
ntsl=[]
for c in tsl:
if s[c]==ts[c]:
ntsl.append(c)
else:
ts=ts[:c]
ts+='?'
ts+=ts[c+1:]
return len(ntsl),ts,ntsl
def hsp(vs,sn):
lsn=len(sn)
if lsn==1:
return 1,vs[sn[0]]
b,ts,tsl=gpn(vs[sn[0]],vs[sn[1]])
#print('ts=',ts)
if b==0:
return 0,None
for c in range(2,lsn):
b,ts,tsl=gpnts(vs[sn[c]],ts,tsl)
if b==0:
return 0,None
return 1,ts
n,k=[int(x) for x in input().split(' ')]
vs=[]
for c in range(n):
vs.append(input())
sn=[int(x)-1 for x in input().split(' ')]
b,ts=hsp(vs,sn)
if b:
print('Yes')
print(ts)
else:
print('No') | Title: Delete Them
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pattern and all other files shouldn't match the pattern.
Polycarp doesn't know about an asterisk '*', the only special character he knows is a question mark '?' which matches any single character. All other characters in the pattern match themselves only.
Formally, a pattern matches a filename if and only if they have equal lengths and all characters in the corresponding positions are equal except when the character in the pattern is '?', in which case the corresponding filename character does not matter.
For example, the filename pattern "a?ba?":
- matches filenames "aabaa", "abba.", "a.ba9" and "a.ba."; - does not match filenames "aaba", "abaab", "aabaaa" and "aabaa.".
Help Polycarp find a pattern which matches files to be deleted and only them or report if there is no such pattern.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — the total number of files and the number of files to be deleted.
The following *n* lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dots ('.'). The length of each filename doesn't exceed 100. It is guaranteed that all filenames are distinct.
The last line of the input contains *m* distinct integer numbers in ascending order *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=*n*) — indices of files to be deleted. All files are indexed from 1 to *n* in order of their appearance in the input.
Output Specification:
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No".
Demo Input:
['3 2\nab\nac\ncd\n1 2\n', '5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n', '4 4\na\nb\nc\ndd\n1 2 3 4\n', '6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n']
Demo Output:
['Yes\na?\n', 'Yes\n?es?\n', 'No\n', 'Yes\n.???\n']
Note:
none | ```python
def gpn(sf,ss):
#print('>>',sf,ss)
if len(sf)!=len(ss):
return 0,None,None
n=len(sf)
ts,b,tsl='',0,[]
for c in range(n):
if sf[c]==ss[c]:
b=1
ts+=sf[c]
tsl.append(c)
else:
ts+='?'
return b,ts,tsl
def gpnts(s,ts,tsl):
#print('>>',s,ts,tsl)
ntsl=[]
for c in tsl:
if s[c]==ts[c]:
ntsl.append(c)
else:
ts=ts[:c]
ts+='?'
ts+=ts[c+1:]
return len(ntsl),ts,ntsl
def hsp(vs,sn):
lsn=len(sn)
if lsn==1:
return 1,vs[sn[0]]
b,ts,tsl=gpn(vs[sn[0]],vs[sn[1]])
#print('ts=',ts)
if b==0:
return 0,None
for c in range(2,lsn):
b,ts,tsl=gpnts(vs[sn[c]],ts,tsl)
if b==0:
return 0,None
return 1,ts
n,k=[int(x) for x in input().split(' ')]
vs=[]
for c in range(n):
vs.append(input())
sn=[int(x)-1 for x in input().split(' ')]
b,ts=hsp(vs,sn)
if b:
print('Yes')
print(ts)
else:
print('No')
``` | 0 |
|
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him. | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "1 10",
"output": "<"
},
{
"input": "9 1",
"output": ">"
},
{
"input": "1 1",
"output": "="
},
{
"input": "2 2",
"output": "="
},
{
"input": "3 3",
"output": "="
},
{
"input": "4 4",
"output": "="
},
{
"input": "5 5",
"output": "="
},
{
"input": "2 3",
"output": "<"
},
{
"input": "2 5",
"output": ">"
},
{
"input": "3 2",
"output": ">"
},
{
"input": "3 4",
"output": ">"
},
{
"input": "3 5",
"output": ">"
},
{
"input": "4 2",
"output": "="
},
{
"input": "4 3",
"output": "<"
},
{
"input": "4 5",
"output": ">"
},
{
"input": "5 2",
"output": "<"
},
{
"input": "5 3",
"output": "<"
},
{
"input": "5 4",
"output": "<"
},
{
"input": "100 101",
"output": ">"
},
{
"input": "876543 372647",
"output": "<"
},
{
"input": "1000000000 999999999",
"output": "<"
},
{
"input": "1000000000 2",
"output": "<"
},
{
"input": "1000000000 1",
"output": ">"
},
{
"input": "987654321 123456789",
"output": "<"
},
{
"input": "1000000000 1000000000",
"output": "="
},
{
"input": "4359435 4396510",
"output": ">"
},
{
"input": "25936809 25936809",
"output": "="
},
{
"input": "53602896 3",
"output": "<"
},
{
"input": "13208659 1",
"output": ">"
},
{
"input": "620537015 620537016",
"output": ">"
},
{
"input": "56498103 56498102",
"output": "<"
},
{
"input": "4 1000000000",
"output": ">"
},
{
"input": "11 15",
"output": ">"
},
{
"input": "2 6",
"output": ">"
},
{
"input": "1 100",
"output": "<"
},
{
"input": "3 9",
"output": ">"
},
{
"input": "5 25",
"output": ">"
},
{
"input": "17 18",
"output": ">"
},
{
"input": "100 99",
"output": "<"
},
{
"input": "10000035 1000432",
"output": "<"
},
{
"input": "27 3",
"output": "<"
},
{
"input": "15657413 15657414",
"output": ">"
}
] | 1,628,583,448 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 62 | 6,963,200 | x, y = map(int, input().split())
if ((x == y) or ((x == 2) and (y == 4)) or ((x == 4) and (y == 2))) : print('=')
else :
if (((x == 2) and (y == 3)) or (x == 1)) : print('<')
else :
if (((x == 3) and (y == 2)) or (y == 1)) : print('>')
else :
if (x < y) : print('>')
else :
if (x > y) : print('<') | Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-class android which is produced by a little-known company. His design is not perfect, his characteristics also could be better. So he is bullied by other androids.
One of the popular pranks on Vasya is to force him to compare $x^y$ with $y^x$. Other androids can do it in milliseconds while Vasya's memory is too small to store such big numbers.
Please help Vasya! Write a fast program to compare $x^y$ with $y^x$ for Vasya, maybe then other androids will respect him.
Input Specification:
On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$).
Output Specification:
If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes).
Demo Input:
['5 8\n', '10 3\n', '6 6\n']
Demo Output:
['>\n', '<\n', '=\n']
Note:
In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | ```python
x, y = map(int, input().split())
if ((x == y) or ((x == 2) and (y == 4)) or ((x == 4) and (y == 2))) : print('=')
else :
if (((x == 2) and (y == 3)) or (x == 1)) : print('<')
else :
if (((x == 3) and (y == 2)) or (y == 1)) : print('>')
else :
if (x < y) : print('>')
else :
if (x > y) : print('<')
``` | 3 |
|
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him. | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*. | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"input": "12 3\n1 2 1 15 2 3 6 8 3 3 8 6",
"output": "4 7"
},
{
"input": "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3",
"output": "3 7"
},
{
"input": "2 1\n1 1",
"output": "1 2"
},
{
"input": "2 1\n1000000000 999999999",
"output": "1 2"
},
{
"input": "3 1\n100 30 563",
"output": "1 3"
},
{
"input": "3 1\n547468 78578678 6467834",
"output": "2 3"
},
{
"input": "4 1\n90000 34567 90000 90001",
"output": "1 4"
},
{
"input": "4 2\n999999 8888888 7777777 666666",
"output": "1 3"
},
{
"input": "5 1\n2 1 2 1 2",
"output": "1 3"
},
{
"input": "5 2\n98 96 98 96 96",
"output": "1 3"
},
{
"input": "6 2\n4 4 7 1 1 7",
"output": "2 5"
},
{
"input": "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22 32 34 91 37 30 26 92 77 69 11 59 78 24 66 88 15 32 49 46 14 57 20 5 69 53 99 81 70 67 22 54 31 49 52 46 51 46 2 53 59 8 66 28 53 54 5 85 75 15 55 87 16 68 6 36 98",
"output": "30 67"
},
{
"input": "6 3\n1 2 2 2 1 1",
"output": "1 4"
},
{
"input": "10 4\n9 3 3 9 1 9 9 4 4 9",
"output": "1 6"
},
{
"input": "7 3\n1 2 5 5 5 5 5",
"output": "2 5"
}
] | 1,662,732,476 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 614,400 | # Init ---------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
from random import randint
RANDOM = randint(1, 10 ** 9)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class IntWrapper(int):
def __init__(self, x):
int.__init__(x)
def __hash__(self):
return super(IntWrapper, self).__hash__() ^ RANDOM
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def LI():
return list(map(int, input().split()))
def I():
return int(input())
def LIW():
return list(map(IntWrapper, input().split()))
def IW():
return IntWrapper(input())
# End---------------------------------------------------------
def slide(values, start, end, size):
i = -1
best_sum, curr_sum = 0, 0
for pos in range(start, end):
if (pos - start) >= size:
curr_sum -= values[pos - size]
curr_sum += values[pos]
if (pos - start) >= size - 1:
if curr_sum > best_sum:
i = pos - size + 1
best_sum = curr_sum
# print(start, end, size, i, best_sum)
return i, best_sum
n, k = LI()
values = LI()
pref_sum = [values[0]]
for x in range(1, n):
pref_sum.append(pref_sum[-1] + values[x])
def f(cache, i, s):
if s == 0: return 0
if (i, s) not in cache:
ans = float('-inf')
for x in range(i, n - k + 1):
total_sum = pref_sum[x + k - 1]
if x > 0:
total_sum -= pref_sum[x - 1]
ans = max(ans, f(cache, x + k, s - 1) + total_sum)
cache[i, s] = ans
return cache[i, s]
cache = {}
f(cache, 0, 2)
dp = [[0] * (n + 1) for _ in range(3)]
for i, s in cache:
dp[s][i] = cache[i, s]
v2 = dp[1][k]
v1 = dp[2][0] - v2
a, b = -1, -1
curr_sum = 0
for x in range(len(values)):
if x >= k:
curr_sum -= values[x-k]
curr_sum += values[x]
if x >= (k - 1):
if (curr_sum == v1) and (a == -1):
a = x - k + 1
if (curr_sum == v2) and (b == -1) and (x > a + k):
b = x - k + 1
a, b = min(a, b), max(a, b)
print(a + 1, b + 1)
| Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign 2*k* laws. He decided to choose exactly two non-intersecting segments of integers from 1 to *n* of length *k* and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers *a*, *b* (1<=≤<=*a*<=≤<=*b*<=≤<=*n*<=-<=*k*<=+<=1,<=*b*<=-<=*a*<=≥<=*k*) and sign all laws with numbers lying in the segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1] (borders are included).
As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109).
Output Specification:
Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple solutions, print the one with the minimum *b*.
Demo Input:
['5 2\n3 6 1 1 6\n', '6 2\n1 1 1 1 1 1\n']
Demo Output:
['1 4\n', '1 3\n']
Note:
In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | ```python
# Init ---------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
from random import randint
RANDOM = randint(1, 10 ** 9)
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class IntWrapper(int):
def __init__(self, x):
int.__init__(x)
def __hash__(self):
return super(IntWrapper, self).__hash__() ^ RANDOM
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def LI():
return list(map(int, input().split()))
def I():
return int(input())
def LIW():
return list(map(IntWrapper, input().split()))
def IW():
return IntWrapper(input())
# End---------------------------------------------------------
def slide(values, start, end, size):
i = -1
best_sum, curr_sum = 0, 0
for pos in range(start, end):
if (pos - start) >= size:
curr_sum -= values[pos - size]
curr_sum += values[pos]
if (pos - start) >= size - 1:
if curr_sum > best_sum:
i = pos - size + 1
best_sum = curr_sum
# print(start, end, size, i, best_sum)
return i, best_sum
n, k = LI()
values = LI()
pref_sum = [values[0]]
for x in range(1, n):
pref_sum.append(pref_sum[-1] + values[x])
def f(cache, i, s):
if s == 0: return 0
if (i, s) not in cache:
ans = float('-inf')
for x in range(i, n - k + 1):
total_sum = pref_sum[x + k - 1]
if x > 0:
total_sum -= pref_sum[x - 1]
ans = max(ans, f(cache, x + k, s - 1) + total_sum)
cache[i, s] = ans
return cache[i, s]
cache = {}
f(cache, 0, 2)
dp = [[0] * (n + 1) for _ in range(3)]
for i, s in cache:
dp[s][i] = cache[i, s]
v2 = dp[1][k]
v1 = dp[2][0] - v2
a, b = -1, -1
curr_sum = 0
for x in range(len(values)):
if x >= k:
curr_sum -= values[x-k]
curr_sum += values[x]
if x >= (k - 1):
if (curr_sum == v1) and (a == -1):
a = x - k + 1
if (curr_sum == v2) and (b == -1) and (x > a + k):
b = x - k + 1
a, b = min(a, b), max(a, b)
print(a + 1, b + 1)
``` | 0 |
|
413 | A | Data Recovery | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*.
The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*. | The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. | If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). | [
"2 1 1 2\n1\n",
"3 1 1 3\n2\n",
"2 1 1 3\n2\n"
] | [
"Correct\n",
"Correct\n",
"Incorrect\n"
] | In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3. | 500 | [
{
"input": "2 1 1 2\n1",
"output": "Correct"
},
{
"input": "3 1 1 3\n2",
"output": "Correct"
},
{
"input": "2 1 1 3\n2",
"output": "Incorrect"
},
{
"input": "3 1 1 5\n3",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 5",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 1",
"output": "Correct"
},
{
"input": "3 2 1 5\n5 5",
"output": "Correct"
},
{
"input": "3 2 1 5\n1 6",
"output": "Incorrect"
},
{
"input": "3 2 5 10\n1 10",
"output": "Incorrect"
},
{
"input": "6 5 3 6\n4 4 4 4 4",
"output": "Incorrect"
},
{
"input": "100 50 68 97\n20 42 93 1 98 6 32 11 48 46 82 96 24 73 40 100 99 10 55 87 65 80 97 54 59 48 30 22 16 92 66 2 22 60 23 81 64 60 34 60 99 99 4 70 91 99 30 20 41 96",
"output": "Incorrect"
},
{
"input": "100 50 1 2\n1 1 2 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 2 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 1 1 1 1 1 2 1 1 1 2 1 2 2 2 1 2",
"output": "Correct"
},
{
"input": "100 99 1 2\n2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 1 1 1 2 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 1 2 1 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 2",
"output": "Correct"
},
{
"input": "3 2 2 100\n40 1",
"output": "Incorrect"
},
{
"input": "3 2 2 3\n4 4",
"output": "Incorrect"
},
{
"input": "5 2 2 4\n2 2",
"output": "Correct"
},
{
"input": "5 1 1 4\n1",
"output": "Correct"
},
{
"input": "9 7 1 4\n4 3 3 2 2 4 1",
"output": "Correct"
},
{
"input": "9 5 2 3\n4 2 4 3 3",
"output": "Incorrect"
},
{
"input": "6 3 1 3\n1 4 2",
"output": "Incorrect"
},
{
"input": "3 2 1 99\n34 100",
"output": "Incorrect"
},
{
"input": "4 2 1 99\n100 38",
"output": "Incorrect"
},
{
"input": "5 2 1 99\n100 38",
"output": "Incorrect"
},
{
"input": "4 2 1 99\n36 51",
"output": "Correct"
},
{
"input": "7 6 3 10\n5 10 7 7 4 5",
"output": "Correct"
},
{
"input": "8 6 3 10\n8 5 7 8 4 4",
"output": "Correct"
},
{
"input": "9 6 3 10\n9 7 7 5 3 10",
"output": "Correct"
},
{
"input": "16 15 30 40\n36 37 35 36 34 34 37 35 32 33 31 38 39 38 38",
"output": "Incorrect"
},
{
"input": "17 15 30 40\n38 36 37 34 30 38 38 31 38 38 36 39 39 37 35",
"output": "Correct"
},
{
"input": "18 15 30 40\n35 37 31 32 30 33 36 38 36 38 31 30 39 32 36",
"output": "Correct"
},
{
"input": "17 16 30 40\n39 32 37 31 40 32 36 34 56 34 40 36 37 36 33 36",
"output": "Incorrect"
},
{
"input": "18 16 30 40\n32 35 33 39 34 30 37 34 30 34 39 18 32 37 37 36",
"output": "Incorrect"
},
{
"input": "19 16 30 40\n36 30 37 30 37 32 34 30 35 35 33 35 39 37 46 37",
"output": "Incorrect"
},
{
"input": "2 1 2 100\n38",
"output": "Incorrect"
},
{
"input": "3 1 2 100\n1",
"output": "Incorrect"
},
{
"input": "4 1 2 100\n1",
"output": "Incorrect"
},
{
"input": "91 38 1 3\n3 2 3 2 3 2 3 3 1 1 1 2 2 1 3 2 3 1 3 3 1 3 3 2 1 2 2 3 1 2 1 3 2 2 3 1 1 2",
"output": "Correct"
},
{
"input": "4 3 2 10\n6 3 10",
"output": "Correct"
},
{
"input": "41 6 4 10\n10 7 4 9 9 10",
"output": "Correct"
},
{
"input": "21 1 1 9\n9",
"output": "Correct"
},
{
"input": "2 1 9 10\n10",
"output": "Correct"
},
{
"input": "2 1 2 9\n9",
"output": "Correct"
},
{
"input": "8 7 5 9\n6 7 8 5 5 6 6",
"output": "Correct"
},
{
"input": "3 2 2 8\n7 2",
"output": "Correct"
},
{
"input": "71 36 1 10\n7 10 8 1 3 8 5 7 3 10 8 1 6 4 5 7 8 2 4 3 4 10 8 5 1 2 8 8 10 10 4 3 7 9 7 8",
"output": "Correct"
},
{
"input": "85 3 4 9\n4 8 7",
"output": "Correct"
},
{
"input": "4 3 4 10\n9 10 5",
"output": "Correct"
},
{
"input": "2 1 1 5\n1",
"output": "Correct"
},
{
"input": "91 75 1 10\n2 6 9 7 4 9 4 8 10 6 4 1 10 6 5 9 7 5 1 4 6 4 8 2 1 3 5 7 6 9 5 5 8 1 7 1 4 2 8 3 1 6 6 2 10 6 2 2 8 5 4 5 5 3 10 9 4 3 1 9 10 3 2 4 8 7 4 9 3 1 1 1 3 4 5",
"output": "Correct"
},
{
"input": "10 4 1 8\n7 9 6 6",
"output": "Incorrect"
},
{
"input": "18 1 3 10\n2",
"output": "Incorrect"
},
{
"input": "6 2 4 8\n6 3",
"output": "Incorrect"
},
{
"input": "17 6 2 8\n3 8 6 1 6 4",
"output": "Incorrect"
},
{
"input": "21 1 5 8\n4",
"output": "Incorrect"
},
{
"input": "2 1 1 10\n9",
"output": "Incorrect"
},
{
"input": "2 1 4 8\n5",
"output": "Incorrect"
},
{
"input": "2 1 1 7\n6",
"output": "Incorrect"
},
{
"input": "2 1 4 9\n5",
"output": "Incorrect"
},
{
"input": "2 1 3 8\n7",
"output": "Incorrect"
},
{
"input": "2 1 5 9\n6",
"output": "Incorrect"
},
{
"input": "3 2 1 10\n4 9",
"output": "Incorrect"
},
{
"input": "2 1 4 10\n7",
"output": "Incorrect"
},
{
"input": "2 1 2 9\n8",
"output": "Incorrect"
},
{
"input": "2 1 3 9\n3",
"output": "Correct"
},
{
"input": "3 2 6 7\n6 6",
"output": "Correct"
},
{
"input": "6 4 1 10\n11 10 9 1",
"output": "Incorrect"
},
{
"input": "7 6 3 8\n3 4 5 6 7 8",
"output": "Correct"
},
{
"input": "5 3 1 5\n2 3 4",
"output": "Correct"
}
] | 1,597,905,534 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 124 | 0 | a,b,c,d=map(int,input().split())
z=list(map(int,input().split()))
k=z.copy()
if c in k:k.remove(c)
if d in k:k.remove(d)
if (max(z)>d or min(z)<c or len(k)+2>a ):print("Incorrect")
else:print("Correct") | Title: Data Recovery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.
The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*.
The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*.
Input Specification:
The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=<<=*n*<=≤<=100; 1<=≤<=*min*<=<<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant.
Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.
Output Specification:
If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes).
Demo Input:
['2 1 1 2\n1\n', '3 1 1 3\n2\n', '2 1 1 3\n2\n']
Demo Output:
['Correct\n', 'Correct\n', 'Incorrect\n']
Note:
In the first test sample one of the possible initial configurations of temperatures is [1, 2].
In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].
In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3. | ```python
a,b,c,d=map(int,input().split())
z=list(map(int,input().split()))
k=z.copy()
if c in k:k.remove(c)
if d in k:k.remove(d)
if (max(z)>d or min(z)<c or len(k)+2>a ):print("Incorrect")
else:print("Correct")
``` | 3 |
|
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"output": "653"
},
{
"input": "194",
"output": "120"
},
{
"input": "906",
"output": "786"
},
{
"input": "659",
"output": "535"
},
{
"input": "75",
"output": "37"
},
{
"input": "787",
"output": "664"
},
{
"input": "851",
"output": "730"
},
{
"input": "563",
"output": "446"
},
{
"input": "979",
"output": "862"
},
{
"input": "395",
"output": "291"
},
{
"input": "755",
"output": "634"
},
{
"input": "171",
"output": "103"
},
{
"input": "883",
"output": "759"
},
{
"input": "400",
"output": "294"
},
{
"input": "817",
"output": "693"
},
{
"input": "177",
"output": "107"
},
{
"input": "593",
"output": "476"
},
{
"input": "305",
"output": "214"
},
{
"input": "721",
"output": "595"
},
{
"input": "785",
"output": "664"
},
{
"input": "497",
"output": "383"
},
{
"input": "913",
"output": "791"
},
{
"input": "625",
"output": "507"
},
{
"input": "334",
"output": "236"
},
{
"input": "10000",
"output": "12471"
},
{
"input": "9999",
"output": "12467"
}
] | 1,665,848,579 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 1,536,000 | import math
n = int(input())
times = 0
for a in range(1, n+1):
for b in range(a, n+1):
c2 = a**2 + b**2
if math.sqrt(c2).is_integer():
times += 1
print(times) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
Input Specification:
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5\n', '74\n']
Demo Output:
['1\n', '35\n']
Note:
none | ```python
import math
n = int(input())
times = 0
for a in range(1, n+1):
for b in range(a, n+1):
c2 = a**2 + b**2
if math.sqrt(c2).is_integer():
times += 1
print(times)
``` | 0 |
|
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
"input": "3 5\n1 10 20",
"output": "1"
},
{
"input": "3 10\n1 2 3",
"output": "3"
},
{
"input": "2 1\n1 100",
"output": "1"
},
{
"input": "3 1\n1 2 10",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
}
] | 1,677,316,257 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def main():
n,c = [int(i) for i in input().split()]
n_list = [int(i) for i in input().split()]
res = 1
for i in range(n):
res+=1
if i!=0:
if n_list[i]-n_list[i-1]>c:
res = 1
return res
print(main()) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
Input Specification:
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Output Specification:
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
Demo Input:
['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n']
Demo Output:
['3', '2']
Note:
The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | ```python
def main():
n,c = [int(i) for i in input().split()]
n_list = [int(i) for i in input().split()]
res = 1
for i in range(n):
res+=1
if i!=0:
if n_list[i]-n_list[i-1]>c:
res = 1
return res
print(main())
``` | 0 |
|
467 | A | George and Accommodation | PROGRAMMING | 800 | [
"implementation"
] | null | null | George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. | Print a single integer — the number of rooms where George and Alex can move in. | [
"3\n1 1\n2 2\n3 3\n",
"3\n1 10\n0 10\n10 10\n"
] | [
"0\n",
"2\n"
] | none | 500 | [
{
"input": "3\n1 1\n2 2\n3 3",
"output": "0"
},
{
"input": "3\n1 10\n0 10\n10 10",
"output": "2"
},
{
"input": "2\n36 67\n61 69",
"output": "2"
},
{
"input": "3\n21 71\n10 88\n43 62",
"output": "3"
},
{
"input": "3\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "10\n0 10\n0 20\n0 30\n0 40\n0 50\n0 60\n0 70\n0 80\n0 90\n0 100",
"output": "10"
},
{
"input": "13\n14 16\n30 31\n45 46\n19 20\n15 17\n66 67\n75 76\n95 97\n29 30\n37 38\n0 2\n36 37\n8 9",
"output": "4"
},
{
"input": "19\n66 67\n97 98\n89 91\n67 69\n67 68\n18 20\n72 74\n28 30\n91 92\n27 28\n75 77\n17 18\n74 75\n28 30\n16 18\n90 92\n9 11\n22 24\n52 54",
"output": "12"
},
{
"input": "15\n55 57\n95 97\n57 59\n34 36\n50 52\n96 98\n39 40\n13 15\n13 14\n74 76\n47 48\n56 58\n24 25\n11 13\n67 68",
"output": "10"
},
{
"input": "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30",
"output": "8"
},
{
"input": "14\n64 66\n43 44\n10 12\n76 77\n11 12\n25 27\n87 88\n62 64\n39 41\n58 60\n10 11\n28 29\n57 58\n12 14",
"output": "7"
},
{
"input": "38\n74 76\n52 54\n78 80\n48 49\n40 41\n64 65\n28 30\n6 8\n49 51\n68 70\n44 45\n57 59\n24 25\n46 48\n49 51\n4 6\n63 64\n76 78\n57 59\n18 20\n63 64\n71 73\n88 90\n21 22\n89 90\n65 66\n89 91\n96 98\n42 44\n1 1\n74 76\n72 74\n39 40\n75 76\n29 30\n48 49\n87 89\n27 28",
"output": "22"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2",
"output": "0"
},
{
"input": "68\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2\n0 2",
"output": "68"
},
{
"input": "7\n0 1\n1 5\n2 4\n3 5\n4 6\n5 6\n6 8",
"output": "5"
},
{
"input": "1\n0 0",
"output": "0"
},
{
"input": "1\n100 100",
"output": "0"
},
{
"input": "44\n0 8\n1 11\n2 19\n3 5\n4 29\n5 45\n6 6\n7 40\n8 19\n9 22\n10 18\n11 26\n12 46\n13 13\n14 27\n15 48\n16 25\n17 20\n18 29\n19 27\n20 45\n21 39\n22 29\n23 39\n24 42\n25 37\n26 52\n27 36\n28 43\n29 35\n30 38\n31 70\n32 47\n33 38\n34 61\n35 71\n36 51\n37 71\n38 59\n39 77\n40 70\n41 80\n42 77\n43 73",
"output": "42"
},
{
"input": "3\n1 3\n2 7\n8 9",
"output": "2"
},
{
"input": "53\n0 1\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n12 13\n13 14\n14 15\n15 16\n16 17\n17 18\n18 19\n19 20\n20 21\n21 22\n22 23\n23 24\n24 25\n25 26\n26 27\n27 28\n28 29\n29 30\n30 31\n31 32\n32 33\n33 34\n34 35\n35 36\n36 37\n37 38\n38 39\n39 40\n40 41\n41 42\n42 43\n43 44\n44 45\n45 46\n46 47\n47 48\n48 49\n49 50\n50 51\n51 52\n52 53",
"output": "0"
},
{
"input": "55\n0 0\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 13\n14 14\n15 15\n16 16\n17 17\n18 18\n19 19\n20 20\n21 21\n22 22\n23 23\n24 24\n25 25\n26 26\n27 27\n28 28\n29 29\n30 30\n31 31\n32 32\n33 33\n34 34\n35 35\n36 36\n37 37\n38 38\n39 39\n40 40\n41 41\n42 42\n43 43\n44 44\n45 45\n46 46\n47 47\n48 48\n49 49\n50 50\n51 51\n52 52\n53 53\n54 54",
"output": "0"
},
{
"input": "51\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 62\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 82\n55 68\n55 70\n55 63\n55 55\n55 55\n55 55\n55 75\n55 75\n55 55\n55 55\n55 55\n55 55\n55 55\n55 55\n55 73\n55 55\n55 82\n55 99\n55 60",
"output": "12"
},
{
"input": "14\n1 1\n1 1\n1 55\n1 16\n1 1\n1 1\n1 55\n1 62\n1 53\n1 26\n1 1\n1 36\n1 2\n1 3",
"output": "8"
}
] | 1,691,077,472 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | def count_rooms_with_free_space(n, rooms):
count = 0
for i in range(n):
pi, qi = rooms[i]
if qi - pi >= 2:
count += 1
return count
# Read input
n = int(input())
rooms = [tuple(map(int, input().split())) for _ in range(n)]
# Count the number of rooms with free space for George and Alex
result = count_rooms_with_free_space(n, rooms)
# Print the output
print(result)
| Title: George and Accommodation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory.
George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms.
The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Output Specification:
Print a single integer — the number of rooms where George and Alex can move in.
Demo Input:
['3\n1 1\n2 2\n3 3\n', '3\n1 10\n0 10\n10 10\n']
Demo Output:
['0\n', '2\n']
Note:
none | ```python
def count_rooms_with_free_space(n, rooms):
count = 0
for i in range(n):
pi, qi = rooms[i]
if qi - pi >= 2:
count += 1
return count
# Read input
n = int(input())
rooms = [tuple(map(int, input().split())) for _ in range(n)]
# Count the number of rooms with free space for George and Alex
result = count_rooms_with_free_space(n, rooms)
# Print the output
print(result)
``` | 3 |
|
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "ZJWUBWUBWUBJWUBWUBWUBL",
"output": "ZJ J L "
},
{
"input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB",
"output": "C B E Q "
},
{
"input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB",
"output": "JKD WBIRAQKF YE WV "
},
{
"input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB",
"output": "KSDHEMIXUJ R S H "
},
{
"input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB",
"output": "OG X I KO "
},
{
"input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH",
"output": "Q QQ I WW JOPJPBRH "
},
{
"input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB",
"output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C "
},
{
"input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV",
"output": "E IQMJNIQ GZZBQZAUHYP PMR DCV "
},
{
"input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB",
"output": "FV BPS RXNETCJ JDMBH B V B "
},
{
"input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL",
"output": "FBQ IDFSY CTWDM SXO QI L "
},
{
"input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL",
"output": "I QLHD YIIKZDFQ CX U K NL "
},
{
"input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE",
"output": "K UPDYXGOKU AGOAH IZD IY V P E "
},
{
"input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB",
"output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ "
},
{
"input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB",
"output": "PAMJGY XGPQM TKGSXUY E N H E "
},
{
"input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB",
"output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB "
},
{
"input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM",
"output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M "
},
{
"input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW",
"output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W "
},
{
"input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG",
"output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G "
},
{
"input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN",
"output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N "
},
{
"input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG",
"output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG "
},
{
"input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB",
"output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L "
},
{
"input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB",
"output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U "
},
{
"input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB",
"output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ "
},
{
"input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB",
"output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J "
},
{
"input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO",
"output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O "
},
{
"input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR",
"output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R "
},
{
"input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB",
"output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM "
},
{
"input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB",
"output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H "
},
{
"input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB",
"output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S "
},
{
"input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB",
"output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J "
},
{
"input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF",
"output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F "
},
{
"input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY",
"output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y "
},
{
"input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB",
"output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO "
},
{
"input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW",
"output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W "
},
{
"input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD",
"output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D "
},
{
"input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB",
"output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A "
},
{
"input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB",
"output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y "
},
{
"input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB",
"output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R "
},
{
"input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY",
"output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y "
},
{
"input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE",
"output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E "
},
{
"input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS",
"output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S "
},
{
"input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP",
"output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP "
},
{
"input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB",
"output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y "
},
{
"input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL",
"output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL "
},
{
"input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO",
"output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O "
},
{
"input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU",
"output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU "
},
{
"input": "A",
"output": "A "
},
{
"input": "WUBA",
"output": "A "
},
{
"input": "WUBWUBA",
"output": "A "
},
{
"input": "AWUBWUBWUB",
"output": "A "
},
{
"input": "AWUBBWUBCWUBD",
"output": "A B C D "
},
{
"input": "WUBWWUBWUBWUBUWUBWUBBWUB",
"output": "W U B "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA "
},
{
"input": "WUWUBBWWUBUB",
"output": "WU BW UB "
},
{
"input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB",
"output": "WUAB "
},
{
"input": "ZWUB",
"output": "Z "
},
{
"input": "WU",
"output": "WU "
},
{
"input": "UB",
"output": "UB "
},
{
"input": "U",
"output": "U "
},
{
"input": "WUBW",
"output": "W "
},
{
"input": "WUBWU",
"output": "WU "
},
{
"input": "WUWUB",
"output": "WU "
},
{
"input": "UBWUB",
"output": "UB "
},
{
"input": "WUWUBUBWUBUWUB",
"output": "WU UB U "
},
{
"input": "WUBWWUBAWUB",
"output": "W A "
},
{
"input": "WUUUUU",
"output": "WUUUUU "
}
] | 1,675,782,705 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | s = input().split("WUB")
output = ""
for k in s:
if k != '':
output += k + " "
print(output) | Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club.
For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX".
Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
Input Specification:
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Output Specification:
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
Demo Input:
['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n']
Demo Output:
['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND ']
Note:
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB". | ```python
s = input().split("WUB")
output = ""
for k in s:
if k != '':
output += k + " "
print(output)
``` | 3 |
|
411 | A | Password Check | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:
- the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q. | The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". | If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). | [
"abacaba\n",
"X12345\n",
"CONTEST_is_STARTED!!11\n"
] | [
"Too weak\n",
"Too weak\n",
"Correct\n"
] | none | 0 | [
{
"input": "abacaba",
"output": "Too weak"
},
{
"input": "X12345",
"output": "Too weak"
},
{
"input": "CONTEST_is_STARTED!!11",
"output": "Correct"
},
{
"input": "1zA__",
"output": "Correct"
},
{
"input": "1zA_",
"output": "Too weak"
},
{
"input": "zA___",
"output": "Too weak"
},
{
"input": "1A___",
"output": "Too weak"
},
{
"input": "z1___",
"output": "Too weak"
},
{
"input": "0",
"output": "Too weak"
},
{
"input": "_",
"output": "Too weak"
},
{
"input": "a",
"output": "Too weak"
},
{
"input": "D",
"output": "Too weak"
},
{
"input": "_",
"output": "Too weak"
},
{
"input": "?",
"output": "Too weak"
},
{
"input": "?",
"output": "Too weak"
},
{
"input": "._,.!.,...?_,!.",
"output": "Too weak"
},
{
"input": "!_?_,?,?.,.,_!!!.!,.__,?!!,_!,?_,!??,?!..._!?_,?_!,?_.,._,,_.,.",
"output": "Too weak"
},
{
"input": "?..!.,,?,__.,...????_???__!,?...?.,,,,___!,.!,_,,_,??!_?_,!!?_!_??.?,.!!?_?_.,!",
"output": "Too weak"
},
{
"input": "XZX",
"output": "Too weak"
},
{
"input": "R",
"output": "Too weak"
},
{
"input": "H.FZ",
"output": "Too weak"
},
{
"input": "KSHMICWPK,LSBM_JVZ!IPDYDG_GOPCHXFJTKJBIFY,FPHMY,CB?PZEAG..,X,.GFHPIDBB,IQ?MZ",
"output": "Too weak"
},
{
"input": "EFHI,,Y?HMMUI,,FJGAY?FYPBJQMYM!DZHLFCTFWT?JOPDW,S_!OR?ATT?RWFBMAAKUHIDMHSD?LCZQY!UD_CGYGBAIRDPICYS",
"output": "Too weak"
},
{
"input": "T,NDMUYCCXH_L_FJHMCCAGX_XSCPGOUZSY?D?CNDSYRITYS,VAT!PJVKNTBMXGGRYKACLYU.RJQ_?UWKXYIDE_AE",
"output": "Too weak"
},
{
"input": "y",
"output": "Too weak"
},
{
"input": "qgw",
"output": "Too weak"
},
{
"input": "g",
"output": "Too weak"
},
{
"input": "loaray",
"output": "Too weak"
},
{
"input": "d_iymyvxolmjayhwpedocopqwmy.oalrdg!_n?.lrxpamhygps?kkzxydsbcaihfs.j?eu!oszjsy.vzu?!vs.bprz_j",
"output": "Too weak"
},
{
"input": "txguglvclyillwnono",
"output": "Too weak"
},
{
"input": "FwX",
"output": "Too weak"
},
{
"input": "Zi",
"output": "Too weak"
},
{
"input": "PodE",
"output": "Too weak"
},
{
"input": "SdoOuJ?nj_wJyf",
"output": "Too weak"
},
{
"input": "MhnfZjsUyXYw?f?ubKA",
"output": "Too weak"
},
{
"input": "CpWxDVzwHfYFfoXNtXMFuAZr",
"output": "Too weak"
},
{
"input": "9.,0",
"output": "Too weak"
},
{
"input": "5,8",
"output": "Too weak"
},
{
"input": "7",
"output": "Too weak"
},
{
"input": "34__39_02!,!,82!129!2!566",
"output": "Too weak"
},
{
"input": "96156027.65935663!_87!,44,..7914_!0_1,.4!!62!.8350!17_282!!9.2584,!!7__51.526.7",
"output": "Too weak"
},
{
"input": "90328_",
"output": "Too weak"
},
{
"input": "B9",
"output": "Too weak"
},
{
"input": "P1H",
"output": "Too weak"
},
{
"input": "J2",
"output": "Too weak"
},
{
"input": "M6BCAKW!85OSYX1D?.53KDXP42F",
"output": "Too weak"
},
{
"input": "C672F429Y8X6XU7S,.K9111UD3232YXT81S4!729ER7DZ.J7U1R_7VG6.FQO,LDH",
"output": "Too weak"
},
{
"input": "W2PI__!.O91H8OFY6AB__R30L9XOU8800?ZUD84L5KT99818NFNE35V.8LJJ5P2MM.B6B",
"output": "Too weak"
},
{
"input": "z1",
"output": "Too weak"
},
{
"input": "p1j",
"output": "Too weak"
},
{
"input": "j9",
"output": "Too weak"
},
{
"input": "v8eycoylzv0qkix5mfs_nhkn6k!?ovrk9!b69zy!4frc?k",
"output": "Too weak"
},
{
"input": "l4!m_44kpw8.jg!?oh,?y5oraw1tg7_x1.osl0!ny?_aihzhtt0e2!mr92tnk0es!1f,9he40_usa6c50l",
"output": "Too weak"
},
{
"input": "d4r!ak.igzhnu!boghwd6jl",
"output": "Too weak"
},
{
"input": "It0",
"output": "Too weak"
},
{
"input": "Yb1x",
"output": "Too weak"
},
{
"input": "Qf7",
"output": "Too weak"
},
{
"input": "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te",
"output": "Correct"
},
{
"input": "Ka4hGE,vkvNQbNolnfwp",
"output": "Correct"
},
{
"input": "Ee9oluD?amNItsjeQVtOjwj4w_ALCRh7F3eaZah",
"output": "Correct"
},
{
"input": "Um3Fj?QLhNuRE_Gx0cjMLOkGCm",
"output": "Correct"
},
{
"input": "Oq2LYmV9HmlaW",
"output": "Correct"
},
{
"input": "Cq7r3Wrb.lDb_0wsf7!ruUUGSf08RkxD?VsBEDdyE?SHK73TFFy0f8gmcATqGafgTv8OOg8or2HyMPIPiQ2Hsx8q5rn3_WZe",
"output": "Correct"
},
{
"input": "Wx4p1fOrEMDlQpTlIx0p.1cnFD7BnX2K8?_dNLh4cQBx_Zqsv83BnL5hGKNcBE9g3QB,!fmSvgBeQ_qiH7",
"output": "Correct"
},
{
"input": "k673,",
"output": "Too weak"
},
{
"input": "LzuYQ",
"output": "Too weak"
},
{
"input": "Pasq!",
"output": "Too weak"
},
{
"input": "x5hve",
"output": "Too weak"
},
{
"input": "b27fk",
"output": "Too weak"
},
{
"input": "h6y1l",
"output": "Too weak"
},
{
"input": "i9nij",
"output": "Too weak"
},
{
"input": "Gf5Q6",
"output": "Correct"
},
{
"input": "Uf24o",
"output": "Correct"
},
{
"input": "Oj9vu",
"output": "Correct"
},
{
"input": "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr",
"output": "Too weak"
},
{
"input": "i6a.,8jb,n0kv4.1!7h?p.96pnhhgy6cl7dg7e4o6o384ys3z.t71kkq,,w,oqi4?u,,m5!rzu6wym_4hm,ohjy!.vvksl?pt,,1",
"output": "Too weak"
},
{
"input": "M10V_MN_1K8YX2LA!89EYV7!5V9?,.IDHDP6JEC.OGLY.180LMZ6KW3Z5E17IT94ZNHS!79GN09Q6LH0,F3AYNKP?KM,QP_?XRD6",
"output": "Too weak"
},
{
"input": "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1QZd4ycIrQ5Kcrhk5k0jTrwdAAEEP_T2f",
"output": "Correct"
},
{
"input": "Bk2Q38vDSW5JqYu.077iYC.9YoiPc!Dh6FJWOVze6?YXiFjPNa4F1RG?154m9mY2jQobBnbxM,cDV8l1UX1?v?p.tTYIyJO!NYmE",
"output": "Correct"
},
{
"input": "Ro1HcZ.piN,JRR88DLh,WtW!pbFM076?wCSbqfK7N2s5zUySFBtzk7HV,BxHXR0zALAr016z5jvvB.WUdEcKgYFav5TygwHQC..C",
"output": "Correct"
},
{
"input": "!?.,_",
"output": "Too weak"
}
] | 1,666,022,010 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = list(input())
print(n)
ph = 0
if len(n) >= 5:
ph += 1
for i in range(len(n)):
if ord(n[i]) >= ord('a') and ord(n[i]) <= ord('z'):
ph += 1
break
for i in range(len(n)):
if ord(n[i]) >= ord('A') and ord(n[i]) <= ord('Z'):
ph += 1
break
for i in range(len(n)):
if ord(n[i]) >= ord('0') and ord(n[i]) <= ord('9'):
ph += 1
break
for i in range(len(n)):
if n[i] == '!' or n[i] == ',' or n[i] == '.' or n[i] == '?' or n[i] == '_':
ph += 1
break
if ph >= 5:
print('Correct')
else:
print('Too weak')
| Title: Password Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.
Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions:
- the password length is at least 5 characters; - the password contains at least one large English letter; - the password contains at least one small English letter; - the password contains at least one digit.
You are given a password. Please implement the automatic check of its complexity for company Q.
Input Specification:
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
Output Specification:
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
Demo Input:
['abacaba\n', 'X12345\n', 'CONTEST_is_STARTED!!11\n']
Demo Output:
['Too weak\n', 'Too weak\n', 'Correct\n']
Note:
none | ```python
n = list(input())
print(n)
ph = 0
if len(n) >= 5:
ph += 1
for i in range(len(n)):
if ord(n[i]) >= ord('a') and ord(n[i]) <= ord('z'):
ph += 1
break
for i in range(len(n)):
if ord(n[i]) >= ord('A') and ord(n[i]) <= ord('Z'):
ph += 1
break
for i in range(len(n)):
if ord(n[i]) >= ord('0') and ord(n[i]) <= ord('9'):
ph += 1
break
for i in range(len(n)):
if n[i] == '!' or n[i] == ',' or n[i] == '.' or n[i] == '?' or n[i] == '_':
ph += 1
break
if ph >= 5:
print('Correct')
else:
print('Too weak')
``` | 0 |
|
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array. | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them. | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 52 -35 4 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 86 -25 -94 -56 60 -24 -37 -72 -41 -31 11 -48 28 -38 -42 -39 -33 -70 -84 0 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 17 -2 -63 -89 88 13 -58 -82",
"output": "89 -64 -51 -75 -98 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -18 -91 -92 -16 -23 -95 -9 -19 -44 -46 -79 -35 -87 -7 -90 -20 -71 -61 -67 -50 -66 -68 -49 -27 -32 -57 -85 -59 -30 -36 -3 -77 -25 -94 -56 -24 -37 -72 -41 -31 -48 -38 -42 -39 -33 -70 -84 -93 -73 -14 -69 -40 -97 -6 -55 -45 -54 -10 -29 -96 -12 -83 -15 -21 -47 -2 -63 -89 -58 -82\n10 74 52 4 86 60 11 28 17 88 13\n1 0"
},
{
"input": "100\n3 -66 -17 54 24 -29 76 89 32 -37 93 -16 99 -25 51 78 23 68 -95 59 18 34 -45 77 9 39 -10 19 8 73 -5 60 12 31 0 2 26 40 48 30 52 49 27 4 87 57 85 58 -61 50 83 80 69 67 91 97 -96 11 100 56 82 53 13 -92 -72 70 1 -94 -63 47 21 14 74 7 6 33 55 65 64 -41 81 42 36 28 38 20 43 71 90 -88 22 84 -86 15 75 62 44 35 98 46",
"output": "19 -66 -17 -29 -37 -16 -25 -95 -45 -10 -5 -61 -96 -92 -72 -94 -63 -41 -88 -86\n80 3 54 24 76 89 32 93 99 51 78 23 68 59 18 34 77 9 39 19 8 73 60 12 31 2 26 40 48 30 52 49 27 4 87 57 85 58 50 83 80 69 67 91 97 11 100 56 82 53 13 70 1 47 21 14 74 7 6 33 55 65 64 81 42 36 28 38 20 43 71 90 22 84 15 75 62 44 35 98 46\n1 0"
},
{
"input": "100\n-17 16 -70 32 -60 75 -100 -9 -68 -30 -42 86 -88 -98 -47 -5 58 -14 -94 -73 -80 -51 -66 -85 -53 49 -25 -3 -45 -69 -11 -64 83 74 -65 67 13 -91 81 6 -90 -54 -12 -39 0 -24 -71 -41 -44 57 -93 -20 -92 18 -43 -52 -55 -84 -89 -19 40 -4 -99 -26 -87 -36 -56 -61 -62 37 -95 -28 63 23 35 -82 1 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 46 -15 -48 -34 -59 -7 -29 50 -33 -72 -79 22 38",
"output": "75 -17 -70 -60 -100 -9 -68 -30 -42 -88 -98 -47 -5 -14 -94 -73 -80 -51 -66 -85 -53 -25 -3 -45 -69 -11 -64 -65 -91 -90 -54 -12 -39 -24 -71 -41 -44 -93 -20 -92 -43 -52 -55 -84 -89 -19 -4 -99 -26 -87 -36 -56 -61 -62 -95 -28 -82 -2 -78 -96 -21 -77 -76 -27 -10 -97 -8 -15 -48 -34 -59 -7 -29 -33 -72 -79\n24 16 32 75 86 58 49 83 74 67 13 81 6 57 18 40 37 63 23 35 1 46 50 22 38\n1 0"
},
{
"input": "100\n-97 -90 61 78 87 -52 -3 65 83 38 30 -60 35 -50 -73 -77 44 -32 -81 17 -67 58 -6 -34 47 -28 71 -45 69 -80 -4 -7 -57 -79 43 -27 -31 29 16 -89 -21 -93 95 -82 74 -5 -70 -20 -18 36 -64 -66 72 53 62 -68 26 15 76 -40 -99 8 59 88 49 -23 9 10 56 -48 -98 0 100 -54 25 94 13 -63 42 39 -1 55 24 -12 75 51 41 84 -96 -85 -2 -92 14 -46 -91 -19 -11 -86 22 -37",
"output": "51 -97 -90 -52 -3 -60 -50 -73 -77 -32 -81 -67 -6 -34 -28 -45 -80 -4 -7 -57 -79 -27 -31 -89 -21 -93 -82 -5 -70 -20 -18 -64 -66 -68 -40 -99 -23 -48 -98 -54 -63 -1 -12 -96 -85 -2 -92 -46 -91 -19 -11 -86\n47 61 78 87 65 83 38 30 35 44 17 58 47 71 69 43 29 16 95 74 36 72 53 62 26 15 76 8 59 88 49 9 10 56 100 25 94 13 42 39 55 24 75 51 41 84 14 22\n2 0 -37"
},
{
"input": "100\n-75 -60 -18 -92 -71 -9 -37 -34 -82 28 -54 93 -83 -76 -58 -88 -17 -97 64 -39 -96 -81 -10 -98 -47 -100 -22 27 14 -33 -19 -99 87 -66 57 -21 -90 -70 -32 -26 24 -77 -74 13 -44 16 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 69 0 -20 -79 59 -48 -4 -72 -67 -46 62 51 -52 -86 -40 56 -53 85 -35 -8 49 50 65 29 11 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 78 94 -23 -63 84 89 -61",
"output": "73 -75 -60 -18 -92 -71 -9 -37 -34 -82 -54 -83 -76 -58 -88 -17 -97 -39 -96 -81 -10 -98 -47 -100 -22 -33 -19 -99 -66 -21 -90 -70 -32 -26 -77 -74 -44 -5 -55 -2 -6 -7 -73 -1 -68 -30 -95 -42 -20 -79 -48 -4 -72 -67 -46 -52 -86 -40 -53 -35 -8 -43 -15 -41 -12 -3 -80 -31 -38 -91 -45 -25 -23 -63\n25 28 93 64 27 14 87 57 24 13 16 69 59 62 51 56 85 49 50 65 29 11 78 94 84 89\n2 0 -61"
},
{
"input": "100\n-87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 49 38 -20 -45 -64 44 -96 -35 -74 -65 -41 -21 -75 37 -12 -67 0 -3 5 -80 -93 -81 -97 -47 -63 53 -100 95 -79 -83 -90 -32 88 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 60 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 8 -72 18 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 84 -86 -7 -57 -14 40 -33 51 -26 46 59 -31 -58 -66",
"output": "83 -87 -48 -76 -1 -10 -17 -22 -19 -27 -99 -43 -20 -45 -64 -96 -35 -74 -65 -41 -21 -75 -12 -67 -3 -80 -93 -81 -97 -47 -63 -100 -79 -83 -90 -32 -77 -16 -23 -54 -28 -4 -73 -98 -25 -39 -56 -34 -2 -11 -55 -52 -69 -68 -29 -82 -62 -36 -13 -6 -89 -72 -15 -50 -71 -70 -92 -42 -78 -61 -9 -30 -85 -91 -94 -86 -7 -57 -14 -33 -26 -31 -58 -66\n16 49 38 44 37 5 53 95 88 60 8 18 84 40 51 46 59\n1 0"
},
{
"input": "100\n-95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 77 -69 -10 -12 -78 -14 -52 -57 -40 -75 4 -98 -6 7 -53 -3 -90 -63 -8 -20 88 -91 -32 -76 -80 -97 -34 -27 -19 0 70 -38 -9 -49 -67 73 -36 2 81 -39 -65 -83 -64 -18 -94 -79 -58 -16 87 -22 -74 -25 -13 -46 -89 -47 5 -15 -54 -99 56 -30 -60 -21 -86 33 -1 -50 -68 -100 -85 -29 92 -48 -61 42 -84 -93 -41 -82",
"output": "85 -95 -28 -43 -72 -11 -24 -37 -35 -44 -66 -45 -62 -96 -51 -55 -23 -31 -26 -59 -17 -69 -10 -12 -78 -14 -52 -57 -40 -75 -98 -6 -53 -3 -90 -63 -8 -20 -91 -32 -76 -80 -97 -34 -27 -19 -38 -9 -49 -67 -36 -39 -65 -83 -64 -18 -94 -79 -58 -16 -22 -74 -25 -13 -46 -89 -47 -15 -54 -99 -30 -60 -21 -86 -1 -50 -68 -100 -85 -29 -48 -61 -84 -93 -41 -82\n14 77 4 7 88 70 73 2 81 87 5 56 33 92 42\n1 0"
},
{
"input": "100\n-12 -41 57 13 83 -36 53 69 -6 86 -75 87 11 -5 -4 -14 -37 -84 70 2 -73 16 31 34 -45 94 -9 26 27 52 -42 46 96 21 32 7 -18 61 66 -51 95 -48 -76 90 80 -40 89 77 78 54 -30 8 88 33 -24 82 -15 19 1 59 44 64 -97 -60 43 56 35 47 39 50 29 28 -17 -67 74 23 85 -68 79 0 65 55 -3 92 -99 72 93 -71 38 -10 -100 -98 81 62 91 -63 -58 49 -20 22",
"output": "35 -12 -41 -36 -6 -75 -5 -4 -14 -37 -84 -73 -45 -9 -42 -18 -51 -48 -76 -40 -30 -24 -15 -97 -60 -17 -67 -68 -3 -99 -71 -10 -100 -98 -63 -58\n63 57 13 83 53 69 86 87 11 70 2 16 31 34 94 26 27 52 46 96 21 32 7 61 66 95 90 80 89 77 78 54 8 88 33 82 19 1 59 44 64 43 56 35 47 39 50 29 28 74 23 85 79 65 55 92 72 93 38 81 62 91 49 22\n2 0 -20"
},
{
"input": "100\n-34 81 85 -96 50 20 54 86 22 10 -19 52 65 44 30 53 63 71 17 98 -92 4 5 -99 89 -23 48 9 7 33 75 2 47 -56 42 70 -68 57 51 83 82 94 91 45 46 25 95 11 -12 62 -31 -87 58 38 67 97 -60 66 73 -28 13 93 29 59 -49 77 37 -43 -27 0 -16 72 15 79 61 78 35 21 3 8 84 1 -32 36 74 -88 26 100 6 14 40 76 18 90 24 69 80 64 55 41",
"output": "19 -34 -96 -19 -92 -99 -23 -56 -68 -12 -31 -87 -60 -28 -49 -43 -27 -16 -32 -88\n80 81 85 50 20 54 86 22 10 52 65 44 30 53 63 71 17 98 4 5 89 48 9 7 33 75 2 47 42 70 57 51 83 82 94 91 45 46 25 95 11 62 58 38 67 97 66 73 13 93 29 59 77 37 72 15 79 61 78 35 21 3 8 84 1 36 74 26 100 6 14 40 76 18 90 24 69 80 64 55 41\n1 0"
},
{
"input": "100\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952 -935",
"output": "97 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983\n2 -935 -952\n1 0"
},
{
"input": "99\n-1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 0 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941 -961 -983 -952",
"output": "95 -1000 -986 -979 -955 -966 -963 -973 -959 -972 -906 -924 -927 -929 -918 -977 -967 -921 -989 -911 -995 -945 -919 -971 -913 -912 -933 -969 -975 -920 -988 -997 -994 -953 -962 -940 -905 -978 -948 -957 -996 -976 -949 -931 -903 -985 -923 -993 -944 -909 -938 -946 -934 -992 -904 -980 -954 -943 -917 -968 -991 -956 -902 -942 -999 -998 -908 -928 -930 -914 -922 -936 -960 -937 -939 -926 -965 -925 -951 -910 -907 -970 -990 -984 -964 -987 -916 -947 -982 -950 -974 -915 -932 -958 -981 -941\n2 -952 -983\n2 0 -961"
},
{
"input": "59\n-990 -876 -641 -726 718 -53 803 -954 894 -265 -587 -665 904 349 754 -978 441 794 -768 -428 -569 -476 188 -620 -290 -333 45 705 -201 109 165 446 13 122 714 -562 -15 -86 -960 43 329 578 287 -776 -14 -71 915 886 -259 337 -495 913 -498 -669 -673 818 225 647 0",
"output": "29 -990 -876 -641 -726 -53 -954 -265 -587 -665 -978 -768 -428 -569 -476 -620 -290 -333 -201 -562 -15 -86 -960 -776 -14 -71 -259 -495 -498 -669\n28 718 803 894 904 349 754 441 794 188 45 705 109 165 446 13 122 714 43 329 578 287 915 886 337 913 818 225 647\n2 0 -673"
},
{
"input": "64\n502 885 -631 -906 735 687 642 -29 -696 -165 -524 15 -129 -663 -846 -501 -651 895 -341 -833 -142 33 -847 688 945 -192 -587 -930 603 849 736 676 788 256 863 -509 319 -49 -807 -158 218 -886 -143 -639 118 -156 -291 325 892 -916 -622 -960 -959 -731 -943 436 -535 861 745 589 -159 376 -182 0",
"output": "35 -631 -906 -29 -696 -165 -524 -129 -663 -846 -501 -651 -341 -833 -142 -847 -192 -587 -930 -509 -49 -807 -158 -886 -143 -639 -156 -291 -916 -622 -960 -959 -731 -943 -535 -159\n27 502 885 735 687 642 15 895 33 688 945 603 849 736 676 788 256 863 319 218 118 325 892 436 861 745 589 376\n2 0 -182"
},
{
"input": "5\n-1 -2 -3 -4 0",
"output": "1 -1\n2 -4 -3\n2 0 -2"
},
{
"input": "3\n-101 101 0",
"output": "1 -101\n1 101\n1 0"
},
{
"input": "21\n-100 -200 -300 -400 -500 -600 -700 -800 -900 -1000 0 100 200 300 400 500 600 700 800 900 1000",
"output": "9 -100 -200 -300 -400 -500 -600 -700 -800 -900\n10 100 200 300 400 500 600 700 800 900 1000\n2 0 -1000"
},
{
"input": "4\n0 -1 -2 -3",
"output": "1 -1\n2 -3 -2\n1 0"
}
] | 1,593,516,160 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 216 | 6,963,200 | n = int(input())
a = [int(x) for x in input().split()]
n1 = []
n2 = []
n3 = []
for i in range(len(a)):
if a[i] < 0:
n1.append(a[i])
a.pop(i)
break
for i in range(len(a)):
if a[i] == 0:
n3.append(a[i])
a.pop(i)
break
n2 = a
str1 = str(len(n1))
for x in n1:
str1 = str1 + ' ' + str(x)
str2 = str(len(n2))
for x in n2:
str2 = str2 + ' ' + str(x)
str3 = str(len(n3))
for x in n3:
str3 = str3 + ' ' + str(x)
print(str1)
print(str2)
print(str3)
| Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The product of all numbers in the third set is equal to zero. 1. Each number from the initial array must occur in exactly one set.
Help Vitaly. Divide the given array.
Input Specification:
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements.
Output Specification:
In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second set.
In the next line print integer *n*3 (*n*3<=><=0) — the number of elements in the third set. Then print *n*3 numbers — the elements that got to the third set.
The printed sets must meet the described conditions. It is guaranteed that the solution exists. If there are several solutions, you are allowed to print any of them.
Demo Input:
['3\n-1 2 0\n', '4\n-1 -2 -3 0\n']
Demo Output:
['1 -1\n1 2\n1 0\n', '1 -1\n2 -3 -2\n1 0\n']
Note:
none | ```python
n = int(input())
a = [int(x) for x in input().split()]
n1 = []
n2 = []
n3 = []
for i in range(len(a)):
if a[i] < 0:
n1.append(a[i])
a.pop(i)
break
for i in range(len(a)):
if a[i] == 0:
n3.append(a[i])
a.pop(i)
break
n2 = a
str1 = str(len(n1))
for x in n1:
str1 = str1 + ' ' + str(x)
str2 = str(len(n2))
for x in n2:
str2 = str2 + ' ' + str(x)
str3 = str(len(n3))
for x in n3:
str3 = str3 + ' ' + str(x)
print(str1)
print(str2)
print(str3)
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,676,737,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | x=0
lest=[0,1,2,3,4,5,6,7,8,9]
word=input()
if len(word)>10:
print(word[0]+str(len(word))+word[len(word)-1])
if True:
for i in lest:
if i==word[x]:
x+=1
""
else:
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
x=0
lest=[0,1,2,3,4,5,6,7,8,9]
word=input()
if len(word)>10:
print(word[0]+str(len(word))+word[len(word)-1])
if True:
for i in lest:
if i==word[x]:
x+=1
""
else:
print(word)
``` | 0 |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party? | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "9 240",
"output": "0"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "9 235",
"output": "1"
},
{
"input": "9 236",
"output": "0"
},
{
"input": "5 225",
"output": "2"
},
{
"input": "5 226",
"output": "1"
},
{
"input": "4 210",
"output": "3"
},
{
"input": "4 211",
"output": "2"
},
{
"input": "4 191",
"output": "3"
},
{
"input": "10 165",
"output": "5"
},
{
"input": "10 166",
"output": "4"
},
{
"input": "8 100",
"output": "7"
},
{
"input": "8 101",
"output": "6"
},
{
"input": "8 60",
"output": "8"
},
{
"input": "8 61",
"output": "7"
},
{
"input": "10 15",
"output": "9"
},
{
"input": "10 16",
"output": "8"
},
{
"input": "4 100",
"output": "4"
},
{
"input": "4 101",
"output": "4"
},
{
"input": "7 167",
"output": "4"
},
{
"input": "10 164",
"output": "5"
},
{
"input": "9 170",
"output": "4"
},
{
"input": "8 160",
"output": "5"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "8 123",
"output": "6"
},
{
"input": "2 99",
"output": "2"
},
{
"input": "10 88",
"output": "7"
},
{
"input": "1 235",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 240",
"output": "0"
},
{
"input": "1 55",
"output": "1"
},
{
"input": "1 240",
"output": "0"
},
{
"input": "3 240",
"output": "0"
},
{
"input": "10 240",
"output": "0"
},
{
"input": "2 240",
"output": "0"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "9 1",
"output": "9"
},
{
"input": "2 236",
"output": "0"
},
{
"input": "10 2",
"output": "9"
},
{
"input": "3 239",
"output": "0"
},
{
"input": "1 237",
"output": "0"
},
{
"input": "7 8",
"output": "7"
},
{
"input": "10 235",
"output": "1"
}
] | 1,698,582,765 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 46 | 0 | def solve(n, k):
l = 240 - k
for i in range(1, n+1):
if l >= 5*i:
l -= 5*i
else:
return i-1
return n
n, k = list(map(int, input().split()))
print(solve(n, k)) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve the *i*-th problem.
Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs *k* minutes to get there from his house, where he will participate in the contest first.
How many problems can Limak solve if he wants to make it to the party?
Input Specification:
The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Output Specification:
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
Demo Input:
['3 222\n', '4 190\n', '7 1\n']
Demo Output:
['2\n', '4\n', '7\n']
Note:
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2.
In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight.
In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. | ```python
def solve(n, k):
l = 240 - k
for i in range(1, n+1):
if l >= 5*i:
l -= 5*i
else:
return i-1
return n
n, k = list(map(int, input().split()))
print(solve(n, k))
``` | 3 |
|
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
"output": "1\n1 "
},
{
"input": "2\nBB",
"output": "1\n2 "
},
{
"input": "100\nWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWB",
"output": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "1\nW",
"output": "0"
},
{
"input": "2\nWW",
"output": "0"
},
{
"input": "2\nWB",
"output": "1\n1 "
},
{
"input": "2\nBW",
"output": "1\n1 "
},
{
"input": "3\nBBB",
"output": "1\n3 "
},
{
"input": "3\nBWB",
"output": "2\n1 1 "
},
{
"input": "3\nWBB",
"output": "1\n2 "
},
{
"input": "3\nWWB",
"output": "1\n1 "
},
{
"input": "3\nWBW",
"output": "1\n1 "
},
{
"input": "3\nBWW",
"output": "1\n1 "
},
{
"input": "3\nWWW",
"output": "0"
},
{
"input": "100\nBBBWWWWWWBBWWBBWWWBBWBBBBBBBBBBBWBBBWBBWWWBBWWBBBWBWWBBBWWBBBWBBBBBWWWBWWBBWWWWWWBWBBWWBWWWBWBWWWWWB",
"output": "21\n3 2 2 2 11 3 2 2 3 1 3 3 5 1 2 1 2 1 1 1 1 "
},
{
"input": "5\nBBBWB",
"output": "2\n3 1 "
},
{
"input": "5\nBWWWB",
"output": "2\n1 1 "
},
{
"input": "5\nWWWWB",
"output": "1\n1 "
},
{
"input": "5\nBWWWW",
"output": "1\n1 "
},
{
"input": "5\nBBBWW",
"output": "1\n3 "
},
{
"input": "5\nWWBBB",
"output": "1\n3 "
},
{
"input": "10\nBBBBBWWBBB",
"output": "2\n5 3 "
},
{
"input": "10\nBBBBWBBWBB",
"output": "3\n4 2 2 "
},
{
"input": "20\nBBBBBWWBWBBWBWWBWBBB",
"output": "6\n5 1 2 1 1 3 "
},
{
"input": "20\nBBBWWWWBBWWWBWBWWBBB",
"output": "5\n3 2 1 1 3 "
},
{
"input": "20\nBBBBBBBBWBBBWBWBWBBB",
"output": "5\n8 3 1 1 3 "
},
{
"input": "20\nBBBWBWBWWWBBWWWWBWBB",
"output": "6\n3 1 1 2 1 2 "
},
{
"input": "40\nBBBBBBWWWWBWBWWWBWWWWWWWWWWWBBBBBBBBBBBB",
"output": "5\n6 1 1 1 12 "
},
{
"input": "40\nBBBBBWBWWWBBWWWBWBWWBBBBWWWWBWBWBBBBBBBB",
"output": "9\n5 1 2 1 1 4 1 1 8 "
},
{
"input": "50\nBBBBBBBBBBBWWWWBWBWWWWBBBBBBBBWWWWWWWBWWWWBWBBBBBB",
"output": "7\n11 1 1 8 1 1 6 "
},
{
"input": "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
"output": "0"
},
{
"input": "50\nBBBBBWWWWWBWWWBWWWWWBWWWBWWWWWWBBWBBWWWWBWWWWWWWBW",
"output": "9\n5 1 1 1 1 2 2 1 1 "
},
{
"input": "50\nWWWWBWWBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWBWWWWWWWBBBBB",
"output": "6\n1 1 1 1 1 5 "
},
{
"input": "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB",
"output": "12\n5 1 1 1 1 1 1 1 1 1 1 1 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "100\nBBBBBBBBBBBWBWWWWBWWBBWBBWWWWWWWWWWBWBWWBWWWWWWWWWWWBBBWWBBWWWWWBWBWWWWBWWWWWWWWWWWBWWWWWBBBBBBBBBBB",
"output": "15\n11 1 1 2 2 1 1 1 3 2 1 1 1 1 11 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n100 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBWBWBWWWWWBWWWWWWWWWWWWWWBBWWWBWWWWBWWBWWWWWWBWWWWWWWWWWWWWBWBBBBBBBBBBBBBBBBBBBB",
"output": "11\n20 1 1 1 2 1 1 1 1 1 20 "
},
{
"input": "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBBWWWWWWWWWWWWBWWWWBWWWWWWWWWWWWBWWWWWWWBWWWWWWWBBBBBB",
"output": "11\n4 1 1 1 1 2 1 1 1 1 6 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "10\nWWBWWWBWBB",
"output": "3\n1 1 2 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "1\n50 "
},
{
"input": "50\nBBBBBBBBBBBBBBBBBWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n17 31 "
},
{
"input": "100\nBBBBBBBBBBBBBBBBBBBBBBBBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "2\n24 42 "
},
{
"input": "90\nWWBWWBWBBWBBWWBWBWBBBWBWBBBWBWBWBWBWBWBWBWBBBBBWBBWWWWBWBBWBWWBBBWBWBWWBWBWBWBWWWWWWBWBBBB",
"output": "30\n1 1 2 2 1 1 3 1 3 1 1 1 1 1 1 1 5 2 1 2 1 3 1 1 1 1 1 1 1 4 "
},
{
"input": "100\nBWWWBWBWBBBBBWBWWBWBWWWBWBWBWWBBWWBBBWBBBWWBWBWWBBBBWBWBBBWBWBBWWWWWWBWWBBBBWBWBWWBWBWWWBWBWWBWBWWWB",
"output": "31\n1 1 1 5 1 1 1 1 1 1 2 3 3 1 1 4 1 3 1 2 1 4 1 1 1 1 1 1 1 1 1 "
},
{
"input": "90\nWBWBBBBBBWWWBBWWBWWWBBWWBWWWBWBBWBWBBWWWWBWBWBBWBBWBWWWBBWBBWWWWBWBBWWWBBBWBBWBWBBBBWWBWWB",
"output": "25\n1 6 2 1 2 1 1 2 1 2 1 1 2 2 1 2 2 1 2 3 2 1 4 1 1 "
},
{
"input": "80\nBBWWBBBWBBWWWWBBWBWBBWWWWWBWBBWWBWBWBWBWBWWBWWBWWWBWBBWBBWBBWBBBWWBBBBBBBWBBBWBB",
"output": "23\n2 3 2 2 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 3 7 3 2 "
},
{
"input": "65\nWWWWBWWWBBBBBWWWWWWBBBWWBBBBWWWWWWWWBBBWWWWBWBWWBBWWWWBWWWBBWBBBB",
"output": "11\n1 5 3 4 3 1 1 2 1 2 4 "
}
] | 1,593,255,407 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 109 | 6,963,200 | def Remove(s):
a = []
for i in range(len(s)):
if len(s[i]) == 0:
a.append(i)
a.reverse()
for i in a:
del s[i]
return s
def Print(s):
print(len(s))
for i in s:
print(len(i),end=' ')
n = int(input())
s = list(map(str,input().split('W')))
s = Remove(s)
Print(s) | Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia [https://en.wikipedia.org/wiki/Japanese_crossword](https://en.wikipedia.org/wiki/Japanese_crossword)).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of *n* squares (e.g. japanese crossword sized 1<=×<=*n*), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
Output Specification:
The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
Demo Input:
['3\nBBW\n', '5\nBWBWB\n', '4\nWWWW\n', '4\nBBBB\n', '13\nWBBBBWWBWBBBW\n']
Demo Output:
['1\n2 ', '3\n1 1 1 ', '0\n', '1\n4 ', '3\n4 1 3 ']
Note:
The last sample case correspond to the picture in the statement. | ```python
def Remove(s):
a = []
for i in range(len(s)):
if len(s[i]) == 0:
a.append(i)
a.reverse()
for i in a:
del s[i]
return s
def Print(s):
print(len(s))
for i in s:
print(len(i),end=' ')
n = int(input())
s = list(map(str,input().split('W')))
s = Remove(s)
Print(s)
``` | 3 |
|
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices. | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input": "3 3\n1 2 1\n1 3 2\n2 3 1",
"output": "1 3 "
},
{
"input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173",
"output": "1 5 8 7 3 10 "
},
{
"input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157",
"output": "1 8 10 "
},
{
"input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135",
"output": "1 9 5 8 10 "
},
{
"input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242",
"output": "1 4 6 10 "
}
] | 1,687,875,222 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 30 | 1,000 | 24,268,800 | import sys
v, e = map(int, input().split(' '))
adj_list = [[] for _ in range(v)]
distances = [sys.maxsize] * v
parent = [-1] * v
for _ in range(e):
a, b, w = map(int, input().split(' '))
adj_list[a - 1].append((b - 1, w))
adj_list[b - 1].append((a - 1, w))
distances[0] = 0
visited = [False] * v
def min_distance(distances, visited):
minimum = sys.maxsize
min_index = -1
for t in range(v):
if not visited[t] and distances[t] < minimum:
minimum = distances[t]
min_index = t
return min_index
for _ in range(v):
u = min_distance(distances, visited)
if u == -1 or u == v - 1:
break
visited[u] = True
for g, w in adj_list[u]:
if not visited[g] and distances[g] > distances[u] + w:
distances[g] = distances[u] + w
parent[g] = u
if u == -1:
print(-1)
else:
path = []
indx = v - 1
path.append(indx + 1)
while indx != 0:
parent_indx = parent[indx]
path.append(parent_indx + 1)
indx = parent_indx
path.reverse()
print(*path)
| Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge.
It is possible that the graph has loops and multiple edges between pair of vertices.
Output Specification:
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
Demo Input:
['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n']
Demo Output:
['1 4 3 5 ', '1 4 3 5 ']
Note:
none | ```python
import sys
v, e = map(int, input().split(' '))
adj_list = [[] for _ in range(v)]
distances = [sys.maxsize] * v
parent = [-1] * v
for _ in range(e):
a, b, w = map(int, input().split(' '))
adj_list[a - 1].append((b - 1, w))
adj_list[b - 1].append((a - 1, w))
distances[0] = 0
visited = [False] * v
def min_distance(distances, visited):
minimum = sys.maxsize
min_index = -1
for t in range(v):
if not visited[t] and distances[t] < minimum:
minimum = distances[t]
min_index = t
return min_index
for _ in range(v):
u = min_distance(distances, visited)
if u == -1 or u == v - 1:
break
visited[u] = True
for g, w in adj_list[u]:
if not visited[g] and distances[g] > distances[u] + w:
distances[g] = distances[u] + w
parent[g] = u
if u == -1:
print(-1)
else:
path = []
indx = v - 1
path.append(indx + 1)
while indx != 0:
parent_indx = parent[indx]
path.append(parent_indx + 1)
indx = parent_indx
path.reverse()
print(*path)
``` | 0 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,683,655,208 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 122 | 0 | y=input("")
z=y.upper()
count=0
for i in range(len(z)):
if y[i]==z[i]:
count=count+1
if count>len(y)/2:
y=y.upper()
else:
y=y.lower()
print(y) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
y=input("")
z=y.upper()
count=0
for i in range(len(z)):
if y[i]==z[i]:
count=count+1
if count>len(y)/2:
y=y.upper()
else:
y=y.lower()
print(y)
``` | 3.9695 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event. | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 20 9 14 14 10 13 6 13 14 17 6 8 20 12 10 15 13 17 5 12 13 11 7 5 5 2 3 15 13 7 14 14 19 2 13 14 5 15 3 19 15 16 4 1",
"output": "1891"
},
{
"input": "100 9000\n5 2 3 1 1 3 4 9 9 6 7 10 10 10 2 10 6 8 8 6 7 9 9 5 6 2 1 10 10 9 4 5 9 2 4 3 8 5 6 1 1 5 3 6 2 6 6 6 5 8 3 6 7 3 1 10 9 1 8 3 10 9 5 6 3 4 1 1 10 10 2 3 4 8 10 10 5 1 5 3 6 8 10 6 10 2 1 8 10 1 7 6 9 10 5 2 3 5 3 2",
"output": "1688"
},
{
"input": "100 8007\n5 19 14 18 9 6 15 8 1 14 11 20 3 17 7 12 2 6 3 17 7 20 1 14 20 17 2 10 13 7 18 18 9 10 16 8 1 11 11 9 13 18 9 20 12 12 7 15 12 17 11 5 11 15 9 2 15 1 18 3 18 16 15 4 10 5 18 13 13 12 3 8 17 2 12 2 13 3 1 13 2 4 9 10 18 10 14 4 4 17 12 19 2 9 6 5 5 20 18 12",
"output": "1391"
},
{
"input": "39 2412\n1 1 1 1 1 1 26 1 1 1 99 1 1 1 1 1 1 1 1 1 1 88 7 1 1 1 1 76 1 1 1 93 40 1 13 1 68 1 32",
"output": "368"
},
{
"input": "39 2617\n47 1 1 1 63 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 70 1 99 63 1 1 1 1 1 1 1 1 64 1 1",
"output": "435"
},
{
"input": "39 3681\n83 77 1 94 85 47 1 98 29 16 1 1 1 71 96 85 31 97 96 93 40 50 98 1 60 51 1 96 100 72 1 1 1 89 1 93 1 92 100",
"output": "326"
},
{
"input": "45 894\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 28 28 1 1 1 1 1 1 1 1 1 1 1 1 1 1 99 3 1 1",
"output": "139"
},
{
"input": "45 4534\n1 99 65 99 4 46 54 80 51 30 96 1 28 30 44 70 78 1 1 100 1 62 1 1 1 85 1 1 1 61 1 46 75 1 61 77 97 26 67 1 1 63 81 85 86",
"output": "514"
},
{
"input": "72 3538\n52 1 8 1 1 1 7 1 1 1 1 48 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 40 1 1 38 1 1 1 1 1 1 1 1 1 1 1 35 1 93 79 1 1 1 1 1 1 1 1 1 51 1 1 1 1 1 1 1 1 1 1 1 1 96 1",
"output": "586"
},
{
"input": "81 2200\n1 59 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 93 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 50 1 1 1 1 1 1 1 1 1 1 1",
"output": "384"
},
{
"input": "81 2577\n85 91 1 1 2 1 1 100 1 80 1 1 17 86 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 37 1 66 24 1 1 96 49 1 66 1 44 1 1 1 1 98 1 1 1 1 35 1 37 3 35 1 1 87 64 1 24 1 58 1 1 42 83 5 1 1 1 1 1 95 1 94 1 50 1 1",
"output": "174"
},
{
"input": "81 4131\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "807"
},
{
"input": "81 6315\n1 1 67 100 1 99 36 1 92 5 1 96 42 12 1 57 91 1 1 66 41 30 74 95 1 37 1 39 91 69 1 52 77 47 65 1 1 93 96 74 90 35 85 76 71 92 92 1 1 67 92 74 1 1 86 76 35 1 56 16 27 57 37 95 1 40 20 100 51 1 80 60 45 79 95 1 46 1 25 100 96",
"output": "490"
},
{
"input": "96 1688\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 71 1 1 1 30 1 1 1",
"output": "284"
},
{
"input": "96 8889\n1 1 18 1 1 1 1 1 1 1 1 1 99 1 1 1 1 88 1 45 1 1 1 1 1 1 1 1 1 1 1 1 1 1 96 1 1 1 1 21 1 1 1 1 1 1 1 73 1 1 1 1 1 10 1 1 1 1 1 1 1 46 43 1 1 1 1 1 98 1 1 1 1 1 1 6 1 1 1 1 1 74 1 25 1 55 1 1 1 13 1 1 54 1 1 1",
"output": "1589"
},
{
"input": "10 100\n1 1 1 1 1 1 1 1 1 1",
"output": "18"
},
{
"input": "100 10000\n54 46 72 94 79 83 91 54 73 3 24 55 54 31 28 20 19 6 25 19 47 23 1 70 15 87 51 39 54 77 55 5 60 3 15 99 56 88 22 78 79 21 38 27 28 86 7 88 12 59 55 70 25 1 70 49 1 45 69 72 50 17 4 56 8 100 90 34 35 20 61 76 88 79 4 74 65 68 75 26 40 72 59 94 10 67 96 85 29 90 47 24 44 1 66 93 55 36 1 99",
"output": "1017"
},
{
"input": "100 6000\n41 31 23 17 24 78 26 96 93 48 46 2 49 33 35 9 73 100 34 48 83 36 33 69 43 24 3 74 8 81 27 33 94 38 77 9 76 90 62 90 21 67 22 22 12 2 17 27 61 18 72 85 59 65 71 38 90 75 74 66 60 47 58 50 90 95 75 10 5 100 97 29 83 88 65 26 93 90 22 98 36 55 70 38 50 92 88 72 99 96 25 14 74 16 25 92 67 94 77 96",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 6\n1",
"output": "1"
},
{
"input": "1 5\n1",
"output": "0"
},
{
"input": "1 3\n4",
"output": "-1"
},
{
"input": "3 24\n2 1 2",
"output": "-1"
}
] | 1,578,119,411 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 109 | 0 | n,d=map(int,input().split())
s=0
j=0
t=list(map(int,input().split()))
for i in range(n):
s=s+t[i]
s=s+(n-1)*10
if(s<=d):
j=2*(n-1)+(d-s)//5
print(j)
else:
print(-1) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* song will take *t**i* minutes exactly.
The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.
People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.
You as one of the organizers should make an optimal sсhedule for the event. For some reasons you must follow the conditions:
- The duration of the event must be no more than *d* minutes; - Devu must complete all his songs; - With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible.
If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.
Input Specification:
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
Output Specification:
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
Demo Input:
['3 30\n2 2 1\n', '3 20\n2 1 1\n']
Demo Output:
['5\n', '-1\n']
Note:
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now finally Devu will perform his last song in 1 minutes.
Total time spent is 5 + 2 + 10 + 2 + 10 + 1 = 30 minutes.
Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. | ```python
n,d=map(int,input().split())
s=0
j=0
t=list(map(int,input().split()))
for i in range(n):
s=s+t[i]
s=s+(n-1)*10
if(s<=d):
j=2*(n-1)+(d-s)//5
print(j)
else:
print(-1)
``` | 3 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,637,256,061 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | def angle(z):
ans=int((z-2)*180/z)
return ans
x=int(input())
arr=[]
for k in range(x):
inp=int(input())
arr.append(inp)
x=3
for i in arr:
a=0
while angle(x)<=i:
if angle(x)==i:
print('YES')
a=10
break
else:
x+=1
if a==0:
print('NO') | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
def angle(z):
ans=int((z-2)*180/z)
return ans
x=int(input())
arr=[]
for k in range(x):
inp=int(input())
arr.append(inp)
x=3
for i in arr:
a=0
while angle(x)<=i:
if angle(x)==i:
print('YES')
a=10
break
else:
x+=1
if a==0:
print('NO')
``` | 0 |
|
690 | C2 | Brain Network (medium) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of its nervous system. More precisely, we define the distance between two brains *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) as the minimum number of brain connectors used when transmitting a thought between these two brains. The brain latency of a zombie is defined to be the maximum distance between any two of its brains. Researchers conjecture that the brain latency is the crucial parameter which determines how smart a given zombie is. Help them test this conjecture by writing a program to compute brain latencies of nervous systems.
In this problem you may assume that any nervous system given in the input is valid, i.e., it satisfies conditions (1) and (2) from the easy version. | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n* and *a*<=≠<=*b*). | Print one number – the brain latency. | [
"4 3\n1 2\n1 3\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n"
] | [
"2",
"3"
] | none | 0 | [
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 2\n2 1\n3 2",
"output": "2"
},
{
"input": "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "6"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n3 5",
"output": "3"
}
] | 1,695,531,292 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 405 | 19,865,600 | def solution(idx):
visited = [False] * n # visited
max_distance = (0, idx) # (distance, index)
stack = [max_distance] # stack
while stack:
distance, idx = stack.pop() # distance, index
visited[idx] = True
if distance > max_distance[0]:
max_distance = (distance, idx)
stack += [(distance + 1, j) for j in links[idx] if not visited[j]]
return max_distance
if __name__ == '__main__':
n, m = map(int, input().split())
links = [[] for i in range(n)]
for j in range(m):
a, b = map(int, input().split())
links[a - 1].append(b - 1)
links[b - 1].append(a - 1)
print(solution(solution(0)[1])[0])
| Title: Brain Network (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of its nervous system. More precisely, we define the distance between two brains *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) as the minimum number of brain connectors used when transmitting a thought between these two brains. The brain latency of a zombie is defined to be the maximum distance between any two of its brains. Researchers conjecture that the brain latency is the crucial parameter which determines how smart a given zombie is. Help them test this conjecture by writing a program to compute brain latencies of nervous systems.
In this problem you may assume that any nervous system given in the input is valid, i.e., it satisfies conditions (1) and (2) from the easy version.
Input Specification:
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n* and *a*<=≠<=*b*).
Output Specification:
Print one number – the brain latency.
Demo Input:
['4 3\n1 2\n1 3\n1 4\n', '5 4\n1 2\n2 3\n3 4\n3 5\n']
Demo Output:
['2', '3']
Note:
none | ```python
def solution(idx):
visited = [False] * n # visited
max_distance = (0, idx) # (distance, index)
stack = [max_distance] # stack
while stack:
distance, idx = stack.pop() # distance, index
visited[idx] = True
if distance > max_distance[0]:
max_distance = (distance, idx)
stack += [(distance + 1, j) for j in links[idx] if not visited[j]]
return max_distance
if __name__ == '__main__':
n, m = map(int, input().split())
links = [[] for i in range(n)]
for j in range(m):
a, b = map(int, input().split())
links[a - 1].append(b - 1)
links[b - 1].append(a - 1)
print(solution(solution(0)[1])[0])
``` | 3 |
|
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15",
"output": "6"
},
{
"input": "1 4\n-3",
"output": "1"
},
{
"input": "10 7\n6 4 6 6 -3 4 -1 2 3 3",
"output": "5"
},
{
"input": "2 1\n1 -1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "8 13\n-11 -1 -11 12 -2 -2 -10 -11",
"output": "3"
},
{
"input": "16 11\n3 -7 7 -9 -2 -3 -4 -2 -6 8 10 7 1 4 6 7",
"output": "2"
},
{
"input": "67 15\n-2 -2 6 -4 -7 4 3 13 -9 -4 11 -7 -6 -11 1 11 -1 11 14 10 -8 7 5 11 -13 1 -1 7 -14 9 -11 -11 13 -4 12 -11 -8 -5 -11 6 10 -2 6 9 9 6 -11 -2 7 -10 -1 9 -8 -5 1 -7 -2 3 -1 -13 -6 -9 -8 10 13 -3 9",
"output": "1"
},
{
"input": "123 222\n44 -190 -188 -185 -55 17 190 176 157 176 -24 -113 -54 -61 -53 53 -77 68 -12 -114 -217 163 -122 37 -37 20 -108 17 -140 -210 218 19 -89 54 18 197 111 -150 -36 -131 -172 36 67 16 -202 72 169 -137 -34 -122 137 -72 196 -17 -104 180 -102 96 -69 -184 21 -15 217 -61 175 -221 62 173 -93 -106 122 -135 58 7 -110 -108 156 -141 -102 -50 29 -204 -46 -76 101 -33 -190 99 52 -197 175 -71 161 -140 155 10 189 -217 -97 -170 183 -88 83 -149 157 -208 154 -3 77 90 74 165 198 -181 -166 -4 -200 -89 -200 131 100 -61 -149",
"output": "8"
},
{
"input": "130 142\n58 -50 43 -126 84 -92 -108 -92 57 127 12 -135 -49 89 141 -112 -31 47 75 -19 80 81 -5 17 10 4 -26 68 -102 -10 7 -62 -135 -123 -16 55 -72 -97 -34 21 21 137 130 97 40 -18 110 -52 73 52 85 103 -134 -107 88 30 66 97 126 82 13 125 127 -87 81 22 45 102 13 95 4 10 -35 39 -43 -112 -5 14 -46 19 61 -44 -116 137 -116 -80 -39 92 -75 29 -65 -15 5 -108 -114 -129 -5 52 -21 118 -41 35 -62 -125 130 -95 -11 -75 19 108 108 127 141 2 -130 54 96 -81 -102 140 -58 -102 132 50 -126 82 6 45 -114 -42",
"output": "5"
},
{
"input": "7 12\n2 5 -1 -4 -7 4 3",
"output": "1"
},
{
"input": "57 53\n-49 7 -41 7 38 -51 -23 8 45 1 -24 26 37 28 -31 -40 38 25 -32 -47 -3 20 -40 -32 -44 -36 5 33 -16 -5 28 10 -22 3 -10 -51 -32 -51 27 -50 -22 -12 41 3 15 24 30 -12 -34 -15 -29 38 -10 -35 -9 6 -51",
"output": "8"
},
{
"input": "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128 13 -151 158 110 -116 68 -2 -148 -206 -52 79 -152 -223 74 -149 -69 232 38 -70 -256 -213 -236 132 -189 -200 199 -57 -108 -53 269 -101 -134",
"output": "8"
},
{
"input": "1 1000\n997",
"output": "1"
},
{
"input": "4 3\n2 -1 -2 -1",
"output": "1"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n1 -1",
"output": "0"
},
{
"input": "2 2\n-1 1",
"output": "0"
},
{
"input": "2 3\n-1 1",
"output": "0"
},
{
"input": "2 2\n-2 2",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "2"
},
{
"input": "4 2\n-1 -1 -1 -1",
"output": "2"
},
{
"input": "4 1\n-1 -1 -1 1",
"output": "2"
},
{
"input": "3 2\n2 2 2",
"output": "3"
},
{
"input": "10 300\n300 300 300 300 300 300 300 300 300 300",
"output": "10"
}
] | 1,618,350,535 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | n,x=map(int,input().split())
l=list(map(int,input().split()))
import math as m
print(m.ceil(abs(sum(l))/x)) | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*.
Input Specification:
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value.
Output Specification:
Print a single number — the answer to the problem.
Demo Input:
['3 2\n-1 1 2\n', '2 3\n-2 -2\n']
Demo Output:
['1\n', '2\n']
Note:
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | ```python
n,x=map(int,input().split())
l=list(map(int,input().split()))
import math as m
print(m.ceil(abs(sum(l))/x))
``` | 3 |
|
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"input": "sunday\nsaturday",
"output": "NO"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "monday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "monday\nsaturday",
"output": "NO"
},
{
"input": "monday\nsunday",
"output": "NO"
},
{
"input": "tuesday\nmonday",
"output": "NO"
},
{
"input": "tuesday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nwednesday",
"output": "NO"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "tuesday\nsaturday",
"output": "NO"
},
{
"input": "tuesday\nsunday",
"output": "NO"
},
{
"input": "wednesday\nmonday",
"output": "NO"
},
{
"input": "wednesday\ntuesday",
"output": "NO"
},
{
"input": "wednesday\nwednesday",
"output": "YES"
},
{
"input": "wednesday\nthursday",
"output": "NO"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "thursday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nwednesday",
"output": "NO"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "friday\nthursday",
"output": "NO"
},
{
"input": "friday\nsaturday",
"output": "NO"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "saturday\nmonday",
"output": "YES"
},
{
"input": "saturday\nwednesday",
"output": "NO"
},
{
"input": "saturday\nthursday",
"output": "NO"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nsaturday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "sunday\nmonday",
"output": "NO"
},
{
"input": "sunday\ntuesday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "sunday\nthursday",
"output": "NO"
},
{
"input": "sunday\nfriday",
"output": "NO"
},
{
"input": "friday\nfriday",
"output": "YES"
},
{
"input": "friday\nsunday",
"output": "YES"
},
{
"input": "monday\nmonday",
"output": "YES"
},
{
"input": "friday\ntuesday",
"output": "NO"
},
{
"input": "thursday\nsaturday",
"output": "YES"
},
{
"input": "tuesday\nfriday",
"output": "YES"
},
{
"input": "sunday\nwednesday",
"output": "YES"
},
{
"input": "monday\nthursday",
"output": "YES"
},
{
"input": "saturday\nsunday",
"output": "NO"
},
{
"input": "friday\nmonday",
"output": "YES"
},
{
"input": "thursday\nthursday",
"output": "YES"
},
{
"input": "wednesday\nfriday",
"output": "YES"
},
{
"input": "thursday\nmonday",
"output": "NO"
},
{
"input": "wednesday\nsunday",
"output": "NO"
},
{
"input": "thursday\nfriday",
"output": "NO"
},
{
"input": "monday\nfriday",
"output": "NO"
},
{
"input": "wednesday\nsaturday",
"output": "YES"
},
{
"input": "thursday\nsunday",
"output": "YES"
},
{
"input": "saturday\nfriday",
"output": "NO"
},
{
"input": "saturday\nmonday",
"output": "YES"
}
] | 1,688,919,495 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | x = ["sunday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
day1 = input()
day2 = input()
start = x.index(day1)
i = start
res = []
for days in [29 , 31 , 32 ] :
ref = None
while days > 0 :
ref = x[i]
i+=1
if i == 7 :
i = 0
days -= 1
res.append(ref)
if day2 in res :
print("YES")
else :
print("NO") | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.
In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.
Names of the days of the week are given with lowercase English letters: "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Input Specification:
The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday".
Output Specification:
Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes).
Demo Input:
['monday\ntuesday\n', 'sunday\nsunday\n', 'saturday\ntuesday\n']
Demo Output:
['NO\n', 'YES\n', 'YES\n']
Note:
In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | ```python
x = ["sunday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
day1 = input()
day2 = input()
start = x.index(day1)
i = start
res = []
for days in [29 , 31 , 32 ] :
ref = None
while days > 0 :
ref = x[i]
i+=1
if i == 7 :
i = 0
days -= 1
res.append(ref)
if day2 in res :
print("YES")
else :
print("NO")
``` | 0 |
|
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them. | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "9",
"output": "ROYGBIVGB"
},
{
"input": "11",
"output": "ROYGBIVYGBI"
},
{
"input": "12",
"output": "ROYGBIVOYGBI"
},
{
"input": "15",
"output": "ROYGBIVROYGBIVG"
},
{
"input": "16",
"output": "ROYGBIVROYGBIVGB"
},
{
"input": "17",
"output": "ROYGBIVROYGBIVYGB"
},
{
"input": "18",
"output": "ROYGBIVROYGBIVYGBI"
},
{
"input": "19",
"output": "ROYGBIVROYGBIVOYGBI"
},
{
"input": "20",
"output": "ROYGBIVROYGBIVOYGBIV"
},
{
"input": "21",
"output": "ROYGBIVROYGBIVROYGBIV"
},
{
"input": "22",
"output": "ROYGBIVROYGBIVROYGBIVG"
},
{
"input": "23",
"output": "ROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "24",
"output": "ROYGBIVROYGBIVROYGBIVYGB"
},
{
"input": "25",
"output": "ROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "28",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "29",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "34",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "43",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "61",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "79",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
},
{
"input": "81",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "92",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "95",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI"
},
{
"input": "96",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI"
},
{
"input": "97",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV"
},
{
"input": "98",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV"
},
{
"input": "99",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG"
},
{
"input": "100",
"output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB"
}
] | 1,533,133,929 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 0 | n=int(input())
arr=['R','O','Y','G']
print("BIV",end='')
for i in range(n-3):
print(arr[i%4],end='') | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors.
Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
Input Specification:
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Output Specification:
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet.
If there are several answers, print any of them.
Demo Input:
['8\n', '13\n']
Demo Output:
['ROYGRBIV\n', 'ROYGBIVGBIVYG\n']
Note:
The way the eggs will be painted in the first sample is shown on the picture: | ```python
n=int(input())
arr=['R','O','Y','G']
print("BIV",end='')
for i in range(n-3):
print(arr[i%4],end='')
``` | 3.938 |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation. | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{
"input": "10 6 3",
"output": "<< 3 4 5 (6) 7 8 9 >> "
},
{
"input": "8 5 4",
"output": "1 2 3 4 (5) 6 7 8 "
},
{
"input": "100 10 20",
"output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 >> "
},
{
"input": "100 25 11",
"output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >> "
},
{
"input": "5 2 1",
"output": "1 (2) 3 >> "
},
{
"input": "5 3 1",
"output": "<< 2 (3) 4 >> "
},
{
"input": "79 35 12",
"output": "<< 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 >> "
},
{
"input": "100 99 5",
"output": "<< 94 95 96 97 98 (99) 100 "
},
{
"input": "100 99 15",
"output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 "
},
{
"input": "100 100 17",
"output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) "
},
{
"input": "100 35 28",
"output": "<< 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 >> "
},
{
"input": "100 46 38",
"output": "<< 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 >> "
},
{
"input": "100 46 48",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 >> "
},
{
"input": "100 10 100",
"output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3 1 1",
"output": "(1) 2 >> "
},
{
"input": "3 2 1",
"output": "1 (2) 3 "
},
{
"input": "17 5 3",
"output": "<< 2 3 4 (5) 6 7 8 >> "
},
{
"input": "3 1 3",
"output": "(1) 2 3 "
},
{
"input": "7 5 1",
"output": "<< 4 (5) 6 >> "
},
{
"input": "5 5 5",
"output": "1 2 3 4 (5) "
},
{
"input": "5 3 5",
"output": "1 2 (3) 4 5 "
}
] | 1,550,231,131 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | n, p, k= map(int,input().split())
d = [""]*(2*k+1)
m=0
for i in range(-k,k+1):
if i == 0:
d[m]="("+str(p)+")"
elif p+i <= n and p+i >= 1:
d[m]= str(p+i)
m = m+1
if '' in d:
d.remove('')
print(d)
check = "(" + str(n) + ")"
if not "1" in d and not "(1)" in d:
d.insert(0,"<<")
if not str(n) in d and not check in d:
d.insert(len(d),">>")
print(' '.join(d)) | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input Specification:
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Output Specification:
Print the proper navigation. Follow the format of the output from the test samples.
Demo Input:
['17 5 2\n', '6 5 2\n', '6 1 2\n', '6 2 2\n', '9 6 3\n', '10 6 3\n', '8 5 4\n']
Demo Output:
['<< 3 4 (5) 6 7 >> ', '<< 3 4 (5) 6 ', '(1) 2 3 >> ', '1 (2) 3 4 >>', '<< 3 4 5 (6) 7 8 9', '<< 3 4 5 (6) 7 8 9 >>', '1 2 3 4 (5) 6 7 8 ']
Note:
none | ```python
n, p, k= map(int,input().split())
d = [""]*(2*k+1)
m=0
for i in range(-k,k+1):
if i == 0:
d[m]="("+str(p)+")"
elif p+i <= n and p+i >= 1:
d[m]= str(p+i)
m = m+1
if '' in d:
d.remove('')
print(d)
check = "(" + str(n) + ")"
if not "1" in d and not "(1)" in d:
d.insert(0,"<<")
if not str(n) in d and not check in d:
d.insert(len(d),">>")
print(' '.join(d))
``` | 0 |
|
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map.
Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".".
It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n.......*..",
"output": "2 1"
},
{
"input": "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.",
"output": "1 2"
},
{
"input": "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..",
"output": "99 2"
},
{
"input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**",
"output": "2 3"
},
{
"input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..",
"output": "99 2"
},
{
"input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**",
"output": "2 3"
},
{
"input": "2 100\n...................................................................................................*\n*..................................................................................................*",
"output": "1 1"
},
{
"input": "2 2\n*.\n**",
"output": "1 2"
},
{
"input": "2 2\n**\n.*",
"output": "2 1"
},
{
"input": "2 3\n*.*\n..*",
"output": "2 1"
}
] | 1,585,811,201 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 307,200 | r,c = map(int,input().split())
ind_c =[]
ind = None
for i in range(r):
s = input()
if s.count('*') == 1:
ind = [i,s.index('*')]
elif s.count('*')>1:
for j in range(c):
if s[j] == '*':
ind_c.append(j)
if ind[1] == ind_c[1]:
print(ind[0]+1,ind_c[0]+1)
else:
print(ind[0]+1,ind_c[1]+1)
| Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map.
Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed.
Input Specification:
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".".
It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements.
Output Specification:
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
Demo Input:
['3 2\n.*\n..\n**\n', '3 3\n*.*\n*..\n...\n']
Demo Output:
['1 1\n', '2 3\n']
Note:
none | ```python
r,c = map(int,input().split())
ind_c =[]
ind = None
for i in range(r):
s = input()
if s.count('*') == 1:
ind = [i,s.index('*')]
elif s.count('*')>1:
for j in range(c):
if s[j] == '*':
ind_c.append(j)
if ind[1] == ind_c[1]:
print(ind[0]+1,ind_c[0]+1)
else:
print(ind[0]+1,ind_c[1]+1)
``` | 3 |
|
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,597,768,871 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 310 | 0 | s=input()
up_count=0
low_count=0
for i in s:
if(i.islower()):
low_count+=1
else:
up_count+=1
if(low_count>=up_count):
print(s.lower())
else:
print(s.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
s=input()
up_count=0
low_count=0
for i in s:
if(i.islower()):
low_count+=1
else:
up_count+=1
if(low_count>=up_count):
print(s.lower())
else:
print(s.upper())
``` | 3.9225 |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "6"
},
{
"input": "5 1\n998 997 985 937 998",
"output": "0"
},
{
"input": "2 2\n-742 -187",
"output": "929"
},
{
"input": "3 3\n522 597 384",
"output": "0"
},
{
"input": "4 2\n-215 -620 192 647",
"output": "835"
},
{
"input": "10 6\n557 605 685 231 910 633 130 838 -564 -85",
"output": "649"
},
{
"input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59",
"output": "10"
},
{
"input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000",
"output": "0"
},
{
"input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886",
"output": "19441"
},
{
"input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999",
"output": "0"
},
{
"input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993",
"output": "16984"
},
{
"input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981",
"output": "21743"
},
{
"input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654",
"output": "81283"
},
{
"input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782",
"output": "0"
},
{
"input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823",
"output": "0"
},
{
"input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992",
"output": "75068"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n555",
"output": "0"
},
{
"input": "1 1\n-1",
"output": "1"
},
{
"input": "1 1\n-24",
"output": "24"
}
] | 1,663,515,103 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 154 | 2,048,000 | from re import S
a,n=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
p=0
s=0
for i in l:
if p!=n and i<0:
s=s-i
print(s) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
Input Specification:
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output Specification:
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
Demo Input:
['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n']
Demo Output:
['8\n', '7\n']
Note:
none | ```python
from re import S
a,n=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
p=0
s=0
for i in l:
if p!=n and i<0:
s=s-i
print(s)
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,619,244,895 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 78 | 0 | k=input().lower()
a='hello';j=0
for i in range(len(k)):
if k[i]==a[j]:
j+=1
if j==5:
break
print(['NO','YES'][j>4])
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
k=input().lower()
a='hello';j=0
for i in range(len(k)):
if k[i]==a[j]:
j+=1
if j==5:
break
print(['NO','YES'][j>4])
``` | 3.961 |