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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"output": "NO"
},
{
"input": "3 3\n1 1\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n1 2\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n2 2\n1 2 3\n1 2 3",
"output": "NO"
},
{
"input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49",
"output": "YES"
},
{
"input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100",
"output": "YES"
},
{
"input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99",
"output": "YES"
},
{
"input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81",
"output": "YES"
},
{
"input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10",
"output": "NO"
},
{
"input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "1 1\n1 1\n-1000000000\n30",
"output": "YES"
},
{
"input": "3 3\n1 3\n1 3 3\n3 3 3",
"output": "YES"
},
{
"input": "3 3\n1 1\n3 3 3\n2 2 2",
"output": "NO"
},
{
"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7",
"output": "NO"
},
{
"input": "3 4\n2 2\n5 6 7\n1 2 3 4",
"output": "NO"
},
{
"input": "3 3\n3 3\n1 2 3\n4 5 6",
"output": "YES"
},
{
"input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9",
"output": "YES"
}
] | 1,619,502,361 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 296 | 13,926,400 | n,m=map(int,input().split())
a,b=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
i=0
j=0
while(i<n and j<m and i<a):
if(arr1[i]<arr2[j]):
i+=1
else:
j+=1
if(i<a or m-j<b):
print("NO")
else:
print("YES") | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input Specification:
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Output Specification:
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n,m=map(int,input().split())
a,b=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
i=0
j=0
while(i<n and j<m and i<a):
if(arr1[i]<arr2[j]):
i+=1
else:
j+=1
if(i<a or m-j<b):
print("NO")
else:
print("YES")
``` | 3 |
|
572 | A | Arrays | PROGRAMMING | 900 | [
"sortings"
] | null | null | You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array. | The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. | Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes). | [
"3 3\n2 1\n1 2 3\n3 4 5\n",
"3 3\n3 3\n1 2 3\n3 4 5\n",
"5 2\n3 1\n1 1 1 1 1\n2 2\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 500 | [
{
"input": "3 3\n2 1\n1 2 3\n3 4 5",
"output": "YES"
},
{
"input": "3 3\n3 3\n1 2 3\n3 4 5",
"output": "NO"
},
{
"input": "5 2\n3 1\n1 1 1 1 1\n2 2",
"output": "YES"
},
{
"input": "3 5\n1 1\n5 5 5\n5 5 5 5 5",
"output": "NO"
},
{
"input": "1 1\n1 1\n1\n1",
"output": "NO"
},
{
"input": "3 3\n1 1\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n1 2\n1 2 3\n1 2 3",
"output": "YES"
},
{
"input": "3 3\n2 2\n1 2 3\n1 2 3",
"output": "NO"
},
{
"input": "10 15\n10 1\n1 1 5 17 22 29 32 36 39 48\n9 10 20 23 26 26 32 32 33 39 43 45 47 49 49",
"output": "YES"
},
{
"input": "10 15\n1 15\n91 91 91 92 92 94 94 95 98 100\n92 92 93 93 93 94 95 96 97 98 98 99 99 100 100",
"output": "YES"
},
{
"input": "15 10\n12 5\n9 25 25 32 32 38 40 41 46 46 48 51 64 64 73\n5 14 30 35 50 52 67 79 89 99",
"output": "YES"
},
{
"input": "15 10\n4 10\n22 32 35 45 45 50 51 55 79 80 83 88 90 92 93\n46 48 52 55 60 60 68 75 80 81",
"output": "YES"
},
{
"input": "20 30\n2 8\n6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 10\n1 1 2 2 2 2 2 2 2 3 3 4 5 5 5 5 6 6 6 6 6 6 7 7 7 8 8 9 10 10",
"output": "NO"
},
{
"input": "20 30\n19 29\n1 1 2 2 2 3 4 4 7 7 7 8 8 8 8 8 9 9 9 9\n6 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "NO"
},
{
"input": "1 1\n1 1\n-1000000000\n30",
"output": "YES"
},
{
"input": "3 3\n1 3\n1 3 3\n3 3 3",
"output": "YES"
},
{
"input": "3 3\n1 1\n3 3 3\n2 2 2",
"output": "NO"
},
{
"input": "5 5\n3 3\n1 5 6 7 8\n1 2 5 6 7",
"output": "NO"
},
{
"input": "3 4\n2 2\n5 6 7\n1 2 3 4",
"output": "NO"
},
{
"input": "3 3\n3 3\n1 2 3\n4 5 6",
"output": "YES"
},
{
"input": "5 5\n4 5\n2 2 3 4 5\n5 6 7 8 9",
"output": "YES"
}
] | 1,590,520,007 | 2,147,483,647 | PyPy 3 | OK | TESTS | 52 | 327 | 13,926,400 | a,b = map(int,input().split())
c,d = map(int,input().split())
n = sorted(map(int,input().split()))
m = sorted(map(int,input().split()))
m.reverse()
z = n[c-1]+1
for i in m:
if i>=z:d-=1
if d==0:
break
if d==0:print("YES")
else:print("NO") | Title: Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
Input Specification:
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly.
The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space.
The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*.
The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
Output Specification:
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
Demo Input:
['3 3\n2 1\n1 2 3\n3 4 5\n', '3 3\n3 3\n1 2 3\n3 4 5\n', '5 2\n3 1\n1 1 1 1 1\n2 2\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 < 3 and 2 < 3).
In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
a,b = map(int,input().split())
c,d = map(int,input().split())
n = sorted(map(int,input().split()))
m = sorted(map(int,input().split()))
m.reverse()
z = n[c-1]+1
for i in m:
if i>=z:d-=1
if d==0:
break
if d==0:print("YES")
else:print("NO")
``` | 3 |
|
285 | B | Find Marble | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*. | The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*. | If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1. | [
"4 2 1\n2 3 4 1\n",
"4 3 3\n4 1 3 2\n",
"4 3 4\n1 2 3 4\n",
"3 1 3\n2 1 3\n"
] | [
"3\n",
"0\n",
"-1\n",
"-1\n"
] | none | 1,000 | [
{
"input": "4 2 1\n2 3 4 1",
"output": "3"
},
{
"input": "4 3 3\n4 1 3 2",
"output": "0"
},
{
"input": "4 3 4\n1 2 3 4",
"output": "-1"
},
{
"input": "3 1 3\n2 1 3",
"output": "-1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "10 6 7\n10 7 8 1 5 6 2 9 4 3",
"output": "-1"
},
{
"input": "10 3 6\n5 6 7 3 8 4 2 1 10 9",
"output": "3"
},
{
"input": "10 10 4\n4 2 6 9 5 3 8 1 10 7",
"output": "4"
},
{
"input": "100 90 57\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": "-1"
},
{
"input": "100 11 20\n80 25 49 55 22 98 35 59 88 14 91 20 68 66 53 50 77 45 82 63 96 93 85 46 37 74 84 9 7 95 41 86 23 36 33 27 81 39 18 13 12 92 24 71 3 48 83 61 31 87 28 79 75 38 11 21 29 69 44 100 72 62 32 43 30 16 47 56 89 60 42 17 26 70 94 99 4 6 2 73 8 52 65 1 15 90 67 51 78 10 5 76 57 54 34 58 19 64 40 97",
"output": "26"
},
{
"input": "100 84 83\n30 67 53 89 94 54 92 17 26 57 15 5 74 85 10 61 18 70 91 75 14 11 93 41 25 78 88 81 20 51 35 4 62 1 97 39 68 52 47 77 64 3 2 72 60 80 8 83 65 98 21 22 45 7 58 31 43 38 90 99 49 87 55 36 29 6 37 23 66 76 59 79 40 86 63 44 82 32 48 16 50 100 28 96 46 12 27 13 24 9 19 84 73 69 71 42 56 33 34 95",
"output": "71"
},
{
"input": "100 6 93\n74 62 67 81 40 85 35 42 59 72 80 28 79 41 16 19 33 63 13 10 69 76 70 93 49 84 89 94 8 37 11 90 26 52 47 7 36 95 86 75 56 15 61 99 88 12 83 21 20 3 100 17 32 82 6 5 43 25 66 68 73 78 18 77 92 27 23 2 4 39 60 48 22 24 14 97 29 34 54 64 71 57 87 38 9 50 30 53 51 45 44 31 58 91 98 65 55 1 46 96",
"output": "-1"
},
{
"input": "100 27 56\n58 18 50 41 33 37 14 87 77 73 61 53 15 8 70 68 45 96 54 78 39 67 51 60 80 12 93 99 20 92 17 79 4 13 62 91 69 29 49 36 98 34 90 35 84 64 38 83 28 89 97 94 9 16 26 48 10 57 23 75 27 88 44 21 72 76 30 43 32 2 71 24 100 1 31 81 42 40 47 55 86 85 66 5 52 22 95 74 11 19 7 82 6 25 56 63 65 59 46 3",
"output": "20"
},
{
"input": "87 42 49\n45 55 24 44 56 72 74 23 4 7 37 67 22 6 58 76 40 36 3 20 26 87 64 75 49 70 62 42 31 1 80 33 25 59 78 27 32 2 41 61 66 28 19 85 15 69 52 77 50 14 16 34 18 43 73 83 11 39 29 9 35 13 81 54 79 21 60 46 71 57 12 17 5 47 38 30 10 84 53 63 68 8 51 65 48 86 82",
"output": "-1"
},
{
"input": "2 1 2\n1 2",
"output": "-1"
},
{
"input": "2 1 2\n2 1",
"output": "1"
},
{
"input": "2 2 2\n1 2",
"output": "0"
},
{
"input": "2 2 2\n2 1",
"output": "0"
},
{
"input": "2 1 1\n2 1",
"output": "0"
}
] | 1,620,137,799 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 2,000 | 11,776,000 | def main():
n,s,t = map(int,input().split())
li=[-1]+list(map(int,input().split()))
cnt=0
found=1
mov=[]
while(s!=t):
mov.append(s)
s=li[s]
cnt=cnt+1
if(s in mov):
found=0
break
if(found==1):
print(cnt)
else:
print("-1")
main() | Title: Find Marble
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are playing a game. Petya's got *n* non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to *n* from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts a marble under the glass in position *s*. Then he performs some (possibly zero) shuffling operations. One shuffling operation means moving the glass from the first position to position *p*1, the glass from the second position to position *p*2 and so on. That is, a glass goes from position *i* to position *p**i*. Consider all glasses are moving simultaneously during one shuffling operation. When the glasses are shuffled, the marble doesn't travel from one glass to another: it moves together with the glass it was initially been put in.
After all shuffling operations Petya shows Vasya that the ball has moved to position *t*. Vasya's task is to say what minimum number of shuffling operations Petya has performed or determine that Petya has made a mistake and the marble could not have got from position *s* to position *t*.
Input Specification:
The first line contains three integers: *n*,<=*s*,<=*t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*s*,<=*t*<=≤<=*n*) — the number of glasses, the ball's initial and final position. The second line contains *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the shuffling operation parameters. It is guaranteed that all *p**i*'s are distinct.
Note that *s* can equal *t*.
Output Specification:
If the marble can move from position *s* to position *t*, then print on a single line a non-negative integer — the minimum number of shuffling operations, needed to get the marble to position *t*. If it is impossible, print number -1.
Demo Input:
['4 2 1\n2 3 4 1\n', '4 3 3\n4 1 3 2\n', '4 3 4\n1 2 3 4\n', '3 1 3\n2 1 3\n']
Demo Output:
['3\n', '0\n', '-1\n', '-1\n']
Note:
none | ```python
def main():
n,s,t = map(int,input().split())
li=[-1]+list(map(int,input().split()))
cnt=0
found=1
mov=[]
while(s!=t):
mov.append(s)
s=li[s]
cnt=cnt+1
if(s in mov):
found=0
break
if(found==1):
print(cnt)
else:
print("-1")
main()
``` | 0 |
|
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"output": "444"
},
{
"input": "1000000",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "47",
"output": "44477777"
},
{
"input": "100",
"output": "4444777777777777"
},
{
"input": "700",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "485",
"output": "44447777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "111",
"output": "444447777777777777"
},
{
"input": "85",
"output": "4477777777777"
},
{
"input": "114",
"output": "444477777777777777"
},
{
"input": "474",
"output": "444777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "74",
"output": "47777777777"
},
{
"input": "1000",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "1024",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "4444",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "45784",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10000",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9854",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "186",
"output": "477777777777777777777777777"
},
{
"input": "10416",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10417",
"output": "4477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "3840",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "100000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "9876",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "99999",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "777777",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "854759",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "11000",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "18951",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999999",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "888887",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999998",
"output": "4444477777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "40008",
"output": "4444447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "10691",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "-1"
},
{
"input": "9",
"output": "-1"
},
{
"input": "8",
"output": "44"
},
{
"input": "2",
"output": "-1"
},
{
"input": "3",
"output": "-1"
},
{
"input": "999997",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999996",
"output": "4777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999990",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "999980",
"output": "4444777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "800000",
"output": "4447777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
},
{
"input": "980000",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777..."
}
] | 1,607,430,678 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 310 | 2,048,000 | a=int(input())
for i in range(a):
for x in range(a):
if 4*i+7*x==a:
print('4'*i+'7'*x)
exit()
print(-1) | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task.
Input Specification:
The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number.
Output Specification:
Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1.
Demo Input:
['11\n', '10\n']
Demo Output:
['47\n', '-1\n']
Note:
none | ```python
a=int(input())
for i in range(a):
for x in range(a):
if 4*i+7*x==a:
print('4'*i+'7'*x)
exit()
print(-1)
``` | 3.918685 |
975 | A | Aramic script | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script? | The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters. | Output one integer — the number of different objects mentioned in the given ancient Aramic script. | [
"5\na aa aaa ab abb\n",
"3\namer arem mrea\n"
] | [
"2",
"1"
] | In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | 500 | [
{
"input": "5\na aa aaa ab abb",
"output": "2"
},
{
"input": "3\namer arem mrea",
"output": "1"
},
{
"input": "10\nbda bbb cda dca dda dcb bcd dcb ada ddd",
"output": "6"
},
{
"input": "2\nfhjlqs aceginpr",
"output": "2"
},
{
"input": "2\nbcdfghimn efghijlmo",
"output": "2"
}
] | 1,648,446,644 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | input();s=set()
for i in input().split():
s.add(set(i))
print(len(s)) | Title: Aramic script
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Aramic language words can only represent objects.
Words in Aramic have special properties:
- A word is a root if it does not contain the same letter more than once. - A root and all its permutations represent the same object. - The root $x$ of a word $y$ is the word that contains all letters that appear in $y$ in a way that each letter appears once. For example, the root of "aaaa", "aa", "aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab". - Any word in Aramic represents the same object as its root.
You have an ancient script in Aramic. What is the number of different objects mentioned in the script?
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^3$) — the number of words in the script.
The second line contains $n$ words $s_1, s_2, \ldots, s_n$ — the script itself. The length of each string does not exceed $10^3$.
It is guaranteed that all characters of the strings are small latin letters.
Output Specification:
Output one integer — the number of different objects mentioned in the given ancient Aramic script.
Demo Input:
['5\na aa aaa ab abb\n', '3\namer arem mrea\n']
Demo Output:
['2', '1']
Note:
In the first test, there are two objects mentioned. The roots that represent them are "a","ab".
In the second test, there is only one object, its root is "amer", the other strings are just permutations of "amer". | ```python
input();s=set()
for i in input().split():
s.add(set(i))
print(len(s))
``` | -1 |
|
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car. | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 8\n8 8\n9 9\n9 9\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 100\n71 73\n80 94\n81 92\n84 85\n85 100\n88 91\n91 95\n92 98\n92 98\n99 100\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 6\n1 6\n1 2\n1 3\n1 2\n1 3\n2 5\n2 4\n2 3\n2 4\n2 6\n2 2\n2 5\n2 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 9\n3 3\n3 7\n3 9\n3 3\n3 9\n4 6\n4 7\n4 5\n4 7\n5 8\n5 5\n5 9\n5 7\n5 5\n6 6\n6 9\n6 7\n6 8\n6 9\n6 8\n7 7\n7 8\n7 7\n7 8\n8 9\n8 8\n8 9\n8 8\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7\n7 7\n8 10\n8 10\n9 9\n9 9\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 100\n1 38\n2 82\n5 35\n7 71\n8 53\n11 49\n15 27\n17 84\n17 75\n18 99\n18 43\n18 69\n21 89\n27 60\n27 29\n38 62\n38 77\n39 83\n40 66\n48 80\n48 100\n50 51\n50 61\n53 77\n53 63\n55 58\n56 68\n60 82\n62 95\n66 74\n67 83\n69 88\n69 81\n69 88\n69 98\n70 91\n70 76\n71 90\n72 99\n81 99\n85 87\n88 97\n88 93\n90 97\n90 97\n92 98\n98 99\n100 100",
"output": "YES"
},
{
"input": "70 10\n0 4\n0 4\n0 8\n0 9\n0 1\n0 5\n0 7\n1 3\n1 8\n1 8\n1 10\n1 9\n1 6\n1 2\n1 3\n1 2\n2 6\n2 5\n2 4\n2 3\n2 10\n2 2\n2 6\n2 2\n3 10\n3 7\n3 7\n3 4\n3 7\n3 4\n3 8\n3 4\n3 10\n3 5\n3 3\n3 7\n4 8\n4 8\n4 9\n4 6\n5 7\n5 10\n5 7\n5 8\n5 5\n6 8\n6 9\n6 10\n6 6\n6 9\n6 7\n7 8\n7 9\n7 10\n7 10\n8 8\n8 8\n8 9\n8 10\n9 10\n9 9\n9 10\n9 10\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 4\n1 5\n1 9\n1 1\n1 6\n1 6\n2 5\n2 7\n2 7\n2 7\n2 7\n3 4\n3 7\n3 9\n3 5\n3 3\n4 4\n4 6\n4 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n5 8\n5 9\n5 8\n6 8\n6 7\n6 8\n6 9\n6 9\n6 6\n6 9\n6 7\n7 7\n7 7\n7 7\n7 8\n7 7\n7 8\n7 8\n7 9\n8 8\n8 8\n8 8\n8 8\n8 8\n8 9\n8 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 40\n38 38\n40 40",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 92\n92 97\n96 99\n97 98\n97 99\n99 99\n100 100\n100 100\n100 100",
"output": "NO"
},
{
"input": "1 10\n0 10",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 40\n23 23\n23 28\n24 29\n25 38\n26 35\n27 37\n28 39\n28 33\n28 40\n28 33\n29 31\n29 33\n30 38\n30 36\n30 30\n30 38\n31 37\n31 35\n31 32\n31 36\n33 39\n33 40\n35 38\n36 38\n37 38\n37 40\n38 39\n38 40\n38 39\n39 39\n39 40\n40 40\n40 40\n40 40\n40 40",
"output": "YES"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 40\n11 31\n12 26\n13 25\n14 32\n17 19\n21 29\n22 36\n24 27\n25 39\n25 27\n27 32\n27 29\n27 39\n27 29\n28 38\n30 38\n32 40\n32 38\n33 33\n33 40\n34 35\n34 34\n34 38\n34 38\n35 37\n36 39\n36 39\n37 37\n38 40\n39 39\n40 40",
"output": "YES"
},
{
"input": "70 40\n0 34\n1 16\n3 33\n4 36\n4 22\n5 9\n5 9\n7 16\n8 26\n9 29\n9 25\n10 15\n10 22\n10 29\n10 20\n11 27\n11 26\n11 12\n12 19\n13 21\n14 31\n14 36\n15 34\n15 37\n16 21\n17 31\n18 22\n20 27\n20 32\n20 20\n20 29\n21 29\n21 34\n21 30\n22 22\n23 28\n23 39\n24 24\n25 27\n26 38\n27 39\n28 33\n28 39\n28 34\n28 33\n29 30\n29 35\n30 30\n30 38\n30 34\n30 31\n31 36\n31 31\n31 32\n31 38\n33 34\n33 34\n35 36\n36 38\n37 38\n37 39\n38 38\n38 38\n38 38\n39 39\n39 39\n40 40\n40 40\n40 40\n40 40",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n88 99",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 10\n7 10\n9 10",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 5\n4 8\n5 5\n5 7\n6 7\n6 6\n7 7\n7 7\n7 7\n7 8\n7 8\n8 8\n8 8\n8 9\n8 8\n8 9\n9 9\n9 9\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n32 37",
"output": "NO"
},
{
"input": "50 10\n0 2\n0 2\n0 6\n1 9\n1 3\n1 2\n1 6\n1 1\n1 1\n2 7\n2 6\n2 4\n3 9\n3 8\n3 8\n3 8\n3 6\n3 4\n3 7\n3 4\n3 6\n3 10\n4 6\n5 9\n5 5\n6 7\n6 10\n7 8\n7 7\n7 7\n7 7\n7 10\n8 8\n8 8\n8 10\n8 8\n8 8\n9 10\n9 10\n9 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "1 1\n0 1",
"output": "YES"
},
{
"input": "30 40\n0 0\n4 8\n5 17\n7 32\n7 16\n8 16\n10 19\n12 22\n12 27\n13 21\n13 28\n13 36\n14 28\n14 18\n18 21\n21 26\n21 36\n22 38\n23 32\n24 30\n26 35\n29 32\n29 32\n31 34\n31 31\n33 33\n33 35\n35 36\n38 38\n40 40",
"output": "NO"
},
{
"input": "30 100\n0 27\n4 82\n11 81\n14 32\n33 97\n33 34\n37 97\n38 52\n45 91\n49 56\n50 97\n57 70\n59 94\n59 65\n62 76\n64 65\n65 95\n67 77\n68 82\n71 94\n80 90\n81 88\n84 93\n85 89\n88 92\n91 97\n92 99\n92 97\n99 99\n100 100",
"output": "NO"
},
{
"input": "10 100\n0 34\n8 56\n17 79\n24 88\n28 79\n45 79\n48 93\n55 87\n68 93\n79 100",
"output": "YES"
},
{
"input": "10 40\n0 21\n1 19\n4 33\n6 26\n8 39\n15 15\n20 24\n27 27\n29 39\n37 40",
"output": "YES"
},
{
"input": "85 10\n0 9\n0 4\n0 2\n0 5\n0 1\n0 8\n0 7\n1 2\n1 10\n1 2\n1 5\n1 10\n1 8\n1 1\n2 8\n2 7\n2 5\n2 5\n2 7\n3 5\n3 7\n3 5\n3 4\n3 7\n4 7\n4 8\n4 6\n5 7\n5 10\n5 5\n5 6\n5 6\n5 6\n5 6\n5 7\n5 8\n5 5\n5 7\n6 10\n6 9\n6 7\n6 10\n6 8\n6 7\n6 10\n6 10\n7 8\n7 9\n7 8\n7 8\n7 8\n7 8\n7 7\n7 7\n8 8\n8 8\n8 10\n8 9\n8 9\n8 9\n8 9\n9 9\n9 10\n9 9\n9 9\n9 9\n9 9\n9 10\n9 10\n9 9\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10\n10 10",
"output": "YES"
},
{
"input": "50 100\n0 95\n1 7\n1 69\n2 83\n5 67\n7 82\n8 31\n11 25\n15 44\n17 75\n17 27\n18 43\n18 69\n18 40\n21 66\n27 29\n27 64\n38 77\n38 90\n39 52\n40 60\n48 91\n48 98\n50 89\n50 63\n53 54\n53 95\n55 76\n56 59\n60 96\n62 86\n66 70\n67 77\n69 88\n69 98\n69 80\n69 95\n70 74\n70 77\n71 99\n72 73\n81 87\n85 99\n88 96\n88 91\n90 97\n90 99\n92 92\n98 99\n100 100",
"output": "NO"
},
{
"input": "50 40\n0 9\n1 26\n1 27\n2 33\n2 5\n3 30\n4 28\n5 31\n5 27\n5 29\n7 36\n8 32\n8 13\n9 24\n10 10\n10 30\n11 26\n11 22\n11 35\n11 23\n12 36\n13 31\n14 31\n17 17\n21 25\n22 33\n24 26\n25 32\n25 25\n27 39\n27 29\n27 34\n27 32\n28 34\n30 36\n32 37\n32 33\n33 35\n33 33\n34 38\n34 38\n34 36\n34 36\n35 36\n36 36\n36 39\n37 37\n38 39\n39 39\n40 40",
"output": "NO"
},
{
"input": "10 10\n0 2\n3 8\n3 5\n3 3\n3 9\n3 8\n5 7\n6 9\n7 7\n9 9",
"output": "NO"
},
{
"input": "70 100\n0 99\n1 87\n1 94\n1 4\n2 72\n3 39\n3 69\n4 78\n5 85\n7 14\n8 59\n12 69\n14 15\n14 76\n17 17\n19 53\n19 57\n19 21\n21 35\n21 83\n24 52\n24 33\n27 66\n27 97\n30 62\n30 74\n30 64\n32 63\n35 49\n37 60\n40 99\n40 71\n41 83\n42 66\n42 46\n45 83\n51 76\n53 69\n54 82\n54 96\n54 88\n55 91\n56 88\n58 62\n62 87\n64 80\n67 90\n67 69\n68 92\n72 93\n74 93\n77 79\n77 91\n78 97\n78 98\n81 85\n81 83\n81 83\n84 85\n86 88\n89 94\n89 100\n92 97\n96 96\n97 98\n97 100\n99 100\n100 100\n100 100\n100 100",
"output": "YES"
},
{
"input": "2 2\n0 2\n0 1",
"output": "YES"
},
{
"input": "2 100\n0 49\n50 100",
"output": "NO"
},
{
"input": "2 100\n0 50\n50 100",
"output": "YES"
},
{
"input": "10 100\n0 10\n10 20\n20 30\n30 40\n40 50\n50 60\n60 70\n70 80\n80 90\n90 100",
"output": "YES"
},
{
"input": "100 10\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 10",
"output": "YES"
},
{
"input": "1 4\n1 4",
"output": "NO"
},
{
"input": "3 5\n0 2\n2 5\n3 4",
"output": "YES"
},
{
"input": "2 5\n0 5\n1 2",
"output": "YES"
},
{
"input": "5 5\n0 2\n0 2\n3 5\n3 5\n3 5",
"output": "NO"
},
{
"input": "4 10\n0 3\n2 10\n4 10\n5 7",
"output": "YES"
},
{
"input": "3 8\n0 0\n1 8\n2 8",
"output": "NO"
},
{
"input": "6 8\n0 3\n1 5\n2 3\n5 6\n6 7\n7 8",
"output": "YES"
}
] | 1,513,698,450 | 750 | Python 3 | OK | TESTS | 55 | 62 | 5,529,600 | nums = [int(x) for x in input().split()]
n , m = nums[0] , nums[1]
maxb = 0
for i in range(n):
nums = [int(x) for x in input().split()]
if nums[0] > maxb:
break
if nums[1] > maxb:
maxb = nums[1]
if maxb >= m:
print('YES')
else:
print('NO') | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.
Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds.
Determine if Pig can visit the friend using teleports only, or he should use his car.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit.
It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Output Specification:
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Demo Input:
['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n']
Demo Output:
['YES\n', 'NO\n']
Note:
The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You can see that there is no path from Pig's house to his friend's house that uses only teleports. | ```python
nums = [int(x) for x in input().split()]
n , m = nums[0] , nums[1]
maxb = 0
for i in range(n):
nums = [int(x) for x in input().split()]
if nums[0] > maxb:
break
if nums[1] > maxb:
maxb = nums[1]
if maxb >= m:
print('YES')
else:
print('NO')
``` | 3 |
|
998 | A | Balloons | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
- Do not rip the packets (both Grigory and Andrew should get unbroken packets); - Distribute all packets (every packet should be given to someone); - Give both Grigory and Andrew at least one packet; - To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions. | The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet. | If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them. | [
"3\n1 2 1\n",
"2\n5 5\n",
"1\n10\n"
] | [
"2\n1 2\n",
"-1\n",
"-1\n"
] | In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | 500 | [
{
"input": "3\n1 2 1",
"output": "1\n1"
},
{
"input": "2\n5 5",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1\n1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 9",
"output": "1\n1"
},
{
"input": "10\n26 723 970 13 422 968 875 329 234 983",
"output": "1\n4"
},
{
"input": "3\n3 2 1",
"output": "1\n3"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "1\n1"
},
{
"input": "10\n1 9 7 6 2 4 7 8 1 3",
"output": "1\n1"
},
{
"input": "2\n9 6",
"output": "1\n2"
},
{
"input": "2\n89 7",
"output": "1\n2"
},
{
"input": "2\n101 807",
"output": "1\n1"
},
{
"input": "5\n8 7 4 8 3",
"output": "1\n5"
},
{
"input": "5\n55 62 70 100 90",
"output": "1\n1"
},
{
"input": "5\n850 840 521 42 169",
"output": "1\n4"
},
{
"input": "6\n7 1 4 1 6 1",
"output": "1\n2"
},
{
"input": "6\n36 80 38 88 79 69",
"output": "1\n1"
},
{
"input": "6\n108 318 583 10 344 396",
"output": "1\n4"
},
{
"input": "9\n10 9 10 10 8 3 5 10 2",
"output": "1\n9"
},
{
"input": "9\n90 31 28 63 57 57 27 62 42",
"output": "1\n7"
},
{
"input": "9\n665 646 152 829 190 64 555 536 321",
"output": "1\n6"
},
{
"input": "10\n99 62 10 47 53 9 83 33 15 24",
"output": "1\n6"
},
{
"input": "4\n600 200 100 300",
"output": "1\n3"
},
{
"input": "2\n4 5",
"output": "1\n1"
},
{
"input": "2\n5 12",
"output": "1\n1"
},
{
"input": "2\n1 2",
"output": "1\n1"
},
{
"input": "3\n1 1 2",
"output": "1\n1"
},
{
"input": "2\n3 2",
"output": "1\n2"
},
{
"input": "3\n1 4 5",
"output": "1\n1"
},
{
"input": "4\n5 5 5 5",
"output": "1\n1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "3\n5 5 5",
"output": "1\n1"
},
{
"input": "5\n5 5 5 5 5",
"output": "1\n1"
},
{
"input": "4\n2 7 10 1",
"output": "1\n4"
},
{
"input": "3\n1 1 1",
"output": "1\n1"
},
{
"input": "4\n8 4 2 2",
"output": "1\n3"
},
{
"input": "2\n3 4",
"output": "1\n1"
},
{
"input": "4\n1 1 3 1",
"output": "1\n1"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "1\n1"
},
{
"input": "2\n18 19",
"output": "1\n1"
},
{
"input": "2\n17 18",
"output": "1\n1"
},
{
"input": "2\n1 3",
"output": "1\n1"
},
{
"input": "4\n5 5 4 4",
"output": "1\n3"
},
{
"input": "2\n10 11",
"output": "1\n1"
},
{
"input": "2\n10 20",
"output": "1\n1"
},
{
"input": "2\n2 1",
"output": "1\n2"
},
{
"input": "4\n2 3 2 3",
"output": "1\n1"
},
{
"input": "2\n5 6",
"output": "1\n1"
}
] | 1,597,764,064 | 2,164 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 307,200 | n = int(input())
if(1<=n and n<=10) :
a = input()
b = a.split(" ")
count = 0
for j in range(n) :
b[j] = int(b[j])
if(b[j]<1 or b[j]>1000) :
count += 1
if(count == 0) :
if(n == 1) :
print("-1")
else :
if(n == 2) :
if(b[0] == b[1]) :
print("-1")
else :
print("1")
print(b[0])
else :
sum = 0
for i in range(n-1) :
sum = sum + b[i]
if(sum == b[n-1]) :
print("2")
print(b[n-2], b[n-1])
else :
print("1")
print(b[n-1]) | Title: Balloons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.
Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons inside.
They want to divide the balloons among themselves. In addition, there are several conditions to hold:
- Do not rip the packets (both Grigory and Andrew should get unbroken packets); - Distribute all packets (every packet should be given to someone); - Give both Grigory and Andrew at least one packet; - To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets.
Help them to divide the balloons or determine that it's impossible under these conditions.
Input Specification:
The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons.
The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet.
Output Specification:
If it's impossible to divide the balloons satisfying the conditions above, print $-1$.
Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter.
If there are multiple ways to divide balloons, output any of them.
Demo Input:
['3\n1 2 1\n', '2\n5 5\n', '1\n10\n']
Demo Output:
['2\n1 2\n', '-1\n', '-1\n']
Note:
In the first test Grigory gets $3$ balloons in total while Andrey gets $1$.
In the second test there's only one way to divide the packets which leads to equal numbers of balloons.
In the third test one of the boys won't get a packet at all. | ```python
n = int(input())
if(1<=n and n<=10) :
a = input()
b = a.split(" ")
count = 0
for j in range(n) :
b[j] = int(b[j])
if(b[j]<1 or b[j]>1000) :
count += 1
if(count == 0) :
if(n == 1) :
print("-1")
else :
if(n == 2) :
if(b[0] == b[1]) :
print("-1")
else :
print("1")
print(b[0])
else :
sum = 0
for i in range(n-1) :
sum = sum + b[i]
if(sum == b[n-1]) :
print("2")
print(b[n-2], b[n-1])
else :
print("1")
print(b[n-1])
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. | The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. | Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. | [
"1 1 1 1 1 1\n",
"1 2 1 2 1 2\n"
] | [
"6\n",
"13\n"
] | This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 0 | [
{
"input": "1 1 1 1 1 1",
"output": "6"
},
{
"input": "1 2 1 2 1 2",
"output": "13"
},
{
"input": "2 4 5 3 3 6",
"output": "83"
},
{
"input": "45 19 48 18 46 21",
"output": "6099"
},
{
"input": "66 6 65 6 66 5",
"output": "5832"
},
{
"input": "7 5 4 8 4 5",
"output": "175"
},
{
"input": "3 2 1 4 1 2",
"output": "25"
},
{
"input": "7 1 7 3 5 3",
"output": "102"
},
{
"input": "9 2 9 3 8 3",
"output": "174"
},
{
"input": "1 6 1 5 2 5",
"output": "58"
},
{
"input": "41 64 48 61 44 68",
"output": "17488"
},
{
"input": "1 59 2 59 1 60",
"output": "3838"
},
{
"input": "30 36 36 32 34 38",
"output": "7052"
},
{
"input": "50 40 46 38 52 34",
"output": "11176"
},
{
"input": "4 60 4 60 4 60",
"output": "4576"
},
{
"input": "718 466 729 470 714 481",
"output": "2102808"
},
{
"input": "131 425 143 461 95 473",
"output": "441966"
},
{
"input": "125 7 128 8 124 11",
"output": "20215"
},
{
"input": "677 303 685 288 692 296",
"output": "1365807"
},
{
"input": "1 577 7 576 2 582",
"output": "342171"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "6000000"
},
{
"input": "1 1 1000 1 1 1000",
"output": "4002"
},
{
"input": "1000 1000 1 1000 1000 1",
"output": "2004000"
},
{
"input": "1000 1 1000 999 2 999",
"output": "2003997"
},
{
"input": "1 1000 1 1 1000 1",
"output": "4002"
},
{
"input": "888 888 888 887 889 887",
"output": "4729487"
}
] | 1,525,938,638 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 77 | 7,065,600 | a = list(map(int, input().split()))
mx = 0
i = 0
for j in range(6):
k = (a[(i - 1) % 6] + a[(i - 0) % 6] + a[(i + 1) % 6])
if mx < k:
mx = k
i = j
n = mx
f = lambda n : n ** 2
print(f(n) - f(a[(i + 1) % 6]) - f(a[(i + 3) % 6]) - f(a[(i + 5) % 6]))
"""
1 1 1 1 1 1
1 2 1 2 1 2
1 2 2 2 1 3
1 1 2 2 3 3
"""
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.
He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.
Input Specification:
The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≤<=*a**i*<=≤<=1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.
Output Specification:
Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.
Demo Input:
['1 1 1 1 1 1\n', '1 2 1 2 1 2\n']
Demo Output:
['6\n', '13\n']
Note:
This is what Gerald's hexagon looks like in the first sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/84d193e27b02c38eb1eadc536602a2ec0b9f9519.png" style="max-width: 100.0%;max-height: 100.0%;"/>
And that's what it looks like in the second sample:
<img class="tex-graphics" src="https://espresso.codeforces.com/e29076a96da8ca864654cc6195654d9bf07d31ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> | ```python
a = list(map(int, input().split()))
mx = 0
i = 0
for j in range(6):
k = (a[(i - 1) % 6] + a[(i - 0) % 6] + a[(i + 1) % 6])
if mx < k:
mx = k
i = j
n = mx
f = lambda n : n ** 2
print(f(n) - f(a[(i + 1) % 6]) - f(a[(i + 3) % 6]) - f(a[(i + 5) % 6]))
"""
1 1 1 1 1 1
1 2 1 2 1 2
1 2 2 2 1 3
1 1 2 2 3 3
"""
``` | 3 |
|
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club. | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself. | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
{
"input": "5 4\n1 4\n4 3\n4 5\n5 2",
"output": "2"
},
{
"input": "11 10\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n9 10\n10 11",
"output": "4"
},
{
"input": "7 7\n1 2\n2 3\n3 1\n1 4\n4 5\n4 6\n4 7",
"output": "2"
},
{
"input": "12 49\n6 3\n12 9\n10 11\n3 5\n10 2\n6 9\n8 5\n6 12\n7 3\n3 12\n3 2\n5 6\n7 5\n9 2\n11 1\n7 6\n5 4\n8 7\n12 5\n5 11\n8 9\n10 3\n6 2\n10 4\n9 10\n9 11\n11 3\n5 9\n11 6\n10 8\n7 9\n10 7\n4 6\n3 8\n4 11\n12 2\n4 9\n2 11\n7 11\n1 5\n7 2\n8 1\n4 12\n9 1\n4 2\n8 2\n11 12\n3 1\n1 6",
"output": "0"
},
{
"input": "10 29\n4 5\n1 7\n4 2\n3 8\n7 6\n8 10\n10 6\n4 1\n10 1\n6 2\n7 4\n7 10\n2 7\n9 8\n5 10\n2 5\n8 5\n4 9\n2 8\n5 7\n4 8\n7 3\n6 5\n1 3\n1 9\n10 4\n10 9\n10 2\n2 3",
"output": "0"
},
{
"input": "9 33\n5 7\n5 9\n9 6\n9 1\n7 4\n3 5\n7 8\n8 6\n3 6\n8 2\n3 8\n1 6\n1 8\n1 4\n4 2\n1 2\n2 5\n3 4\n8 5\n2 6\n3 1\n1 5\n1 7\n3 2\n5 4\n9 4\n3 9\n7 3\n6 4\n9 8\n7 9\n8 4\n6 5",
"output": "0"
},
{
"input": "7 8\n5 7\n2 7\n1 6\n1 3\n3 7\n6 3\n6 4\n2 6",
"output": "1"
},
{
"input": "6 15\n3 1\n4 5\n1 4\n6 2\n3 5\n6 3\n1 6\n1 5\n2 3\n2 5\n6 4\n5 6\n4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "7 11\n5 3\n6 5\n6 4\n1 6\n7 1\n2 6\n7 5\n2 5\n3 1\n3 4\n2 4",
"output": "0"
},
{
"input": "95 0",
"output": "0"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "62 30\n29 51\n29 55\n4 12\n53 25\n36 28\n32 11\n29 11\n47 9\n21 8\n25 4\n51 19\n26 56\n22 21\n37 9\n9 33\n7 25\n16 7\n40 49\n15 21\n49 58\n34 30\n20 46\n62 48\n53 57\n33 6\n60 37\n41 34\n62 36\n36 43\n11 39",
"output": "2"
},
{
"input": "56 25\n12 40\n31 27\n18 40\n1 43\n9 10\n25 47\n27 29\n26 28\n19 38\n19 40\n22 14\n21 51\n29 31\n55 29\n51 33\n20 17\n24 15\n3 48\n31 56\n15 29\n49 42\n50 4\n22 42\n25 17\n18 51",
"output": "3"
},
{
"input": "51 29\n36 30\n37 45\n4 24\n40 18\n47 35\n15 1\n30 38\n15 18\n32 40\n34 42\n2 47\n35 21\n25 28\n13 1\n13 28\n36 1\n46 47\n22 17\n41 45\n43 45\n40 15\n29 35\n47 15\n30 21\n9 14\n18 38\n18 50\n42 10\n31 41",
"output": "3"
},
{
"input": "72 45\n5 15\n8 18\n40 25\n71 66\n67 22\n6 44\n16 25\n8 23\n19 70\n26 34\n48 15\n24 2\n54 68\n44 43\n17 37\n49 19\n71 49\n34 38\n59 1\n65 70\n11 54\n5 11\n15 31\n29 50\n48 16\n70 57\n25 59\n2 59\n56 12\n66 62\n24 16\n46 27\n45 67\n68 43\n31 11\n31 30\n8 44\n64 33\n38 44\n54 10\n13 9\n7 51\n25 4\n40 70\n26 65",
"output": "5"
},
{
"input": "56 22\n17 27\n48 49\n29 8\n47 20\n32 7\n44 5\n14 39\n5 13\n40 2\n50 42\n38 9\n18 37\n16 44\n21 32\n21 39\n37 54\n19 46\n30 47\n17 13\n30 31\n49 16\n56 7",
"output": "4"
},
{
"input": "81 46\n53 58\n31 14\n18 54\n43 61\n57 65\n6 38\n49 5\n6 40\n6 10\n17 72\n27 48\n58 39\n21 75\n21 43\n78 20\n34 4\n15 35\n74 48\n76 15\n49 38\n46 51\n78 9\n80 5\n26 42\n64 31\n46 72\n1 29\n20 17\n32 45\n53 43\n24 5\n52 59\n3 80\n78 19\n61 17\n80 12\n17 8\n63 2\n8 4\n44 10\n53 72\n18 60\n68 15\n17 58\n79 71\n73 35",
"output": "4"
},
{
"input": "82 46\n64 43\n32 24\n57 30\n24 46\n70 12\n23 41\n63 39\n46 70\n4 61\n19 12\n39 79\n14 28\n37 3\n12 27\n15 20\n35 39\n25 64\n59 16\n68 63\n37 14\n76 7\n67 29\n9 5\n14 55\n46 26\n71 79\n47 42\n5 55\n18 45\n28 40\n44 78\n74 9\n60 53\n44 19\n52 81\n65 52\n40 13\n40 19\n43 1\n24 23\n68 9\n16 20\n70 14\n41 40\n29 10\n45 65",
"output": "8"
},
{
"input": "69 38\n63 35\n52 17\n43 69\n2 57\n12 5\n26 36\n13 10\n16 68\n5 18\n5 41\n10 4\n60 9\n39 22\n39 28\n53 57\n13 52\n66 38\n49 61\n12 19\n27 46\n67 7\n25 8\n23 58\n52 34\n29 2\n2 42\n8 53\n57 43\n68 11\n48 28\n56 19\n46 33\n63 21\n57 16\n68 59\n67 34\n28 43\n56 36",
"output": "4"
},
{
"input": "75 31\n32 50\n52 8\n21 9\n68 35\n12 72\n47 26\n38 58\n40 55\n31 70\n53 75\n44 1\n65 22\n33 22\n33 29\n14 39\n1 63\n16 52\n70 15\n12 27\n63 31\n47 9\n71 31\n43 17\n43 49\n8 26\n11 39\n9 22\n30 45\n65 47\n32 9\n60 70",
"output": "4"
},
{
"input": "77 41\n48 45\n50 36\n6 69\n70 3\n22 21\n72 6\n54 3\n49 31\n2 23\n14 59\n68 58\n4 54\n60 12\n63 60\n44 24\n28 24\n40 8\n5 1\n13 24\n29 15\n19 76\n70 50\n65 71\n23 33\n58 16\n50 42\n71 28\n58 54\n24 73\n6 17\n29 13\n60 4\n42 4\n21 60\n77 39\n57 9\n51 19\n61 6\n49 36\n24 32\n41 66",
"output": "3"
},
{
"input": "72 39\n9 44\n15 12\n2 53\n34 18\n41 70\n54 72\n39 19\n26 7\n4 54\n53 59\n46 49\n70 6\n9 10\n64 51\n31 60\n61 53\n59 71\n9 60\n67 16\n4 16\n34 3\n2 61\n16 23\n34 6\n10 18\n13 38\n66 40\n59 9\n40 14\n38 24\n31 48\n7 69\n20 39\n49 52\n32 67\n61 35\n62 45\n37 54\n5 27",
"output": "8"
},
{
"input": "96 70\n30 37\n47 56\n19 79\n15 28\n2 43\n43 54\n59 75\n42 22\n38 18\n18 14\n47 41\n60 29\n35 11\n90 4\n14 41\n11 71\n41 24\n68 28\n45 92\n14 15\n34 63\n77 32\n67 38\n36 8\n37 4\n58 95\n68 84\n69 81\n35 23\n56 63\n78 91\n35 44\n66 63\n80 19\n87 88\n28 14\n62 35\n24 23\n83 37\n54 89\n14 40\n9 35\n94 9\n56 46\n92 70\n16 58\n96 31\n53 23\n56 5\n36 42\n89 77\n29 51\n26 13\n46 70\n25 56\n95 96\n3 51\n76 8\n36 82\n44 85\n54 56\n89 67\n32 5\n82 78\n33 65\n43 28\n35 1\n94 13\n26 24\n10 51",
"output": "4"
},
{
"input": "76 49\n15 59\n23 26\n57 48\n49 51\n42 76\n36 40\n37 40\n29 15\n28 71\n47 70\n27 39\n76 21\n55 16\n21 18\n19 1\n25 31\n51 71\n54 42\n28 9\n61 69\n33 9\n18 19\n58 51\n51 45\n29 34\n9 67\n26 8\n70 37\n11 62\n24 22\n59 76\n67 17\n59 11\n54 1\n12 57\n23 3\n46 47\n37 20\n65 9\n51 12\n31 19\n56 13\n58 22\n26 59\n39 76\n27 11\n48 64\n59 35\n44 75",
"output": "5"
},
{
"input": "52 26\n29 41\n16 26\n18 48\n31 17\n37 42\n26 1\n11 7\n29 6\n23 17\n12 47\n34 23\n41 16\n15 35\n25 21\n45 7\n52 2\n37 10\n28 19\n1 27\n30 47\n42 35\n50 30\n30 34\n19 30\n42 25\n47 31",
"output": "3"
},
{
"input": "86 48\n59 34\n21 33\n45 20\n62 23\n4 68\n2 65\n63 26\n64 20\n51 34\n64 21\n68 78\n61 80\n81 3\n38 39\n47 48\n24 34\n44 71\n72 78\n50 2\n13 51\n82 78\n11 74\n14 48\n2 75\n49 55\n63 85\n20 85\n4 53\n51 15\n11 67\n1 15\n2 64\n10 81\n6 7\n68 18\n84 28\n77 69\n10 36\n15 14\n32 86\n16 79\n26 13\n38 55\n47 43\n47 39\n45 37\n58 81\n42 35",
"output": "8"
},
{
"input": "58 29\n27 24\n40 52\n51 28\n44 50\n7 28\n14 53\n10 16\n16 45\n8 56\n35 26\n39 6\n6 14\n45 22\n35 13\n20 17\n42 6\n37 21\n4 11\n26 56\n54 55\n3 57\n40 3\n55 27\n4 51\n35 29\n50 16\n47 7\n48 20\n1 37",
"output": "3"
},
{
"input": "51 23\n46 47\n31 27\n1 20\n49 16\n2 10\n29 47\n13 27\n34 26\n31 2\n28 20\n17 40\n39 4\n29 26\n28 44\n3 39\n50 12\n19 1\n30 21\n41 23\n2 29\n16 3\n49 28\n49 41",
"output": "4"
},
{
"input": "75 43\n46 34\n33 12\n51 39\n47 74\n68 64\n40 46\n20 51\n47 19\n4 5\n57 59\n12 26\n68 65\n38 42\n73 37\n5 74\n36 61\n8 18\n58 33\n34 73\n42 43\n10 49\n70 50\n49 18\n24 53\n71 73\n44 24\n49 56\n24 29\n44 67\n70 46\n57 25\n73 63\n3 51\n30 71\n41 44\n17 69\n17 18\n19 68\n42 7\n11 51\n1 5\n72 23\n65 53",
"output": "5"
}
] | 1,565,005,975 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 154 | 0 | import numpy as np
n,m=map(int,input().split())
mat=np.zeros((n,n))
for _ in range(m):
i,j=map(int,input().split())
mat[i-1,j-1]=1
mat[j-1,i-1]=1
flag=True
count=0
while flag:
sumOfRow = np.sum(mat,axis=0)
for x in sumOfRow:
if x==1:
count+=1
flag=True
break
elif x!=1:
flag=False
for i in range(n):
if sumOfRow[i]==1:
for j in range(n):
if mat[i,j]==1:
mat[j,i]=0
mat[i,j]=0
#print(mat)
#print()
print(count) | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the first student with the second one as well as the second student with the first one.
To restore order, Anna and Maria do the following. First, for each student Anna finds out what other students he is tied to. If a student is tied to exactly one other student, Anna reprimands him. Then Maria gathers in a single group all the students who have been just reprimanded. She kicks them out from the club. This group of students immediately leaves the club. These students takes with them the laces that used to tie them. Then again for every student Anna finds out how many other students he is tied to and so on. And they do so until Anna can reprimand at least one student.
Determine how many groups of students will be kicked out of the club.
Input Specification:
The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*). It is guaranteed that no two students are tied with more than one lace. No lace ties a student to himself.
Output Specification:
Print the single number — the number of groups of students that will be kicked out from the club.
Demo Input:
['3 3\n1 2\n2 3\n3 1\n', '6 3\n1 2\n2 3\n3 4\n', '6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n']
Demo Output:
['0\n', '2\n', '1\n']
Note:
In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two students from both ends of the chain (1 and 4), then — two other students from the chain (2 and 3). At that the students who are running by themselves will stay in the club.
In the third sample Anna and Maria will momentarily kick out all students except for the fourth one and the process stops at that point. The correct answer is one. | ```python
import numpy as np
n,m=map(int,input().split())
mat=np.zeros((n,n))
for _ in range(m):
i,j=map(int,input().split())
mat[i-1,j-1]=1
mat[j-1,i-1]=1
flag=True
count=0
while flag:
sumOfRow = np.sum(mat,axis=0)
for x in sumOfRow:
if x==1:
count+=1
flag=True
break
elif x!=1:
flag=False
for i in range(n):
if sumOfRow[i]==1:
for j in range(n):
if mat[i,j]==1:
mat[j,i]=0
mat[i,j]=0
#print(mat)
#print()
print(count)
``` | -1 |
|
267 | A | Subtractions | PROGRAMMING | 900 | [
"math",
"number theory"
] | null | null | You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? | The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). | Print the sought number of operations for each pair on a single line. | [
"2\n4 17\n7 987654321\n"
] | [
"8\n141093479\n"
] | none | 500 | [
{
"input": "2\n4 17\n7 987654321",
"output": "8\n141093479"
},
{
"input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321",
"output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479"
},
{
"input": "1\n536870912 32",
"output": "16777216"
},
{
"input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999",
"output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000"
},
{
"input": "3\n1000000000 1\n1000000000 1\n1 100000000",
"output": "1000000000\n1000000000\n100000000"
}
] | 1,476,824,775 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 77 | 4,608,000 | import sys
line = input().split(" ");
test_cases = int(line[0]);
for tc in range(test_cases):
line = input().split(" ");
num1 = int(line[0]);
num2 = int(line[1]);
count = 0;
while(num1 != 0 and num2 != 0):
if(num1 > num2):
count += int(num1/num2);
num1 %= num2;
else:
count += int(num2/num1);
num2 %= num1;
sys.stdout.write(str(count));
if(tc < test_cases-1):
sys.stdout.write("\n"); | Title: Subtractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5).
You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
Input Specification:
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Output Specification:
Print the sought number of operations for each pair on a single line.
Demo Input:
['2\n4 17\n7 987654321\n']
Demo Output:
['8\n141093479\n']
Note:
none | ```python
import sys
line = input().split(" ");
test_cases = int(line[0]);
for tc in range(test_cases):
line = input().split(" ");
num1 = int(line[0]);
num2 = int(line[1]);
count = 0;
while(num1 != 0 and num2 != 0):
if(num1 > num2):
count += int(num1/num2);
num1 %= num2;
else:
count += int(num2/num1);
num2 %= num1;
sys.stdout.write(str(count));
if(tc < test_cases-1):
sys.stdout.write("\n");
``` | 3 |
|
722 | B | Verse Pattern | PROGRAMMING | 1,200 | [
"implementation",
"strings"
] | null | null | You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.
Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.
The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*.
You are given the text and the verse pattern. Check, if the given text matches the given verse pattern. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters. | If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). | [
"3\n2 2 3\nintel\ncode\nch allenge\n",
"4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n",
"4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | 500 | [
{
"input": "3\n2 2 3\nintel\ncode\nch allenge",
"output": "YES"
},
{
"input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz",
"output": "NO"
},
{
"input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles",
"output": "YES"
},
{
"input": "5\n2 2 1 1 1\nfdbie\naaj\ni\ni n\nshi",
"output": "YES"
},
{
"input": "5\n2 11 10 7 9\nhy of\nyur pjyacbatdoylojayu\nemd ibweioiimyxya\nyocpyivudobua\nuiraueect impxqhzpty e",
"output": "NO"
},
{
"input": "5\n6 9 7 3 10\nabtbdaa\nom auhz ub iaravozegs\ncieulibsdhj ufki\nadu pnpurt\nh naony i jaysjsjxpwuuc",
"output": "NO"
},
{
"input": "2\n26 35\ngouojxaoobw iu bkaadyo degnjkubeabt kbap thwki dyebailrhnoh ooa\npiaeaebaocptyswuc wezesazipu osebhaonouygasjrciyiqaejtqsioubiuakg umynbsvw xpfqdwxo",
"output": "NO"
},
{
"input": "5\n1 0 0 1 1\ngqex\nw\nh\nzsvu\nqcqd",
"output": "NO"
},
{
"input": "5\n0 0 0 0 0\njtv\nl\nqg\ntp\nfgd",
"output": "YES"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0\nj t fr\nn\nnhcgx\np\nmb hmhtz\ndbjc\ncwdxj\nn j whkbt\nzk m cwh\nqr n",
"output": "YES"
},
{
"input": "5\n4 5 1 0 0\noa\nqfohq\ni l\naik\nx",
"output": "NO"
},
{
"input": "10\n2 9 0 3 2 4 1 2 4 2\nxtwl oy\nafgeju fi\nr hy\nddsowagw\nxoredo f\nwufnxy k uh\nod\nlejrinw\nsueecohfjl\nedufg",
"output": "NO"
},
{
"input": "10\n1 1 0 0 0 4 0 4 0 0\na bn\nhnwss f\nd s bn\nbdzxzgsxq\nghh v\neimblv i er\nca kn k\nzm ffc zcb\nn\nz hkhvfkwhg",
"output": "NO"
},
{
"input": "5\n0 10 6 6 0\nfgthrxst\nsohnweymewnnmbobj\nj\nfwwt acdtfvkpv khbxokn\nhndovkkgfhnhqod",
"output": "NO"
},
{
"input": "5\n3 2 2 4 2\ni yu\niu\noa\naiio\nuo",
"output": "YES"
},
{
"input": "5\n11 12 11 4 6\nuuuayoiaoiy\nuaiee iai eieu\nooayaayeuee\noii o\noea uuo",
"output": "YES"
},
{
"input": "3\n2 3 2\nintel\ncode\nch allenge",
"output": "NO"
},
{
"input": "2\n1 2\ncode\na",
"output": "NO"
},
{
"input": "2\n1 1\nbababa\nbababa",
"output": "NO"
},
{
"input": "1\n1\naa",
"output": "NO"
},
{
"input": "1\n1\naaa",
"output": "NO"
},
{
"input": "2\n2 3\naee\nae",
"output": "NO"
}
] | 1,475,332,276 | 1,576 | Python 3 | OK | TESTS | 54 | 77 | 0 | vowels = ['a','e','i','o','u','y']
N = int(input())
P = list(map(int, input().split()))
ans = True
for n in range(N):
s = input()
vc = len(list(True for c in s if c in vowels))
if vc != P[n]:
ans = False
print("YES" if ans else "NO") | Title: Verse Pattern
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters.
We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.
Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.
The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*.
You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the text.
The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern.
Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.
Output Specification:
If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).
Demo Input:
['3\n2 2 3\nintel\ncode\nch allenge\n', '4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz\n', '4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, one can split words into syllables in the following way:
Since the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one. | ```python
vowels = ['a','e','i','o','u','y']
N = int(input())
P = list(map(int, input().split()))
ans = True
for n in range(N):
s = input()
vc = len(list(True for c in s if c in vowels))
if vc != P[n]:
ans = False
print("YES" if ans else "NO")
``` | 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,610,960,484 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 93 | 0 | string = input()
founds = []
p = 0
hello = 'hello'
for i in range(5):
for j in range(p, len(string)):
if hello[i] == string[j]:
p = j + 1
founds.append(hello[i])
break
if ''.join(founds) == 'hello':
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
string = input()
founds = []
p = 0
hello = 'hello'
for i in range(5):
for j in range(p, len(string)):
if hello[i] == string[j]:
p = j + 1
founds.append(hello[i])
break
if ''.join(founds) == 'hello':
print("YES")
else:
print("NO")
``` | 3.9535 |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 7",
"output": "5"
},
{
"input": "14 5 5",
"output": "6"
},
{
"input": "16 6 9",
"output": "10"
},
{
"input": "20 13 17",
"output": "7"
},
{
"input": "22 4 8",
"output": "9"
},
{
"input": "23 8 14",
"output": "15"
},
{
"input": "26 18 22",
"output": "8"
},
{
"input": "28 6 1",
"output": "2"
},
{
"input": "29 5 23",
"output": "24"
},
{
"input": "32 27 15",
"output": "5"
},
{
"input": "33 11 5",
"output": "6"
},
{
"input": "37 21 15",
"output": "16"
},
{
"input": "39 34 33",
"output": "5"
},
{
"input": "41 27 11",
"output": "12"
},
{
"input": "42 25 16",
"output": "17"
},
{
"input": "45 7 43",
"output": "38"
},
{
"input": "47 16 17",
"output": "18"
},
{
"input": "49 11 37",
"output": "38"
},
{
"input": "51 38 39",
"output": "13"
},
{
"input": "52 29 7",
"output": "8"
},
{
"input": "56 43 12",
"output": "13"
},
{
"input": "58 57 28",
"output": "1"
},
{
"input": "59 12 39",
"output": "40"
},
{
"input": "62 9 52",
"output": "53"
},
{
"input": "63 29 44",
"output": "34"
},
{
"input": "65 30 22",
"output": "23"
},
{
"input": "66 27 38",
"output": "39"
},
{
"input": "71 33 53",
"output": "38"
},
{
"input": "73 14 12",
"output": "13"
},
{
"input": "73 37 35",
"output": "36"
},
{
"input": "76 69 44",
"output": "7"
},
{
"input": "79 25 20",
"output": "21"
},
{
"input": "81 60 20",
"output": "21"
},
{
"input": "81 79 14",
"output": "2"
},
{
"input": "84 0 42",
"output": "43"
},
{
"input": "88 79 8",
"output": "9"
},
{
"input": "90 76 59",
"output": "14"
},
{
"input": "92 2 22",
"output": "23"
},
{
"input": "94 5 88",
"output": "89"
},
{
"input": "94 62 48",
"output": "32"
},
{
"input": "96 22 72",
"output": "73"
},
{
"input": "100 11 88",
"output": "89"
},
{
"input": "100 81 91",
"output": "19"
},
{
"input": "1 0 0",
"output": "1"
}
] | 1,691,760,924 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 154 | 3,481,600 | import math
import sys
import heapq
from queue import PriorityQueue
from collections import deque
n,a,b = map(int, input().split())
if a+b>=n:
print(n-a)
else:
print(n-b) | Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
Input Specification:
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100).
Output Specification:
Print the single number — the number of the sought positions.
Demo Input:
['3 1 1\n', '5 2 3\n']
Demo Output:
['2\n', '3\n']
Note:
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | ```python
import math
import sys
import heapq
from queue import PriorityQueue
from collections import deque
n,a,b = map(int, input().split())
if a+b>=n:
print(n-a)
else:
print(n-b)
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,678,552,463 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 154 | 0 | t=int(input())
x=list(map(int,input().split()))
m=n=0
for i in range(0,t):
if x[i]%2==0:
k=i
m+=1
if x[i]%2==1:
p=i
n+=1
if n==1:
print(p+1)
elif m==1:
print(k+1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
t=int(input())
x=list(map(int,input().split()))
m=n=0
for i in range(0,t):
if x[i]%2==0:
k=i
m+=1
if x[i]%2==1:
p=i
n+=1
if n==1:
print(p+1)
elif m==1:
print(k+1)
``` | 3.9615 |
191 | A | Dynasty Puzzles | PROGRAMMING | 1,500 | [
"dp"
] | null | null | The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the king, whose name was Victorious Vasily Pupkin, was always called by the berlanders VVP.
In Berland over its long history many dynasties of kings replaced each other, but they were all united by common traditions. Thus, according to one Berland traditions, to maintain stability in the country, the first name of the heir should be the same as the last name his predecessor (hence, the first letter of the abbreviated name of the heir coincides with the last letter of the abbreviated name of the predecessor). Berlanders appreciate stability, so this tradition has never been broken. Also Berlanders like perfection, so another tradition requires that the first name of the first king in the dynasty coincides with the last name of the last king in this dynasty (hence, the first letter of the abbreviated name of the first king coincides with the last letter of the abbreviated name of the last king). This tradition, of course, has also been always observed.
The name of a dynasty is formed by very simple rules: we take all the short names of the kings in the order in which they ruled, and write them in one line. Thus, a dynasty of kings "ab" and "ba" is called "abba", and the dynasty, which had only the king "abca", is called "abca".
Vasya, a historian, has recently found a list of abbreviated names of all Berland kings and their relatives. Help Vasya to find the maximally long name of the dynasty that could have existed in Berland.
Note that in his list all the names are ordered by the time, that is, if name *A* is earlier in the list than *B*, then if *A* and *B* were kings, then king *A* ruled before king *B*. | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of names in Vasya's list. Next *n* lines contain *n* abbreviated names, one per line. An abbreviated name is a non-empty sequence of lowercase Latin letters. Its length does not exceed 10 characters. | Print a single number — length of the sought dynasty's name in letters.
If Vasya's list is wrong and no dynasty can be found there, print a single number 0. | [
"3\nabc\nca\ncba\n",
"4\nvvp\nvvp\ndam\nvvp\n",
"3\nab\nc\ndef\n"
] | [
"6\n",
"0\n",
"1\n"
] | In the first sample two dynasties can exist: the one called "abcca" (with the first and second kings) and the one called "abccba" (with the first and third kings).
In the second sample there aren't acceptable dynasties.
The only dynasty in the third sample consists of one king, his name is "c". | 500 | [
{
"input": "3\nabc\nca\ncba",
"output": "6"
},
{
"input": "4\nvvp\nvvp\ndam\nvvp",
"output": "0"
},
{
"input": "3\nab\nc\ndef",
"output": "1"
},
{
"input": "5\nab\nbc\ncd\nde\nffffffffff",
"output": "10"
},
{
"input": "5\ncab\nbbc\ncaa\nccc\naca",
"output": "9"
},
{
"input": "10\nabdcced\nbdacdac\necb\ndc\neaeeebdd\nadcdbadcac\neb\naadecccde\nedbaeacad\naccd",
"output": "0"
},
{
"input": "50\nagecd\ncghafi\nfiide\niecc\njbdcfjhgd\ndiee\nhfeg\nehc\ngfijgjh\ngacaifebg\ndicbbddc\nhjgciaei\njjcdh\ng\ngc\ncf\nhfdjhd\nc\nicidbec\nji\neeh\ncgeejggc\nacfd\njjg\najefdj\neghhebiic\nbih\ngbb\njjaa\nidc\ngafi\necg\ndbigbjiehj\ncedif\nahidfaaajg\nhfhhiccbgb\ndgegjgieif\nhgjebhfdc\nj\nahehd\nahdah\nbijbhh\na\ndabiggfhac\ndedigbjbf\nihbdj\niihagchd\ngfebhfdi\njbjdcggdh\nf",
"output": "37"
},
{
"input": "10\na\nb\na\nc\nb\na\nb\na\na\na",
"output": "6"
},
{
"input": "100\nd\na\ne\neb\nc\nd\nd\ne\nc\ne\nac\nd\nc\naa\na\ne\nda\ne\ne\nc\ne\na\nc\nc\nbc\nbd\nd\nda\ncc\nbe\nb\na\nee\nd\nbe\nbe\ne\nb\na\ned\ncb\nab\na\nea\nac\naa\ned\nd\nb\neb\ne\ned\nc\nce\nc\nd\nc\nd\nd\nee\ne\nb\nea\nea\nda\nab\nba\ned\nda\nec\nea\nbd\nee\ndc\nd\nbd\nd\nc\ncc\nab\nbd\na\nad\ne\nd\ne\nbc\nbb\nc\nbc\na\na\ne\nca\nac\nc\nad\nc\nbe\nd",
"output": "35"
},
{
"input": "16\nddgcb\nfgbhgbdg\ngha\ndh\nddfb\nfggbc\nedb\nhd\nd\nhfgcabf\nhdaef\nfhbcdgba\nchee\ncafeggc\nf\necb",
"output": "7"
},
{
"input": "3\nab\nacb\nba",
"output": "5"
},
{
"input": "3\nac\nabc\nca",
"output": "5"
}
] | 1,618,312,285 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 186 | 1,638,400 | n=int(input())
s=[input() for i in range(n)]
cnt=[[0]*26 for i in range(26)]
for i in range(n):
t=s[i]
m=len(t)
l=ord(t[0])-97
r=ord(t[-1])-97
for i in range(26):
if cnt[i][l]>0:
cnt[i][r]=cnt[i][l]+m
cnt[l][r]=max(cnt[l][r],m)
ans=max([cnt[i][i] for i in range(26)])
print(ans) | Title: Dynasty Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. They called every king by the first letters of its name. Thus, the king, whose name was Victorious Vasily Pupkin, was always called by the berlanders VVP.
In Berland over its long history many dynasties of kings replaced each other, but they were all united by common traditions. Thus, according to one Berland traditions, to maintain stability in the country, the first name of the heir should be the same as the last name his predecessor (hence, the first letter of the abbreviated name of the heir coincides with the last letter of the abbreviated name of the predecessor). Berlanders appreciate stability, so this tradition has never been broken. Also Berlanders like perfection, so another tradition requires that the first name of the first king in the dynasty coincides with the last name of the last king in this dynasty (hence, the first letter of the abbreviated name of the first king coincides with the last letter of the abbreviated name of the last king). This tradition, of course, has also been always observed.
The name of a dynasty is formed by very simple rules: we take all the short names of the kings in the order in which they ruled, and write them in one line. Thus, a dynasty of kings "ab" and "ba" is called "abba", and the dynasty, which had only the king "abca", is called "abca".
Vasya, a historian, has recently found a list of abbreviated names of all Berland kings and their relatives. Help Vasya to find the maximally long name of the dynasty that could have existed in Berland.
Note that in his list all the names are ordered by the time, that is, if name *A* is earlier in the list than *B*, then if *A* and *B* were kings, then king *A* ruled before king *B*.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of names in Vasya's list. Next *n* lines contain *n* abbreviated names, one per line. An abbreviated name is a non-empty sequence of lowercase Latin letters. Its length does not exceed 10 characters.
Output Specification:
Print a single number — length of the sought dynasty's name in letters.
If Vasya's list is wrong and no dynasty can be found there, print a single number 0.
Demo Input:
['3\nabc\nca\ncba\n', '4\nvvp\nvvp\ndam\nvvp\n', '3\nab\nc\ndef\n']
Demo Output:
['6\n', '0\n', '1\n']
Note:
In the first sample two dynasties can exist: the one called "abcca" (with the first and second kings) and the one called "abccba" (with the first and third kings).
In the second sample there aren't acceptable dynasties.
The only dynasty in the third sample consists of one king, his name is "c". | ```python
n=int(input())
s=[input() for i in range(n)]
cnt=[[0]*26 for i in range(26)]
for i in range(n):
t=s[i]
m=len(t)
l=ord(t[0])-97
r=ord(t[-1])-97
for i in range(26):
if cnt[i][l]>0:
cnt[i][r]=cnt[i][l]+m
cnt[l][r]=max(cnt[l][r],m)
ans=max([cnt[i][i] for i in range(26)])
print(ans)
``` | 0 |
|
501 | B | Misha and Changing Handles | PROGRAMMING | 1,100 | [
"data structures",
"dsu",
"strings"
] | null | null | Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. | The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. | In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description. | [
"5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n"
] | [
"3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n"
] | none | 500 | [
{
"input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov",
"output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123"
},
{
"input": "1\nMisha Vasya",
"output": "1\nMisha Vasya"
},
{
"input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k",
"output": "1\na k"
},
{
"input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha",
"output": "2\n123abc 1A2B3C\n1 Misha"
},
{
"input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e",
"output": "3\nM G\n1 R\nS e"
},
{
"input": "17\nn5WhQ VCczxtxKwFio5U\nVCczxtxKwFio5U 1WMVGA17cd1LRcp4r\n1WMVGA17cd1LRcp4r SJl\nSJl D8bPUoIft5v1\nNAvvUgunbPZNCL9ZY2 jnLkarKYsotz\nD8bPUoIft5v1 DnDkHi7\njnLkarKYsotz GfjX109HSQ81gFEBJc\nGfjX109HSQ81gFEBJc kBJ0zrH78mveJ\nkBJ0zrH78mveJ 9DrAypYW\nDnDkHi7 3Wkho2PglMDaFQw\n3Wkho2PglMDaFQw pOqW\n9DrAypYW G3y0cXXGsWAh\npOqW yr1Ec\nG3y0cXXGsWAh HrmWWg5u4Hsy\nyr1Ec GkFeivXjQ01\nGkFeivXjQ01 mSsWgbCCZcotV4goiA\nHrmWWg5u4Hsy zkCmEV",
"output": "2\nn5WhQ mSsWgbCCZcotV4goiA\nNAvvUgunbPZNCL9ZY2 zkCmEV"
},
{
"input": "10\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9\nSEj 2knOMLyzr\n0v69ijnAc S7d7zGTjmlku01Gv\n2knOMLyzr otGmEd\nacwr3TfMV7oCIp RUSVFa9TIWlLsd7SB\nS7d7zGTjmlku01Gv Gd6ZufVmQnBpi\nS1 WOJLpk\nWOJLpk Gu\nRUSVFa9TIWlLsd7SB RFawatGnbVB\notGmEd OTB1zKiOI",
"output": "5\n0v69ijnAc Gd6ZufVmQnBpi\nS1 Gu\nSEj OTB1zKiOI\nacwr3TfMV7oCIp RFawatGnbVB\nH1nauWCJOImtVqXk gWPMQ9DHv5CtkYp9lwm9"
},
{
"input": "14\nTPdoztSZROpjZe z6F8bYFvnER4V5SP0n\n8Aa3PQY3hzHZTPEUz fhrZZPJ3iUS\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nAO s1VGWTCbHzM\ni 4F\nfhrZZPJ3iUS j0OVZQF6MvNcKN9xDZFJ\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\nj0OVZQF6MvNcKN9xDZFJ DzjmeNqN0H4Teq0Awr\n4F wJcdxt1kwqfDeJ\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nJ0Usg DKdKMFJ6tK8XA\nz6F8bYFvnER4V5SP0n 0alJ\nMijh2O6 qic8kXWuR6",
"output": "10\nTPdoztSZROpjZe 0alJ\nJ0Usg DKdKMFJ6tK8XA\nDnlkXtaKNlYEI2ApBuwu DMA9i8ScKRxwhe72a3\n8Aa3PQY3hzHZTPEUz DzjmeNqN0H4Teq0Awr\nm9p888KaZAoQaO KNmdRSAlUVn8zXOM0\nqxXlsa5t RHCL1K6aUyns\nr6WYbDaXt hEHw\nMijh2O6 qic8kXWuR6\nAO s1VGWTCbHzM\ni wJcdxt1kwqfDeJ"
},
{
"input": "14\nHAXRxayyf1Dj1F0mT hjR4A8IQMb0nyBtqG\nWNuMJa5Jg05qkqZOrL noNkWXrSidHGwxgbQ\nmOitVy6W52s0FENMz6 oLUkLNfojssvLvb1t\nhjR4A8IQMb0nyBtqG oA7uBFu4Oo\noA7uBFu4Oo M450\nM450 LXEzO4\noLUkLNfojssvLvb1t YG5\nnoNkWXrSidHGwxgbQ L\nL YBWzu4W\nYBWzu4W ML\nML scVZE9m8JnH\nLXEzO4 Ne0oBPY0Iy\nscVZE9m8JnH GXhznv\nYG5 UY08abilYF1LaXj49hQ",
"output": "3\nWNuMJa5Jg05qkqZOrL GXhznv\nHAXRxayyf1Dj1F0mT Ne0oBPY0Iy\nmOitVy6W52s0FENMz6 UY08abilYF1LaXj49hQ"
}
] | 1,593,066,274 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 187 | 23,961,600 | def find(x):
if a[x] not in a.keys():
return a[x]
else:
return find(a[x])
n=int(input())
a={}
d={}
for i in range(n):
b,c=input().split()
a[b]=c
d[c]=b
e=[]
for i in a:
if i not in d.keys():
e.append([i,find(i)])
print(len(e))
for i in range(len(e)):
print(*e[i]) | Title: Misha and Changing Handles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.
Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.
Input Specification:
The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests.
Next *q* lines contain the descriptions of the requests, one per line.
Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20.
The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone.
Output Specification:
In the first line output the integer *n* — the number of users that changed their handles at least once.
In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order.
Each user who changes the handle must occur exactly once in this description.
Demo Input:
['5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov\n']
Demo Output:
['3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123\n']
Note:
none | ```python
def find(x):
if a[x] not in a.keys():
return a[x]
else:
return find(a[x])
n=int(input())
a={}
d={}
for i in range(n):
b,c=input().split()
a[b]=c
d[c]=b
e=[]
for i in a:
if i not in d.keys():
e.append([i,find(i)])
print(len(e))
for i in range(len(e)):
print(*e[i])
``` | 3 |
|
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above. | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
},
{
"input": "9",
"output": "12870"
},
{
"input": "10",
"output": "48620"
},
{
"input": "8",
"output": "3432"
}
] | 1,626,363,561 | 2,147,483,647 | PyPy 3 | OK | TESTS | 10 | 93 | 20,172,800 | n=int(input())
b=[]
m=1
for i in range(n):
a=[]
for j in range(n):
if(i==0):
a.append(1)
elif(j==0):
a.append(1)
else:
x=b[i-1][j]+a[j-1]
a.append(x)
if(x>m):
m=x
b.append(a)
print(m)
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the remaining elements are defined by the formula *a**i*,<=*j*<==<=*a**i*<=-<=1,<=*j*<=+<=*a**i*,<=*j*<=-<=1.
These conditions define all the values in the table.
You are given a number *n*. You need to determine the maximum value in the *n*<=×<=*n* table defined by the rules above.
Input Specification:
The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table.
Output Specification:
Print a single line containing a positive integer *m* — the maximum value in the table.
Demo Input:
['1\n', '5\n']
Demo Output:
['1', '70']
Note:
In the second test the rows of the table look as follows: | ```python
n=int(input())
b=[]
m=1
for i in range(n):
a=[]
for j in range(n):
if(i==0):
a.append(1)
elif(j==0):
a.append(1)
else:
x=b[i-1][j]+a[j-1]
a.append(x)
if(x>m):
m=x
b.append(a)
print(m)
``` | 3 |
|
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,692,288,284 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 154 | 0 | x = input()
if int(x[0]) >= int(x[2]):
max = int(x[0])
else:
max = int(x[2])
if (7 - max) % 6 == 0:
print("1/1")
else:
if (7 - max) % 3 == 0:
print("1/2")
else:
if (7 - max) % 2 == 0:
print(str((7 - max) / 2) + "/3")
else:
print(str((7 - max)) + "/6") | 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
x = input()
if int(x[0]) >= int(x[2]):
max = int(x[0])
else:
max = int(x[2])
if (7 - max) % 6 == 0:
print("1/1")
else:
if (7 - max) % 3 == 0:
print("1/2")
else:
if (7 - max) % 2 == 0:
print(str((7 - max) / 2) + "/3")
else:
print(str((7 - max)) + "/6")
``` | 0 |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "4"
},
{
"input": "7\n10 10 5 5 5 5 1",
"output": "3"
},
{
"input": "20\n2 1 2 2 2 1 1 2 1 2 2 1 1 1 1 2 1 1 1 1",
"output": "8"
},
{
"input": "20\n4 2 4 4 3 4 2 2 4 2 3 1 1 2 2 3 3 3 1 4",
"output": "8"
},
{
"input": "20\n35 26 41 40 45 46 22 26 39 23 11 15 47 42 18 15 27 10 45 40",
"output": "8"
},
{
"input": "20\n7 84 100 10 31 35 41 2 63 44 57 4 63 11 23 49 98 71 16 90",
"output": "6"
},
{
"input": "50\n19 2 12 26 17 27 10 26 17 17 5 24 11 15 3 9 16 18 19 1 25 23 18 6 2 7 25 7 21 25 13 29 16 9 25 3 14 30 18 4 10 28 6 10 8 2 2 4 8 28",
"output": "14"
},
{
"input": "70\n2 18 18 47 25 5 14 9 19 46 36 49 33 32 38 23 32 39 8 29 31 17 24 21 10 15 33 37 46 21 22 11 20 35 39 13 11 30 28 40 39 47 1 17 24 24 21 46 12 2 20 43 8 16 44 11 45 10 13 44 31 45 45 46 11 10 33 35 23 42",
"output": "22"
},
{
"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": "51"
},
{
"input": "100\n1 2 2 1 2 1 1 2 1 1 1 2 2 1 1 1 2 2 2 1 2 1 1 1 1 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 2 2 1 1 1 1 2 1 1 1 1 2 2 2 2",
"output": "37"
},
{
"input": "100\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "36"
},
{
"input": "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3",
"output": "33"
},
{
"input": "100\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "30"
},
{
"input": "100\n16 9 11 8 11 4 9 17 4 8 4 10 9 10 6 3 3 15 1 6 1 15 12 18 6 14 13 18 1 7 18 4 10 7 10 12 3 16 14 4 10 8 10 7 19 13 15 1 4 8 16 10 6 4 3 16 11 10 7 3 4 16 1 20 1 11 4 16 10 7 7 12 18 19 3 17 19 3 4 19 2 12 11 3 18 20 2 2 14 4 20 13 13 11 16 20 19 14 7 2",
"output": "29"
},
{
"input": "100\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "30"
},
{
"input": "100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "29"
},
{
"input": "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": "30"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "4\n4 1 2 3",
"output": "2"
},
{
"input": "5\n2 2 2 4 4",
"output": "2"
},
{
"input": "4\n100 99 99 100",
"output": "2"
}
] | 1,696,217,623 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | p=int(input())
c=list(map(int,input().split()))
c.sort(reverse=True)
your_sum=0
twin_sum=sum(c)
for i, coin in enumerate(c):
your_sum+=coin
twin_sum-=coin
if your_sum>twin_sum:
print(i+1)
break
| Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.
As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
Output Specification:
In the single line print the single number — the minimum needed number of coins.
Demo Input:
['2\n3 3\n', '3\n2 1 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2. | ```python
p=int(input())
c=list(map(int,input().split()))
c.sort(reverse=True)
your_sum=0
twin_sum=sum(c)
for i, coin in enumerate(c):
your_sum+=coin
twin_sum-=coin
if your_sum>twin_sum:
print(i+1)
break
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 0 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,510,504,005 | 1,305 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 31 | 0 | a, b, c, d, e, f = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = int(f)
if (a+b+c+d+e+f) % 2 == 0:
print('YES')
else:
print('NO')
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | ```python
a, b, c, d, e, f = input().split()
a = int(a)
b = int(b)
c = int(c)
d = int(d)
e = int(e)
f = int(f)
if (a+b+c+d+e+f) % 2 == 0:
print('YES')
else:
print('NO')
``` | 0 |
|
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 87 200 62 168 51 185 192 118",
"output": "48"
},
{
"input": "1 1\n10000",
"output": "5000"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "5"
},
{
"input": "2 2\n2 2",
"output": "1"
}
] | 1,646,399,500 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 2,355,200 | n,k= map(int,input().split())
l = list(map(int,input().split()))
f = sum(l)
x= 2*k
y = k*n
if (sum(l)>(2*k*n)):
y = (sum(l)-(2*k*n))//x
x = len(l)+y
print(x)
else:
print(len(l))
| Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day.
Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
Output Specification:
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
Demo Input:
['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n']
Demo Output:
['3\n', '5\n']
Note:
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type. | ```python
n,k= map(int,input().split())
l = list(map(int,input().split()))
f = sum(l)
x= 2*k
y = k*n
if (sum(l)>(2*k*n)):
y = (sum(l)-(2*k*n))//x
x = len(l)+y
print(x)
else:
print(len(l))
``` | 0 |
|
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book. | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4"
},
{
"input": "7 13\n6 8 14 9 4 11 10",
"output": "2"
},
{
"input": "10 15\n10 9 1 1 5 10 5 3 7 2",
"output": "3"
},
{
"input": "20 30\n8 1 2 6 9 4 1 9 9 10 4 7 8 9 5 7 1 8 7 4",
"output": "6"
},
{
"input": "30 60\n16 13 22 38 13 35 17 17 20 38 12 19 9 22 20 3 35 34 34 21 35 40 22 3 27 19 12 4 8 19",
"output": "4"
},
{
"input": "100 100\n75 92 18 6 81 67 7 92 100 65 82 32 50 67 85 31 80 91 84 63 39 52 92 81 1 98 24 12 43 48 17 86 51 72 48 95 45 50 12 66 19 79 49 89 34 1 97 75 20 33 96 27 42 23 73 71 93 1 85 19 66 14 17 61 20 39 36 33 42 61 56 64 23 91 80 99 40 74 13 18 98 85 74 39 62 84 46 74 50 23 38 11 79 14 9 25 66 100 25 52",
"output": "3"
},
{
"input": "10 1\n4418 7528 8170 1736 1317 3205 8183 4995 8039 4708",
"output": "0"
},
{
"input": "50 2\n124 214 63 73 996 760 38 571 451 300 970 1 706 937 837 494 619 88 851 411 957 990 842 613 821 649 627 34 693 678 734 116 816 985 705 940 499 493 922 967 854 439 112 644 961 438 189 572 655 550",
"output": "1"
}
] | 1,673,024,755 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 372 | 7,372,800 | n, t = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
c = 0
mc = 0
while r < n and l < n:
if c + a[r] <= t:
c += a[r]
r += 1
mc = max(r - l, mc)
else:
c -= a[l];
l += 1
print(mc)
| Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to read the *i*-th book.
Valera decided to choose an arbitrary book with number *i* and read the books one by one, starting from this book. In other words, he will first read book number *i*, then book number *i*<=+<=1, then book number *i*<=+<=2 and so on. He continues the process until he either runs out of the free time or finishes reading the *n*-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it.
Print the maximum number of books Valera can read.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy needs to read the *i*-th book.
Output Specification:
Print a single integer — the maximum number of books Valera can read.
Demo Input:
['4 5\n3 1 2 1\n', '3 3\n2 2 3\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
n, t = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 0
c = 0
mc = 0
while r < n and l < n:
if c + a[r] <= t:
c += a[r]
r += 1
mc = max(r - l, mc)
else:
c -= a[l];
l += 1
print(mc)
``` | 3 |
|
577 | B | Modulo Sum | PROGRAMMING | 1,900 | [
"combinatorics",
"data structures",
"dp",
"two pointers"
] | null | null | You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*. | The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist. | [
"3 5\n1 2 3\n",
"1 6\n5\n",
"4 6\n3 1 1 3\n",
"6 6\n5 5 5 5 5 5\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | 1,250 | [
{
"input": "3 5\n1 2 3",
"output": "YES"
},
{
"input": "1 6\n5",
"output": "NO"
},
{
"input": "4 6\n3 1 1 3",
"output": "YES"
},
{
"input": "6 6\n5 5 5 5 5 5",
"output": "YES"
},
{
"input": "4 5\n1 1 1 1",
"output": "NO"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "YES"
},
{
"input": "4 7\n1 2 3 3",
"output": "YES"
},
{
"input": "1 47\n0",
"output": "YES"
},
{
"input": "2 47\n1 0",
"output": "YES"
},
{
"input": "9 11\n8 8 8 8 8 8 8 8 5",
"output": "NO"
},
{
"input": "10 11\n8 8 8 8 8 8 8 8 7 8",
"output": "YES"
},
{
"input": "3 5\n2 1 3",
"output": "YES"
},
{
"input": "100 968\n966 966 967 966 967 967 967 967 966 966 966 967 966 966 966 967 967 966 966 967 967 967 967 966 967 967 967 967 563 967 967 967 600 967 967 966 967 966 967 966 967 966 967 966 966 966 967 966 967 966 966 967 967 193 966 966 967 966 967 967 967 966 967 966 966 580 966 967 966 966 967 966 966 966 967 967 967 967 966 967 967 966 966 966 967 967 966 966 967 966 966 966 967 966 966 967 966 967 966 966",
"output": "YES"
},
{
"input": "100 951\n950 949 949 949 949 950 950 949 949 950 950 949 949 949 496 949 950 949 950 159 950 949 949 950 950 949 950 949 949 950 949 950 949 949 950 949 950 950 950 950 949 949 949 949 949 950 950 950 950 950 950 950 949 950 949 949 950 949 950 950 949 950 950 950 949 950 949 950 950 950 950 949 949 950 950 949 950 950 950 950 949 950 950 949 949 635 612 949 949 949 949 949 949 949 950 949 949 950 949 950",
"output": "YES"
},
{
"input": "100 940\n1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 1 403 2 2 1 1 1 2 2 2 1 2 2 1 1 2 2 1 1 1 1 2 1 2 691 1 2 1 1 1 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 1 1 2 2 1 1 2 786 1",
"output": "YES"
},
{
"input": "100 917\n2 1 2 2 2 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1 1 2 1 2 340 2 399 2 1 2 2 2 2 178 1 1 2 1 1 1 2 2 1 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 2 2 1 1 2 2 2 1 2 2 2 2 1 2 1 2 2 2 2 2 1 1 2 2 2 2",
"output": "YES"
},
{
"input": "1 2\n1000000000",
"output": "YES"
}
] | 1,644,120,660 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 15 | 0 | n,d = [int(x) for x in input().split()]
l1 = [int(x) for x in input().split()]
mp = {}
sm = 0
count = 0
for i in range(len(l1)):
sm += l1[i]
t = sm%d
if t == 0:
count = 1
print('Yes')
break
elif t in mp:
count = 1
print('Yes')
break
else:
mp[t] = i
if count != 1:
print('No') | Title: Modulo Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of numbers *a*1,<=*a*2,<=...,<=*a**n*, and a number *m*.
Check if it is possible to choose a non-empty subsequence *a**i**j* such that the sum of numbers in this subsequence is divisible by *m*.
Input Specification:
The first line contains two numbers, *n* and *m* (1<=≤<=*n*<=≤<=106, 2<=≤<=*m*<=≤<=103) — the size of the original sequence and the number such that sum should be divisible by it.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Output Specification:
In the single line print either "YES" (without the quotes) if there exists the sought subsequence, or "NO" (without the quotes), if such subsequence doesn't exist.
Demo Input:
['3 5\n1 2 3\n', '1 6\n5\n', '4 6\n3 1 1 3\n', '6 6\n5 5 5 5 5 5\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n', 'YES\n']
Note:
In the first sample test you can choose numbers 2 and 3, the sum of which is divisible by 5.
In the second sample test the single non-empty subsequence of numbers is a single number 5. Number 5 is not divisible by 6, that is, the sought subsequence doesn't exist.
In the third sample test you need to choose two numbers 3 on the ends.
In the fourth sample test you can take the whole subsequence. | ```python
n,d = [int(x) for x in input().split()]
l1 = [int(x) for x in input().split()]
mp = {}
sm = 0
count = 0
for i in range(len(l1)):
sm += l1[i]
t = sm%d
if t == 0:
count = 1
print('Yes')
break
elif t in mp:
count = 1
print('Yes')
break
else:
mp[t] = i
if count != 1:
print('No')
``` | 0 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,699,606,603 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 62 | 0 | k,n,w=map(int,input().split())
cost=0
for i in range(1,w+1):
cost=cost+i*k
if cost>n:
b=cost-n
else:
b=0
print(b)
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
k,n,w=map(int,input().split())
cost=0
for i in range(1,w+1):
cost=cost+i*k
if cost>n:
b=cost-n
else:
b=0
print(b)
``` | 3 |
|
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{
"input": "24 54 37\n60 63 6\n1 84 26",
"output": "110\n101\n011"
},
{
"input": "23 10 40\n15 6 40\n92 80 77",
"output": "101\n100\n000"
},
{
"input": "62 74 80\n95 74 93\n2 47 95",
"output": "010\n001\n110"
},
{
"input": "80 83 48\n26 0 66\n47 76 37",
"output": "000\n000\n010"
},
{
"input": "32 15 65\n7 54 36\n5 51 3",
"output": "111\n101\n001"
},
{
"input": "22 97 12\n71 8 24\n100 21 64",
"output": "100\n001\n100"
},
{
"input": "46 37 13\n87 0 50\n90 8 55",
"output": "111\n011\n000"
},
{
"input": "57 43 58\n20 82 83\n66 16 52",
"output": "111\n010\n110"
},
{
"input": "45 56 93\n47 51 59\n18 51 63",
"output": "101\n011\n100"
},
{
"input": "47 66 67\n14 1 37\n27 81 69",
"output": "001\n001\n110"
},
{
"input": "26 69 69\n85 18 23\n14 22 74",
"output": "110\n001\n010"
},
{
"input": "10 70 65\n94 27 25\n74 66 30",
"output": "111\n010\n100"
},
{
"input": "97 1 74\n15 99 1\n88 68 86",
"output": "001\n011\n000"
},
{
"input": "36 48 42\n45 41 66\n26 64 1",
"output": "001\n111\n010"
},
{
"input": "52 81 97\n29 77 71\n66 11 2",
"output": "100\n100\n111"
},
{
"input": "18 66 33\n19 49 49\n48 46 26",
"output": "011\n100\n000"
},
{
"input": "68 79 52\n51 39 100\n29 14 26",
"output": "110\n000\n111"
},
{
"input": "91 69 77\n91 26 64\n91 88 57",
"output": "001\n011\n110"
},
{
"input": "16 69 64\n48 21 80\n81 51 51",
"output": "010\n101\n111"
},
{
"input": "96 14 2\n100 18 12\n65 34 89",
"output": "111\n010\n010"
},
{
"input": "93 95 90\n8 59 42\n53 13 19",
"output": "100\n001\n111"
},
{
"input": "71 84 18\n100 19 67\n9 76 15",
"output": "010\n010\n001"
},
{
"input": "38 93 85\n21 88 64\n4 96 25",
"output": "111\n011\n000"
},
{
"input": "75 20 20\n60 5 78\n77 4 69",
"output": "011\n001\n000"
},
{
"input": "65 70 96\n19 6 83\n33 37 82",
"output": "100\n000\n011"
},
{
"input": "11 13 60\n17 13 46\n42 21 39",
"output": "000\n011\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 0",
"output": "111\n111\n111"
},
{
"input": "0 0 0\n0 1 0\n0 0 0",
"output": "101\n000\n101"
},
{
"input": "0 0 0\n0 0 0\n0 0 1",
"output": "111\n110\n100"
}
] | 1,618,043,925 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | c = []
for i in range(3):
b = []
b = list(map(int,input().split()))
c.append(b)
a = [[1 for i in range(3)] for i in range(3)]
print(a)
for i in range(3):
for j in range(3):
if c[i][j] == 1:
a[i][j] = 0
if i - 1 >= 0 and i - 1 <= 2:
if a[i- 1][j] == 0:
a[i-1][j] = 1
else:
a[i - 1][j] = 0
if j - 1 >= 0 and j - 1 <= 2:
if a[i][j - 1] == 0:
a[i][j - 1] = 1
else:
a[i][j - 1] = 0
if i + 1 >= 0 and i + 1 <= 2:
if a[i + 1][j] == 0:
a[i + 1][j] = 1
else:
a[i + 1][j] = 0
if j +1 >= 0 and j + 1 <= 2:
if a[i][j + 1] == 0:
a[i][j + 1] = 1
else:
a[i][j + 1] = 0
print(a) | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on.
Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
Input Specification:
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Output Specification:
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
Demo Input:
['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n']
Demo Output:
['001\n010\n100\n', '010\n011\n100\n']
Note:
none | ```python
c = []
for i in range(3):
b = []
b = list(map(int,input().split()))
c.append(b)
a = [[1 for i in range(3)] for i in range(3)]
print(a)
for i in range(3):
for j in range(3):
if c[i][j] == 1:
a[i][j] = 0
if i - 1 >= 0 and i - 1 <= 2:
if a[i- 1][j] == 0:
a[i-1][j] = 1
else:
a[i - 1][j] = 0
if j - 1 >= 0 and j - 1 <= 2:
if a[i][j - 1] == 0:
a[i][j - 1] = 1
else:
a[i][j - 1] = 0
if i + 1 >= 0 and i + 1 <= 2:
if a[i + 1][j] == 0:
a[i + 1][j] = 1
else:
a[i + 1][j] = 0
if j +1 >= 0 and j + 1 <= 2:
if a[i][j + 1] == 0:
a[i][j + 1] = 1
else:
a[i][j + 1] = 0
print(a)
``` | 0 |
|
689 | C | Mike and Chocolate Thieves | PROGRAMMING | 1,700 | [
"binary search",
"combinatorics",
"math"
] | null | null | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous one. The value of *k* (*k*<=><=1) is a secret integer known only to them. It is also known that each thief's bag can carry at most *n* chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of *n*, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed *n*, but not fixed *k*) is *m*. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of *n* will help him in that. Please find the smallest possible value of *n* or tell him that the rumors are false and there is no such *n*. | The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say. | Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1. | [
"1\n",
"8\n",
"10\n"
] | [
"8\n",
"54\n",
"-1\n"
] | In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).
There is no *n* leading to exactly 10 ways of stealing chocolates in the third sample case. | 1,500 | [
{
"input": "1",
"output": "8"
},
{
"input": "8",
"output": "54"
},
{
"input": "10",
"output": "-1"
},
{
"input": "27",
"output": "152"
},
{
"input": "28206",
"output": "139840"
},
{
"input": "32",
"output": "184"
},
{
"input": "115",
"output": "608"
},
{
"input": "81258",
"output": "402496"
},
{
"input": "116003",
"output": "574506"
},
{
"input": "149344197",
"output": "739123875"
},
{
"input": "57857854",
"output": "286347520"
},
{
"input": "999999999999999",
"output": "-1"
},
{
"input": "181023403153",
"output": "895903132760"
},
{
"input": "196071196742",
"output": "970376182648"
},
{
"input": "49729446417673",
"output": "246116048009288"
},
{
"input": "14821870173923",
"output": "73354931125416"
},
{
"input": "29031595887308",
"output": "143680297402952"
},
{
"input": "195980601490039",
"output": "969927770453672"
},
{
"input": "181076658641313",
"output": "896166653569800"
},
{
"input": "166173583620704",
"output": "822409831653228"
},
{
"input": "151269640772354",
"output": "748648714769352"
},
{
"input": "136366565751970",
"output": "674891892852776"
},
{
"input": "121463490731834",
"output": "601135070936200"
},
{
"input": "106559547884220",
"output": "527373954052328"
},
{
"input": "91656472864718",
"output": "453617132135750"
},
{
"input": "184061307002930",
"output": "910937979445720"
},
{
"input": "57857853",
"output": "-1"
},
{
"input": "1000000000000000",
"output": "4949100894494448"
},
{
"input": "375402146575334",
"output": "-1"
},
{
"input": "550368702711851",
"output": "-1"
},
{
"input": "645093839227897",
"output": "-1"
},
{
"input": "431",
"output": "-1"
},
{
"input": "99999",
"output": "-1"
},
{
"input": "2",
"output": "16"
},
{
"input": "3",
"output": "24"
},
{
"input": "4",
"output": "27"
},
{
"input": "5",
"output": "32"
},
{
"input": "6",
"output": "40"
},
{
"input": "7",
"output": "48"
},
{
"input": "13",
"output": "80"
},
{
"input": "999999999999998",
"output": "-1"
},
{
"input": "999999999999997",
"output": "4949100894494440"
},
{
"input": "999999999999996",
"output": "4949100894494432"
},
{
"input": "999999999999995",
"output": "4949100894494424"
},
{
"input": "999999999999993",
"output": "4949100894494416"
},
{
"input": "999999999999991",
"output": "4949100894494400"
},
{
"input": "999999999999992",
"output": "4949100894494408"
},
{
"input": "999999999999994",
"output": "4949100894494421"
},
{
"input": "4235246",
"output": "-1"
},
{
"input": "34",
"output": "-1"
},
{
"input": "998749999999991",
"output": "4942914518376840"
},
{
"input": "999999874999991",
"output": "4949100275856792"
},
{
"input": "987654129875642",
"output": "4887999937625136"
},
{
"input": "237648237648000",
"output": "1176145105832192"
}
] | 1,698,372,011 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 1,840 | 1,740,800 | # import sys
# sys.stdout = open('editor/output.txt', 'w')
# sys.stdin = open('editor/input.txt', 'r')
# Add custom packages imports here
# Write solution here
def solution(m):
def check(mid):
ans = 0
i = 2
while i * i * i <= mid:
ans += mid // (i * i * i)
i += 1
return ans
n = -1
low = 0
high = 5e15
while low < high:
mid = int(low + ((high-low) // 2))
if check(mid) < m:
low = mid + 1
else:
high = mid
if check(low) == m:
n = low
return int(n)
# drive code
if __name__ == '__main__':
m = int(input())
ans = solution(m)
print(ans)
| Title: Mike and Chocolate Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous one. The value of *k* (*k*<=><=1) is a secret integer known only to them. It is also known that each thief's bag can carry at most *n* chocolates (if they intend to take more, the deal is cancelled) and that there were exactly four thieves involved.
Sadly, only the thieves know the value of *n*, but rumours say that the numbers of ways they could have taken the chocolates (for a fixed *n*, but not fixed *k*) is *m*. Two ways are considered different if one of the thieves (they should be numbered in the order they take chocolates) took different number of chocolates in them.
Mike want to track the thieves down, so he wants to know what their bags are and value of *n* will help him in that. Please find the smallest possible value of *n* or tell him that the rumors are false and there is no such *n*.
Input Specification:
The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say.
Output Specification:
Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1.
Demo Input:
['1\n', '8\n', '10\n']
Demo Output:
['8\n', '54\n', '-1\n']
Note:
In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the possibilities: (1, 2, 4, 8), (1, 3, 9, 27), (2, 4, 8, 16), (2, 6, 18, 54), (3, 6, 12, 24), (4, 8, 16, 32), (5, 10, 20, 40), (6, 12, 24, 48).
There is no *n* leading to exactly 10 ways of stealing chocolates in the third sample case. | ```python
# import sys
# sys.stdout = open('editor/output.txt', 'w')
# sys.stdin = open('editor/input.txt', 'r')
# Add custom packages imports here
# Write solution here
def solution(m):
def check(mid):
ans = 0
i = 2
while i * i * i <= mid:
ans += mid // (i * i * i)
i += 1
return ans
n = -1
low = 0
high = 5e15
while low < high:
mid = int(low + ((high-low) // 2))
if check(mid) < m:
low = mid + 1
else:
high = mid
if check(low) == m:
n = low
return int(n)
# drive code
if __name__ == '__main__':
m = int(input())
ans = solution(m)
print(ans)
``` | 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,696,531,657 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | arr = []
for d in range(5):
arr.append([int(i) for i in input().split()])
for j in range(5):
for i in range(5):
if arr[i][j] == 1 :
print(abs(2-i)+abs(2-j))
| 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
arr = []
for d in range(5):
arr.append([int(i) for i in input().split()])
for j in range(5):
for i in range(5):
if arr[i][j] == 1 :
print(abs(2-i)+abs(2-j))
``` | 3 |
|
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"input": "H",
"output": "YES"
},
{
"input": "+",
"output": "NO"
},
{
"input": "~",
"output": "NO"
},
{
"input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR",
"output": "YES"
},
{
"input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC",
"output": "YES"
},
{
"input": "@F%K2=%RyL/",
"output": "NO"
},
{
"input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J",
"output": "YES"
},
{
"input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)",
"output": "YES"
},
{
"input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C",
"output": "YES"
},
{
"input": "p-UXsbd&f",
"output": "NO"
},
{
"input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_",
"output": "YES"
},
{
"input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]",
"output": "YES"
},
{
"input": "}do5RU<(w<q[\"-NR)IAH_HyiD{",
"output": "YES"
},
{
"input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8",
"output": "YES"
},
{
"input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv",
"output": "YES"
},
{
"input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`",
"output": "YES"
},
{
"input": "OKBB5z7ud81[Tn@P\"nDUd,>@",
"output": "NO"
},
{
"input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv",
"output": "YES"
},
{
"input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh",
"output": "YES"
},
{
"input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp",
"output": "NO"
},
{
"input": "!3YPv@2JQ44@)R2O_4`GO",
"output": "YES"
},
{
"input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\",
"output": "YES"
},
{
"input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L",
"output": "NO"
},
{
"input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&",
"output": "YES"
},
{
"input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}",
"output": "YES"
},
{
"input": "Uh3>ER](J",
"output": "NO"
},
{
"input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,",
"output": "YES"
},
{
"input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!",
"output": "YES"
},
{
"input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@",
"output": "YES"
},
{
"input": "'jdL(vX",
"output": "NO"
},
{
"input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5",
"output": "YES"
},
{
"input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s",
"output": "YES"
},
{
"input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]",
"output": "YES"
},
{
"input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU",
"output": "YES"
},
{
"input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->",
"output": "YES"
},
{
"input": "&ppw0._:\\p-PuWM@l}%%=",
"output": "NO"
},
{
"input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr",
"output": "YES"
},
{
"input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q",
"output": "YES"
},
{
"input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0",
"output": "YES"
},
{
"input": "VXB&r9Z)IlKOJ:??KDA",
"output": "YES"
},
{
"input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R",
"output": "YES"
},
{
"input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C",
"output": "YES"
},
{
"input": "O.&=qt(`z(",
"output": "NO"
},
{
"input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@",
"output": "YES"
},
{
"input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp",
"output": "YES"
},
{
"input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8",
"output": "YES"
},
{
"input": "!0WKT:$O",
"output": "NO"
},
{
"input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)",
"output": "YES"
},
{
"input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly",
"output": "YES"
},
{
"input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(",
"output": "NO"
},
{
"input": "Qv)X8",
"output": "YES"
},
{
"input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F",
"output": "YES"
},
{
"input": "e{}2vQ+/r@p0}cLKNe4MCk",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH",
"output": "YES"
},
{
"input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky",
"output": "YES"
},
{
"input": "1H1",
"output": "YES"
},
{
"input": "+Q",
"output": "YES"
},
{
"input": "1ab",
"output": "NO"
},
{
"input": "!",
"output": "NO"
},
{
"input": "0+",
"output": "NO"
},
{
"input": "+H",
"output": "YES"
},
{
"input": "cH",
"output": "YES"
},
{
"input": "+8",
"output": "NO"
},
{
"input": "8+",
"output": "NO"
},
{
"input": "++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "(+)",
"output": "NO"
},
{
"input": "H+",
"output": "YES"
},
{
"input": "a!",
"output": "NO"
},
{
"input": "++++++++++++++",
"output": "NO"
},
{
"input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "3",
"output": "NO"
},
{
"input": "HQ9",
"output": "YES"
},
{
"input": "+++H",
"output": "YES"
},
{
"input": "++++++++++",
"output": "NO"
},
{
"input": "HHHHHHH",
"output": "YES"
},
{
"input": "abacabaH",
"output": "YES"
},
{
"input": "+G",
"output": "NO"
}
] | 1,697,727,859 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | a=input()
c=[]
for i in a:
if i=="H":
c.append("yes")
elif i=="Q":
c.append("yes")
elif i=="+":
c.append("no")
elif i=="9":
c.append("yes")
else:
c.append("no")
if "yes" in c:
print("YES")
else:
print("NO") | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.
You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
Input Specification:
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output Specification:
Output "YES", if executing the program will produce any output, and "NO" otherwise.
Demo Input:
['Hi!\n', 'Codeforces\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | ```python
a=input()
c=[]
for i in a:
if i=="H":
c.append("yes")
elif i=="Q":
c.append("yes")
elif i=="+":
c.append("no")
elif i=="9":
c.append("yes")
else:
c.append("no")
if "yes" in c:
print("YES")
else:
print("NO")
``` | 3 |
|
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! | The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). | Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. | [
"1 2\n",
"61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n"
] | [
"1\n",
"61803398874989484820458683436563811772030917980576\n"
] | none | 500 | [
{
"input": "1 2",
"output": "1"
},
{
"input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576",
"output": "61803398874989484820458683436563811772030917980576"
},
{
"input": "1 100",
"output": "1"
},
{
"input": "100 100000",
"output": "1"
},
{
"input": "12345 67890123456789123457",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158",
"output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158"
},
{
"input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "1"
},
{
"input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751",
"output": "1"
},
{
"input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794",
"output": "1"
},
{
"input": "10000 1000000000",
"output": "1"
},
{
"input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "11210171722243 65715435710585778347",
"output": "1"
},
{
"input": "2921881079263974825226940825843 767693191032295360887755303860323261471",
"output": "1"
},
{
"input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085",
"output": "1"
},
{
"input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424",
"output": "1"
},
{
"input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614",
"output": "1"
},
{
"input": "15943150466658398903 15943150466658398903",
"output": "15943150466658398903"
},
{
"input": "410470228200245407491525399055972 410470228200245407491525399055972",
"output": "410470228200245407491525399055972"
},
{
"input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307",
"output": "51894705655711504622197349350106792045098781545973899451307"
},
{
"input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410",
"output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410"
},
{
"input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535",
"output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535"
},
{
"input": "1 2000000000",
"output": "1"
},
{
"input": "13 1928834874",
"output": "1"
},
{
"input": "87 2938984237482934238",
"output": "1"
},
{
"input": "213 413",
"output": "1"
},
{
"input": "3 4",
"output": "1"
}
] | 1,680,291,012 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | a ,b = list(map(int , input().split()))
def GCD(a , b):
if b == 0 :
return a
return GCD(b , a % b)
if b - a >= 1:
print(1)
else:
print(GCD(a , b)) | Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
Input Specification:
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output Specification:
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
Demo Input:
['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n']
Demo Output:
['1\n', '61803398874989484820458683436563811772030917980576\n']
Note:
none | ```python
a ,b = list(map(int , input().split()))
def GCD(a , b):
if b == 0 :
return a
return GCD(b , a % b)
if b - a >= 1:
print(1)
else:
print(GCD(a , b))
``` | 3 |
|
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"input": "10\n68 47 67 29 63 71 71 65 54 56",
"output": "10"
},
{
"input": "15\n77 68 96 60 92 75 61 60 66 79 80 65 60 95 92",
"output": "4"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "20\n30 30 30 14 30 14 30 30 30 14 30 14 14 30 14 14 30 14 14 14",
"output": "0"
},
{
"input": "35\n37 41 46 39 47 39 44 47 44 42 44 43 47 39 46 39 38 42 39 37 40 44 41 42 41 42 39 42 36 36 42 36 42 42 42",
"output": "7"
},
{
"input": "40\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 98 99 99 99 99 99 99 99 99 100 99 99 99 99 99 99",
"output": "47"
},
{
"input": "50\n48 52 44 54 53 56 62 49 39 41 53 39 40 64 53 50 62 48 40 52 51 48 40 52 61 62 62 61 48 64 55 57 56 40 48 58 41 60 60 56 64 50 64 45 48 45 46 63 59 57",
"output": "50"
},
{
"input": "57\n7 24 17 19 6 19 10 11 12 22 14 5 5 11 13 10 24 19 24 24 24 11 21 20 4 14 24 24 18 13 24 3 20 3 3 3 3 9 3 9 22 22 16 3 3 3 15 11 3 3 8 17 10 13 3 14 13",
"output": "3"
},
{
"input": "65\n58 50 35 44 35 37 36 58 38 36 58 56 56 49 48 56 58 43 40 44 52 44 58 58 57 50 43 35 55 39 38 49 53 56 50 42 41 56 34 57 49 38 34 51 56 38 58 40 53 46 48 34 38 43 49 49 58 56 41 43 44 34 38 48 36",
"output": "3"
},
{
"input": "69\n70 48 49 48 49 71 48 53 55 69 48 53 54 58 53 63 48 48 69 67 72 75 71 75 74 74 57 63 65 60 48 48 65 48 48 51 50 49 62 53 76 68 76 56 76 76 64 76 76 57 61 76 73 51 59 76 65 50 69 50 76 67 76 63 62 74 74 58 73",
"output": "73"
},
{
"input": "75\n70 65 64 71 71 64 71 64 68 71 65 64 65 68 71 66 66 69 68 63 69 65 71 69 68 68 71 67 71 65 65 65 71 71 65 69 63 66 62 67 64 63 62 64 67 65 62 69 62 64 69 62 67 64 67 70 64 63 64 64 69 62 62 64 70 62 62 68 67 69 62 64 66 70 68",
"output": "7"
},
{
"input": "84\n92 95 84 85 94 80 90 86 80 92 95 84 86 83 86 83 93 91 95 92 84 88 82 84 84 84 80 94 93 80 94 80 95 83 85 80 95 95 80 84 86 92 83 81 90 87 81 89 92 93 80 87 90 85 93 85 93 94 93 89 94 83 93 91 80 83 90 94 95 80 95 92 85 84 93 94 94 82 91 95 95 89 85 94",
"output": "15"
},
{
"input": "90\n86 87 72 77 82 71 75 78 61 67 79 90 64 94 94 74 85 87 73 76 71 71 60 69 77 73 76 80 82 57 62 57 57 83 76 72 75 87 72 94 77 85 59 82 86 69 62 80 95 73 83 94 79 85 91 68 85 74 93 95 68 75 89 93 83 78 95 78 83 77 81 85 66 92 63 65 75 78 67 91 77 74 59 86 77 76 90 67 70 64",
"output": "104"
},
{
"input": "91\n94 98 96 94 95 98 98 95 98 94 94 98 95 95 99 97 97 94 95 98 94 98 96 98 96 98 97 95 94 94 94 97 94 96 98 98 98 94 96 95 94 95 97 97 97 98 94 98 96 95 98 96 96 98 94 97 96 98 97 95 97 98 94 95 94 94 97 94 96 97 97 93 94 95 95 94 96 98 97 96 94 98 98 96 96 96 96 96 94 96 97",
"output": "33"
},
{
"input": "92\n44 28 32 29 41 41 36 39 40 39 41 35 41 28 35 27 41 34 28 38 43 43 41 38 27 26 28 36 30 29 39 32 35 35 32 30 39 30 37 27 41 41 28 30 43 31 35 33 36 28 44 40 41 35 31 42 37 38 37 34 39 40 27 40 33 33 44 43 34 33 34 34 35 38 38 37 30 39 35 41 45 42 41 32 33 33 31 30 43 41 43 43",
"output": "145"
},
{
"input": "93\n46 32 52 36 39 30 57 63 63 30 32 44 27 59 46 38 40 45 44 62 35 36 51 48 39 58 36 51 51 51 48 58 59 36 29 35 31 49 64 60 34 38 42 56 33 42 52 31 63 34 45 51 35 45 33 53 33 62 31 38 66 29 51 54 28 61 32 45 57 41 36 34 47 36 31 28 67 48 52 46 32 40 64 58 27 53 43 57 34 66 43 39 26",
"output": "76"
},
{
"input": "94\n56 55 54 31 32 42 46 29 24 54 40 40 20 45 35 56 32 33 51 39 26 56 21 56 51 27 29 39 56 52 54 43 43 55 48 51 44 49 52 49 23 19 19 28 20 26 45 33 35 51 42 36 25 25 38 23 21 35 54 50 41 20 37 28 42 20 22 43 37 34 55 21 24 38 19 41 45 34 19 33 44 54 38 31 23 53 35 32 47 40 39 31 20 34",
"output": "15"
},
{
"input": "95\n57 71 70 77 64 64 76 81 81 58 63 75 81 77 71 71 71 60 70 70 69 67 62 64 78 64 69 62 76 76 57 70 68 77 70 68 73 77 79 73 60 57 69 60 74 65 58 75 75 74 73 73 65 75 72 57 81 62 62 70 67 58 76 57 79 81 68 64 58 77 70 59 79 64 80 58 71 59 81 71 80 64 78 80 78 65 70 68 78 80 57 63 64 76 81",
"output": "11"
},
{
"input": "96\n96 95 95 95 96 97 95 97 96 95 98 96 97 95 98 96 98 96 98 96 98 95 96 95 95 95 97 97 95 95 98 98 95 96 96 95 97 96 98 96 95 97 97 95 97 97 95 94 96 96 97 96 97 97 96 94 94 97 95 95 95 96 95 96 95 97 97 95 97 96 95 94 97 97 97 96 97 95 96 94 94 95 97 94 94 97 97 97 95 97 97 95 94 96 95 95",
"output": "13"
},
{
"input": "97\n14 15 12 12 13 15 12 15 12 12 12 12 12 14 15 15 13 12 15 15 12 12 12 13 14 15 15 13 14 15 14 14 14 14 12 13 12 13 13 12 15 12 13 13 15 12 15 13 12 13 13 13 14 13 12 15 14 13 14 15 13 14 14 13 14 12 15 12 14 12 13 14 15 14 13 15 13 12 15 15 15 13 15 15 13 14 16 16 16 13 15 13 15 14 15 15 15",
"output": "104"
},
{
"input": "98\n37 69 35 70 58 69 36 47 41 63 60 54 49 35 55 50 35 53 52 43 35 41 40 49 38 35 48 70 42 35 35 65 56 54 44 59 59 48 51 49 59 67 35 60 69 35 58 50 35 44 48 69 41 58 44 45 35 47 70 61 49 47 37 39 35 51 44 70 72 65 36 41 63 63 48 66 45 50 50 71 37 52 72 67 72 39 72 39 36 64 48 72 69 49 45 72 72 67",
"output": "100"
},
{
"input": "99\n31 31 16 15 19 31 19 22 29 27 12 22 28 30 25 33 26 25 19 22 34 21 17 33 31 22 16 26 22 30 31 17 13 33 13 17 28 25 18 33 27 22 31 22 13 27 20 22 23 15 24 32 29 13 16 20 32 33 14 33 19 27 16 28 25 17 17 28 18 26 32 33 19 23 30 13 14 23 24 28 14 28 22 20 30 14 24 23 17 29 18 28 29 21 28 18 16 24 32",
"output": "107"
},
{
"input": "100\n37 54 39 29 32 49 21 13 34 21 16 42 34 27 16 26 7 34 51 9 11 27 16 40 36 7 48 52 30 42 42 52 51 11 32 26 6 7 28 54 48 51 6 54 42 20 51 48 46 4 4 31 47 6 9 16 8 23 36 50 49 30 47 37 45 24 48 26 8 50 18 24 27 13 39 7 37 34 5 43 42 19 34 23 52 38 35 6 29 11 53 49 21 29 36 22 45 33 51 22",
"output": "50"
},
{
"input": "100\n41 5 20 23 5 47 28 28 64 5 12 14 34 56 22 48 6 52 39 55 62 40 24 54 39 28 56 27 35 51 14 24 38 10 55 20 39 62 52 2 30 55 49 48 15 23 59 44 31 28 66 29 62 59 31 13 28 12 50 45 41 47 29 27 64 66 14 39 62 22 44 63 24 5 63 17 42 7 25 41 49 33 31 51 63 3 37 66 19 9 2 40 16 45 56 21 34 29 39 61",
"output": "59"
},
{
"input": "100\n66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95 95",
"output": "99"
},
{
"input": "100\n81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 81 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "2\n100 99",
"output": "0"
},
{
"input": "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": "197"
},
{
"input": "100\n87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87 87",
"output": "0"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 3 2",
"output": "2"
}
] | 1,693,385,074 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n = int(input().strip())
heights = list(map(int, input().split()))
min_swaps = 0
for i in range(n - 1):
max_height_idx = i
for j in range(i + 1, n):
if heights[j] > heights[max_height_idx]:
max_height_idx = j
if max_height_idx != i:
heights[i], heights[max_height_idx] = heights[max_height_idx], heights[i]
min_swaps += 1
print(min_swaps)
| Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important.
For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong.
Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct.
Input Specification:
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different.
Output Specification:
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
Demo Input:
['4\n33 44 11 22\n', '7\n10 10 58 31 63 40 76\n']
Demo Output:
['2\n', '10\n']
Note:
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 40, 76) 1. (10, 58, 10, 31, 63, 76, 40) 1. (10, 58, 10, 31, 76, 63, 40) 1. (10, 58, 31, 10, 76, 63, 40) 1. (10, 58, 31, 76, 10, 63, 40) 1. (10, 58, 31, 76, 63, 10, 40) 1. (10, 58, 76, 31, 63, 10, 40) 1. (10, 76, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 10, 40) 1. (76, 10, 58, 31, 63, 40, 10) | ```python
n = int(input().strip())
heights = list(map(int, input().split()))
min_swaps = 0
for i in range(n - 1):
max_height_idx = i
for j in range(i + 1, n):
if heights[j] > heights[max_height_idx]:
max_height_idx = j
if max_height_idx != i:
heights[i], heights[max_height_idx] = heights[max_height_idx], heights[i]
min_swaps += 1
print(min_swaps)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have. | The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO. | Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. | [
"8\n10000011\n",
"2\n01\n"
] | [
"5\n",
"2\n"
] | In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | 0 | [
{
"input": "8\n10000011",
"output": "5"
},
{
"input": "2\n01",
"output": "2"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "75"
},
{
"input": "11\n00000000000",
"output": "3"
},
{
"input": "56\n10101011010101010101010101010101010101011010101010101010",
"output": "56"
},
{
"input": "50\n01011010110101010101010101010101010101010101010100",
"output": "49"
},
{
"input": "7\n0110100",
"output": "7"
},
{
"input": "8\n11011111",
"output": "5"
},
{
"input": "6\n000000",
"output": "3"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "59\n10101010101010101010101010101010101010101010101010101010101",
"output": "59"
},
{
"input": "88\n1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "88"
},
{
"input": "93\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010",
"output": "93"
},
{
"input": "70\n0101010101010101010101010101010101010101010101010101010101010101010101",
"output": "70"
},
{
"input": "78\n010101010101010101010101010101101010101010101010101010101010101010101010101010",
"output": "78"
},
{
"input": "83\n10101010101010101010101010101010101010101010101010110101010101010101010101010101010",
"output": "83"
},
{
"input": "87\n101010101010101010101010101010101010101010101010101010101010101010101010101010010101010",
"output": "87"
},
{
"input": "65\n01010101101010101010101010101010101010101010101010101010101010101",
"output": "65"
},
{
"input": "69\n010101010101010101101010101010101010101010101010101010101010101010101",
"output": "69"
},
{
"input": "74\n01010101010101010101010101010101010101010101010101010101010101000101010101",
"output": "74"
},
{
"input": "77\n01010101010101001010101010101010100101010101010101010101010101010101010101010",
"output": "77"
},
{
"input": "60\n101010110101010101010101010110101010101010101010101010101010",
"output": "60"
},
{
"input": "89\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010",
"output": "89"
},
{
"input": "68\n01010101010101010101010101010101010100101010100101010101010100101010",
"output": "67"
},
{
"input": "73\n0101010101010101010101010101010101010101010111011010101010101010101010101",
"output": "72"
},
{
"input": "55\n1010101010101010010101010101101010101010101010100101010",
"output": "54"
},
{
"input": "85\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010",
"output": "84"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1111111111",
"output": "3"
},
{
"input": "2\n10",
"output": "2"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "3\n000",
"output": "3"
},
{
"input": "3\n001",
"output": "3"
},
{
"input": "3\n010",
"output": "3"
},
{
"input": "3\n011",
"output": "3"
},
{
"input": "3\n100",
"output": "3"
},
{
"input": "3\n101",
"output": "3"
},
{
"input": "3\n110",
"output": "3"
},
{
"input": "3\n111",
"output": "3"
},
{
"input": "4\n0000",
"output": "3"
},
{
"input": "4\n0001",
"output": "4"
},
{
"input": "4\n0010",
"output": "4"
},
{
"input": "4\n0011",
"output": "4"
},
{
"input": "4\n0100",
"output": "4"
},
{
"input": "4\n0101",
"output": "4"
},
{
"input": "4\n0110",
"output": "4"
},
{
"input": "4\n0111",
"output": "4"
},
{
"input": "4\n1000",
"output": "4"
},
{
"input": "4\n1001",
"output": "4"
},
{
"input": "4\n1010",
"output": "4"
},
{
"input": "4\n1011",
"output": "4"
},
{
"input": "4\n1100",
"output": "4"
},
{
"input": "4\n1101",
"output": "4"
},
{
"input": "4\n1110",
"output": "4"
},
{
"input": "4\n1111",
"output": "3"
},
{
"input": "5\n00000",
"output": "3"
},
{
"input": "5\n00001",
"output": "4"
},
{
"input": "5\n00010",
"output": "5"
},
{
"input": "5\n00011",
"output": "4"
},
{
"input": "5\n00100",
"output": "5"
},
{
"input": "5\n00101",
"output": "5"
},
{
"input": "5\n00110",
"output": "5"
},
{
"input": "5\n00111",
"output": "4"
},
{
"input": "5\n01000",
"output": "5"
},
{
"input": "5\n01001",
"output": "5"
},
{
"input": "5\n01010",
"output": "5"
},
{
"input": "5\n01011",
"output": "5"
},
{
"input": "5\n01100",
"output": "5"
},
{
"input": "5\n01101",
"output": "5"
},
{
"input": "5\n01110",
"output": "5"
},
{
"input": "5\n01111",
"output": "4"
},
{
"input": "5\n10000",
"output": "4"
},
{
"input": "5\n10001",
"output": "5"
},
{
"input": "5\n10010",
"output": "5"
},
{
"input": "5\n10100",
"output": "5"
},
{
"input": "5\n10101",
"output": "5"
},
{
"input": "5\n10110",
"output": "5"
},
{
"input": "5\n10111",
"output": "5"
},
{
"input": "5\n11000",
"output": "4"
},
{
"input": "5\n11001",
"output": "5"
},
{
"input": "5\n11010",
"output": "5"
},
{
"input": "5\n11011",
"output": "5"
},
{
"input": "5\n11100",
"output": "4"
},
{
"input": "5\n11101",
"output": "5"
},
{
"input": "5\n11110",
"output": "4"
},
{
"input": "5\n11111",
"output": "3"
}
] | 1,624,781,157 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 204,800 | #This code is contributed by Siddharth
from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf=10**18
mod=10**9+7
# ---------------------------------------------------------Code---------------------------------------------------------
n=int(input())
s=input()
vis=[0 for _ in range( n)]
pre=s[0]
vis[0]=1
for i in range(1,n):
if pre!=s[i]:
vis[i]=1
pre=s[i]
cnt=0
ans=False
for i in range(n):
if vis[i]==0:
cnt+=1
else:
cnt=0
if cnt>=2:
ans=True
break
if ans:
print(sum(vis)+2)
else:
print(sum(vis))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.
However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not.
Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.
Input Specification:
The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000).
The following line contains a binary string of length *n* representing Kevin's results on the USAICO.
Output Specification:
Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.
Demo Input:
['8\n10000011\n', '2\n01\n']
Demo Output:
['5\n', '2\n']
Note:
In the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.
In the second sample, Kevin can flip the entire string and still have the same score. | ```python
#This code is contributed by Siddharth
from bisect import *
import math
from collections import *
from heapq import *
from itertools import *
inf=10**18
mod=10**9+7
# ---------------------------------------------------------Code---------------------------------------------------------
n=int(input())
s=input()
vis=[0 for _ in range( n)]
pre=s[0]
vis[0]=1
for i in range(1,n):
if pre!=s[i]:
vis[i]=1
pre=s[i]
cnt=0
ans=False
for i in range(n):
if vis[i]==0:
cnt+=1
else:
cnt=0
if cnt>=2:
ans=True
break
if ans:
print(sum(vis)+2)
else:
print(sum(vis))
``` | 0 |
|
586 | A | Alena's Schedule | PROGRAMMING | 900 | [
"implementation"
] | null | null | Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces. | Print a single number — the number of pairs during which Alena stays at the university. | [
"5\n0 1 0 1 1\n",
"7\n1 0 1 0 0 1 0\n",
"1\n0\n"
] | [
"4\n",
"4\n",
"0\n"
] | In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | 500 | [
{
"input": "5\n0 1 0 1 1",
"output": "4"
},
{
"input": "7\n1 0 1 0 0 1 0",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "2\n0 1",
"output": "1"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1",
"output": "9"
},
{
"input": "11\n0 0 0 0 0 0 0 0 0 0 1",
"output": "1"
},
{
"input": "12\n1 0 0 0 0 0 0 0 0 0 0 0",
"output": "1"
},
{
"input": "20\n1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0 1 0 0",
"output": "16"
},
{
"input": "41\n1 1 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0 1 0 1 1",
"output": "28"
},
{
"input": "63\n1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 0",
"output": "39"
},
{
"input": "80\n0 1 1 1 0 1 1 1 1 1 0 0 1 0 1 1 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1",
"output": "52"
},
{
"input": "99\n1 1 0 0 0 1 0 0 1 1 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 0 1 0 0 1 1 0 1 0 0 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1",
"output": "72"
},
{
"input": "100\n0 1 1 0 1 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 0 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 1 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0",
"output": "65"
},
{
"input": "11\n0 1 1 0 0 0 0 0 0 0 0",
"output": "2"
},
{
"input": "11\n0 1 0 1 0 0 1 1 0 1 1",
"output": "8"
},
{
"input": "11\n1 0 1 0 1 1 0 1 1 1 0",
"output": "10"
},
{
"input": "11\n1 0 0 0 0 0 1 0 1 1 1",
"output": "6"
},
{
"input": "22\n0 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 1 0",
"output": "7"
},
{
"input": "22\n0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 1",
"output": "16"
},
{
"input": "22\n1 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 0",
"output": "11"
},
{
"input": "22\n1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 1",
"output": "14"
},
{
"input": "33\n0 1 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 1 0 0 1 1 0 0 1 1 0 1 1 0 0",
"output": "26"
},
{
"input": "33\n0 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 0 1 1 1 0 1 1 1 0 1",
"output": "27"
},
{
"input": "33\n1 0 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 0",
"output": "25"
},
{
"input": "33\n1 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 1 1",
"output": "24"
},
{
"input": "44\n0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 1 0 1 1 0 0",
"output": "19"
},
{
"input": "44\n0 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 1",
"output": "32"
},
{
"input": "44\n1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0",
"output": "23"
},
{
"input": "44\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 0 1 0 1 1 1 1",
"output": "32"
},
{
"input": "55\n0 1 1 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1 0",
"output": "23"
},
{
"input": "55\n0 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1",
"output": "39"
},
{
"input": "55\n1 0 1 0 0 1 0 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0",
"output": "32"
},
{
"input": "55\n1 0 1 0 1 0 1 0 1 1 0 0 1 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 1 1 1",
"output": "36"
},
{
"input": "66\n0 1 1 0 0 1 0 1 0 1 0 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 1 1 0 1 1 1 0 0 0 0 0 1 0",
"output": "41"
},
{
"input": "66\n0 1 1 0 1 1 1 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 1",
"output": "42"
},
{
"input": "66\n1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 1 1 0 0 0 1 1 1 0 1 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 0 0 0 1 1 0 1 0 1 1 0 0 0 1 1 0 1 1 0 1 1 0 0",
"output": "46"
},
{
"input": "66\n1 0 1 0 0 0 1 1 1 1 1 0 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 1",
"output": "46"
},
{
"input": "77\n0 0 1 0 0 1 0 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0 1 0 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 0 0 1 0 1 1 0 1 1 1 0 1 1 0 1 0",
"output": "47"
},
{
"input": "77\n0 0 1 0 0 0 1 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 1 0 1 0 0 0 0 1 1",
"output": "44"
},
{
"input": "77\n1 0 0 0 1 0 1 1 0 0 1 0 0 0 1 1 1 1 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 1 1 0 0 1 0 0 1 1 1 1 0 1 0 0 0 1 0 1 1 0 0 0 0 0",
"output": "45"
},
{
"input": "77\n1 0 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 1 1",
"output": "51"
},
{
"input": "88\n0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 1 1 0 0 1 1 0 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0",
"output": "44"
},
{
"input": "88\n0 0 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 0 0 1",
"output": "59"
},
{
"input": "88\n1 0 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 0 1 1 0 0 1 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 1 0 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0",
"output": "53"
},
{
"input": "88\n1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 0 1",
"output": "63"
},
{
"input": "99\n0 0 0 0 1 0 0 1 0 0 0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 1 1 0 0 1 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 1 1 1 0 1 1 0 1 0 1 0 0 0 1 1 0 0 0 0",
"output": "56"
},
{
"input": "99\n0 0 1 0 0 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 0 0 0 1 1 0 0 0 1 0 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 0 0 0 0 0 0 1 1 1",
"output": "58"
},
{
"input": "99\n1 1 0 0 1 1 1 0 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0 1 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 1 0 1 1 1 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 1 0 0 1 0 1 0 1 1 0 1 0 1 1 1 1 0 0 1 0",
"output": "65"
},
{
"input": "99\n1 1 1 0 1 0 1 1 0 1 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 1 0 1 0 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 1 1 1",
"output": "77"
},
{
"input": "90\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",
"output": "0"
},
{
"input": "90\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",
"output": "90"
},
{
"input": "95\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",
"output": "0"
},
{
"input": "95\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",
"output": "95"
},
{
"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": "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": "100"
}
] | 1,444,677,986 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 13 | 62 | 204,800 | import re
input()
print(re.sub('1 0 1', '1 1 1', input()).count('1')) | Title: Alena's Schedule
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.
One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).
The University works in such a way that every day it holds exactly *n* lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).
The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the *n* pairs she knows if there will be a class at that time or not.
Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.
Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.
Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.
Input Specification:
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of lessons at the university.
The second line contains *n* numbers *a**i* (0<=≤<=*a**i*<=≤<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* are separated by spaces.
Output Specification:
Print a single number — the number of pairs during which Alena stays at the university.
Demo Input:
['5\n0 1 0 1 1\n', '7\n1 0 1 0 0 1 0\n', '1\n0\n']
Demo Output:
['4\n', '4\n', '0\n']
Note:
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.
In the last sample Alena doesn't have a single pair, so she spends all the time at home. | ```python
import re
input()
print(re.sub('1 0 1', '1 1 1', input()).count('1'))
``` | 0 |
|
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,578,134,801 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 80 | 310 | 0 | import sys
n = int(sys.stdin.readline())
x=0
y=0
z=0
for _ in range(n):
tem = [int(i) for i in sys.stdin.readline().split(' ')]
x+=tem[0]
y+=tem[1]
z+=tem[2]
total = x+y+z
if total == 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
import sys
n = int(sys.stdin.readline())
x=0
y=0
z=0
for _ in range(n):
tem = [int(i) for i in sys.stdin.readline().split(' ')]
x+=tem[0]
y+=tem[1]
z+=tem[2]
total = x+y+z
if total == 0:
print('YES')
else:
print('NO')
``` | 0 |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
},
{
"input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1",
"output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 "
},
{
"input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3",
"output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 "
},
{
"input": "10 17\n5 1\n8 1\n2 1\n2 6\n3 1\n5 7\n3 7\n8 6\n4 7\n2 7\n9 7\n10 7\n3 6\n4 1\n9 1\n8 7\n10 1",
"output": "7\n5 3 2 8 4 9 10 \n3\n1 7 6 "
},
{
"input": "10 15\n5 9\n7 8\n2 9\n1 9\n3 8\n3 9\n5 8\n1 8\n6 9\n7 9\n4 8\n4 9\n10 9\n10 8\n6 8",
"output": "2\n9 8 \n8\n1 5 7 3 4 10 6 2 "
},
{
"input": "10 9\n4 9\n1 9\n10 9\n2 9\n3 9\n6 9\n5 9\n7 9\n8 9",
"output": "1\n9 \n9\n1 4 10 2 3 6 5 7 8 "
},
{
"input": "2 1\n1 2",
"output": "1\n2 \n1\n1 "
},
{
"input": "10 10\n6 4\n9 1\n3 6\n6 7\n4 2\n9 6\n8 6\n5 7\n1 4\n6 10",
"output": "6\n9 4 3 7 8 10 \n4\n1 6 2 5 "
},
{
"input": "20 22\n20 8\n1 3\n3 18\n14 7\n19 6\n7 20\n14 8\n8 10\n2 5\n11 2\n4 19\n14 2\n7 11\n15 1\n12 15\n7 6\n11 13\n1 16\n9 12\n1 19\n17 3\n11 20",
"output": "-1"
},
{
"input": "20 22\n3 18\n9 19\n6 15\n7 1\n16 8\n18 7\n12 3\n18 4\n9 15\n20 1\n4 2\n6 7\n14 2\n7 15\n7 10\n8 1\n13 6\n9 7\n11 8\n2 6\n18 5\n17 15",
"output": "-1"
},
{
"input": "1000 1\n839 771",
"output": "1\n839 \n1\n771 "
},
{
"input": "1000 1\n195 788",
"output": "1\n788 \n1\n195 "
},
{
"input": "100000 1\n42833 64396",
"output": "1\n64396 \n1\n42833 "
},
{
"input": "100000 1\n26257 21752",
"output": "1\n26257 \n1\n21752 "
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "-1"
}
] | 1,603,826,858 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 139 | 102,400 |
#A. NP-Hard Problem
from collections import deque , defaultdict
vx = 0
e = 0
def bfs(node):
global vx , e
q = deque()
q.append(node)
while q :
s = q.popleft()
if not visited[s]:
vx += 1
visited[s] = True
for i in g[s]:
e +=1
q.append(i)
n , m = map(int,input().split())
g = defaultdict(list)
c = set()
for i in range(m):
u , v = map(int,input().split())
g[u].append(v)
g[v].append(u)
c.add(u)
c.add(v)
visited = [False] * (n + 1)
flag = True
for i in c :
vx = e = 0
r = bfs(i)
e //= 2
#print(e , vx)
if e != 0 and vx != 0 :
if e == vx * (vx - 1) //2:
flag = False
#print(flag)
if flag == False:
print('-1')
exit(0)
#print(g)
st = set()
#print(visited)
f = deque()
t = deque()
for i in range(1 , n + 1):
if visited[i]:
f.append(i)
else:
t.append(i)
print(len(f))
print(*f)
print(len(t))
print(*t)
| Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both).
Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.
They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges.
Output Specification:
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty.
Demo Input:
['4 2\n1 2\n2 3\n', '3 3\n1 2\n2 3\n1 3\n']
Demo Output:
['1\n2 \n2\n1 3 \n', '-1\n']
Note:
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | ```python
#A. NP-Hard Problem
from collections import deque , defaultdict
vx = 0
e = 0
def bfs(node):
global vx , e
q = deque()
q.append(node)
while q :
s = q.popleft()
if not visited[s]:
vx += 1
visited[s] = True
for i in g[s]:
e +=1
q.append(i)
n , m = map(int,input().split())
g = defaultdict(list)
c = set()
for i in range(m):
u , v = map(int,input().split())
g[u].append(v)
g[v].append(u)
c.add(u)
c.add(v)
visited = [False] * (n + 1)
flag = True
for i in c :
vx = e = 0
r = bfs(i)
e //= 2
#print(e , vx)
if e != 0 and vx != 0 :
if e == vx * (vx - 1) //2:
flag = False
#print(flag)
if flag == False:
print('-1')
exit(0)
#print(g)
st = set()
#print(visited)
f = deque()
t = deque()
for i in range(1 , n + 1):
if visited[i]:
f.append(i)
else:
t.append(i)
print(len(f))
print(*f)
print(len(t))
print(*t)
``` | 0 |
|
222 | B | Cosmic Tables | PROGRAMMING | 1,300 | [
"data structures",
"implementation"
] | null | null | The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
- The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you. | The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly.
Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106.
Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers.
- If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*).
The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*. | For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input. | [
"3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n",
"2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n"
] | [
"8\n9\n6\n",
"5\n"
] | Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5. | 1,000 | [
{
"input": "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2",
"output": "8\n9\n6"
},
{
"input": "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3",
"output": "5"
},
{
"input": "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2",
"output": "2\n1"
},
{
"input": "2 2 6\n1 2\n3 4\nc 1 2\nr 1 2\ng 1 1\ng 1 2\ng 2 1\ng 2 2",
"output": "4\n3\n2\n1"
},
{
"input": "3 4 5\n1 2 3 4\n5 6 7 8\n9 10 11 12\nr 1 2\nr 1 3\nr 2 3\ng 1 1\ng 2 2",
"output": "9\n6"
},
{
"input": "5 5 12\n1 2 3 4 5\n6 7 8 9 10\n11 12 13 14 15\n16 17 18 19 20\n21 22 23 24 25\nc 1 2\nr 1 2\nr 2 3\nr 1 2\nr 4 5\nc 3 4\ng 1 1\ng 2 2\ng 3 3\ng 4 4\ng 5 5\ng 2 3",
"output": "12\n6\n4\n23\n20\n9"
},
{
"input": "6 5 30\n536048 34640 572197 62457 304174\n194764 325606 270468 784237 551632\n10580 294606 63164 543647 531895\n430397 576813 678878 323394 603231\n534567 804015 403517 886087 981939\n518845 962097 609792 877955 88610\nc 1 5\nc 2 5\nc 2 5\nr 5 3\nc 5 2\nc 4 5\nr 6 5\nc 2 1\nr 3 4\nr 4 3\nc 4 5\nc 2 1\nr 1 5\nr 5 6\nc 3 1\ng 1 1\ng 5 4\ng 2 2\ng 2 1\nr 4 5\ng 1 1\nr 3 2\ng 5 1\nr 2 3\nr 6 5\nr 4 2\ng 5 2\nr 1 3\nr 1 3\nc 5 1",
"output": "609792\n543647\n194764\n270468\n609792\n678878\n536048"
},
{
"input": "2 1 3\n1\n2\nr 1 2\ng 1 1\ng 2 1",
"output": "2\n1"
},
{
"input": "3 3 13\n1 2 3\n4 5 6\n7 8 9\nc 1 2\nc 2 3\nr 2 3\nr 1 2\ng 1 1\ng 1 2\ng 1 3\ng 2 1\ng 2 2\ng 2 3\ng 3 1\ng 3 2\ng 3 3",
"output": "8\n9\n7\n2\n3\n1\n5\n6\n4"
},
{
"input": "1 3 7\n1 2 3\nc 1 2\nc 2 3\nc 1 3\nc 2 3\ng 1 1\ng 1 2\ng 1 3",
"output": "1\n2\n3"
},
{
"input": "3 1 7\n1\n2\n3\nr 1 2\nr 2 3\nr 1 3\nr 2 3\ng 1 1\ng 2 1\ng 3 1",
"output": "1\n2\n3"
},
{
"input": "5 6 20\n495907 68740 954868 197572 577456 641857\n16591 602443 981187 646143 137121 884307\n371452 725384 373988 59165 980490 837686\n514286 881540 886532 10541 684975 411009\n314261 127191 461802 89232 749116 563889\nr 2 1\nr 3 4\nc 3 4\nr 2 3\nc 6 3\nc 5 6\nc 4 1\nc 4 2\nr 2 4\nc 1 6\nr 5 3\nr 2 5\nr 4 2\ng 3 4\nc 2 5\nc 3 1\ng 3 6\ng 4 3\ng 2 3\nr 5 4",
"output": "127191\n461802\n577456\n684975"
}
] | 1,619,526,997 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 1 | 92 | 0 | n, m, k = [int(X) for X in input().split()]
mat = [[int(X) for X in input().split()] for i in range(m)]
a = []
for _ in range(k):
t, x, y = [x for x in input().split()]
a.append([t, int(x), int(y)])
rowd = {i: i for i in range(m)}
cold = {i: i for i in range(n)}
for (t, x, y) in a:
if t == 'g':
print(mat[rowd[x-1]][cold[y-1]])
if t == 'r':
rowd[x-1] = y-1
rowd[y-1] = x-1
if t == 'c':
cold[x-1] = y-1
cold[y-1] = x-1
| Title: Cosmic Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
- The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input Specification:
The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly.
Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106.
Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers.
- If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*).
The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*.
Output Specification:
For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Demo Input:
['3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n', '2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n']
Demo Output:
['8\n9\n6\n', '5\n']
Note:
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5. | ```python
n, m, k = [int(X) for X in input().split()]
mat = [[int(X) for X in input().split()] for i in range(m)]
a = []
for _ in range(k):
t, x, y = [x for x in input().split()]
a.append([t, int(x), int(y)])
rowd = {i: i for i in range(m)}
cold = {i: i for i in range(n)}
for (t, x, y) in a:
if t == 'g':
print(mat[rowd[x-1]][cold[y-1]])
if t == 'r':
rowd[x-1] = y-1
rowd[y-1] = x-1
if t == 'c':
cold[x-1] = y-1
cold[y-1] = x-1
``` | -1 |
|
373 | A | Collecting Beats is Fun | PROGRAMMING | 900 | [
"implementation"
] | null | null | Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing. | The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel. | Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes). | [
"1\n.135\n1247\n3468\n5789\n",
"5\n..1.\n1111\n..1.\n..1.\n",
"1\n....\n12.1\n.2..\n.2..\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | 500 | [
{
"input": "1\n.135\n1247\n3468\n5789",
"output": "YES"
},
{
"input": "5\n..1.\n1111\n..1.\n..1.",
"output": "YES"
},
{
"input": "1\n....\n12.1\n.2..\n.2..",
"output": "NO"
},
{
"input": "1\n6981\n.527\n4163\n2345",
"output": "YES"
},
{
"input": "5\n9999\n9999\n9999\n9999",
"output": "NO"
},
{
"input": "2\n4444\n3333\n2222\n1111",
"output": "YES"
},
{
"input": "3\n2123\n1232\n2321\n3213",
"output": "NO"
},
{
"input": "2\n1...\n.1..\n..1.\n...1",
"output": "YES"
},
{
"input": "2\n1.1.\n.1.1\n2.2.\n.222",
"output": "NO"
},
{
"input": "1\n1..2\n.3.4\n567.\n.89.",
"output": "YES"
},
{
"input": "1\n1122\n3344\n5588\n6699",
"output": "YES"
},
{
"input": "4\n1111\n1221\n1221\n1111",
"output": "NO"
},
{
"input": "5\n3141\n5926\n5358\n9793",
"output": "YES"
},
{
"input": "5\n5454\n4343\n3232\n2121",
"output": "YES"
},
{
"input": "5\n1222\n2221\n2221\n1122",
"output": "NO"
},
{
"input": "1\n....\n5..5\n6..6\n7..7",
"output": "YES"
},
{
"input": "1\n9875\n8643\n7421\n531.",
"output": "YES"
},
{
"input": "1\n..1.\n..1.\n..1.\n..1.",
"output": "NO"
},
{
"input": "4\n4.4.\n4.4.\n4444\n..4.",
"output": "NO"
},
{
"input": "5\n4.4.\n4.4.\n4444\n..4.",
"output": "YES"
},
{
"input": "3\n1.1.\n.1.1\n1.1.\n.1.1",
"output": "NO"
},
{
"input": "2\n1131\n4412\n2569\n3478",
"output": "YES"
},
{
"input": "2\n8888\n8888\n8888\n8888",
"output": "NO"
}
] | 1,492,340,427 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 62 | 5,529,600 | '''input
1
....
12.1
.2..
.2..
'''
k = int(input())
x = input() + input() + input() + input()
print("NO" if any(x.count(i) > 2*k for i in set(x) if i != ".") else "YES")
| Title: Collecting Beats is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4<=×<=4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most *k* panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.
You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.
Input Specification:
The first line contains a single integer *k* (1<=≤<=*k*<=≤<=5) — the number of panels Cucumber boy can press with his one hand.
Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit *i* was written on the panel, it means the boy has to press that panel in time *i*. If period was written on the panel, he doesn't have to press that panel.
Output Specification:
Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).
Demo Input:
['1\n.135\n1247\n3468\n5789\n', '5\n..1.\n1111\n..1.\n..1.\n', '1\n....\n12.1\n.2..\n.2..\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands. | ```python
'''input
1
....
12.1
.2..
.2..
'''
k = int(input())
x = input() + input() + input() + input()
print("NO" if any(x.count(i) > 2*k for i in set(x) if i != ".") else "YES")
``` | 3 |
|
870 | C | Maximum splitting | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"math",
"number theory"
] | null | null | You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself. | The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
*q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query. | For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings. | [
"1\n12\n",
"2\n6\n8\n",
"3\n1\n2\n3\n"
] | [
"3\n",
"1\n2\n",
"-1\n-1\n-1\n"
] | 12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings. | 1,500 | [
{
"input": "1\n12",
"output": "3"
},
{
"input": "2\n6\n8",
"output": "1\n2"
},
{
"input": "3\n1\n2\n3",
"output": "-1\n-1\n-1"
},
{
"input": "6\n1\n2\n3\n5\n7\n11",
"output": "-1\n-1\n-1\n-1\n-1\n-1"
},
{
"input": "3\n4\n6\n9",
"output": "1\n1\n1"
},
{
"input": "20\n8\n13\n20\n12\n9\n16\n4\n19\n7\n15\n10\n6\n14\n11\n3\n2\n5\n17\n18\n1",
"output": "2\n2\n5\n3\n1\n4\n1\n3\n-1\n2\n2\n1\n3\n-1\n-1\n-1\n-1\n3\n4\n-1"
},
{
"input": "100\n611\n513\n544\n463\n38\n778\n347\n317\n848\n664\n382\n108\n718\n33\n334\n876\n234\n22\n944\n305\n159\n245\n513\n691\n639\n135\n308\n324\n813\n459\n304\n116\n331\n993\n184\n224\n853\n769\n121\n687\n93\n930\n751\n308\n485\n914\n400\n695\n95\n981\n175\n972\n121\n654\n242\n610\n617\n999\n237\n548\n742\n767\n613\n172\n223\n391\n102\n907\n673\n116\n230\n355\n189\n552\n399\n493\n903\n201\n985\n459\n776\n641\n693\n919\n253\n540\n427\n394\n655\n101\n461\n854\n417\n249\n66\n380\n213\n906\n212\n528",
"output": "151\n127\n136\n114\n9\n194\n85\n78\n212\n166\n95\n27\n179\n7\n83\n219\n58\n5\n236\n75\n38\n60\n127\n171\n158\n32\n77\n81\n202\n113\n76\n29\n81\n247\n46\n56\n212\n191\n29\n170\n22\n232\n186\n77\n120\n228\n100\n172\n22\n244\n42\n243\n29\n163\n60\n152\n153\n248\n58\n137\n185\n190\n152\n43\n54\n96\n25\n225\n167\n29\n57\n87\n46\n138\n98\n122\n224\n49\n245\n113\n194\n159\n172\n228\n62\n135\n105\n98\n162\n24\n114\n213\n103\n61\n16\n95\n52\n226\n53\n132"
},
{
"input": "1\n10000001",
"output": "2499999"
}
] | 1,511,140,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 5,529,600 | number = int(input())
for i in range(number):
lst = []
newLst = []
count = 0
num = int(input())
if num%2 == 0:
if num//4 == 0:
print("-1")
else:
print(num//4)
else:
for i in range(2, num+1):
lst.append(i)
newLst = [item for item in lst if item == 2 or item%2 == 1]
lst = []
lst = [thing for thing in newLst if thing == 2 or thing == 3 or thing%3 == 1 or thing%3 == 2]
newLst = []
newLst = [bob for bob in lst if bob == 2 or bob == 3 or bob == 5 or bob%5 == 1 or bob%5 == 2 or bob%5 == 3 or bob%5 == 4]
lst = []
lst = [stuff for stuff in newLst if stuff == 2 or stuff == 3 or stuff == 5 or stuff == 7 or stuff%7 == 1 or stuff%7 == 2 or stuff%7 == 3 or stuff%7 == 4 or stuff%7 == 5 or stuff%7 == 6]
if num in lst:
print("-1")
else:
print(num//5) | Title: Maximum splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given several queries. In the *i*-th query you are given a single positive integer *n**i*. You are to represent *n**i* as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.
Input Specification:
The first line contains single integer *q* (1<=≤<=*q*<=≤<=105) — the number of queries.
*q* lines follow. The (*i*<=+<=1)-th line contains single integer *n**i* (1<=≤<=*n**i*<=≤<=109) — the *i*-th query.
Output Specification:
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
Demo Input:
['1\n12\n', '2\n6\n8\n', '3\n1\n2\n3\n']
Demo Output:
['3\n', '1\n2\n', '-1\n-1\n-1\n']
Note:
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings. | ```python
number = int(input())
for i in range(number):
lst = []
newLst = []
count = 0
num = int(input())
if num%2 == 0:
if num//4 == 0:
print("-1")
else:
print(num//4)
else:
for i in range(2, num+1):
lst.append(i)
newLst = [item for item in lst if item == 2 or item%2 == 1]
lst = []
lst = [thing for thing in newLst if thing == 2 or thing == 3 or thing%3 == 1 or thing%3 == 2]
newLst = []
newLst = [bob for bob in lst if bob == 2 or bob == 3 or bob == 5 or bob%5 == 1 or bob%5 == 2 or bob%5 == 3 or bob%5 == 4]
lst = []
lst = [stuff for stuff in newLst if stuff == 2 or stuff == 3 or stuff == 5 or stuff == 7 or stuff%7 == 1 or stuff%7 == 2 or stuff%7 == 3 or stuff%7 == 4 or stuff%7 == 5 or stuff%7 == 6]
if num in lst:
print("-1")
else:
print(num//5)
``` | 0 |
|
185 | A | Plant | PROGRAMMING | 1,300 | [
"math"
] | null | null | Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
Help the dwarfs find out how many triangle plants that point "upwards" will be in *n* years. | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7). | [
"1\n",
"2\n"
] | [
"3\n",
"10\n"
] | The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | 500 | [
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "10"
},
{
"input": "385599124",
"output": "493875375"
},
{
"input": "989464295",
"output": "31966163"
},
{
"input": "376367012",
"output": "523204186"
},
{
"input": "529357306",
"output": "142578489"
},
{
"input": "782916801",
"output": "51174574"
},
{
"input": "74859961358140080",
"output": "478768275"
},
{
"input": "0",
"output": "1"
},
{
"input": "252509053898415171",
"output": "886314547"
},
{
"input": "760713016078377938",
"output": "79611270"
},
{
"input": "919845424847912644",
"output": "388845650"
},
{
"input": "585335721566249104",
"output": "301383716"
},
{
"input": "522842183413115087",
"output": "556012763"
},
{
"input": "148049062285906746",
"output": "913927498"
},
{
"input": "84324827171274022",
"output": "462535280"
},
{
"input": "354979172034763159",
"output": "239287993"
},
{
"input": "1312148742261680",
"output": "799725655"
},
{
"input": "269587448053313253",
"output": "536645997"
},
{
"input": "645762257531682045",
"output": "543988614"
},
{
"input": "615812227854199662",
"output": "357939938"
},
{
"input": "819875140559301751",
"output": "968653685"
},
{
"input": "349993003033420740",
"output": "709392758"
},
{
"input": "891351282398722856",
"output": "70758467"
},
{
"input": "563324730406715801",
"output": "353494903"
},
{
"input": "520974001002628386",
"output": "164118419"
},
{
"input": "666729339260489789",
"output": "784700006"
},
{
"input": "856674609788912527",
"output": "720540265"
},
{
"input": "791809296233191092",
"output": "369199735"
},
{
"input": "711066335916901717",
"output": "15590358"
},
{
"input": "931356501703211379",
"output": "239824013"
},
{
"input": "234122431978145893",
"output": "905163056"
},
{
"input": "1000000000000000000",
"output": "899770636"
},
{
"input": "3",
"output": "36"
},
{
"input": "4",
"output": "136"
},
{
"input": "5",
"output": "528"
},
{
"input": "6",
"output": "2080"
},
{
"input": "7",
"output": "8256"
},
{
"input": "8",
"output": "32896"
},
{
"input": "9",
"output": "131328"
},
{
"input": "10",
"output": "524800"
},
{
"input": "11",
"output": "2098176"
},
{
"input": "12",
"output": "8390656"
},
{
"input": "13",
"output": "33558528"
},
{
"input": "14",
"output": "134225920"
},
{
"input": "15",
"output": "536887296"
},
{
"input": "16",
"output": "147516402"
},
{
"input": "0",
"output": "1"
},
{
"input": "6265",
"output": "980996097"
}
] | 1,691,156,361 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n = int(input())
a = [1, 0]
matrix = [[3, 1],[1,3]]
res = [[1,0],[0,1]]
modulo = 1e9+7
def matmul(a,b):
ans = [[1,0],[0,1]]
ans[0][0] = (a[0][0]*b[0][0] + a[0][1]*b[1][0])%modulo
ans[0][1] = (a[0][0]*b[1][0] + a[0][1]*b[1][1])%modulo
ans[1][0] = (a[1][0]*b[0][0] + a[1][1]*b[1][0])%modulo
ans[1][1] = (a[1][0]*b[1][0] + a[1][1]*b[1][1])%modulo
return ans
while(n!=0):
if n%2 == 0:
matrix = matmul(matrix,matrix)
n //= 2
else:
res = matmul(res,matrix)
n-=1
#print(res)
print(int(res[0][0]%modulo))
| Title: Plant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.
Help the dwarfs find out how many triangle plants that point "upwards" will be in *n* years.
Input Specification:
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Output Specification:
Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7).
Demo Input:
['1\n', '2\n']
Demo Output:
['3\n', '10\n']
Note:
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one. | ```python
n = int(input())
a = [1, 0]
matrix = [[3, 1],[1,3]]
res = [[1,0],[0,1]]
modulo = 1e9+7
def matmul(a,b):
ans = [[1,0],[0,1]]
ans[0][0] = (a[0][0]*b[0][0] + a[0][1]*b[1][0])%modulo
ans[0][1] = (a[0][0]*b[1][0] + a[0][1]*b[1][1])%modulo
ans[1][0] = (a[1][0]*b[0][0] + a[1][1]*b[1][0])%modulo
ans[1][1] = (a[1][0]*b[1][0] + a[1][1]*b[1][1])%modulo
return ans
while(n!=0):
if n%2 == 0:
matrix = matmul(matrix,matrix)
n //= 2
else:
res = matmul(res,matrix)
n-=1
#print(res)
print(int(res[0][0]%modulo))
``` | 0 |
|
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"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": "100"
},
{
"input": "9 3\n9 5 2 3 7 1 8 4 6",
"output": "7"
},
{
"input": "20 10\n58 4 32 10 73 7 30 39 47 6 59 21 24 66 79 79 46 13 29 58",
"output": "16"
},
{
"input": "50 5\n89 56 3 2 40 37 56 52 83 59 43 83 43 59 29 74 22 58 53 41 53 67 78 30 57 32 58 29 95 46 45 85 60 49 41 82 8 71 52 40 45 26 6 71 84 91 4 93 40 54",
"output": "48"
},
{
"input": "50 1\n4 3 9 7 6 8 3 7 10 9 8 8 10 2 9 3 2 4 4 10 4 6 8 10 9 9 4 2 8 9 4 4 9 5 1 5 2 4 4 9 10 2 5 10 7 2 8 6 8 1",
"output": "44"
},
{
"input": "50 5\n3 9 10 8 3 3 4 6 8 2 9 9 3 1 2 10 6 8 7 2 7 4 2 7 5 10 2 2 2 5 10 5 6 6 8 7 10 4 3 2 10 8 6 6 8 6 4 4 1 3",
"output": "46"
},
{
"input": "50 2\n56 69 72 15 95 92 51 1 74 87 100 29 46 54 18 81 84 72 84 83 20 63 71 27 45 74 50 89 48 8 21 15 47 3 39 73 80 84 6 99 17 25 56 3 74 64 71 39 89 78",
"output": "40"
},
{
"input": "50 3\n31 39 64 16 86 3 1 9 25 54 98 42 20 3 49 41 73 37 55 62 33 77 64 22 33 82 26 13 10 13 7 40 48 18 46 79 94 72 19 12 11 61 16 37 10 49 14 94 48 69",
"output": "11"
},
{
"input": "50 100\n67 67 61 68 42 29 70 77 12 61 71 27 4 73 87 52 59 38 93 90 31 27 87 47 26 57 76 6 28 72 81 68 50 84 69 79 39 93 52 6 88 12 46 13 90 68 71 38 90 95",
"output": "50"
},
{
"input": "100 3\n4 14 20 11 19 11 14 20 5 7 6 12 11 17 5 11 7 6 2 10 13 5 12 8 5 17 20 18 7 19 11 7 7 20 20 8 10 17 17 19 20 5 15 16 19 7 11 16 4 17 2 10 1 20 20 16 19 9 9 11 5 7 12 9 9 6 20 18 13 19 8 4 8 1 2 4 10 11 15 14 1 7 17 12 13 19 12 2 3 14 15 15 5 17 14 12 17 14 16 9",
"output": "86"
},
{
"input": "100 5\n16 8 14 16 12 11 17 19 19 2 8 9 5 6 19 9 11 18 6 9 14 16 14 18 17 17 17 5 15 20 19 7 7 10 10 5 14 20 5 19 11 16 16 19 17 9 7 12 14 10 2 11 14 5 20 8 10 11 19 2 14 14 19 17 5 10 8 8 4 2 1 10 20 12 14 11 7 6 6 15 1 5 9 15 3 17 16 17 5 14 11 9 16 15 1 11 10 6 15 7",
"output": "93"
},
{
"input": "100 1\n58 94 18 50 17 14 96 62 83 80 75 5 9 22 25 41 3 96 74 45 66 37 2 37 13 85 68 54 77 11 85 19 25 21 52 59 90 61 72 89 82 22 10 16 3 68 61 29 55 76 28 85 65 76 27 3 14 10 56 37 86 18 35 38 56 68 23 88 33 38 52 87 55 83 94 34 100 41 83 56 91 77 32 74 97 13 67 31 57 81 53 39 5 88 46 1 79 4 49 42",
"output": "77"
},
{
"input": "100 2\n1 51 76 62 34 93 90 43 57 59 52 78 3 48 11 60 57 48 5 54 28 81 87 23 44 77 67 61 14 73 29 53 21 89 67 41 47 9 63 37 1 71 40 85 4 14 77 40 78 75 89 74 4 70 32 65 81 95 49 90 72 41 76 55 69 83 73 84 85 93 46 6 74 90 62 37 97 7 7 37 83 30 37 88 34 16 11 59 85 19 57 63 85 20 63 97 97 65 61 48",
"output": "97"
},
{
"input": "100 3\n30 83 14 55 61 66 34 98 90 62 89 74 45 93 33 31 75 35 82 100 63 69 48 18 99 2 36 71 14 30 70 76 96 85 97 90 49 36 6 76 37 94 70 3 63 73 75 48 39 29 13 2 46 26 9 56 1 18 54 53 85 34 2 12 1 93 75 67 77 77 14 26 33 25 55 9 57 70 75 6 87 66 18 3 41 69 73 24 49 2 20 72 39 58 91 54 74 56 66 78",
"output": "20"
},
{
"input": "100 4\n69 92 76 3 32 50 15 38 21 22 14 3 67 41 95 12 10 62 83 52 78 1 18 58 94 35 62 71 58 75 13 73 60 34 50 97 50 70 19 96 53 10 100 26 20 39 62 59 88 26 24 83 70 68 66 8 6 38 16 93 2 91 81 89 78 74 21 8 31 56 28 53 77 5 81 5 94 42 77 75 92 15 59 36 61 18 55 45 69 68 81 51 12 42 85 74 98 31 17 41",
"output": "97"
},
{
"input": "100 5\n2 72 10 60 6 50 72 34 97 77 35 43 80 64 40 53 46 6 90 22 29 70 26 68 52 19 72 88 83 18 55 32 99 81 11 21 39 42 41 63 60 97 30 23 55 78 89 35 24 50 99 52 27 76 24 8 20 27 51 37 17 82 69 18 46 19 26 77 52 83 76 65 43 66 84 84 13 30 66 88 84 23 37 1 17 26 11 50 73 56 54 37 40 29 35 8 1 39 50 82",
"output": "51"
},
{
"input": "100 7\n6 73 7 54 92 33 66 65 80 47 2 53 28 59 61 16 54 89 37 48 77 40 49 59 27 52 17 22 78 80 81 80 8 93 50 7 87 57 29 16 89 55 20 7 51 54 30 98 44 96 27 70 1 1 32 61 22 92 84 98 31 89 91 90 28 56 49 25 86 49 55 16 19 1 18 8 88 47 16 18 73 86 2 96 16 91 74 49 38 98 94 25 34 85 29 27 99 31 31 58",
"output": "97"
},
{
"input": "100 9\n36 4 45 16 19 6 10 87 44 82 71 49 70 35 83 19 40 76 45 94 44 96 10 54 82 77 86 63 11 37 21 3 15 89 80 88 89 16 72 23 25 9 51 25 10 45 96 5 6 18 51 31 42 57 41 51 42 15 89 61 45 82 16 48 61 67 19 40 9 33 90 36 78 36 79 79 16 10 83 87 9 22 84 12 23 76 36 14 2 81 56 33 56 23 57 84 76 55 35 88",
"output": "47"
},
{
"input": "100 10\n75 81 39 64 90 58 92 28 75 9 96 78 92 83 77 68 76 71 14 46 58 60 80 25 78 11 13 63 22 82 65 68 47 6 33 63 90 50 85 43 73 94 80 48 67 11 83 17 22 15 94 80 66 99 66 4 46 35 52 1 62 39 96 57 37 47 97 49 64 12 36 63 90 16 4 75 85 82 85 56 13 4 92 45 44 93 17 35 22 46 18 44 29 7 52 4 100 98 87 51",
"output": "98"
},
{
"input": "100 20\n21 19 61 70 54 97 98 14 61 72 25 94 24 56 55 25 12 80 76 11 35 17 80 26 11 94 52 47 84 61 10 2 74 25 10 21 2 79 55 50 30 75 10 64 44 5 60 96 52 16 74 41 20 77 20 44 8 86 74 36 49 61 99 13 54 64 19 99 50 43 12 73 48 48 83 55 72 73 63 81 30 27 95 9 97 82 24 3 89 90 33 14 47 88 22 78 12 75 58 67",
"output": "94"
},
{
"input": "100 30\n56 79 59 23 11 23 67 82 81 80 99 79 8 58 93 36 98 81 46 39 34 67 3 50 4 68 70 71 2 21 52 30 75 23 33 21 16 100 56 43 8 27 40 8 56 24 17 40 94 10 67 49 61 36 95 87 17 41 7 94 33 19 17 50 26 11 94 54 38 46 77 9 53 35 98 42 50 20 43 6 78 6 38 24 100 45 43 16 1 50 16 46 14 91 95 88 10 1 50 19",
"output": "95"
},
{
"input": "100 40\n86 11 97 17 38 95 11 5 13 83 67 75 50 2 46 39 84 68 22 85 70 23 64 46 59 93 39 80 35 78 93 21 83 19 64 1 49 59 99 83 44 81 70 58 15 82 83 47 55 65 91 10 2 92 4 77 37 32 12 57 78 11 42 8 59 21 96 69 61 30 44 29 12 70 91 14 10 83 11 75 14 10 19 39 8 98 5 81 66 66 79 55 36 29 22 45 19 24 55 49",
"output": "88"
},
{
"input": "100 50\n22 39 95 69 94 53 80 73 33 90 40 60 2 4 84 50 70 38 92 12 36 74 87 70 51 36 57 5 54 6 35 81 52 17 55 100 95 81 32 76 21 1 100 1 95 1 40 91 98 59 84 19 11 51 79 19 47 86 45 15 62 2 59 77 31 68 71 92 17 33 10 33 85 57 5 2 88 97 91 99 63 20 63 54 79 93 24 62 46 27 30 87 3 64 95 88 16 50 79 1",
"output": "99"
},
{
"input": "100 70\n61 48 89 17 97 6 93 13 64 50 66 88 24 52 46 99 6 65 93 64 82 37 57 41 47 1 84 5 97 83 79 46 16 35 40 7 64 15 44 96 37 17 30 92 51 67 26 3 14 56 27 68 66 93 36 39 51 6 40 55 79 26 71 54 8 48 18 2 71 12 55 60 29 37 31 97 26 37 25 68 67 70 3 87 100 41 5 82 65 92 24 66 76 48 89 8 40 93 31 95",
"output": "100"
},
{
"input": "100 90\n87 32 30 15 10 52 93 63 84 1 82 41 27 51 75 32 42 94 39 53 70 13 4 22 99 35 44 38 5 23 18 100 61 80 9 12 42 93 9 77 3 7 60 95 66 78 95 42 69 8 1 88 93 66 96 20 76 63 15 36 92 52 2 72 36 57 48 63 29 20 74 88 49 47 81 61 94 74 70 93 47 3 19 52 59 41 5 40 22 3 76 97 91 37 95 88 91 99 76 15",
"output": "98"
},
{
"input": "100 100\n79 75 7 28 6 96 38 35 57 95 41 74 24 96 32 78 81 13 63 84 24 95 3 23 66 1 60 6 96 49 41 5 14 18 31 97 66 19 49 89 49 70 51 28 20 99 18 1 28 77 24 46 69 21 40 32 31 66 28 6 66 97 9 16 70 90 91 30 34 82 93 41 65 11 39 52 1 88 63 43 80 50 60 49 28 56 18 76 24 57 74 1 28 99 36 35 79 54 18 16",
"output": "100"
},
{
"input": "1 3\n5",
"output": "1"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 3\n4 2",
"output": "1"
},
{
"input": "2 5\n99 97",
"output": "2"
},
{
"input": "3 4\n7 5 2",
"output": "2"
},
{
"input": "3 50\n47 86 51",
"output": "3"
},
{
"input": "5 100\n82 100 85 1 37",
"output": "5"
},
{
"input": "5 20\n40 39 21 5 20",
"output": "3"
},
{
"input": "1 27\n81",
"output": "1"
},
{
"input": "20 13\n7 8 29 83 74 28 93 85 7 8 3 9 8 70 49 50 39 41 57 1",
"output": "7"
},
{
"input": "2 1\n100 2",
"output": "1"
},
{
"input": "2 2\n6 4",
"output": "1"
},
{
"input": "5 2\n6 4 4 1 1",
"output": "1"
},
{
"input": "1 4\n3",
"output": "1"
},
{
"input": "3 2\n1 5 3",
"output": "2"
},
{
"input": "3 1\n3 2 2",
"output": "1"
},
{
"input": "3 1\n2 3 2",
"output": "2"
},
{
"input": "5 1\n5 1 1 1 1",
"output": "1"
},
{
"input": "2 3\n7 4",
"output": "1"
}
] | 1,689,903,282 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 46 | 307,200 | from collections import deque
_, m = map(int, input().split())
vls = list(map(int, input().split()))
cola = deque()
for i, v in enumerate(vls):
cola.append([i + 1, v])
while len(cola) != 1:
x = cola.popleft()
if x[1] > m:
cola.append([x[0], x[1] - m])
print(cola.pop()[0])
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:
1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty.
Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?
Input Specification:
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output Specification:
Output a single integer, representing the number of the last child.
Demo Input:
['5 2\n1 3 1 4 2\n', '6 4\n1 1 2 2 3 3\n']
Demo Output:
['4\n', '6\n']
Note:
Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.
Child 4 is the last one who goes home. | ```python
from collections import deque
_, m = map(int, input().split())
vls = list(map(int, input().split()))
cola = deque()
for i, v in enumerate(vls):
cola.append([i + 1, v])
while len(cola) != 1:
x = cola.popleft()
if x[1] > m:
cola.append([x[0], x[1] - m])
print(cola.pop()[0])
``` | 3 |
|
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan. | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters. | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",
"output": "Impossible"
},
{
"input": "|\nZXCVBANMIO",
"output": "XVAMO|ZCBNI"
},
{
"input": "|C\nA",
"output": "A|C"
},
{
"input": "|\nAB",
"output": "B|A"
},
{
"input": "A|XYZ\nUIOPL",
"output": "Impossible"
},
{
"input": "K|B\nY",
"output": "Impossible"
},
{
"input": "EQJWDOHKZRBISPLXUYVCMNFGT|\nA",
"output": "Impossible"
},
{
"input": "|MACKERIGZPVHNDYXJBUFLWSO\nQT",
"output": "Impossible"
},
{
"input": "ERACGIZOVPT|WXUYMDLJNQS\nKB",
"output": "ERACGIZOVPTB|WXUYMDLJNQSK"
},
{
"input": "CKQHRUZMISGE|FBVWPXDLTJYN\nOA",
"output": "CKQHRUZMISGEA|FBVWPXDLTJYNO"
},
{
"input": "V|CMOEUTAXBFWSK\nDLRZJGIYNQHP",
"output": "VDLRZJGIYNQHP|CMOEUTAXBFWSK"
},
{
"input": "QWHNMALDGKTJ|\nPBRYVXZUESCOIF",
"output": "QWHNMALDGKTJF|PBRYVXZUESCOI"
},
{
"input": "|\nFXCVMUEWZAHNDOSITPRLKQJYBG",
"output": "XVUWANOIPLQYG|FCMEZHDSTRKJB"
},
{
"input": "IB|PCGHZ\nFXWTJQNEKAUM",
"output": "Impossible"
},
{
"input": "EC|IWAXQ\nJUHSRKGZTOMYN",
"output": "ECJUHRGTMN|IWAXQSKZOY"
},
{
"input": "VDINYMA|UQKWBCLRHZJ\nXEGOF",
"output": "Impossible"
},
{
"input": "ZLTPSIQUBAR|XFDEMYC\nHNOJWG",
"output": "ZLTPSIQUBARG|XFDEMYCHNOJW"
},
{
"input": "R|FLZOTJNU\nGIYHKVX",
"output": "RGIYHKVX|FLZOTJNU"
},
{
"input": "W|TL\nQROFSADYPKHEJNMXBZVUCIG",
"output": "WQOSDPHJMBVCG|TLRFAYKENXZUI"
},
{
"input": "NRDFQSEKLAYMOT|ZH\nGUXIBJCVPW",
"output": "Impossible"
},
{
"input": "FGRT|\nAC",
"output": "Impossible"
},
{
"input": "|FGRT\nAC",
"output": "Impossible"
},
{
"input": "A|\nB",
"output": "A|B"
},
{
"input": "|A\nB",
"output": "B|A"
},
{
"input": "|\nA",
"output": "Impossible"
},
{
"input": "|\nQWERTYUIOPASDFGHJKLZXCVBNM",
"output": "WRYIPSFHKZCBM|QETUOADGJLXVN"
},
{
"input": "QWERTYUIOPASDFGHJKLZXCVBN|\nM",
"output": "Impossible"
},
{
"input": "QWERTY|VBN\nUIOPASDFGHJKLZXC",
"output": "Impossible"
},
{
"input": "ABC|D\nKSL",
"output": "Impossible"
},
{
"input": "A|BCDEF\nGH",
"output": "Impossible"
},
{
"input": "|ABC\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDE",
"output": "Impossible"
},
{
"input": "|ASD\nX",
"output": "Impossible"
},
{
"input": "AB|CDEF\nXYZRT",
"output": "Impossible"
}
] | 1,599,151,555 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | #
# Author: eloyhz
# Date: Sep/03/2020
#
if __name__ == '__main__':
scales = input()
left = scales.find('|')
right = len(scales) - (left + 1)
rest = input()
if left + len(rest) == right:
scales = rest + scales
elif left == right + len(rest):
scales += rest
else:
scales = 'Impossible'
print(scales)
| Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.
Input Specification:
The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.
The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.
It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.
Output Specification:
If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them.
Demo Input:
['AC|T\nL\n', '|ABC\nXYZ\n', 'W|T\nF\n', 'ABC|\nD\n']
Demo Output:
['AC|TL\n', 'XYZ|ABC\n', 'Impossible\n', 'Impossible\n']
Note:
none | ```python
#
# Author: eloyhz
# Date: Sep/03/2020
#
if __name__ == '__main__':
scales = input()
left = scales.find('|')
right = len(scales) - (left + 1)
rest = input()
if left + len(rest) == right:
scales = rest + scales
elif left == right + len(rest):
scales += rest
else:
scales = 'Impossible'
print(scales)
``` | 0 |
|
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1 "
},
{
"input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7",
"output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 "
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39",
"output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 "
},
{
"input": "2\n2 1",
"output": "2 \n1 "
}
] | 1,679,829,261 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 374 | 16,179,200 | n = int(input())
snacks = {int(num): day for day, num in enumerate(input().split(" "))}
days = [[] for _ in range(n)]
sorted_snacks = sorted(snacks, reverse=True)
current_day = None
for snack in sorted_snacks:
snack_day = snacks[snack]
if current_day is None:
current_day = snack_day
if snack_day > current_day:
current_day = snack_day
days[current_day].append(snack)
for day in days:
if not day:
print("")
else:
print(" ".join([str(snack) for snack in day]))
| Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.
Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.
However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.
Write a program that models the behavior of Ankh-Morpork residents.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Output Specification:
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
Demo Input:
['3\n3 1 2\n', '5\n4 5 1 2 3\n']
Demo Output:
['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n']
Note:
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before. | ```python
n = int(input())
snacks = {int(num): day for day, num in enumerate(input().split(" "))}
days = [[] for _ in range(n)]
sorted_snacks = sorted(snacks, reverse=True)
current_day = None
for snack in sorted_snacks:
snack_day = snacks[snack]
if current_day is None:
current_day = snack_day
if snack_day > current_day:
current_day = snack_day
days[current_day].append(snack)
for day in days:
if not day:
print("")
else:
print(" ".join([str(snack) for snack in day]))
``` | 3 |
|
746 | A | Compote | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. | The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. | Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. | [
"2\n5\n7\n",
"4\n7\n13\n",
"2\n3\n2\n"
] | [
"7\n",
"21\n",
"0\n"
] | In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | 500 | [
{
"input": "2\n5\n7",
"output": "7"
},
{
"input": "4\n7\n13",
"output": "21"
},
{
"input": "2\n3\n2",
"output": "0"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n4",
"output": "7"
},
{
"input": "1000\n1000\n1000",
"output": "1750"
},
{
"input": "1\n1\n4",
"output": "0"
},
{
"input": "1\n2\n3",
"output": "0"
},
{
"input": "1\n1000\n1000",
"output": "7"
},
{
"input": "1000\n1\n1000",
"output": "0"
},
{
"input": "1000\n2\n1000",
"output": "7"
},
{
"input": "1000\n500\n1000",
"output": "1750"
},
{
"input": "1000\n1000\n4",
"output": "7"
},
{
"input": "1000\n1000\n3",
"output": "0"
},
{
"input": "4\n8\n12",
"output": "21"
},
{
"input": "10\n20\n40",
"output": "70"
},
{
"input": "100\n200\n399",
"output": "693"
},
{
"input": "200\n400\n800",
"output": "1400"
},
{
"input": "199\n400\n800",
"output": "1393"
},
{
"input": "201\n400\n800",
"output": "1400"
},
{
"input": "200\n399\n800",
"output": "1393"
},
{
"input": "200\n401\n800",
"output": "1400"
},
{
"input": "200\n400\n799",
"output": "1393"
},
{
"input": "200\n400\n801",
"output": "1400"
},
{
"input": "139\n252\n871",
"output": "882"
},
{
"input": "109\n346\n811",
"output": "763"
},
{
"input": "237\n487\n517",
"output": "903"
},
{
"input": "161\n331\n725",
"output": "1127"
},
{
"input": "39\n471\n665",
"output": "273"
},
{
"input": "9\n270\n879",
"output": "63"
},
{
"input": "137\n422\n812",
"output": "959"
},
{
"input": "15\n313\n525",
"output": "105"
},
{
"input": "189\n407\n966",
"output": "1323"
},
{
"input": "18\n268\n538",
"output": "126"
},
{
"input": "146\n421\n978",
"output": "1022"
},
{
"input": "70\n311\n685",
"output": "490"
},
{
"input": "244\n405\n625",
"output": "1092"
},
{
"input": "168\n454\n832",
"output": "1176"
},
{
"input": "46\n344\n772",
"output": "322"
},
{
"input": "174\n438\n987",
"output": "1218"
},
{
"input": "144\n387\n693",
"output": "1008"
},
{
"input": "22\n481\n633",
"output": "154"
},
{
"input": "196\n280\n848",
"output": "980"
},
{
"input": "190\n454\n699",
"output": "1218"
},
{
"input": "231\n464\n928",
"output": "1617"
},
{
"input": "151\n308\n616",
"output": "1057"
},
{
"input": "88\n182\n364",
"output": "616"
},
{
"input": "12\n26\n52",
"output": "84"
},
{
"input": "204\n412\n824",
"output": "1428"
},
{
"input": "127\n256\n512",
"output": "889"
},
{
"input": "224\n446\n896",
"output": "1561"
},
{
"input": "146\n291\n584",
"output": "1015"
},
{
"input": "83\n164\n332",
"output": "574"
},
{
"input": "20\n38\n80",
"output": "133"
},
{
"input": "198\n393\n792",
"output": "1372"
},
{
"input": "120\n239\n480",
"output": "833"
},
{
"input": "208\n416\n831",
"output": "1449"
},
{
"input": "130\n260\n517",
"output": "903"
},
{
"input": "67\n134\n267",
"output": "462"
},
{
"input": "245\n490\n979",
"output": "1708"
},
{
"input": "182\n364\n727",
"output": "1267"
},
{
"input": "104\n208\n413",
"output": "721"
},
{
"input": "10\n2\n100",
"output": "7"
},
{
"input": "2\n100\n100",
"output": "14"
},
{
"input": "2\n3\n8",
"output": "7"
},
{
"input": "1\n2\n8",
"output": "7"
},
{
"input": "1\n2\n200",
"output": "7"
},
{
"input": "5\n4\n16",
"output": "14"
},
{
"input": "1\n10\n10",
"output": "7"
},
{
"input": "1\n4\n8",
"output": "7"
},
{
"input": "100\n4\n1000",
"output": "14"
},
{
"input": "2\n6\n12",
"output": "14"
},
{
"input": "10\n7\n4",
"output": "7"
},
{
"input": "2\n10\n100",
"output": "14"
},
{
"input": "2\n3\n4",
"output": "7"
},
{
"input": "1\n2\n999",
"output": "7"
},
{
"input": "1\n10\n20",
"output": "7"
},
{
"input": "100\n18\n20",
"output": "35"
},
{
"input": "100\n1\n100",
"output": "0"
},
{
"input": "3\n7\n80",
"output": "21"
},
{
"input": "2\n8\n24",
"output": "14"
},
{
"input": "1\n100\n100",
"output": "7"
},
{
"input": "2\n1\n8",
"output": "0"
},
{
"input": "10\n5\n23",
"output": "14"
}
] | 1,619,617,592 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 77 | 0 | a=int(input())
b=int(input())
c=int(input())
count=0
for i in range(a):
if a>=1 and b>=2 and c>=4:
a-=1
b-=2
c-=4
count+=1
if count!=0:
print(7*count)
else:
print(0)
| Title: Compote
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits.
Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
Input Specification:
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has.
The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has.
The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Output Specification:
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
Demo Input:
['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n']
Demo Output:
['7\n', '21\n', '0\n']
Note:
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7.
In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21.
In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. | ```python
a=int(input())
b=int(input())
c=int(input())
count=0
for i in range(a):
if a>=1 and b>=2 and c>=4:
a-=1
b-=2
c-=4
count+=1
if count!=0:
print(7*count)
else:
print(0)
``` | 3 |
|
660 | A | Co-prime Array | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them. | [
"3\n2 7 28\n"
] | [
"1\n2 7 9 28\n"
] | none | 0 | [
{
"input": "3\n2 7 28",
"output": "1\n2 7 1 28"
},
{
"input": "1\n1",
"output": "0\n1"
},
{
"input": "1\n548",
"output": "0\n548"
},
{
"input": "1\n963837006",
"output": "0\n963837006"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "0\n1 1 1 1 1 1 1 1 1 1"
},
{
"input": "10\n26 723 970 13 422 968 875 329 234 983",
"output": "2\n26 723 970 13 422 1 968 875 1 329 234 983"
},
{
"input": "10\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396",
"output": "7\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396"
},
{
"input": "100\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1",
"output": "19\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1"
},
{
"input": "100\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917",
"output": "38\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917"
},
{
"input": "5\n472882027 472882027 472882027 472882027 472882027",
"output": "4\n472882027 1 472882027 1 472882027 1 472882027 1 472882027"
},
{
"input": "2\n1000000000 1000000000",
"output": "1\n1000000000 1 1000000000"
},
{
"input": "2\n8 6",
"output": "1\n8 1 6"
},
{
"input": "3\n100000000 1000000000 1000000000",
"output": "2\n100000000 1 1000000000 1 1000000000"
},
{
"input": "5\n1 2 3 4 5",
"output": "0\n1 2 3 4 5"
},
{
"input": "20\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000",
"output": "19\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000"
},
{
"input": "2\n223092870 23",
"output": "1\n223092870 1 23"
},
{
"input": "2\n100000003 100000003",
"output": "1\n100000003 1 100000003"
},
{
"input": "2\n999999937 999999937",
"output": "1\n999999937 1 999999937"
},
{
"input": "4\n999 999999937 999999937 999",
"output": "1\n999 999999937 1 999999937 999"
},
{
"input": "2\n999999929 999999929",
"output": "1\n999999929 1 999999929"
},
{
"input": "2\n1049459 2098918",
"output": "1\n1049459 1 2098918"
},
{
"input": "2\n352229 704458",
"output": "1\n352229 1 704458"
},
{
"input": "2\n7293 4011",
"output": "1\n7293 1 4011"
},
{
"input": "2\n5565651 3999930",
"output": "1\n5565651 1 3999930"
},
{
"input": "2\n997 997",
"output": "1\n997 1 997"
},
{
"input": "3\n9994223 9994223 9994223",
"output": "2\n9994223 1 9994223 1 9994223"
},
{
"input": "2\n99999998 1000000000",
"output": "1\n99999998 1 1000000000"
},
{
"input": "3\n1000000000 1000000000 1000000000",
"output": "2\n1000000000 1 1000000000 1 1000000000"
},
{
"input": "2\n130471 130471",
"output": "1\n130471 1 130471"
},
{
"input": "3\n1000000000 2 2",
"output": "2\n1000000000 1 2 1 2"
},
{
"input": "2\n223092870 66526",
"output": "1\n223092870 1 66526"
},
{
"input": "14\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449",
"output": "10\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449"
},
{
"input": "2\n3996017 3996017",
"output": "1\n3996017 1 3996017"
},
{
"input": "2\n999983 999983",
"output": "1\n999983 1 999983"
},
{
"input": "2\n618575685 773990454",
"output": "1\n618575685 1 773990454"
},
{
"input": "3\n9699690 3 7",
"output": "1\n9699690 1 3 7"
},
{
"input": "2\n999999999 999999996",
"output": "1\n999999999 1 999999996"
},
{
"input": "2\n99999910 99999910",
"output": "1\n99999910 1 99999910"
},
{
"input": "12\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491",
"output": "9\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491"
},
{
"input": "3\n999999937 999999937 999999937",
"output": "2\n999999937 1 999999937 1 999999937"
},
{
"input": "2\n99839 99839",
"output": "1\n99839 1 99839"
},
{
"input": "3\n19999909 19999909 19999909",
"output": "2\n19999909 1 19999909 1 19999909"
},
{
"input": "4\n1 1000000000 1 1000000000",
"output": "0\n1 1000000000 1 1000000000"
},
{
"input": "2\n64006 64006",
"output": "1\n64006 1 64006"
},
{
"input": "2\n1956955 1956955",
"output": "1\n1956955 1 1956955"
},
{
"input": "3\n1 1000000000 1000000000",
"output": "1\n1 1000000000 1 1000000000"
},
{
"input": "2\n982451707 982451707",
"output": "1\n982451707 1 982451707"
},
{
"input": "2\n999999733 999999733",
"output": "1\n999999733 1 999999733"
},
{
"input": "3\n999999733 999999733 999999733",
"output": "2\n999999733 1 999999733 1 999999733"
},
{
"input": "2\n3257 3257",
"output": "1\n3257 1 3257"
},
{
"input": "2\n223092870 181598",
"output": "1\n223092870 1 181598"
},
{
"input": "3\n959919409 105935 105935",
"output": "2\n959919409 1 105935 1 105935"
},
{
"input": "2\n510510 510510",
"output": "1\n510510 1 510510"
},
{
"input": "3\n223092870 1000000000 1000000000",
"output": "2\n223092870 1 1000000000 1 1000000000"
},
{
"input": "14\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000",
"output": "11\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000"
},
{
"input": "7\n1 982451653 982451653 1 982451653 982451653 982451653",
"output": "3\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653"
},
{
"input": "2\n100000007 100000007",
"output": "1\n100000007 1 100000007"
},
{
"input": "3\n999999757 999999757 999999757",
"output": "2\n999999757 1 999999757 1 999999757"
},
{
"input": "3\n99999989 99999989 99999989",
"output": "2\n99999989 1 99999989 1 99999989"
},
{
"input": "5\n2 4 982451707 982451707 3",
"output": "2\n2 1 4 982451707 1 982451707 3"
},
{
"input": "2\n20000014 20000014",
"output": "1\n20000014 1 20000014"
},
{
"input": "2\n99999989 99999989",
"output": "1\n99999989 1 99999989"
},
{
"input": "2\n111546435 111546435",
"output": "1\n111546435 1 111546435"
},
{
"input": "2\n55288874 33538046",
"output": "1\n55288874 1 33538046"
},
{
"input": "5\n179424673 179424673 179424673 179424673 179424673",
"output": "4\n179424673 1 179424673 1 179424673 1 179424673 1 179424673"
},
{
"input": "2\n199999978 199999978",
"output": "1\n199999978 1 199999978"
},
{
"input": "2\n1000000000 2",
"output": "1\n1000000000 1 2"
},
{
"input": "3\n19999897 19999897 19999897",
"output": "2\n19999897 1 19999897 1 19999897"
},
{
"input": "2\n19999982 19999982",
"output": "1\n19999982 1 19999982"
},
{
"input": "2\n10000007 10000007",
"output": "1\n10000007 1 10000007"
},
{
"input": "3\n999999937 999999937 2",
"output": "1\n999999937 1 999999937 2"
},
{
"input": "5\n2017 2017 2017 2017 2017",
"output": "4\n2017 1 2017 1 2017 1 2017 1 2017"
},
{
"input": "2\n19999909 39999818",
"output": "1\n19999909 1 39999818"
},
{
"input": "2\n62615533 7919",
"output": "1\n62615533 1 7919"
},
{
"input": "5\n39989 39989 33 31 29",
"output": "1\n39989 1 39989 33 31 29"
},
{
"input": "2\n1000000000 100000",
"output": "1\n1000000000 1 100000"
},
{
"input": "2\n1938 10010",
"output": "1\n1938 1 10010"
},
{
"input": "2\n199999 199999",
"output": "1\n199999 1 199999"
},
{
"input": "2\n107273 107273",
"output": "1\n107273 1 107273"
},
{
"input": "3\n49999 49999 49999",
"output": "2\n49999 1 49999 1 49999"
},
{
"input": "2\n1999966 1999958",
"output": "1\n1999966 1 1999958"
},
{
"input": "2\n86020 300846",
"output": "1\n86020 1 300846"
},
{
"input": "2\n999999997 213",
"output": "1\n999999997 1 213"
},
{
"input": "2\n200000014 200000434",
"output": "1\n200000014 1 200000434"
}
] | 1,693,586,062 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 93 | 155 | 3,072,000 | def primeFactors(n):
factors = []
i = 2
while n > 1:
while n % i == 0:
factors.append(i)
n //= i
i += 1
if i * i > n : break
if n > 1:
factors.append(n)
return factors
def areCoprime(n1,n2):
n1Factors = primeFactors(n1)
areCoprime = True
for f in n1Factors:
if n2 % f == 0:
areCoprime = False
break
return areCoprime
def sieve(n):
primes = [True for i in range(n+1)]
primeNums = []
p = 2
while p * p <= n:
if primes[p]:
for i in range(p*p,n+1,p):
primes[i] = False
p += 1
for i in range(2,n+1):
if primes[i]:
primeNums.append(i)
return primeNums
n = int(input())
A = list(map(int,input().split()))
k = 0
added = {}
primes = sieve(10**5) # esse valor foi um chute, n dá pra gerar todos os fatores até 10^9
for i in range(1,len(A)):
checkCoprime = areCoprime(A[i],A[i-1])
factor = -1
if not checkCoprime:
k += 1
for p in primes:
if A[i] % p != 0 and A[i-1] % p != 0:
factor = p
break
added[i] = factor
print(k)
out = f"{A[0]} "
for i in range(1,len(A)):
if i in added:
out += f"{str(added[i])} "
out += str(A[i])
if i < len(A) - 1:
out += " "
print(out)
| Title: Co-prime Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 109 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Output Specification:
Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime.
The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it.
If there are multiple answers you can print any one of them.
Demo Input:
['3\n2 7 28\n']
Demo Output:
['1\n2 7 9 28\n']
Note:
none | ```python
def primeFactors(n):
factors = []
i = 2
while n > 1:
while n % i == 0:
factors.append(i)
n //= i
i += 1
if i * i > n : break
if n > 1:
factors.append(n)
return factors
def areCoprime(n1,n2):
n1Factors = primeFactors(n1)
areCoprime = True
for f in n1Factors:
if n2 % f == 0:
areCoprime = False
break
return areCoprime
def sieve(n):
primes = [True for i in range(n+1)]
primeNums = []
p = 2
while p * p <= n:
if primes[p]:
for i in range(p*p,n+1,p):
primes[i] = False
p += 1
for i in range(2,n+1):
if primes[i]:
primeNums.append(i)
return primeNums
n = int(input())
A = list(map(int,input().split()))
k = 0
added = {}
primes = sieve(10**5) # esse valor foi um chute, n dá pra gerar todos os fatores até 10^9
for i in range(1,len(A)):
checkCoprime = areCoprime(A[i],A[i-1])
factor = -1
if not checkCoprime:
k += 1
for p in primes:
if A[i] % p != 0 and A[i-1] % p != 0:
factor = p
break
added[i] = factor
print(k)
out = f"{A[0]} "
for i in range(1,len(A)):
if i in added:
out += f"{str(added[i])} "
out += str(A[i])
if i < len(A) - 1:
out += " "
print(out)
``` | 3 |
|
447 | A | DZY Loves Hash | PROGRAMMING | 800 | [
"implementation"
] | null | null | DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1. | The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109). | Output a single integer — the answer to the problem. | [
"10 5\n0\n21\n53\n41\n53\n",
"5 5\n0\n1\n2\n3\n4\n"
] | [
"4\n",
"-1\n"
] | none | 500 | [
{
"input": "10 5\n0\n21\n53\n41\n53",
"output": "4"
},
{
"input": "5 5\n0\n1\n2\n3\n4",
"output": "-1"
},
{
"input": "10 6\n811966798\n734823552\n790326404\n929189974\n414343256\n560346537",
"output": "4"
},
{
"input": "2 2\n788371161\n801743052",
"output": "-1"
},
{
"input": "10 6\n812796223\n122860157\n199259103\n597650585\n447742024\n521549402",
"output": "3"
},
{
"input": "300 2\n822454942\n119374431",
"output": "-1"
},
{
"input": "300 2\n823284367\n507345500",
"output": "-1"
},
{
"input": "2 5\n791579811\n35613889\n997079893\n878677665\n693717467",
"output": "2"
},
{
"input": "20 5\n793926268\n28931770\n842870287\n974950617\n859404206",
"output": "-1"
},
{
"input": "100 15\n805069249\n778178198\n633897389\n844316223\n146759898\n870527016\n82668754\n42060733\n943602929\n979451110\n746979598\n47406033\n607284062\n850870259\n229415316",
"output": "5"
},
{
"input": "100 15\n806204335\n189490323\n718805086\n716787474\n262315718\n822030596\n894644222\n724054623\n141384399\n579354205\n192622443\n672556242\n97417563\n243354557\n208957882",
"output": "8"
},
{
"input": "100 15\n807033760\n577461392\n275221433\n532633429\n295714486\n783298996\n255799943\n99107143\n729119412\n59302896\n37640015\n313610861\n630550567\n534283052\n681062462",
"output": "8"
},
{
"input": "100 15\n808103310\n136224397\n360129131\n405104681\n263786657\n734802577\n67808179\n928584682\n926900882\n511722343\n483348395\n938695534\n120684068\n74152694\n808088675",
"output": "9"
},
{
"input": "2 2\n2\n2",
"output": "2"
},
{
"input": "300 2\n0\n300",
"output": "2"
},
{
"input": "2 2\n0\n0",
"output": "2"
}
] | 1,696,255,421 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | p, n = map(int, input().split())
hash_table = [False] * p
ans = -1
for i in range(n):
x = int(input())
if ans == -1:
if hash_table[x % p]: ans = i + 1
hash_table[x % p] = True
print(ans) | Title: DZY Loves Hash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY has a hash table with *p* buckets, numbered from 0 to *p*<=-<=1. He wants to insert *n* numbers, in the order they are given, into the hash table. For the *i*-th number *x**i*, DZY will put it into the bucket numbered *h*(*x**i*), where *h*(*x*) is the hash function. In this problem we will assume, that *h*(*x*)<==<=*x* *mod* *p*. Operation *a* *mod* *b* denotes taking a remainder after division *a* by *b*.
However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the *i*-th insertion, you should output *i*. If no conflict happens, just output -1.
Input Specification:
The first line contains two integers, *p* and *n* (2<=≤<=*p*,<=*n*<=≤<=300). Then *n* lines follow. The *i*-th of them contains an integer *x**i* (0<=≤<=*x**i*<=≤<=109).
Output Specification:
Output a single integer — the answer to the problem.
Demo Input:
['10 5\n0\n21\n53\n41\n53\n', '5 5\n0\n1\n2\n3\n4\n']
Demo Output:
['4\n', '-1\n']
Note:
none | ```python
p, n = map(int, input().split())
hash_table = [False] * p
ans = -1
for i in range(n):
x = int(input())
if ans == -1:
if hash_table[x % p]: ans = i + 1
hash_table[x % p] = True
print(ans)
``` | 3 |
|
386 | C | Diverse Substrings | PROGRAMMING | 2,000 | [
"dp",
"strings",
"two pointers"
] | null | null | String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3.
Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to *d*(*s*). Find statistics about substrings diversity: for each *k* from 1 to *d*(*s*), find how many substrings of *s* has a diversity of exactly *k*. | The input consists of a single line containing *s*. It contains only lowercase Latin letters, the length of *s* is from 1 to 3·105. | Print to the first line the value *d*(*s*). Print sequence *t*1,<=*t*2,<=...,<=*t**d*(*s*) to the following lines, where *t**i* is the number of substrings of *s* having diversity of exactly *i*. | [
"abca\n",
"aabacaabbad\n"
] | [
"3\n4\n3\n3\n",
"4\n14\n19\n28\n5\n"
] | Consider the first example.
We denote by *s*(*i*, *j*) a substring of "abca" with the indices in the segment [*i*, *j*].
- *s*(1, 1) = "a", *d*("a") = 1 - *s*(2, 2) = "b", *d*("b") = 1 - *s*(3, 3) = "c", *d*("c") = 1 - *s*(4, 4) = "a", *d*("a") = 1 - *s*(1, 2) = "ab", *d*("ab") = 2 - *s*(2, 3) = "bc", *d*("bc") = 2 - *s*(3, 4) = "ca", *d*("ca") = 2 - *s*(1, 3) = "abc", *d*("abc") = 3 - *s*(2, 4) = "bca", *d*("bca") = 3 - *s*(1, 4) = "abca", *d*("abca") = 3
Total number of substring with diversity 1 is 4, with diversity 2 equals 3, 3 diversity is 3. | 1,500 | [
{
"input": "abca",
"output": "3\n4\n3\n3"
},
{
"input": "aabacaabbad",
"output": "4\n14\n19\n28\n5"
},
{
"input": "a",
"output": "1\n1"
},
{
"input": "cabaccbcaa",
"output": "3\n12\n13\n30"
},
{
"input": "ccabaccbbb",
"output": "3\n15\n13\n27"
},
{
"input": "accbbaabaa",
"output": "3\n14\n24\n17"
},
{
"input": "bdbdeabeecddebabaebbcaeabeabcadcbcacebdebaaadbcebabacdedbadadbcbdeccabecbecedcbdadbaabdaaaeebbdddcde",
"output": "5\n116\n140\n215\n377\n4202"
},
{
"input": "faaacffcdacdbafffebbaecbbddadbafcddfbbafbebedafcbbccdefcfcddbdefbaabbeacbdcadfdfbeffdbccdbbcefdbeacf",
"output": "6\n120\n138\n171\n226\n469\n3926"
},
{
"input": "ccdfadbdcdadgcgabgcebbccebeabbcebeeacabcbcbdgebabeebbbbecgedecedbeabceegdbbaggagggfgbddgddaaaafeggad",
"output": "7\n127\n166\n208\n394\n478\n2183\n1494"
},
{
"input": "bbcbcaabaccbbbbbccbccbabcaacbacbacacbacbaabbcaccaabccabcaacababcabbacaacccbcbbbcccbacbcbaccbbbaaccca",
"output": "3\n141\n268\n4641"
},
{
"input": "edcdedddbceddbbccceecbdebdaeadeaaeedbdbbbcdaaabaccaadabdcaeeecbdadbebdbeceedbdedcecadecbdeccdeacedce",
"output": "5\n124\n157\n221\n676\n3872"
},
{
"input": "bacebgfbaceddfbfbddaadfgadfcgdfcbeefdfafggadgbfeebcgafefedafgaebafbaadedbffdgcdfacaegeacecgbeabggfed",
"output": "7\n109\n123\n149\n214\n304\n424\n3727"
},
{
"input": "gefighcgdehbaidhajhfhhigfgdbhabejcadbdbecfiabgjdecedbcicggfdajahjgbdbfheggibhieijdjihcfgbbbchddjdcci",
"output": "10\n108\n120\n126\n142\n149\n186\n223\n271\n680\n3045"
},
{
"input": "oqhvuewbdwqslxqigksfkuykyrfnzpbjdispjazvmyvbthdoquzeldlxuzjowjoxebgogjwhxgordphgbmtrkfooknjvjigskskz",
"output": "25\n101\n107\n114\n110\n117\n127\n137\n152\n148\n140\n172\n152\n172\n186\n173\n186\n183\n198\n202\n181\n194\n214\n174\n224\n1186"
},
{
"input": "cbbaacbaba",
"output": "3\n12\n15\n28"
},
{
"input": "acabaaabbc",
"output": "3\n14\n22\n19"
},
{
"input": "bccbcabaaa",
"output": "3\n14\n17\n24"
},
{
"input": "cbbcaaaabc",
"output": "3\n17\n14\n24"
},
{
"input": "caacbbbbab",
"output": "3\n17\n18\n20"
},
{
"input": "bbbbaccbac",
"output": "3\n17\n10\n28"
}
] | 1,695,297,284 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
set<char> st;
vector<int> vec[26];
int it[26] = {0};
ll ans[26] = {0};
cin >> s;
int n = (int)s.size();
for(int i=0;i<n;i++){
st.insert(s[i]);
vec[s[i]-'a'].push_back(i);
}
for(int i=0;i<n;i++){
vector<int> vec2;
for(int j=0;j<26;j++){
if(it[j] < (int)vec[j].size()){
vec2.push_back(vec[j][it[j]]);
}
}
sort(vec2.begin(), vec2.end());
vec2.push_back(n);
int cur = 0;
int pos = i;
for(auto v : vec2){
ans[cur] += v-pos;
pos = v;
cur++;
}
it[s[i]-'a']++;
}
cout << st.size() << "\n";
for(int i=1;i<=(int)st.size();i++){
cout << ans[i] << "\n";
}
return 0;
} | Title: Diverse Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String diversity is the number of symbols that occur in the string at least once. Diversity of *s* will be denoted by *d*(*s*). For example , *d*("aaa")=1, *d*("abacaba")=3.
Given a string *s*, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to *d*(*s*). Find statistics about substrings diversity: for each *k* from 1 to *d*(*s*), find how many substrings of *s* has a diversity of exactly *k*.
Input Specification:
The input consists of a single line containing *s*. It contains only lowercase Latin letters, the length of *s* is from 1 to 3·105.
Output Specification:
Print to the first line the value *d*(*s*). Print sequence *t*1,<=*t*2,<=...,<=*t**d*(*s*) to the following lines, where *t**i* is the number of substrings of *s* having diversity of exactly *i*.
Demo Input:
['abca\n', 'aabacaabbad\n']
Demo Output:
['3\n4\n3\n3\n', '4\n14\n19\n28\n5\n']
Note:
Consider the first example.
We denote by *s*(*i*, *j*) a substring of "abca" with the indices in the segment [*i*, *j*].
- *s*(1, 1) = "a", *d*("a") = 1 - *s*(2, 2) = "b", *d*("b") = 1 - *s*(3, 3) = "c", *d*("c") = 1 - *s*(4, 4) = "a", *d*("a") = 1 - *s*(1, 2) = "ab", *d*("ab") = 2 - *s*(2, 3) = "bc", *d*("bc") = 2 - *s*(3, 4) = "ca", *d*("ca") = 2 - *s*(1, 3) = "abc", *d*("abc") = 3 - *s*(2, 4) = "bca", *d*("bca") = 3 - *s*(1, 4) = "abca", *d*("abca") = 3
Total number of substring with diversity 1 is 4, with diversity 2 equals 3, 3 diversity is 3. | ```python
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
string s;
set<char> st;
vector<int> vec[26];
int it[26] = {0};
ll ans[26] = {0};
cin >> s;
int n = (int)s.size();
for(int i=0;i<n;i++){
st.insert(s[i]);
vec[s[i]-'a'].push_back(i);
}
for(int i=0;i<n;i++){
vector<int> vec2;
for(int j=0;j<26;j++){
if(it[j] < (int)vec[j].size()){
vec2.push_back(vec[j][it[j]]);
}
}
sort(vec2.begin(), vec2.end());
vec2.push_back(n);
int cur = 0;
int pos = i;
for(auto v : vec2){
ans[cur] += v-pos;
pos = v;
cur++;
}
it[s[i]-'a']++;
}
cout << st.size() << "\n";
for(int i=1;i<=(int)st.size();i++){
cout << ans[i] << "\n";
}
return 0;
}
``` | -1 |
|
666 | A | Reberland Linguistics | PROGRAMMING | 1,800 | [
"dp",
"implementation",
"strings"
] | null | null | First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).
Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.
Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.
Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}. | The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. | On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes.
Print suffixes in lexicographical (alphabetical) order. | [
"abacabaca\n",
"abaca\n"
] | [
"3\naca\nba\nca\n",
"0\n"
] | The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix. | 500 | [
{
"input": "abacabaca",
"output": "3\naca\nba\nca"
},
{
"input": "abaca",
"output": "0"
},
{
"input": "gzqgchv",
"output": "1\nhv"
},
{
"input": "iosdwvzerqfi",
"output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer"
},
{
"input": "oawtxikrpvfuzugjweki",
"output": "25\neki\nfu\nfuz\ngj\ngjw\nik\nikr\njw\njwe\nki\nkr\nkrp\npv\npvf\nrp\nrpv\nug\nugj\nuz\nuzu\nvf\nvfu\nwe\nzu\nzug"
},
{
"input": "abcdexyzzzz",
"output": "5\nxyz\nyz\nyzz\nzz\nzzz"
},
{
"input": "affviytdmexpwfqplpyrlniprbdphrcwlboacoqec",
"output": "67\nac\naco\nbd\nbdp\nbo\nboa\nco\ncoq\ncw\ncwl\ndm\ndme\ndp\ndph\nec\nex\nexp\nfq\nfqp\nhr\nhrc\nip\nipr\nlb\nlbo\nln\nlni\nlp\nlpy\nme\nmex\nni\nnip\noa\noac\noq\nph\nphr\npl\nplp\npr\nprb\npw\npwf\npy\npyr\nqec\nqp\nqpl\nrb\nrbd\nrc\nrcw\nrl\nrln\ntd\ntdm\nwf\nwfq\nwl\nwlb\nxp\nxpw\nyr\nyrl\nyt\nytd"
},
{
"input": "lmnxtobrknqjvnzwadpccrlvisxyqbxxmghvl",
"output": "59\nad\nadp\nbr\nbrk\nbx\nbxx\ncc\nccr\ncr\ncrl\ndp\ndpc\ngh\nhvl\nis\nisx\njv\njvn\nkn\nknq\nlv\nlvi\nmg\nmgh\nnq\nnqj\nnz\nnzw\nob\nobr\npc\npcc\nqb\nqbx\nqj\nqjv\nrk\nrkn\nrl\nrlv\nsx\nsxy\nvi\nvis\nvl\nvn\nvnz\nwa\nwad\nxm\nxmg\nxx\nxxm\nxy\nxyq\nyq\nyqb\nzw\nzwa"
},
{
"input": "tbdbdpkluawodlrwldjgplbiylrhuywkhafbkiuoppzsjxwbaqqiwagprqtoauowtaexrhbmctcxwpmplkyjnpwukzwqrqpv",
"output": "170\nae\naex\naf\nafb\nag\nagp\naq\naqq\nau\nauo\naw\nawo\nba\nbaq\nbi\nbiy\nbk\nbki\nbm\nbmc\nct\nctc\ncx\ncxw\ndj\ndjg\ndl\ndlr\nex\nexr\nfb\nfbk\ngp\ngpl\ngpr\nha\nhaf\nhb\nhbm\nhu\nhuy\niu\niuo\niw\niwa\niy\niyl\njg\njgp\njn\njnp\njx\njxw\nkh\nkha\nki\nkiu\nkl\nklu\nky\nkyj\nkz\nkzw\nlb\nlbi\nld\nldj\nlk\nlky\nlr\nlrh\nlrw\nlu\nlua\nmc\nmct\nmp\nmpl\nnp\nnpw\noa\noau\nod\nodl\nop\nopp\now\nowt\npk\npkl\npl\nplb\nplk\npm\npmp\npp\nppz\npr\nprq\npv\npw\npwu\npz\npzs\nqi\nqiw\nqpv\nqq\nqqi\nqr\nqrq\nqt\nq..."
},
{
"input": "caqmjjtwmqxytcsawfufvlofqcqdwnyvywvbbhmpzqwqqxieptiaguwvqdrdftccsglgfezrzhstjcxdknftpyslyqdmkwdolwbusyrgyndqllgesktvgarpfkiglxgtcfepclqhgfbfmkymsszrtynlxbosmrvntsqwccdtahkpnelwiqn",
"output": "323\nag\nagu\nah\nahk\nar\narp\naw\nawf\nbb\nbbh\nbf\nbfm\nbh\nbhm\nbo\nbos\nbu\nbus\ncc\nccd\nccs\ncd\ncdt\ncf\ncfe\ncl\nclq\ncq\ncqd\ncs\ncsa\ncsg\ncx\ncxd\ndf\ndft\ndk\ndkn\ndm\ndmk\ndo\ndol\ndq\ndql\ndr\ndrd\ndt\ndta\ndw\ndwn\nel\nelw\nep\nepc\nept\nes\nesk\nez\nezr\nfb\nfbf\nfe\nfep\nfez\nfk\nfki\nfm\nfmk\nfq\nfqc\nft\nftc\nftp\nfu\nfuf\nfv\nfvl\nga\ngar\nge\nges\ngf\ngfb\ngfe\ngl\nglg\nglx\ngt\ngtc\ngu\nguw\ngy\ngyn\nhg\nhgf\nhk\nhkp\nhm\nhmp\nhs\nhst\nia\niag\nie\niep\nig\nigl\niqn\njc\njcx\njt\njtw..."
},
{
"input": "prntaxhysjfcfmrjngdsitlguahtpnwgbaxptubgpwcfxqehrulbxfcjssgocqncscduvyvarvwxzvmjoatnqfsvsilubexmwugedtzavyamqjqtkxzuslielibjnvkpvyrbndehsqcaqzcrmomqqwskwcypgqoawxdutnxmeivnfpzwvxiyscbfnloqjhjacsfnkfmbhgzpujrqdbaemjsqphokkiplblbflvadcyykcqrdohfasstobwrobslaofbasylwiizrpozvhtwyxtzl",
"output": "505\nac\nacs\nad\nadc\nae\naem\nah\naht\nam\namq\nao\naof\naq\naqz\nar\narv\nas\nass\nasy\nat\natn\nav\navy\naw\nawx\nax\naxp\nba\nbae\nbas\nbax\nbe\nbex\nbf\nbfl\nbfn\nbg\nbgp\nbh\nbhg\nbj\nbjn\nbl\nblb\nbn\nbnd\nbs\nbsl\nbw\nbwr\nbx\nbxf\nca\ncaq\ncb\ncbf\ncd\ncdu\ncf\ncfm\ncfx\ncj\ncjs\ncq\ncqn\ncqr\ncr\ncrm\ncs\ncsc\ncsf\ncy\ncyp\ncyy\ndb\ndba\ndc\ndcy\nde\ndeh\ndo\ndoh\nds\ndsi\ndt\ndtz\ndu\ndut\nduv\ned\nedt\neh\nehr\nehs\nei\neiv\nel\neli\nem\nemj\nex\nexm\nfa\nfas\nfb\nfba\nfc\nfcf\nfcj\nfl\nflv\nf..."
},
{
"input": "gvtgnjyfvnuhagulgmjlqzpvxsygmikofsnvkuplnkxeibnicygpvfvtebppadpdnrxjodxdhxqceaulbfxogwrigstsjudhkgwkhseuwngbppisuzvhzzxxbaggfngmevksbrntpprxvcczlalutdzhwmzbalkqmykmodacjrmwhwugyhwlrbnqxsznldmaxpndwmovcolowxhj",
"output": "375\nac\nacj\nad\nadp\nag\nagg\nagu\nal\nalk\nalu\nau\naul\nax\naxp\nba\nbag\nbal\nbf\nbfx\nbn\nbni\nbnq\nbp\nbpp\nbr\nbrn\ncc\nccz\nce\ncea\ncj\ncjr\nco\ncol\ncy\ncyg\ncz\nczl\nda\ndac\ndh\ndhk\ndhx\ndm\ndma\ndn\ndnr\ndp\ndpd\ndw\ndwm\ndx\ndxd\ndz\ndzh\nea\neau\neb\nebp\nei\neib\neu\neuw\nev\nevk\nfn\nfng\nfs\nfsn\nfv\nfvn\nfvt\nfx\nfxo\ngb\ngbp\ngf\ngfn\ngg\nggf\ngm\ngme\ngmi\ngmj\ngp\ngpv\ngs\ngst\ngu\ngul\ngw\ngwk\ngwr\ngy\ngyh\nha\nhag\nhj\nhk\nhkg\nhs\nhse\nhw\nhwl\nhwm\nhwu\nhx\nhxq\nhz\nhzz\nib\nib..."
},
{
"input": "topqexoicgzjmssuxnswdhpwbsqwfhhziwqibjgeepcvouhjezlomobgireaxaceppoxfxvkwlvgwtjoiplihbpsdhczddwfvcbxqqmqtveaunshmobdlkmmfyajjlkhxnvfmibtbbqswrhcfwytrccgtnlztkddrevkfovunuxtzhhhnorecyfgmlqcwjfjtqegxagfiuqtpjpqlwiefofpatxuqxvikyynncsueynmigieototnbcwxavlbgeqao",
"output": "462\nac\nace\nag\nagf\naj\najj\nao\nat\natx\nau\naun\nav\navl\nax\naxa\nbb\nbbq\nbc\nbcw\nbd\nbdl\nbg\nbge\nbgi\nbj\nbjg\nbp\nbps\nbq\nbqs\nbs\nbsq\nbt\nbtb\nbx\nbxq\ncb\ncbx\ncc\nccg\nce\ncep\ncf\ncfw\ncg\ncgt\ncgz\ncs\ncsu\ncv\ncvo\ncw\ncwj\ncwx\ncy\ncyf\ncz\nczd\ndd\nddr\nddw\ndh\ndhc\ndhp\ndl\ndlk\ndr\ndre\ndw\ndwf\nea\neau\neax\nec\necy\nee\neep\nef\nefo\neg\negx\neo\neot\nep\nepc\nepp\neq\nev\nevk\ney\neyn\nez\nezl\nfg\nfgm\nfh\nfhh\nfi\nfiu\nfj\nfjt\nfm\nfmi\nfo\nfof\nfov\nfp\nfpa\nfv\nfvc\nfw\nfwy\n..."
},
{
"input": "lcrjhbybgamwetyrppxmvvxiyufdkcotwhmptefkqxjhrknjdponulsynpkgszhbkeinpnjdonjfwzbsaweqwlsvuijauwezfydktfljxgclpxpknhygdqyiapvzudyyqomgnsrdhhxhsrdfrwnxdolkmwmw",
"output": "276\nam\namw\nap\napv\nau\nauw\naw\nawe\nbg\nbga\nbk\nbke\nbs\nbsa\nby\nbyb\ncl\nclp\nco\ncot\ndf\ndfr\ndh\ndhh\ndk\ndkc\ndkt\ndo\ndol\ndon\ndp\ndpo\ndq\ndqy\ndy\ndyy\nef\nefk\nei\nein\neq\neqw\net\nety\nez\nezf\nfd\nfdk\nfk\nfkq\nfl\nflj\nfr\nfrw\nfw\nfwz\nfy\nfyd\nga\ngam\ngc\ngcl\ngd\ngdq\ngn\ngns\ngs\ngsz\nhb\nhbk\nhh\nhhx\nhm\nhmp\nhr\nhrk\nhs\nhsr\nhx\nhxh\nhy\nhyg\nia\niap\nij\nija\nin\ninp\niy\niyu\nja\njau\njd\njdo\njdp\njf\njfw\njh\njhr\njx\njxg\nkc\nkco\nke\nkei\nkg\nkgs\nkm\nkmw\nkn\nknh\nknj\n..."
},
{
"input": "hzobjysjhbebobkoror",
"output": "20\nbe\nbeb\nbko\nbo\nbob\neb\nebo\nhb\nhbe\njh\njhb\nko\nkor\nob\nor\nror\nsj\nsjh\nys\nysj"
},
{
"input": "safgmgpzljarfswowdxqhuhypxcmiddyvehjtnlflzknznrukdsbatxoytzxkqngopeipbythhbhfkvlcdxwqrxumbtbgiosjnbeorkzsrfarqofsrcwsfpyheaszjpkjysrcxbzebkxzovdchhososo",
"output": "274\nar\narf\narq\nas\nasz\nat\natx\nba\nbat\nbe\nbeo\nbg\nbgi\nbh\nbhf\nbk\nbkx\nbt\nbtb\nby\nbyt\nbz\nbze\ncd\ncdx\nch\nchh\ncm\ncmi\ncw\ncws\ncx\ncxb\ndc\ndch\ndd\nddy\nds\ndsb\ndx\ndxq\ndxw\ndy\ndyv\nea\neas\neb\nebk\neh\nehj\nei\neip\neo\neor\nfa\nfar\nfk\nfkv\nfl\nflz\nfp\nfpy\nfs\nfsr\nfsw\ngi\ngio\ngo\ngop\ngp\ngpz\nhb\nhbh\nhe\nhea\nhf\nhfk\nhh\nhhb\nhj\nhjt\nhos\nhu\nhuh\nhy\nhyp\nid\nidd\nio\nios\nip\nipb\nja\njar\njn\njnb\njp\njpk\njt\njtn\njy\njys\nkd\nkds\nkj\nkjy\nkn\nknz\nkq\nkqn\nkv\nkvl\n..."
},
{
"input": "glaoyryxrgsysy",
"output": "10\ngs\ngsy\nrgs\nry\nryx\nsy\nxr\nysy\nyx\nyxr"
},
{
"input": "aaaaaxyxxxx",
"output": "5\nxx\nxxx\nxyx\nyx\nyxx"
},
{
"input": "aaaaax",
"output": "0"
},
{
"input": "aaaaaxx",
"output": "1\nxx"
},
{
"input": "aaaaaaa",
"output": "1\naa"
},
{
"input": "aaaaaxxx",
"output": "2\nxx\nxxx"
},
{
"input": "aaaaayxx",
"output": "2\nxx\nyxx"
},
{
"input": "aaaaaxyz",
"output": "2\nxyz\nyz"
},
{
"input": "aaaaaxyxy",
"output": "2\nxy\nyxy"
},
{
"input": "aaaxyyxyy",
"output": "3\nxyy\nyx\nyy"
},
{
"input": "aaaaaxxxxxx",
"output": "2\nxx\nxxx"
},
{
"input": "aaaaaxxxxx",
"output": "2\nxx\nxxx"
},
{
"input": "aaaaaxyzxyxy",
"output": "5\nxy\nyxy\nyzx\nzx\nzxy"
},
{
"input": "aaaaadddgggg",
"output": "6\ndd\nddg\ndg\ndgg\ngg\nggg"
},
{
"input": "abcdeabzzzzzzzz",
"output": "5\nab\nabz\nbz\nzz\nzzz"
},
{
"input": "bbbbbccaaaaaa",
"output": "4\naa\naaa\nca\ncca"
},
{
"input": "xxxxxababc",
"output": "5\nab\naba\nabc\nba\nbc"
},
{
"input": "dddddaabbbbbb",
"output": "4\naab\nab\nbb\nbbb"
},
{
"input": "xxxxxababe",
"output": "5\nab\naba\nabe\nba\nbe"
},
{
"input": "aaaaababaaaaaaaaaaaa",
"output": "6\naa\naaa\nab\nba\nbaa\nbab"
}
] | 1,508,184,303 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 93 | 6,963,200 | t = input()
s, d = set(), set()
p = {(len(t), 2)}
while p:
m, x = p.pop()
r = m + x
for y in [x, 5 - x]:
l = m - y
q = (l, y)
if q in d or l < 5 or t[l:m] == t[m:r]: continue
s.add(t[l:m])
d.add(q)
p.add(q)
print(len(s))
print('\n'.join(sorted(s))) | Title: Reberland Linguistics
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other.
For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to).
Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language.
Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match.
Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}.
Input Specification:
The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters.
Output Specification:
On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes.
Print suffixes in lexicographical (alphabetical) order.
Demo Input:
['abacabaca\n', 'abaca\n']
Demo Output:
['3\naca\nba\nca\n', '0\n']
Note:
The first test was analysed in the problem statement.
In the second example the length of the string equals 5. The length of the root equals 5, so no string can be used as a suffix. | ```python
t = input()
s, d = set(), set()
p = {(len(t), 2)}
while p:
m, x = p.pop()
r = m + x
for y in [x, 5 - x]:
l = m - y
q = (l, y)
if q in d or l < 5 or t[l:m] == t[m:r]: continue
s.add(t[l:m])
d.add(q)
p.add(q)
print(len(s))
print('\n'.join(sorted(s)))
``` | 3 |
|
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"input": "2 3",
"output": "2 0 4"
},
{
"input": "5 6",
"output": "5 0 1"
},
{
"input": "4 4",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
},
{
"input": "6 4",
"output": "1 1 4"
},
{
"input": "1 4",
"output": "2 0 4"
},
{
"input": "5 5",
"output": "0 6 0"
},
{
"input": "4 5",
"output": "4 0 2"
},
{
"input": "4 3",
"output": "3 0 3"
},
{
"input": "1 5",
"output": "2 1 3"
},
{
"input": "6 5",
"output": "1 0 5"
},
{
"input": "2 2",
"output": "0 6 0"
},
{
"input": "1 3",
"output": "1 1 4"
},
{
"input": "3 6",
"output": "4 0 2"
},
{
"input": "3 1",
"output": "4 1 1"
},
{
"input": "3 2",
"output": "4 0 2"
},
{
"input": "3 5",
"output": "3 1 2"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "6 2",
"output": "2 1 3"
},
{
"input": "4 1",
"output": "4 0 2"
},
{
"input": "5 2",
"output": "3 0 3"
},
{
"input": "4 2",
"output": "3 1 2"
},
{
"input": "2 1",
"output": "5 0 1"
},
{
"input": "6 1",
"output": "3 0 3"
},
{
"input": "4 6",
"output": "4 1 1"
},
{
"input": "2 6",
"output": "3 1 2"
},
{
"input": "3 4",
"output": "3 0 3"
},
{
"input": "1 2",
"output": "1 0 5"
},
{
"input": "6 6",
"output": "0 6 0"
},
{
"input": "5 4",
"output": "2 0 4"
},
{
"input": "3 3",
"output": "0 6 0"
},
{
"input": "1 1",
"output": "0 6 0"
}
] | 1,591,422,971 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 109 | 307,200 | a,b=map(int,input().split())
arr=[1,2,3,4,5,6]
if a<b:
count=0
for i in range(0,len(arr),1):
if abs(a-arr[i])<abs(b-arr[i]):
count+=1
else:
break
count1=0
for i in range(len(arr)-1,-1,-1):
if abs(b-arr[i])<abs(a-arr[i]):
count1+=1
else:
break
print(count,6-(count+count1),count1)
elif a>b:
count1=0
for i in range(len(arr)-1,-1,-1):
if abs(a-arr[i])<abs(b-arr[i]):
count1+=1
else:
break
count=0
for i in range(0,len(arr),1):
if abs(b-arr[i])<abs(a-arr[i]):
count+=1
else:
break
print(count1,6-(count+count1),count) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
Input Specification:
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Output Specification:
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
Demo Input:
['2 5\n', '2 4\n']
Demo Output:
['3 0 3\n', '2 1 3\n']
Note:
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | ```python
a,b=map(int,input().split())
arr=[1,2,3,4,5,6]
if a<b:
count=0
for i in range(0,len(arr),1):
if abs(a-arr[i])<abs(b-arr[i]):
count+=1
else:
break
count1=0
for i in range(len(arr)-1,-1,-1):
if abs(b-arr[i])<abs(a-arr[i]):
count1+=1
else:
break
print(count,6-(count+count1),count1)
elif a>b:
count1=0
for i in range(len(arr)-1,-1,-1):
if abs(a-arr[i])<abs(b-arr[i]):
count1+=1
else:
break
count=0
for i in range(0,len(arr),1):
if abs(b-arr[i])<abs(a-arr[i]):
count+=1
else:
break
print(count1,6-(count+count1),count)
``` | 0 |
|
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
},
{
"input": "859 453892 543",
"output": "126416972"
},
{
"input": "1000 1000000000 1000",
"output": "0"
},
{
"input": "1000 500500000 1000",
"output": "0"
},
{
"input": "1000 500500001 1000",
"output": "0"
},
{
"input": "1000 500499999 1000",
"output": "1"
},
{
"input": "634 87973 214",
"output": "14497197"
},
{
"input": "432 10000 241",
"output": "12587552"
},
{
"input": "111 111111111 111",
"output": "0"
},
{
"input": "20 43 3",
"output": "77"
}
] | 1,697,790,965 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 46 | 0 | x,y,z=map(int,input().split())
total=0
for i in range(1,z+1):
total+=x*i;
if y> total:
print(0)
else:
print(total-y) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
Input Specification:
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output Specification:
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Demo Input:
['3 17 4\n']
Demo Output:
['13']
Note:
none | ```python
x,y,z=map(int,input().split())
total=0
for i in range(1,z+1):
total+=x*i;
if y> total:
print(0)
else:
print(total-y)
``` | 3 |
|
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"input": "10\n50 50 50 50 50 50 50 50 50 50",
"output": "NO"
},
{
"input": "10\n100 100 100 100 100 100 100 100 100 100",
"output": "NO"
},
{
"input": "7\n25 25 25 25 50 100 50",
"output": "YES"
},
{
"input": "2\n25 25",
"output": "YES"
},
{
"input": "3\n50 100 100",
"output": "NO"
},
{
"input": "3\n25 50 50",
"output": "NO"
},
{
"input": "2\n50 25",
"output": "NO"
},
{
"input": "14\n25 25 25 25 25 25 25 50 50 50 100 100 100 100",
"output": "NO"
},
{
"input": "5\n25 25 25 100 100",
"output": "NO"
},
{
"input": "7\n25 50 25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 50 25 50 100",
"output": "NO"
},
{
"input": "5\n25 25 50 50 50",
"output": "NO"
},
{
"input": "5\n25 25 50 100 50",
"output": "NO"
},
{
"input": "5\n25 25 50 50 100",
"output": "NO"
},
{
"input": "1\n50",
"output": "NO"
}
] | 1,634,080,693 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | def cinemaLine():
n = int(input())
cincuenta = 0
veinCinco = 0
cien = 0
flag = True
for i in range(n):
aux = int(input())
if i == 0 and (aux == 50 or aux == 100):
flag = False
break
if aux == 25:
veinCinco += 1
elif aux == 50:
veinCinco -= 1
cincuenta += 1
else:
if cincuenta:
veinCinco -= 1
cincuenta -= 1
#cien += 1
else:
veinCinco -= 3
if veinCinco < 0 and cincuenta < 0:
flag = False
if flag:
print("YES")
else:
print("NO")
def main():
cinemaLine()
main() | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Output Specification:
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
Demo Input:
['4\n25 25 50 50\n', '2\n25 100\n', '4\n50 50 25 25\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
def cinemaLine():
n = int(input())
cincuenta = 0
veinCinco = 0
cien = 0
flag = True
for i in range(n):
aux = int(input())
if i == 0 and (aux == 50 or aux == 100):
flag = False
break
if aux == 25:
veinCinco += 1
elif aux == 50:
veinCinco -= 1
cincuenta += 1
else:
if cincuenta:
veinCinco -= 1
cincuenta -= 1
#cien += 1
else:
veinCinco -= 3
if veinCinco < 0 and cincuenta < 0:
flag = False
if flag:
print("YES")
else:
print("NO")
def main():
cinemaLine()
main()
``` | -1 |
|
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,680,266,487 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 92 | 1,740,800 | s=""
for _ in range(int(input())):s+=input()+";"
print("YES\n"+s.replace("OO","++",1).replace(";","\n") if s.find("OO")!=-1 else "NO")
| 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
s=""
for _ in range(int(input())):s+=input()+";"
print("YES\n"+s.replace("OO","++",1).replace(";","\n") if s.find("OO")!=-1 else "NO")
``` | 3 |
|
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order. | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
{
"input": "CACCBAA.BC",
"output": "Yes"
},
{
"input": ".CAACCBBA.CBB.AC..BABCCBCCB..B.BC..CBC.CA.CC.C.CC.B.A.CC.BBCCBB..ACAACAC.CBCCB.AABAAC.CBCC.BA..CCBC.",
"output": "Yes"
},
{
"input": "A",
"output": "No"
},
{
"input": "..",
"output": "No"
},
{
"input": "BC",
"output": "No"
},
{
"input": "CAB",
"output": "Yes"
},
{
"input": "A.CB",
"output": "No"
},
{
"input": "B.ACAA.CA..CBCBBAA.B.CCBCB.CAC.ABC...BC.BCCC.BC.CB",
"output": "Yes"
},
{
"input": "B.B...CC.B..CCCB.CB..CBCB..CBCC.CCBC.B.CB..CA.C.C.",
"output": "No"
},
{
"input": "AA.CBAABABCCC..B..B.ABBABAB.B.B.CCA..CB.B...A..CBC",
"output": "Yes"
},
{
"input": "CA.ABB.CC.B.C.BBBABAAB.BBBAACACAAA.C.AACA.AAC.C.BCCB.CCBC.C..CCACA.CBCCB.CCAABAAB.AACAA..A.AAA.",
"output": "No"
},
{
"input": "CBC...AC.BBBB.BBABABA.CAAACC.AAABB..A.BA..BC.CBBBC.BBBBCCCAA.ACCBB.AB.C.BA..CC..AAAC...AB.A.AAABBA.A",
"output": "No"
},
{
"input": "CC.AAAC.BA.BBB.AABABBCCAA.A.CBCCB.B.BC.ABCBCBBAA.CACA.CCCA.CB.CCB.A.BCCCB...C.A.BCCBC..B.ABABB.C.BCB",
"output": "Yes"
},
{
"input": "CCC..A..CACACCA.CA.ABAAB.BBA..C.AAA...ACB.ACA.CA.B.AB.A..C.BC.BC.A.C....ABBCCACCCBCC.BBBAA.ACCACB.BB",
"output": "Yes"
},
{
"input": "BC.ABACAACC..AC.A..CCCAABBCCACAC.AA.CC.BAABABABBCBB.BA..C.C.C.A.BBA.C..BC.ACACCC.AAAACCCCC.AAC.AC.AB",
"output": "Yes"
},
{
"input": "ACAC.BAA.C..CAAC..ABBAACC..BAA...CC...ACCBBCA.BAABABAACCAC.A.BBCACCC..BCB.BABAAAACCBCB.BCAABBC.C.BBB",
"output": "Yes"
},
{
"input": "CCAC.BCBC.A.ABBAB.C.C.BC.CCABBCBCCBC..B.AA.C.BC...B..BAA.ACCCCBBB.AAAACA.CAACCB.CCB.CC.BCCAB.BBBBABB",
"output": "Yes"
},
{
"input": ".AACAA.AAAAC.BBBB.BC...CCACCACAAA.A..CCA..BCC.AB.ABAAB..AABA...B.C.CBAB.BAAB.A.C.AAC.BBBA.ACAAA.BB.C",
"output": "Yes"
},
{
"input": "CC.ACCC.BCCCCAA.BBAACB.ABABAAAA.A.CBAB.CBACBBC..C.CA.AAA..AA..ABBB.A.C..CBBCAAACC.B..CC.AC..CAABACB.",
"output": "Yes"
},
{
"input": ".BAB.",
"output": "No"
},
{
"input": "BBBBBBBBB",
"output": "No"
},
{
"input": "..AAC..",
"output": "No"
},
{
"input": ".AAABBBCCC.",
"output": "No"
},
{
"input": "AAABC",
"output": "Yes"
},
{
"input": "BBB",
"output": "No"
},
{
"input": "AAAAABABAAAAA",
"output": "No"
},
{
"input": "AABBCC",
"output": "No"
},
{
"input": ".BA",
"output": "No"
},
{
"input": "CAAAAB",
"output": "No"
}
] | 1,623,658,017 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 77 | 0 | s=input()
l=['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
def f(l,s):
for i in l:
if i in s:
return "Yes"
return "No"
print(f(l,s)) | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower of colour amber or buff or canary yellow, or is empty.
When a flower withers, it disappears from the cell that it originally belonged to, and it spreads petals of its colour in its two neighbouring cells (or outside the field if the cell is on the side of the landscape). In case petals fall outside the given cells, they simply become invisible.
You are to help Kanno determine whether it's possible that after some (possibly none or all) flowers shed their petals, at least one of the cells contains all three colours, considering both petals and flowers. Note that flowers can wither in arbitrary order.
Input Specification:
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output Specification:
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower).
Demo Input:
['.BAC.\n', 'AA..CB\n']
Demo Output:
['Yes\n', 'No\n']
Note:
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | ```python
s=input()
l=['ABC', 'ACB', 'BAC', 'BCA', 'CAB', 'CBA']
def f(l,s):
for i in l:
if i in s:
return "Yes"
return "No"
print(f(l,s))
``` | 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,479,638,020 | 5,320 | Python 3 | OK | TESTS | 48 | 78 | 512,000 | #!/usr/bin/env python3
from sys import stdin
import re
def main():
n, = stdin_get_ints_from_line()
s = stdin_get_string_from_line()
print(re.sub(r'(ogo((go)+)?)', '***', s))
def stdin_get_ints_from_line():
return (int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_ints_list_from_line():
return list(int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_string_from_line():
return stdin.readline().strip()
if __name__ == '__main__':
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
#!/usr/bin/env python3
from sys import stdin
import re
def main():
n, = stdin_get_ints_from_line()
s = stdin_get_string_from_line()
print(re.sub(r'(ogo((go)+)?)', '***', s))
def stdin_get_ints_from_line():
return (int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_ints_list_from_line():
return list(int(x) for x in stdin.readline().strip().split(' '))
def stdin_get_string_from_line():
return stdin.readline().strip()
if __name__ == '__main__':
main()
``` | 3 |
|
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,617,201,916 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 109 | 0 | n = int(input())
s = input()
while 'ogo' in s:
x = s.replace("ogo" , "***" , 1)
while x!=s:
s = x
x = s.replace("*go" , '*')
print(s) | 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
n = int(input())
s = input()
while 'ogo' in s:
x = s.replace("ogo" , "***" , 1)
while x!=s:
s = x
x = s.replace("*go" , '*')
print(s)
``` | 3 |
|
733 | D | Kostya the Sculptor | PROGRAMMING | 1,600 | [
"data structures",
"hashing"
] | null | null | Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has *n* stones which are rectangular parallelepipeds. The edges sizes of the *i*-th of them are *a**i*, *b**i* and *c**i*. He can take no more than two stones and present them to Kostya.
If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.
Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=105).
*n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109) — the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. | In the first line print *k* (1<=≤<=*k*<=≤<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n* — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data.
You can print the stones in arbitrary order. If there are several answers print any of them. | [
"6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n",
"7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n"
] | [
"1\n1\n",
"2\n1 5\n"
] | In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 - 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5
Or take only one stone:
- 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 - 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 - 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 - 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5
It is most profitable to take only the first stone. | 2,000 | [
{
"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4",
"output": "1\n1"
},
{
"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7",
"output": "2\n1 5"
},
{
"input": "1\n1 1 1",
"output": "1\n1"
},
{
"input": "2\n2 3 1\n2 2 3",
"output": "2\n2 1"
},
{
"input": "1\n1000000000 1000000000 1000000000",
"output": "1\n1"
},
{
"input": "3\n100 100 100\n25 63 11\n63 15 11",
"output": "1\n1"
},
{
"input": "2\n999999999 1000000000 1000000000\n1000000000 1000000000 1000000000",
"output": "2\n2 1"
},
{
"input": "3\n1 1 2\n1 2 2\n1 1 1",
"output": "1\n1"
},
{
"input": "3\n500 1000 1000\n1000 499 1000\n999 999 999",
"output": "2\n1 2"
},
{
"input": "3\n500 1000 1000\n1000 499 1000\n1000 1001 1001",
"output": "1\n3"
},
{
"input": "9\n1 3 2\n3 3 1\n3 1 2\n3 3 2\n2 2 2\n3 2 1\n3 3 1\n3 3 1\n2 1 2",
"output": "2\n4 8"
},
{
"input": "3\n20 30 5\n20 30 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n6 20 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n20 6 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 30 5\n30 20 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 30 5\n6 20 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 30 5\n6 30 20\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 30 5\n20 6 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 30 5\n30 6 20\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n20 30 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n30 20 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n6 20 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n6 30 20\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n20 5 30\n30 6 20\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n20 30 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n30 20 6\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n6 30 20\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n20 6 30\n10 10 10",
"output": "2\n2 1"
},
{
"input": "3\n5 20 30\n30 6 20\n10 10 10",
"output": "2\n2 1"
}
] | 1,689,442,776 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1689442775.9862297")# 1689442775.9862494 | Title: Kostya the Sculptor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has *n* stones which are rectangular parallelepipeds. The edges sizes of the *i*-th of them are *a**i*, *b**i* and *c**i*. He can take no more than two stones and present them to Kostya.
If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way.
Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=105).
*n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109) — the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.
Output Specification:
In the first line print *k* (1<=≤<=*k*<=≤<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n* — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data.
You can print the stones in arbitrary order. If there are several answers print any of them.
Demo Input:
['6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n', '7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n']
Demo Output:
['1\n1\n', '2\n1 5\n']
Note:
In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 - 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5
Or take only one stone:
- 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 - 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 - 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 - 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 - 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5
It is most profitable to take only the first stone. | ```python
print("_RANDOM_GUESS_1689442775.9862297")# 1689442775.9862494
``` | 0 |
|
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding. | The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. | Print one integer number — the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16",
"output": "50"
},
{
"input": "100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75",
"output": "7"
},
{
"input": "8 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "3 8\n4 3 2",
"output": "2"
},
{
"input": "3 8\n2 4 2",
"output": "2"
},
{
"input": "3 6\n1 3 2",
"output": "2"
},
{
"input": "3 6\n3 2 5",
"output": "2"
},
{
"input": "3 8\n4 2 1",
"output": "2"
},
{
"input": "5 6\n2 3 5 1 2",
"output": "2"
},
{
"input": "2 6\n5 3",
"output": "2"
},
{
"input": "4 12\n6 4 3 1",
"output": "2"
},
{
"input": "3 18\n1 9 6",
"output": "2"
},
{
"input": "3 9\n3 2 1",
"output": "3"
},
{
"input": "3 6\n5 3 2",
"output": "2"
},
{
"input": "2 10\n5 2",
"output": "2"
},
{
"input": "2 18\n6 3",
"output": "3"
},
{
"input": "4 12\n1 2 12 3",
"output": "1"
},
{
"input": "3 7\n3 2 1",
"output": "7"
},
{
"input": "3 6\n3 2 1",
"output": "2"
},
{
"input": "5 10\n5 4 3 2 1",
"output": "2"
},
{
"input": "5 16\n8 4 2 1 7",
"output": "2"
},
{
"input": "6 7\n6 5 4 3 7 1",
"output": "1"
},
{
"input": "2 6\n3 2",
"output": "2"
},
{
"input": "2 4\n4 1",
"output": "1"
},
{
"input": "6 8\n2 4 1 3 5 7",
"output": "2"
},
{
"input": "6 8\n6 5 4 3 2 1",
"output": "2"
},
{
"input": "6 15\n5 2 3 6 4 3",
"output": "3"
},
{
"input": "4 8\n2 4 8 1",
"output": "1"
},
{
"input": "2 5\n5 1",
"output": "1"
},
{
"input": "4 18\n3 1 1 2",
"output": "6"
},
{
"input": "2 1\n2 1",
"output": "1"
},
{
"input": "3 10\n2 10 5",
"output": "1"
},
{
"input": "5 12\n12 4 4 4 3",
"output": "1"
},
{
"input": "3 6\n6 3 2",
"output": "1"
},
{
"input": "2 2\n2 1",
"output": "1"
},
{
"input": "3 18\n1 9 3",
"output": "2"
},
{
"input": "3 8\n7 2 4",
"output": "2"
},
{
"input": "2 100\n99 1",
"output": "100"
},
{
"input": "4 12\n1 3 4 2",
"output": "3"
},
{
"input": "3 6\n2 3 1",
"output": "2"
},
{
"input": "4 6\n3 2 5 12",
"output": "2"
},
{
"input": "4 97\n97 1 50 10",
"output": "1"
},
{
"input": "3 12\n1 12 2",
"output": "1"
},
{
"input": "4 12\n1 4 3 2",
"output": "3"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 19\n7 1 1",
"output": "19"
},
{
"input": "5 12\n12 4 3 4 4",
"output": "1"
},
{
"input": "3 8\n8 4 2",
"output": "1"
},
{
"input": "3 3\n3 2 1",
"output": "1"
},
{
"input": "5 6\n3 2 4 2 2",
"output": "2"
},
{
"input": "2 16\n8 4",
"output": "2"
},
{
"input": "3 6\n10 2 3",
"output": "2"
},
{
"input": "5 3\n2 4 5 3 6",
"output": "1"
},
{
"input": "11 99\n1 2 3 6 5 4 7 8 99 33 66",
"output": "1"
},
{
"input": "3 12\n3 12 2",
"output": "1"
},
{
"input": "5 25\n24 5 15 25 23",
"output": "1"
},
{
"input": "2 4\n8 1",
"output": "4"
},
{
"input": "4 100\n2 50 4 1",
"output": "2"
},
{
"input": "3 28\n7 14 1",
"output": "2"
},
{
"input": "4 8\n2 8 4 1",
"output": "1"
},
{
"input": "4 6\n6 1 2 3",
"output": "1"
},
{
"input": "2 12\n4 3",
"output": "3"
},
{
"input": "4 12\n1 2 4 3",
"output": "3"
},
{
"input": "5 12\n2 3 12 6 4",
"output": "1"
},
{
"input": "4 4\n1 2 2 4",
"output": "1"
},
{
"input": "3 6\n2 3 2",
"output": "2"
},
{
"input": "4 21\n21 20 21 2",
"output": "1"
},
{
"input": "3 8\n3 4 2",
"output": "2"
},
{
"input": "1 25\n25",
"output": "1"
},
{
"input": "99 12\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",
"output": "1"
},
{
"input": "98 12\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",
"output": "1"
},
{
"input": "79 12\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",
"output": "1"
},
{
"input": "4 32\n1 1 1 1",
"output": "32"
},
{
"input": "1 100\n1",
"output": "100"
},
{
"input": "2 100\n7 1",
"output": "100"
},
{
"input": "7 24\n1 3 6 4 5 2 7",
"output": "4"
},
{
"input": "6 87\n1 2 8 4 5 7",
"output": "87"
},
{
"input": "1 88\n1",
"output": "88"
},
{
"input": "1 89\n1",
"output": "89"
}
] | 1,634,713,604 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 61 | 17,715,200 | import sys
n, k = map(int, input().split())
lst = list(map(int, input().split()))
for x in range(k, 0, -1):
if k % x == 0:
for i in lst:
if i == x:
print(i)
sys.exit() | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input Specification:
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output Specification:
Print one integer number — the minimum number of hours required to water the garden.
Demo Input:
['3 6\n2 3 5\n', '6 7\n1 2 3 4 5 6\n']
Demo Output:
['2\n', '7\n']
Note:
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | ```python
import sys
n, k = map(int, input().split())
lst = list(map(int, input().split()))
for x in range(k, 0, -1):
if k % x == 0:
for i in lst:
if i == x:
print(i)
sys.exit()
``` | 0 |
|
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself. | The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon. | Print single integer — the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}.
In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1. | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23 84 98 8 14 4 42 56 83 87 28 22 32 50 5 96 90 1 59 74 77 88 71 38 62 36 85 97 99 6 81 20 49 57 66 9 45 41 29 68 35 19 27 76 78 72 55 25 46 48 26 53 39 31 94 34 63 37 64 16 79 24 82 17 12 3 89 61 80 30 10",
"output": "38"
},
{
"input": "95\n72 38 75 62 87 30 11 65 35 16 73 23 18 48 19 4 22 42 14 60 49 83 59 15 51 27 80 97 37 100 64 81 54 71 52 20 5 98 78 86 26 55 25 57 36 3 8 74 82 21 29 1 76 2 79 61 39 9 89 77 70 63 56 28 92 53 31 45 93 47 67 99 58 12 84 44 32 34 69 40 13 7 66 68 17 85 6 90 33 91 94 24 46 10 50",
"output": "48"
},
{
"input": "44\n39706 21317 26213 55086 10799 31825 29024 6565 96535 11412 14642 91901 41932 24538 81351 53861 63403 34199 82286 32594 29684 42753 16857 73821 71085 36306 70080 11233 21023 8551 85406 95390 92375 52675 77938 46265 74855 5229 5856 66713 65730 24525 84078 20684",
"output": "19"
},
{
"input": "35\n45633 86983 46174 48399 33926 51395 76300 6387 48852 82808 28694 79864 4482 35982 21956 76522 19656 74518 28480 71481 25700 46815 14170 95705 8535 96993 29029 8898 97637 62710 14615 22864 69849 27068 68557",
"output": "20"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n10 7 9 8 3 3 10 7 3 3",
"output": "5"
},
{
"input": "9\n10 10 6 10 9 1 8 3 5",
"output": "5"
},
{
"input": "7\n9 4 2 3 3 9 8",
"output": "4"
},
{
"input": "1\n4",
"output": "1"
},
{
"input": "6\n1623 45906 37856 34727 27156 12598",
"output": "4"
},
{
"input": "30\n83172 59163 67334 83980 5932 8773 77649 41428 62789 28159 17183 10199 41496 59500 14614 10468 54886 64679 42382 57021 50499 95643 77239 61434 16181 30505 59152 55972 18265 70566",
"output": "15"
},
{
"input": "23\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 22 16 2 13 16",
"output": "22"
},
{
"input": "46\n12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 12553 15 1 18 28 20 6 31 16 5 23 21 38 3 11 18 11 3 25 33",
"output": "27"
},
{
"input": "43\n8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8831 8 23 40 33 11 5 21 16 19 15 41 30 28 31 5 32 16 5 38 11 21 34",
"output": "21"
},
{
"input": "25\n58427 26687 48857 46477 7039 25423 58757 48119 38113 40637 22391 48337 4157 10597 8167 19031 64613 70913 69313 18047 17159 77491 13499 70949 24107",
"output": "1"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "1"
},
{
"input": "2\n3 6",
"output": "2"
},
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "5\n3 3 3 3 3",
"output": "5"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "2\n541 541",
"output": "2"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "2\n99989 99989",
"output": "2"
},
{
"input": "3\n3 9 27",
"output": "3"
},
{
"input": "2\n1009 1009",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "6\n2 10 20 5 15 25",
"output": "5"
},
{
"input": "3\n3 3 6",
"output": "3"
},
{
"input": "3\n457 457 457",
"output": "3"
},
{
"input": "2\n34 17",
"output": "2"
},
{
"input": "3\n12 24 3",
"output": "3"
},
{
"input": "10\n99991 99991 99991 99991 99991 99991 99991 99991 99991 99991",
"output": "10"
},
{
"input": "2\n1009 2018",
"output": "2"
},
{
"input": "3\n3 3 3",
"output": "3"
},
{
"input": "7\n6 9 12 15 21 27 33",
"output": "7"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n557 557",
"output": "2"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "5\n2 2 101 101 101",
"output": "3"
},
{
"input": "2\n122 3721",
"output": "2"
},
{
"input": "2\n49201 98402",
"output": "2"
},
{
"input": "2\n88258 44129",
"output": "2"
},
{
"input": "2\n7919 47514",
"output": "2"
},
{
"input": "5\n1 2 1 1 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "5\n1 1 1 1 2",
"output": "1"
},
{
"input": "3\n10007 20014 30021",
"output": "3"
},
{
"input": "4\n10 10 5 5",
"output": "4"
},
{
"input": "2\n6 9",
"output": "2"
},
{
"input": "3\n6 12 9",
"output": "3"
},
{
"input": "2\n14 7",
"output": "2"
},
{
"input": "2\n199 199",
"output": "2"
},
{
"input": "3\n49999 49999 99998",
"output": "3"
},
{
"input": "5\n1009 1009 1009 1009 1009",
"output": "5"
},
{
"input": "3\n17 17 17",
"output": "3"
},
{
"input": "2\n503 1509",
"output": "2"
},
{
"input": "3\n49999 99998 99998",
"output": "3"
},
{
"input": "2\n28657 28657",
"output": "2"
},
{
"input": "3\n121 22 33",
"output": "3"
},
{
"input": "2\n10079 20158",
"output": "2"
},
{
"input": "2\n6 15",
"output": "2"
},
{
"input": "4\n6 6 6 3",
"output": "4"
},
{
"input": "2\n991 1982",
"output": "2"
},
{
"input": "3\n20362 30543 50905",
"output": "3"
},
{
"input": "2\n443 886",
"output": "2"
},
{
"input": "4\n3 7 7 21",
"output": "3"
},
{
"input": "3\n3 6 9",
"output": "3"
},
{
"input": "2\n217 31",
"output": "2"
},
{
"input": "6\n10 10 10 5 5 5",
"output": "6"
},
{
"input": "4\n49441 25225 9081 4036",
"output": "4"
},
{
"input": "2\n4 9",
"output": "1"
},
{
"input": "2\n18 27",
"output": "2"
},
{
"input": "2\n13 26",
"output": "2"
},
{
"input": "4\n6 6 6 15",
"output": "4"
}
] | 1,623,807,523 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 0 | import math
n=int(input())
lst = list(map(int, input().strip().split(' ')))
l=[]
cl=[]
m=0
for i in range(n):
f=0
for j in range(len(l)):
if math.gcd(l[j],lst[i])!=1:
f=1
cl[j]+=1
if cl[j]>m:
m=cl[j]
if f==0:
l.append(lst[i])
cl.append(1)
print(max(m,1))
| Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*} tend to fight among each other if *gcd*(*s*1,<=*s*2,<=*s*3,<=...,<=*s**k*)<==<=1 (see notes for *gcd* definition).
Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?
Note: A Pokemon cannot fight with itself.
Input Specification:
The input consists of two lines.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=≤<=*s**i*<=≤<=105), the strength of the *i*-th Pokemon.
Output Specification:
Print single integer — the maximum number of Pokemons Bash can take.
Demo Input:
['3\n2 3 4\n', '5\n2 3 4 6 7\n']
Demo Output:
['2\n', '3\n']
Note:
*gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub>}.
In the first sample, we can take Pokemons with strengths {2, 4} since *gcd*(2, 4) = 2.
In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with *gcd* ≠ 1. | ```python
import math
n=int(input())
lst = list(map(int, input().strip().split(' ')))
l=[]
cl=[]
m=0
for i in range(n):
f=0
for j in range(len(l)):
if math.gcd(l[j],lst[i])!=1:
f=1
cl[j]+=1
if cl[j]>m:
m=cl[j]
if f==0:
l.append(lst[i])
cl.append(1)
print(max(m,1))
``` | 0 |
|
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations. | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\nX.X\nX..",
"output": "NO"
},
{
"input": ".X.\nX.X\n.X.",
"output": "YES"
},
{
"input": "X.X\n.X.\nX.X",
"output": "YES"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "XXX\n...\nXXX",
"output": "YES"
},
{
"input": "..X\nX..\n..X",
"output": "NO"
},
{
"input": ".X.\n...\nX.X",
"output": "NO"
},
{
"input": "X.X\nX.X\nX.X",
"output": "YES"
},
{
"input": ".X.\nX.X\nXX.",
"output": "NO"
},
{
"input": "...\nXXX\nXXX",
"output": "NO"
},
{
"input": "XXX\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX.X\n.X.",
"output": "NO"
},
{
"input": "...\n..X\nXXX",
"output": "NO"
},
{
"input": "..X\nX.X\nX..",
"output": "YES"
},
{
"input": "..X\n..X\nXXX",
"output": "NO"
},
{
"input": "X..\nX..\nX..",
"output": "NO"
},
{
"input": "XXX\n.X.\nXXX",
"output": "YES"
},
{
"input": "..X\n...\nX..",
"output": "YES"
},
{
"input": "...\n...\nX..",
"output": "NO"
},
{
"input": "...\n...\n.X.",
"output": "NO"
},
{
"input": "...\n...\n..X",
"output": "NO"
},
{
"input": "...\n.X.\nX..",
"output": "NO"
}
] | 1,648,197,230 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | s=input()
s+=input()
s+=input()
flag=True
for i in range(5):
if(s[i]!=s[8-i]):
flag=False
break;
if flag:
print("YES")
else:
print("NO") | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.
Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3<=×<=3 with digits from 1 to 9.
Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.
Input Specification:
Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».
Output Specification:
Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.
Demo Input:
['XX.\n...\n.XX\n', 'X.X\nX..\n...\n']
Demo Output:
['YES\n', 'NO\n']
Note:
If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | ```python
s=input()
s+=input()
s+=input()
flag=True
for i in range(5):
if(s[i]!=s[8-i]):
flag=False
break;
if flag:
print("YES")
else:
print("NO")
``` | 3.977 |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,633,285,612 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 154 | 6,963,200 | from math import sqrt
n_1,m_1 = input().split(' ')
n = int(n_1)
m = int(m_1)
sn = int(sqrt(n))
sm = int(sqrt(m))
count = 0
for a in range(min(m , sn)+1):
for b in range(min(sm , n)+1):
if n == (a*a) +b and m == (b*b) +a:
count+=1
print(count) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
from math import sqrt
n_1,m_1 = input().split(' ')
n = int(n_1)
m = int(m_1)
sn = int(sqrt(n))
sm = int(sqrt(m))
count = 0
for a in range(min(m , sn)+1):
for b in range(min(sm , n)+1):
if n == (a*a) +b and m == (b*b) +a:
count+=1
print(count)
``` | 3 |
|
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
},
{
"input": "999",
"output": "9"
},
{
"input": "100",
"output": "5"
},
{
"input": "123",
"output": "6"
},
{
"input": "8",
"output": "8"
},
{
"input": "157",
"output": "3"
},
{
"input": "289",
"output": "1"
},
{
"input": "179",
"output": "4"
},
{
"input": "942",
"output": "0"
},
{
"input": "879",
"output": "9"
},
{
"input": "394",
"output": "1"
},
{
"input": "423",
"output": "7"
},
{
"input": "952",
"output": "3"
},
{
"input": "121",
"output": "5"
},
{
"input": "613",
"output": "2"
},
{
"input": "945",
"output": "1"
},
{
"input": "270",
"output": "6"
},
{
"input": "781",
"output": "2"
},
{
"input": "453",
"output": "7"
},
{
"input": "171",
"output": "0"
},
{
"input": "643",
"output": "2"
},
{
"input": "570",
"output": "6"
},
{
"input": "750",
"output": "6"
},
{
"input": "500",
"output": "0"
},
{
"input": "2",
"output": "2"
},
{
"input": "1",
"output": "1"
},
{
"input": "108",
"output": "5"
},
{
"input": "500",
"output": "0"
},
{
"input": "189",
"output": "9"
},
{
"input": "491",
"output": "0"
},
{
"input": "191",
"output": "0"
}
] | 1,632,571,954 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 6,758,400 | a = int(input())
s = ""
i = 1
while len(s) < a:
s+=str(i)
i+=1
print(s[a-1]) | Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Output Specification:
Print the *n*-th digit of the line.
Demo Input:
['3\n', '11\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | ```python
a = int(input())
s = ""
i = 1
while len(s) < a:
s+=str(i)
i+=1
print(s[a-1])
``` | 3 |
|
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "3 2",
"output": "5"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "999 2",
"output": "1997"
},
{
"input": "1000 3",
"output": "1499"
},
{
"input": "1000 4",
"output": "1333"
},
{
"input": "1 1000",
"output": "1"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "80 970",
"output": "80"
},
{
"input": "10 4",
"output": "13"
},
{
"input": "4 3",
"output": "5"
},
{
"input": "91 5",
"output": "113"
},
{
"input": "777 17",
"output": "825"
},
{
"input": "100 4",
"output": "133"
},
{
"input": "5 3",
"output": "7"
},
{
"input": "6 4",
"output": "7"
},
{
"input": "26 8",
"output": "29"
},
{
"input": "9 4",
"output": "11"
},
{
"input": "20 3",
"output": "29"
},
{
"input": "17 3",
"output": "25"
}
] | 1,675,763,559 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | a, b = tuple(int(i) for i in input().split())
c = 0
total = 0
flag = True
while flag:
total += a
c += a % b
a //= b
a += c // b
c %= b
if a == 0:
flag = False
print(total) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input Specification:
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Output Specification:
Print a single integer — the number of hours Vasily can light up the room for.
Demo Input:
['4 2\n', '6 3\n']
Demo Output:
['7\n', '8\n']
Note:
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | ```python
a, b = tuple(int(i) for i in input().split())
c = 0
total = 0
flag = True
while flag:
total += a
c += a % b
a //= b
a += c // b
c %= b
if a == 0:
flag = False
print(total)
``` | 3 |
|
1,000 | B | Light It Up | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up. | First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$. | Print the only integer — maximum possible total time when the lamp is lit. | [
"3 10\n4 6 7\n",
"2 12\n1 10\n",
"2 7\n3 4\n"
] | [
"8\n",
"9\n",
"6\n"
] | In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | 0 | [
{
"input": "3 10\n4 6 7",
"output": "8"
},
{
"input": "2 12\n1 10",
"output": "9"
},
{
"input": "2 7\n3 4",
"output": "6"
},
{
"input": "1 2\n1",
"output": "1"
},
{
"input": "5 10\n1 3 5 6 8",
"output": "6"
},
{
"input": "7 1000000000\n1 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "7 1000000000\n3 10001 10011 20011 20021 40021 40031",
"output": "999999969"
},
{
"input": "1 10\n1",
"output": "9"
},
{
"input": "1 10000000\n1",
"output": "9999999"
},
{
"input": "1 8\n1",
"output": "7"
},
{
"input": "7 17\n1 5 9 10 11 14 16",
"output": "9"
},
{
"input": "4 17\n1 5 9 10",
"output": "12"
},
{
"input": "5 12\n1 2 3 4 5",
"output": "9"
},
{
"input": "2 1000000000\n100 111",
"output": "999999989"
},
{
"input": "3 90591\n90579 90580 90581",
"output": "90589"
},
{
"input": "5 16\n1 2 3 4 5",
"output": "13"
},
{
"input": "6 981231233\n1 6 15 30 130 1875",
"output": "981229468"
},
{
"input": "1 3\n1",
"output": "2"
},
{
"input": "3 12\n4 7 11",
"output": "8"
},
{
"input": "1 100000\n1",
"output": "99999"
},
{
"input": "2 5\n1 3",
"output": "3"
},
{
"input": "1 1000000000\n1",
"output": "999999999"
},
{
"input": "1 1000000000\n999999999",
"output": "999999999"
},
{
"input": "3 4\n1 2 3",
"output": "2"
},
{
"input": "3 5\n1 2 3",
"output": "3"
},
{
"input": "1 4\n2",
"output": "3"
},
{
"input": "3 5\n1 3 4",
"output": "3"
},
{
"input": "9 20\n5 9 11 12 14 15 16 17 19",
"output": "12"
},
{
"input": "2 4\n1 2",
"output": "3"
},
{
"input": "1 10\n2",
"output": "9"
},
{
"input": "2 6\n2 4",
"output": "4"
},
{
"input": "2 4\n1 3",
"output": "2"
},
{
"input": "3 6\n1 2 4",
"output": "4"
},
{
"input": "7 9863\n65 96 97 98 101 112 1115",
"output": "9819"
}
] | 1,645,356,191 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 170 | 14,233,600 | # template begins
#####################################
import enum
from io import BytesIO, IOBase
from mimetypes import suffix_map
import sys
import math
import os
import heapq
from collections import defaultdict, deque
from math import ceil
from bisect import bisect_left, bisect_right
from time import perf_counter
# region fastio
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")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def mint(): return map(int, input().split())
def mfloat(): return map(float, input().split())
def intin(): return int(input())
#####################################
# template ends
# Use the recursion snippet if heavy recursion is needed (depth>1000)
# If constraints are tight, use 1d arrays instead of 2d, like g[i*m+j] instead of g[i][j]
def one_less(x):
return x-1 if x > 0 else x + 1
def solve():
n, m = map(int, input().split())
*a, = map(int, input().split())
times = [0]*(n+1)
factor = 1
prev = 0
for idx, i in enumerate(a):
times[idx] = (i - prev) * factor
factor = factor * -1
prev = i
times[-1] = (m - prev) * factor
# print(times)
suffix_pos = [0]*(n+1)
suffix_neg = [0]*(n+1)
suffix_pos[-1] = times[-1] if times[-1] > 0 else 0
suffix_neg[-1] = times[-1] if times[-1] < 0 else 0
for i in range(n-1, -1, -1):
suffix_pos[i] = suffix_pos[i+1] + (times[i] if times[i] > 0 else 0)
suffix_neg[i] = suffix_neg[i+1] + (times[i] if times[i] < 0 else 0)
# print(suffix_pos)
# print(suffix_neg)
ans = suffix_pos[0]
if a[i] != 1:
# put a point at 1
current = -suffix_pos[0] - suffix_neg[0]
if times[0] > 0:
current -= 1
ans = max(ans, current)
start = suffix_pos[0]
# print(start)
for idx, i in enumerate(a):
# put a point before and after a and check how it affects
if i > 1 and (idx == 0 or a[idx-1] < i-1):
current = start
current = (current - times[idx] + one_less(times[idx]))
current -= suffix_pos[idx+1] + suffix_neg[idx+1]
ans = max(ans, current)
current = start
current -= times[idx+1] if times[idx+1] > 0 else 0
# if i == 7:
# print(i, current)
if times[idx+1] > 0:
current += 1
else:
current += -times[idx+1] - 1
# if i == 7:
# print(i, current)
if idx+2 <= n:
current -= suffix_pos[idx+2] + suffix_neg[idx+2]
ans = max(ans, current)
print(ans)
def main():
t = 1
# t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
start_time = perf_counter()
main()
print(perf_counter()-start_time, file=sys.stderr)
| Title: Light It Up
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, you bought a brand new smart lamp with programming features. At first, you set up a schedule to the lamp. Every day it will turn power on at moment $0$ and turn power off at moment $M$. Moreover, the lamp allows you to set a program of switching its state (states are "lights on" and "lights off"). Unfortunately, some program is already installed into the lamp.
The lamp allows only good programs. Good program can be represented as a non-empty array $a$, where $0 < a_1 < a_2 < \dots < a_{|a|} < M$. All $a_i$ must be integers. Of course, preinstalled program is a good program.
The lamp follows program $a$ in next manner: at moment $0$ turns power and light on. Then at moment $a_i$ the lamp flips its state to opposite (if it was lit, it turns off, and vice versa). The state of the lamp flips instantly: for example, if you turn the light off at moment $1$ and then do nothing, the total time when the lamp is lit will be $1$. Finally, at moment $M$ the lamp is turning its power off regardless of its state.
Since you are not among those people who read instructions, and you don't understand the language it's written in, you realize (after some testing) the only possible way to alter the preinstalled program. You can insert at most one element into the program $a$, so it still should be a good program after alteration. Insertion can be done between any pair of consecutive elements of $a$, or even at the begining or at the end of $a$.
Find such a way to alter the program that the total time when the lamp is lit is maximum possible. Maybe you should leave program untouched. If the lamp is lit from $x$ till moment $y$, then its lit for $y - x$ units of time. Segments of time when the lamp is lit are summed up.
Input Specification:
First line contains two space separated integers $n$ and $M$ ($1 \le n \le 10^5$, $2 \le M \le 10^9$) — the length of program $a$ and the moment when power turns off.
Second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($0 < a_1 < a_2 < \dots < a_n < M$) — initially installed program $a$.
Output Specification:
Print the only integer — maximum possible total time when the lamp is lit.
Demo Input:
['3 10\n4 6 7\n', '2 12\n1 10\n', '2 7\n3 4\n']
Demo Output:
['8\n', '9\n', '6\n']
Note:
In the first example, one of possible optimal solutions is to insert value $x = 3$ before $a_1$, so program will be $[3, 4, 6, 7]$ and time of lamp being lit equals $(3 - 0) + (6 - 4) + (10 - 7) = 8$. Other possible solution is to insert $x = 5$ in appropriate place.
In the second example, there is only one optimal solution: to insert $x = 2$ between $a_1$ and $a_2$. Program will become $[1, 2, 10]$, and answer will be $(1 - 0) + (10 - 2) = 9$.
In the third example, optimal answer is to leave program untouched, so answer will be $(3 - 0) + (7 - 4) = 6$. | ```python
# template begins
#####################################
import enum
from io import BytesIO, IOBase
from mimetypes import suffix_map
import sys
import math
import os
import heapq
from collections import defaultdict, deque
from math import ceil
from bisect import bisect_left, bisect_right
from time import perf_counter
# region fastio
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")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
def mint(): return map(int, input().split())
def mfloat(): return map(float, input().split())
def intin(): return int(input())
#####################################
# template ends
# Use the recursion snippet if heavy recursion is needed (depth>1000)
# If constraints are tight, use 1d arrays instead of 2d, like g[i*m+j] instead of g[i][j]
def one_less(x):
return x-1 if x > 0 else x + 1
def solve():
n, m = map(int, input().split())
*a, = map(int, input().split())
times = [0]*(n+1)
factor = 1
prev = 0
for idx, i in enumerate(a):
times[idx] = (i - prev) * factor
factor = factor * -1
prev = i
times[-1] = (m - prev) * factor
# print(times)
suffix_pos = [0]*(n+1)
suffix_neg = [0]*(n+1)
suffix_pos[-1] = times[-1] if times[-1] > 0 else 0
suffix_neg[-1] = times[-1] if times[-1] < 0 else 0
for i in range(n-1, -1, -1):
suffix_pos[i] = suffix_pos[i+1] + (times[i] if times[i] > 0 else 0)
suffix_neg[i] = suffix_neg[i+1] + (times[i] if times[i] < 0 else 0)
# print(suffix_pos)
# print(suffix_neg)
ans = suffix_pos[0]
if a[i] != 1:
# put a point at 1
current = -suffix_pos[0] - suffix_neg[0]
if times[0] > 0:
current -= 1
ans = max(ans, current)
start = suffix_pos[0]
# print(start)
for idx, i in enumerate(a):
# put a point before and after a and check how it affects
if i > 1 and (idx == 0 or a[idx-1] < i-1):
current = start
current = (current - times[idx] + one_less(times[idx]))
current -= suffix_pos[idx+1] + suffix_neg[idx+1]
ans = max(ans, current)
current = start
current -= times[idx+1] if times[idx+1] > 0 else 0
# if i == 7:
# print(i, current)
if times[idx+1] > 0:
current += 1
else:
current += -times[idx+1] - 1
# if i == 7:
# print(i, current)
if idx+2 <= n:
current -= suffix_pos[idx+2] + suffix_neg[idx+2]
ans = max(ans, current)
print(ans)
def main():
t = 1
# t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
start_time = perf_counter()
main()
print(perf_counter()-start_time, file=sys.stderr)
``` | 0 |
|
4 | C | Registration System | PROGRAMMING | 1,300 | [
"data structures",
"hashing",
"implementation"
] | C. Registration system | 5 | 64 | A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. | The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. | Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. | [
"4\nabacaba\nacaba\nabacaba\nacab\n",
"6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n"
] | [
"OK\nOK\nabacaba1\nOK\n",
"OK\nfirst1\nOK\nsecond1\nOK\nthird1\n"
] | none | 0 | [
{
"input": "4\nabacaba\nacaba\nabacaba\nacab",
"output": "OK\nOK\nabacaba1\nOK"
},
{
"input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird",
"output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1"
},
{
"input": "1\nn",
"output": "OK"
},
{
"input": "2\nu\nu",
"output": "OK\nu1"
},
{
"input": "3\nb\nb\nb",
"output": "OK\nb1\nb2"
},
{
"input": "2\nc\ncn",
"output": "OK\nOK"
},
{
"input": "3\nvhn\nvhn\nh",
"output": "OK\nvhn1\nOK"
},
{
"input": "4\nd\nhd\nd\nh",
"output": "OK\nOK\nd1\nOK"
},
{
"input": "10\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp\nbhnqaptmp",
"output": "OK\nbhnqaptmp1\nbhnqaptmp2\nbhnqaptmp3\nbhnqaptmp4\nbhnqaptmp5\nbhnqaptmp6\nbhnqaptmp7\nbhnqaptmp8\nbhnqaptmp9"
},
{
"input": "10\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh\njmvlplnrmba\nfpqhfouqdldravpjttarh",
"output": "OK\nfpqhfouqdldravpjttarh1\nfpqhfouqdldravpjttarh2\nfpqhfouqdldravpjttarh3\nfpqhfouqdldravpjttarh4\nfpqhfouqdldravpjttarh5\nOK\nfpqhfouqdldravpjttarh6\njmvlplnrmba1\nfpqhfouqdldravpjttarh7"
},
{
"input": "10\niwexcrupuubwzbooj\niwexcrupuubwzbooj\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\njzsyjnxttliyfpunxyhsouhunenzxedi\niwexcrupuubwzbooj\niwexcrupuubwzbooj\niwexcrupuubwzbooj",
"output": "OK\niwexcrupuubwzbooj1\nOK\njzsyjnxttliyfpunxyhsouhunenzxedi1\njzsyjnxttliyfpunxyhsouhunenzxedi2\njzsyjnxttliyfpunxyhsouhunenzxedi3\njzsyjnxttliyfpunxyhsouhunenzxedi4\niwexcrupuubwzbooj2\niwexcrupuubwzbooj3\niwexcrupuubwzbooj4"
},
{
"input": "10\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nOK\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz4\nzzzzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzzzzzzzzzzzzzzzz3\nzzzzzzzzzzzzzzzzzzzzzzzzzzz4"
},
{
"input": "20\nzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzz\nz\nzzzzzzzzz\nzzzzzzzzz\nzzzzzzzzzzzzz\nzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "OK\nOK\nOK\nzzzzzzzzzzzzz1\nzzzzzzzzz1\nzzzzzzzzz2\nzzzzzzzzzzzzz2\nzzzzzzzzzzzzz3\nOK\nzzzzzzzzzzzzz4\nzzzzzzzzzzzzz5\nzzzzzzzzzzzzzzzzzzzzzzzz1\nzzzzzzzzzzzzzzzzzzzzzzzz2\nzzzzzzzzzzzzz6\nzzzzzzzzzzzzz7\nz1\nzzzzzzzzz3\nzzzzzzzzz4\nzzzzzzzzzzzzz8\nzzzzzzzzzzzzzzzzzzzzzzzz3"
}
] | 1,691,872,857 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 1,404 | 1,228,800 | x = int(input())
a = {}
for i in range(x):
s = input()
if(s in a):
a[s]+=1
print(s+str(a[s]))
else:
a[s]=0
print("OK") | Title: Registration System
Time Limit: 5 seconds
Memory Limit: 64 megabytes
Problem Description:
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
Input Specification:
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Output Specification:
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
Demo Input:
['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n']
Demo Output:
['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n']
Note:
none | ```python
x = int(input())
a = {}
for i in range(x):
s = input()
if(s in a):
a[s]+=1
print(s+str(a[s]))
else:
a[s]=0
print("OK")
``` | 3.850445 |
235 | A | LCM Challenge | PROGRAMMING | 1,600 | [
"number theory"
] | null | null | Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers? | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. | Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. | [
"9\n",
"7\n"
] | [
"504\n",
"210\n"
] | The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get. | 500 | [
{
"input": "9",
"output": "504"
},
{
"input": "7",
"output": "210"
},
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "60"
},
{
"input": "6",
"output": "60"
},
{
"input": "33",
"output": "32736"
},
{
"input": "21",
"output": "7980"
},
{
"input": "2",
"output": "2"
},
{
"input": "41",
"output": "63960"
},
{
"input": "29",
"output": "21924"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "149",
"output": "3241644"
},
{
"input": "733",
"output": "392222436"
},
{
"input": "925",
"output": "788888100"
},
{
"input": "509",
"output": "131096004"
},
{
"input": "829",
"output": "567662724"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "925",
"output": "788888100"
},
{
"input": "213",
"output": "9527916"
},
{
"input": "53",
"output": "140556"
},
{
"input": "341",
"output": "39303660"
},
{
"input": "21",
"output": "7980"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "149",
"output": "3241644"
},
{
"input": "733",
"output": "392222436"
},
{
"input": "117",
"output": "1560780"
},
{
"input": "53",
"output": "140556"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "829",
"output": "567662724"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "20",
"output": "6460"
},
{
"input": "604",
"output": "218891412"
},
{
"input": "796",
"output": "501826260"
},
{
"input": "732",
"output": "389016270"
},
{
"input": "412",
"output": "69256788"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "244",
"output": "14289372"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "796",
"output": "501826260"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "245",
"output": "14526540"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "21",
"output": "7980"
},
{
"input": "605",
"output": "220348260"
},
{
"input": "636",
"output": "254839470"
},
{
"input": "924",
"output": "783776526"
},
{
"input": "116",
"output": "1507420"
},
{
"input": "700",
"output": "341042100"
},
{
"input": "732",
"output": "389016270"
},
{
"input": "20",
"output": "6460"
},
{
"input": "508",
"output": "130065780"
},
{
"input": "148",
"output": "3154620"
},
{
"input": "828",
"output": "563559150"
},
{
"input": "763116",
"output": "444394078546562430"
},
{
"input": "756604",
"output": "433115377058855412"
},
{
"input": "447244",
"output": "89460162932862372"
},
{
"input": "372636",
"output": "51742503205363470"
},
{
"input": "546924",
"output": "163597318076822526"
},
{
"input": "540412",
"output": "157823524476316788"
},
{
"input": "714700",
"output": "365063922340784100"
},
{
"input": "520731",
"output": "141201007712496270"
},
{
"input": "695019",
"output": "335728459024850814"
},
{
"input": "688507",
"output": "326379736779169710"
},
{
"input": "862795",
"output": "642275489615199390"
},
{
"input": "668827",
"output": "299184742915995150"
},
{
"input": "810411",
"output": "532248411551110590"
},
{
"input": "836603",
"output": "585540171302562606"
},
{
"input": "978187",
"output": "935975171582120670"
},
{
"input": "816923",
"output": "545182335484592526"
},
{
"input": "958507",
"output": "880611813728059710"
},
{
"input": "984699",
"output": "954792870629291694"
},
{
"input": "642635",
"output": "265393998349453470"
},
{
"input": "296604",
"output": "26092892528622606"
},
{
"input": "1000000",
"output": "999996000003000000"
},
{
"input": "8",
"output": "280"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "12"
},
{
"input": "30",
"output": "21924"
},
{
"input": "18",
"output": "4080"
},
{
"input": "12",
"output": "990"
}
] | 1,629,575,830 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 31 | 186 | 20,172,800 | n = int(input())
if (n <= 2):
print(n)
elif (n%2 == 1):
print(n*(n-1)*(n-2))
elif (n%3 != 0):
print(n*(n-1)*(n-3))
else:
if (n == 6):
print(60)
quit()
m = n
fator = [2]
atual = 0
while m != 1:
while (m%fator[atual] == 0):
m = m/fator[atual]
if (m == 1):
break
novo_fator = fator[atual]+1
while (m%novo_fator != 0):
novo_fator += 1
fator.append(novo_fator)
atual += 1
primo = n - 3
encontrado = False
while not encontrado:
encontrado = True
for i in fator:
if (primo%i == 0):
primo -= 2
encontrado = False
break
# print(n, (n-1), primo)
print(n*(n-1)*primo)
| Title: LCM Challenge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers?
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement.
Output Specification:
Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*.
Demo Input:
['9\n', '7\n']
Demo Output:
['504\n', '210\n']
Note:
The least common multiple of some positive integers is the least positive integer which is multiple for each of them.
The result may become very large, 32-bit integer won't be enough. So using 64-bit integers is recommended.
For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7·6·5 = 210. It is the maximum value we can get. | ```python
n = int(input())
if (n <= 2):
print(n)
elif (n%2 == 1):
print(n*(n-1)*(n-2))
elif (n%3 != 0):
print(n*(n-1)*(n-3))
else:
if (n == 6):
print(60)
quit()
m = n
fator = [2]
atual = 0
while m != 1:
while (m%fator[atual] == 0):
m = m/fator[atual]
if (m == 1):
break
novo_fator = fator[atual]+1
while (m%novo_fator != 0):
novo_fator += 1
fator.append(novo_fator)
atual += 1
primo = n - 3
encontrado = False
while not encontrado:
encontrado = True
for i in fator:
if (primo%i == 0):
primo -= 2
encontrado = False
break
# print(n, (n-1), primo)
print(n*(n-1)*primo)
``` | 0 |
|
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
{
"input": "8",
"output": "2 4 7 3 8 6 5"
},
{
"input": "9",
"output": "2 4 7 2 7 4 2 1"
},
{
"input": "2",
"output": "2"
},
{
"input": "11",
"output": "2 4 7 11 5 11 7 4 2 1"
},
{
"input": "12",
"output": "2 4 7 11 4 10 5 1 10 8 7"
},
{
"input": "13",
"output": "2 4 7 11 3 9 3 11 7 4 2 1"
},
{
"input": "20",
"output": "2 4 7 11 16 2 9 17 6 16 7 19 12 6 1 17 14 12 11"
},
{
"input": "25",
"output": "2 4 7 11 16 22 4 12 21 6 17 4 17 6 21 12 4 22 16 11 7 4 2 1"
},
{
"input": "30",
"output": "2 4 7 11 16 22 29 7 16 26 7 19 2 16 1 17 4 22 11 1 22 14 7 1 26 22 19 17 16"
},
{
"input": "35",
"output": "2 4 7 11 16 22 29 2 11 21 32 9 22 1 16 32 14 32 16 1 22 9 32 21 11 2 29 22 16 11 7 4 2 1"
},
{
"input": "40",
"output": "2 4 7 11 16 22 29 37 6 16 27 39 12 26 1 17 34 12 31 11 32 14 37 21 6 32 19 7 36 26 17 9 2 36 31 27 24 22 21"
},
{
"input": "45",
"output": "2 4 7 11 16 22 29 37 1 11 22 34 2 16 31 2 19 37 11 31 7 29 7 31 11 37 19 2 31 16 2 34 22 11 1 37 29 22 16 11 7 4 2 1"
},
{
"input": "50",
"output": "2 4 7 11 16 22 29 37 46 6 17 29 42 6 21 37 4 22 41 11 32 4 27 1 26 2 29 7 36 16 47 29 12 46 31 17 4 42 31 21 12 4 47 41 36 32 29 27 26"
},
{
"input": "55",
"output": "2 4 7 11 16 22 29 37 46 1 12 24 37 51 11 27 44 7 26 46 12 34 2 26 51 22 49 22 51 26 2 34 12 46 26 7 44 27 11 51 37 24 12 1 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "60",
"output": "2 4 7 11 16 22 29 37 46 56 7 19 32 46 1 17 34 52 11 31 52 14 37 1 26 52 19 47 16 46 17 49 22 56 31 7 44 22 1 41 22 4 47 31 16 2 49 37 26 16 7 59 52 46 41 37 34 32 31"
},
{
"input": "65",
"output": "2 4 7 11 16 22 29 37 46 56 2 14 27 41 56 7 24 42 61 16 37 59 17 41 1 27 54 17 46 11 42 9 42 11 46 17 54 27 1 41 17 59 37 16 61 42 24 7 56 41 27 14 2 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "70",
"output": "2 4 7 11 16 22 29 37 46 56 67 9 22 36 51 67 14 32 51 1 22 44 67 21 46 2 29 57 16 46 7 39 2 36 1 37 4 42 11 51 22 64 37 11 56 32 9 57 36 16 67 49 32 16 1 57 44 32 21 11 2 64 57 51 46 42 39 37 36"
},
{
"input": "75",
"output": "2 4 7 11 16 22 29 37 46 56 67 4 17 31 46 62 4 22 41 61 7 29 52 1 26 52 4 32 61 16 47 4 37 71 31 67 29 67 31 71 37 4 47 16 61 32 4 52 26 1 52 29 7 61 41 22 4 62 46 31 17 4 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "80",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 12 26 41 57 74 12 31 51 72 14 37 61 6 32 59 7 36 66 17 49 2 36 71 27 64 22 61 21 62 24 67 31 76 42 9 57 26 76 47 19 72 46 21 77 54 32 11 71 52 34 17 1 66 52 39 27 16 6 77 69 62 56 51 47 44 42 41"
},
{
"input": "85",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 7 21 36 52 69 2 21 41 62 84 22 46 71 12 39 67 11 41 72 19 52 1 36 72 24 62 16 56 12 54 12 56 16 62 24 72 36 1 52 19 72 41 11 67 39 12 71 46 22 84 62 41 21 2 69 52 36 21 7 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "90",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 2 16 31 47 64 82 11 31 52 74 7 31 56 82 19 47 76 16 47 79 22 56 1 37 74 22 61 11 52 4 47 1 46 2 49 7 56 16 67 29 82 46 11 67 34 2 61 31 2 64 37 11 76 52 29 7 76 56 37 19 2 76 61 47 34 22 11 1 82 74 67 61 56 52 49 47 46"
},
{
"input": "95",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 11 26 42 59 77 1 21 42 64 87 16 41 67 94 27 56 86 22 54 87 26 61 2 39 77 21 61 7 49 92 41 86 37 84 37 86 41 92 49 7 61 21 77 39 2 61 26 87 54 22 86 56 27 94 67 41 16 87 64 42 21 1 77 59 42 26 11 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "96",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 10 25 41 58 76 95 19 40 62 85 13 38 64 91 23 52 82 17 49 82 20 55 91 32 70 13 53 94 40 83 31 76 26 73 25 74 28 79 35 88 46 5 61 22 80 43 7 68 34 1 65 34 4 71 43 16 86 61 37 14 88 67 47 28 10 89 73 58 44 31 19 8 94 85 77 70 64 59 55 52 50 49"
},
{
"input": "97",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 9 24 40 57 75 94 17 38 60 83 10 35 61 88 19 48 78 12 44 77 14 49 85 25 63 5 45 86 31 74 21 66 15 62 13 62 15 66 21 74 31 86 45 5 63 25 85 49 14 77 44 12 78 48 19 88 61 35 10 83 60 38 17 94 75 57 40 24 9 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "98",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 8 23 39 56 74 93 15 36 58 81 7 32 58 85 15 44 74 7 39 72 8 43 79 18 56 95 37 78 22 65 11 56 4 51 1 50 2 53 7 60 16 71 29 86 46 7 67 30 92 57 23 88 56 25 93 64 36 9 81 56 32 9 85 64 44 25 7 88 72 57 43 30 18 7 95 86 78 71 65 60 56 53 51 50"
},
{
"input": "99",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 7 22 38 55 73 92 13 34 56 79 4 29 55 82 11 40 70 2 34 67 2 37 73 11 49 88 29 70 13 56 1 46 92 40 88 38 88 40 92 46 1 56 13 70 29 88 49 11 73 37 2 67 34 2 70 40 11 82 55 29 4 79 56 34 13 92 73 55 38 22 7 92 79 67 56 46 37 29 22 16 11 7 4 2 1"
},
{
"input": "100",
"output": "2 4 7 11 16 22 29 37 46 56 67 79 92 6 21 37 54 72 91 11 32 54 77 1 26 52 79 7 36 66 97 29 62 96 31 67 4 42 81 21 62 4 47 91 36 82 29 77 26 76 27 79 32 86 41 97 54 12 71 31 92 54 17 81 46 12 79 47 16 86 57 29 2 76 51 27 4 82 61 41 22 4 87 71 56 42 29 17 6 96 87 79 72 66 61 57 54 52 51"
}
] | 1,371,646,170 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 78 | 0 | def main():
n=int(input())
i=1
j=1
L=[]
for _ in range(1,n):
L.append((i+j)%n)
i+=(j%n)
j+=1%n
for k in L:
print(k,end=" ")
main() | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is holding the ball. First the first child throws the ball to the next one clockwise, i.e. to the child number 2. Then the child number 2 throws the ball to the next but one child, i.e. to the child number 4, then the fourth child throws the ball to the child that stands two children away from him, i.e. to the child number 7, then the ball is thrown to the child who stands 3 children away from the child number 7, then the ball is thrown to the child who stands 4 children away from the last one, and so on. It should be mentioned that when a ball is thrown it may pass the beginning of the circle. For example, if *n*<==<=5, then after the third throw the child number 2 has the ball again. Overall, *n*<=-<=1 throws are made, and the game ends.
The problem is that not all the children get the ball during the game. If a child doesn't get the ball, he gets very upset and cries until Natalia Pavlovna gives him a candy. That's why Natalia Pavlovna asks you to help her to identify the numbers of the children who will get the ball after each throw.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle.
Output Specification:
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
Demo Input:
['10\n', '3\n']
Demo Output:
['2 4 7 1 6 2 9 7 6\n', '2 1\n']
Note:
none | ```python
def main():
n=int(input())
i=1
j=1
L=[]
for _ in range(1,n):
L.append((i+j)%n)
i+=(j%n)
j+=1%n
for k in L:
print(k,end=" ")
main()
``` | 0 |
959 | B | Mahmoud and Ehab and the message | PROGRAMMING | 1,200 | [
"dsu",
"greedy",
"implementation"
] | null | null | Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?
The cost of sending the message is the sum of the costs of sending every word in it. | The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.
The third line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) where *a**i* is the cost of sending the *i*-th word.
The next *k* lines describe the groups of words of same meaning. The next *k* lines each start with an integer *x* (1<=≤<=*x*<=≤<=*n*) which means that there are *x* words in this group, followed by *x* integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.
The next line contains *m* space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words. | The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning. | [
"5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n",
"5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n"
] | [
"107",
"116"
] | In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | 1,000 | [
{
"input": "5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "107"
},
{
"input": "5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second",
"output": "116"
},
{
"input": "1 1 1\na\n1000000000\n1 1\na",
"output": "1000000000"
},
{
"input": "1 1 10\na\n1000000000\n1 1\na a a a a a a a a a",
"output": "10000000000"
}
] | 1,655,488,782 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 93 | 2,355,200 | import sys
input = sys.stdin.readline
n, k, m = map(int, input().split())
s = input()[:-1].split()
a = list(map(int, input().split()))
for i in range(k):
b, *w = list(map(int, input().split()))
if b > 1:
x = min(a[j-1] for j in w)
for j in w:
a[j - 1] = x
ss = sorted(zip(s, a))
q = sorted(input()[:-1].split())
c = 0
j = 0
for i in range(m):
while q[i] != ss[j][0]:
j += 1
c += ss[j][1]
j += 1
print(c) | Title: Mahmoud and Ehab and the message
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mahmoud wants to send a message to his friend Ehab. Their language consists of *n* words numbered from 1 to *n*. Some words have the same meaning so there are *k* groups of words such that all the words in some group have the same meaning.
Mahmoud knows that the *i*-th word can be sent with cost *a**i*. For each word in his message, Mahmoud can either replace it with another word of the same meaning or leave it as it is. Can you help Mahmoud determine the minimum cost of sending the message?
The cost of sending the message is the sum of the costs of sending every word in it.
Input Specification:
The first line of input contains integers *n*, *k* and *m* (1<=≤<=*k*<=≤<=*n*<=≤<=105,<=1<=≤<=*m*<=≤<=105) — the number of words in their language, the number of groups of words, and the number of words in Mahmoud's message respectively.
The second line contains *n* strings consisting of lowercase English letters of length not exceeding 20 which represent the words. It's guaranteed that the words are distinct.
The third line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109) where *a**i* is the cost of sending the *i*-th word.
The next *k* lines describe the groups of words of same meaning. The next *k* lines each start with an integer *x* (1<=≤<=*x*<=≤<=*n*) which means that there are *x* words in this group, followed by *x* integers which represent the indices of words in this group. It's guaranteed that each word appears in exactly one group.
The next line contains *m* space-separated words which represent Mahmoud's message. Each of these words appears in the list of language's words.
Output Specification:
The only line should contain the minimum cost to send the message after replacing some words (maybe none) with some words of the same meaning.
Demo Input:
['5 4 4\ni loser am the second\n100 1 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n', '5 4 4\ni loser am the second\n100 20 1 5 10\n1 1\n1 3\n2 2 5\n1 4\ni am the second\n']
Demo Output:
['107', '116']
Note:
In the first sample, Mahmoud should replace the word "second" with the word "loser" because it has less cost so the cost will be 100+1+5+1=107.
In the second sample, Mahmoud shouldn't do any replacement so the cost will be 100+1+5+10=116. | ```python
import sys
input = sys.stdin.readline
n, k, m = map(int, input().split())
s = input()[:-1].split()
a = list(map(int, input().split()))
for i in range(k):
b, *w = list(map(int, input().split()))
if b > 1:
x = min(a[j-1] for j in w)
for j in w:
a[j - 1] = x
ss = sorted(zip(s, a))
q = sorted(input()[:-1].split())
c = 0
j = 0
for i in range(m):
while q[i] != ss[j][0]:
j += 1
c += ss[j][1]
j += 1
print(c)
``` | -1 |
|
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! | The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",
"output": "NO"
},
{
"input": "190492",
"output": "YES"
},
{
"input": "5722367",
"output": "NO"
},
{
"input": "816761542",
"output": "YES"
},
{
"input": "1",
"output": "NO"
},
{
"input": "2",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "YES"
},
{
"input": "8",
"output": "NO"
},
{
"input": "9",
"output": "YES"
},
{
"input": "10",
"output": "NO"
},
{
"input": "12",
"output": "YES"
},
{
"input": "13",
"output": "YES"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "NO"
},
{
"input": "16",
"output": "YES"
},
{
"input": "17",
"output": "NO"
},
{
"input": "18",
"output": "YES"
},
{
"input": "19",
"output": "NO"
},
{
"input": "20",
"output": "YES"
},
{
"input": "41",
"output": "NO"
},
{
"input": "11",
"output": "YES"
},
{
"input": "69",
"output": "YES"
},
{
"input": "82",
"output": "NO"
},
{
"input": "85",
"output": "NO"
},
{
"input": "736",
"output": "NO"
},
{
"input": "895",
"output": "YES"
},
{
"input": "934",
"output": "YES"
},
{
"input": "6213",
"output": "YES"
},
{
"input": "7405",
"output": "NO"
},
{
"input": "9919",
"output": "NO"
},
{
"input": "40942",
"output": "YES"
},
{
"input": "41992",
"output": "NO"
},
{
"input": "68535",
"output": "NO"
},
{
"input": "405718",
"output": "NO"
},
{
"input": "1046146",
"output": "YES"
},
{
"input": "3761248",
"output": "YES"
},
{
"input": "6195181",
"output": "YES"
},
{
"input": "35354345",
"output": "NO"
},
{
"input": "81282830",
"output": "NO"
},
{
"input": "187719774",
"output": "NO"
},
{
"input": "296798673",
"output": "NO"
},
{
"input": "938938476",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "999887464",
"output": "YES"
},
{
"input": "999111944",
"output": "NO"
},
{
"input": "999966520",
"output": "YES"
},
{
"input": "999912080",
"output": "NO"
},
{
"input": "999992017",
"output": "YES"
},
{
"input": "999990474",
"output": "NO"
},
{
"input": "999999190",
"output": "YES"
},
{
"input": "999999125",
"output": "NO"
},
{
"input": "999999940",
"output": "YES"
},
{
"input": "999999995",
"output": "NO"
},
{
"input": "1000000000",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "83495494",
"output": "NO"
},
{
"input": "968022000",
"output": "YES"
},
{
"input": "399980000",
"output": "YES"
},
{
"input": "4",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
}
] | 1,591,434,360 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l=[(i*(i+1))//2 for i in range (1, 45000) *
x=int(input())
a="NO"
for i in range((x//2)+1):
if i in l and x-i in l:
a='YES'
break
print(a)
| Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!
Input Specification:
The first input line contains an integer *n* (1<=≤<=*n*<=≤<=109).
Output Specification:
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
Demo Input:
['256\n', '512\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | ```python
l=[(i*(i+1))//2 for i in range (1, 45000) *
x=int(input())
a="NO"
for i in range((x//2)+1):
if i in l and x-i in l:
a='YES'
break
print(a)
``` | -1 |
|
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not. | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
"output": "YES"
},
{
"input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae",
"output": "NO"
},
{
"input": " furuike ya\nkawazu tobikomu\nmizu no oto ",
"output": "YES"
},
{
"input": " noch da leich\na stamperl zum aufwaerma\n da pfarrer kimmt a ",
"output": "NO"
},
{
"input": " sommerfuglene \n hvorfor bruge mange ord\n et kan gore det",
"output": "YES"
},
{
"input": " ab der mittagszeit\n ist es etwas schattiger\n ein wolkenhimmel",
"output": "NO"
},
{
"input": "tornando a vederli\ni fiori di ciliegio la sera\nson divenuti frutti",
"output": "NO"
},
{
"input": "kutaburete\nyado karu koro ya\nfuji no hana",
"output": "YES"
},
{
"input": " beginnings of poetry\n the rice planting songs \n of the interior",
"output": "NO"
},
{
"input": " door zomerregens\n zijn de kraanvogelpoten\n korter geworden",
"output": "NO"
},
{
"input": " derevo na srub\na ptitsi bezzabotno\n gnezdishko tam vyut",
"output": "YES"
},
{
"input": "writing in the dark\nunaware that my pen\nhas run out of ink",
"output": "NO"
},
{
"input": "kusaaiu\nuieueua\nuo efaa",
"output": "YES"
},
{
"input": "v\nh\np",
"output": "NO"
},
{
"input": "i\ni\nu",
"output": "NO"
},
{
"input": "awmio eoj\nabdoolceegood\nwaadeuoy",
"output": "YES"
},
{
"input": "xzpnhhnqsjpxdboqojixmofawhdjcfbscq\nfoparnxnbzbveycoltwdrfbwwsuobyoz hfbrszy\nimtqryscsahrxpic agfjh wvpmczjjdrnwj mcggxcdo",
"output": "YES"
},
{
"input": "wxjcvccp cppwsjpzbd dhizbcnnllckybrnfyamhgkvkjtxxfzzzuyczmhedhztugpbgpvgh\nmdewztdoycbpxtp bsiw hknggnggykdkrlihvsaykzfiiw\ndewdztnngpsnn lfwfbvnwwmxoojknygqb hfe ibsrxsxr",
"output": "YES"
},
{
"input": "nbmtgyyfuxdvrhuhuhpcfywzrbclp znvxw synxmzymyxcntmhrjriqgdjh xkjckydbzjbvtjurnf\nhhnhxdknvamywhsrkprofnyzlcgtdyzzjdsfxyddvilnzjziz qmwfdvzckgcbrrxplxnxf mpxwxyrpesnewjrx ajxlfj\nvcczq hddzd cvefmhxwxxyqcwkr fdsndckmesqeq zyjbwbnbyhybd cta nsxzidl jpcvtzkldwd",
"output": "YES"
},
{
"input": "rvwdsgdsrutgjwscxz pkd qtpmfbqsmctuevxdj kjzknzghdvxzlaljcntg jxhvzn yciktbsbyscfypx x xhkxnfpdp\nwdfhvqgxbcts mnrwbr iqttsvigwdgvlxwhsmnyxnttedonxcfrtmdjjmacvqtkbmsnwwvvrlxwvtggeowtgsqld qj\nvsxcdhbzktrxbywpdvstr meykarwtkbm pkkbhvwvelclfmpngzxdmblhcvf qmabmweldplmczgbqgzbqnhvcdpnpjtch ",
"output": "YES"
},
{
"input": "brydyfsmtzzkpdsqvvztmprhqzbzqvgsblnz naait tdtiprjsttwusdykndwcccxfmzmrmfmzjywkpgbfnjpypgcbcfpsyfj k\nucwdfkfyxxxht lxvnovqnnsqutjsyagrplb jhvtwdptrwcqrovncdvqljjlrpxcfbxqgsfylbgmcjpvpl ccbcybmigpmjrxpu\nfgwtpcjeywgnxgbttgx htntpbk tkkpwbgxwtbxvcpkqbzetjdkcwad tftnjdxxjdvbpfibvxuglvx llyhgjvggtw jtjyphs",
"output": "YES"
},
{
"input": "nyc aqgqzjjlj mswgmjfcxlqdscheskchlzljlsbhyn iobxymwzykrsnljj\nnnebeaoiraga\nqpjximoqzswhyyszhzzrhfwhf iyxysdtcpmikkwpugwlxlhqfkn",
"output": "NO"
},
{
"input": "lzrkztgfe mlcnq ay ydmdzxh cdgcghxnkdgmgfzgahdjjmqkpdbskreswpnblnrc fmkwziiqrbskp\np oukeaz gvvy kghtrjlczyl qeqhgfgfej\nwfolhkmktvsjnrpzfxcxzqmfidtlzmuhxac wsncjgmkckrywvxmnjdpjpfydhk qlmdwphcvyngansqhl",
"output": "NO"
},
{
"input": "yxcboqmpwoevrdhvpxfzqmammak\njmhphkxppkqkszhqqtkvflarsxzla pbxlnnnafqbsnmznfj qmhoktgzix qpmrgzxqvmjxhskkksrtryehfnmrt dtzcvnvwp\nscwymuecjxhw rdgsffqywwhjpjbfcvcrnisfqllnbplpadfklayjguyvtrzhwblftclfmsr",
"output": "NO"
},
{
"input": "qfdwsr jsbrpfmn znplcx nhlselflytndzmgxqpgwhpi ghvbbxrkjdirfghcybhkkqdzmyacvrrcgsneyjlgzfvdmxyjmph\nylxlyrzs drbktzsniwcbahjkgohcghoaczsmtzhuwdryjwdijmxkmbmxv yyfrokdnsx\nyw xtwyzqlfxwxghugoyscqlx pljtz aldfskvxlsxqgbihzndhxkswkxqpwnfcxzfyvncstfpqf",
"output": "NO"
},
{
"input": "g rguhqhcrzmuqthtmwzhfyhpmqzzosa\nmhjimzvchkhejh irvzejhtjgaujkqfxhpdqjnxr dvqallgssktqvsxi\npcwbliftjcvuzrsqiswohi",
"output": "NO"
},
{
"input": " ngxtlq iehiise vgffqcpnmsoqzyseuqqtggokymol zn\nvjdjljazeujwoubkcvtsbepooxqzrueaauokhepiquuopfild\ngoabauauaeotoieufueeknudiilupouaiaexcoapapu",
"output": "NO"
},
{
"input": "ycnvnnqk mhrmhctpkfbc qbyvtjznmndqjzgbcxmvrpkfcll zwspfptmbxgrdv dsgkk nfytsqjrnfbhh pzdldzymvkdxxwh\nvnhjfwgdnyjptsmblyxmpzylsbjlmtkkwjcbqwjctqvrlqqkdsrktxlnslspvnn mdgsmzblhbnvpczmqkcffwhwljqkzmk hxcm\nrghnjvzcpprrgmtgytpkzyc mrdnnhpkwypwqbtzjyfwvrdwyjltbzxtbstzs xdjzdmx yjsqtzlrnvyssvglsdjrmsrfrcdpqt",
"output": "NO"
},
{
"input": "ioeeaioeiuoeaeieuuieooaouiuouiioaueeaiaiuoaoiioeeaauooiuuieeuaeeoauieeaiuoieiaieuoauaaoioooieueueuai\nuooaoeeaoiuuoeioaoouaououoeioiaeueoioaiouaeaoioiuuaueeuaiuoiueoiuaoeeieeouaeeaeeieioeoiiieuuueuuieuo\naeeouieeieoueaioeoioooiouaeeeiaaioueauaueiouuuaieuuioiaeiueauueaoieauauoeueuaiueuuaueeoueauaeaoieeoo",
"output": "NO"
},
{
"input": "mkgycgmrqtmlwj vddlbsgdptyfrcj nmrddjchydvbsyhgzytfzvwbhqmmhkpsyrcnknpsqrr wcnf wfvgskrnsmnrcqgcnc q\npn cclcyjjdp rqkpgyrvyyd hhynrochfa pthyffqvskazfshvzcmvhmsrxvquzkdvivlbfypwbgltfbjmhzljvgzmxjlrjdjq\nauuouieuaaauoooeoiuoaueuueauiuuuiaeuwuoiaeoeaieauieouoaeiiieiioiuuuiuauioiiuoeauueieaueiaioeuaoaaau",
"output": "NO"
},
{
"input": "ab\na\na",
"output": "NO"
},
{
"input": "on codeforcs\nbeta round is runnineg\na rustling of keys",
"output": "NO"
},
{
"input": "coooooooooooooooood\nd\nd",
"output": "NO"
},
{
"input": "on codeforces \nbeta round is runninog\n a rustling of keys",
"output": "NO"
},
{
"input": "aaaaaaaaaaaaaaa\na\na",
"output": "NO"
},
{
"input": "aaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "YES"
},
{
"input": "cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\ncccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc",
"output": "NO"
},
{
"input": "aaaaaa\naaaaaa\naaaaa",
"output": "NO"
}
] | 1,683,028,082 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | a=input()
b=input()
c=input()
d=['a','e','i','o','u']
ans=cnt=count=0
for i in a:
if i in d:
ans+=1
for i in b:
if i in d:
cnt+=1
for i in c:
if i in d:
count+=1
if ans==5 and cnt==7 and count==5:
print("YES")
else: print("NO")
| Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words.
To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u".
Three phases from a certain poem are given. Determine whether it is haiku or not.
Input Specification:
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification.
Output Specification:
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
Demo Input:
['on codeforces \nbeta round is running\n a rustling of keys \n', 'how many gallons\nof edo s rain did you drink\n cuckoo\n']
Demo Output:
['YES', 'NO']
Note:
none | ```python
a=input()
b=input()
c=input()
d=['a','e','i','o','u']
ans=cnt=count=0
for i in a:
if i in d:
ans+=1
for i in b:
if i in d:
cnt+=1
for i in c:
if i in d:
count+=1
if ans==5 and cnt==7 and count==5:
print("YES")
else: print("NO")
``` | 3.977 |
295 | A | Greg and Array | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg. | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces. | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 500 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1",
"output": "0"
}
] | 1,564,562,796 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 1,013 | 31,539,200 |
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
ops = [list(map(int,input().split())) for _ in range(m)]
qus = [list(map(int,input().split())) for _ in range(k)]
# reduce to opcount
starts = [0]*(m+1)
for l,r in qus:
starts[l-1] += 1
starts[r] -= 1
opcount = [0]*m
active = 0
for i in range(m):
active += starts[i]
opcount[i] = active
# reduce to adds
suffixOffset = [0]*(n+1)
for i in range(m):
l,r,d = ops[i]
suffixOffset[l-1] += opcount[i]*d
suffixOffset[r] -= opcount[i]*d
active = 0
for i in range(n):
active += suffixOffset[i]
a[i] += active
print(*a)
| Title: Greg and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* queries on a piece of paper. Each query has the following form: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*). That means that one should apply operations with numbers *x**i*,<=*x**i*<=+<=1,<=...,<=*y**i* to the array.
Now Greg is wondering, what the array *a* will be after all the queries are executed. Help Greg.
Input Specification:
The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), (0<=≤<=*d**i*<=≤<=105).
Next *k* lines contain the queries, the query number *i* is written as two integers: *x**i*, *y**i*, (1<=≤<=*x**i*<=≤<=*y**i*<=≤<=*m*).
The numbers in the lines are separated by single spaces.
Output Specification:
On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.
Demo Input:
['3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n', '1 1 1\n1\n1 1 1\n1 1\n', '4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n']
Demo Output:
['9 18 17\n', '2\n', '5 18 31 20\n']
Note:
none | ```python
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
ops = [list(map(int,input().split())) for _ in range(m)]
qus = [list(map(int,input().split())) for _ in range(k)]
# reduce to opcount
starts = [0]*(m+1)
for l,r in qus:
starts[l-1] += 1
starts[r] -= 1
opcount = [0]*m
active = 0
for i in range(m):
active += starts[i]
opcount[i] = active
# reduce to adds
suffixOffset = [0]*(n+1)
for i in range(m):
l,r,d = ops[i]
suffixOffset[l-1] += opcount[i]*d
suffixOffset[r] -= opcount[i]*d
active = 0
for i in range(n):
active += suffixOffset[i]
a[i] += active
print(*a)
``` | 3 |
|
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system. | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10",
"output": "0"
},
{
"input": "8 20",
"output": "0"
},
{
"input": "2 8",
"output": "0"
},
{
"input": "20 11",
"output": "0"
},
{
"input": "57 447",
"output": "1"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "66 296",
"output": "1"
},
{
"input": "75 683",
"output": "1"
},
{
"input": "227 975",
"output": "1"
},
{
"input": "247 499",
"output": "1"
},
{
"input": "266 116",
"output": "1"
},
{
"input": "286 916",
"output": "1"
},
{
"input": "307 341",
"output": "1"
},
{
"input": "451 121",
"output": "1"
},
{
"input": "471 921",
"output": "1"
},
{
"input": "502 346",
"output": "1"
},
{
"input": "535 59",
"output": "1"
},
{
"input": "555 699",
"output": "1"
},
{
"input": "747 351",
"output": "1"
},
{
"input": "790 64",
"output": "1"
},
{
"input": "810 704",
"output": "1"
},
{
"input": "855 225",
"output": "1"
},
{
"input": "902 34",
"output": "1"
},
{
"input": "922 514",
"output": "1"
},
{
"input": "971 131",
"output": "1"
},
{
"input": "991 931",
"output": "1"
},
{
"input": "840 780",
"output": "0"
},
{
"input": "102 595",
"output": "0"
},
{
"input": "139 433",
"output": "0"
},
{
"input": "968 288",
"output": "0"
},
{
"input": "563 354",
"output": "0"
},
{
"input": "994 975",
"output": "0"
},
{
"input": "456 221",
"output": "0"
},
{
"input": "205 210",
"output": "0"
},
{
"input": "1 11",
"output": "0"
},
{
"input": "1000 1000",
"output": "0"
},
{
"input": "3 3",
"output": "0"
},
{
"input": "11 99",
"output": "0"
},
{
"input": "2 2",
"output": "1"
},
{
"input": "11 1",
"output": "0"
},
{
"input": "6 6",
"output": "1"
},
{
"input": "100 452",
"output": "0"
},
{
"input": "420 380",
"output": "0"
},
{
"input": "31 31",
"output": "0"
},
{
"input": "2 6",
"output": "0"
},
{
"input": "112 134",
"output": "0"
},
{
"input": "13 13",
"output": "0"
},
{
"input": "1 571",
"output": "0"
}
] | 1,694,250,772 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 622 | 0 | a = [int(x) for x in input().split()]
f = 0
for i in range(min(a)+1):
for c in range(min(a)+1):
if ((i ** 2) + c == a[0]) and ((i + (c ** 2)) == a[1]):
f += 1
print(f) | Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≤<=*a*,<=*b*) which satisfy the system.
Input Specification:
A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space.
Output Specification:
On a single line print the answer to the problem.
Demo Input:
['9 3\n', '14 28\n', '4 20\n']
Demo Output:
['1\n', '1\n', '0\n']
Note:
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | ```python
a = [int(x) for x in input().split()]
f = 0
for i in range(min(a)+1):
for c in range(min(a)+1):
if ((i ** 2) + c == a[0]) and ((i + (c ** 2)) == a[1]):
f += 1
print(f)
``` | 3 |
|
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,692,357,240 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | l1=[1,2,3]
l2=list("abc")
print(l1)
print(l2)
# arr=list(map(int,input().split()))
s="abacbdabnm"
print(s.split('b')) | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
l1=[1,2,3]
l2=list("abc")
print(l1)
print(l2)
# arr=list(map(int,input().split()))
s="abacbdabnm"
print(s.split('b'))
``` | 0 |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations. | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input": "10000 1000",
"output": "8991"
},
{
"input": "1000000000000000000 1000000000000000000",
"output": "0"
},
{
"input": "1000000000000000000 100000000000000000",
"output": "899999999999999991"
},
{
"input": "1000000000000000000 10000000000000000",
"output": "989999999999999991"
},
{
"input": "1000000000000000000 1000000000000000",
"output": "998999999999999991"
},
{
"input": "1000000000000000000 100000000000000",
"output": "999899999999999991"
},
{
"input": "1000000000000000000 200000000000000000",
"output": "799999999999999991"
},
{
"input": "10 5",
"output": "1"
},
{
"input": "20 5",
"output": "11"
},
{
"input": "20 9",
"output": "11"
},
{
"input": "100 9",
"output": "91"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "130 118",
"output": "1"
},
{
"input": "190 181",
"output": "0"
},
{
"input": "1999 1971",
"output": "10"
},
{
"input": "100 99",
"output": "1"
},
{
"input": "6909094398 719694282",
"output": "6189400069"
},
{
"input": "260 258",
"output": "0"
},
{
"input": "35 19",
"output": "6"
},
{
"input": "100 87",
"output": "1"
},
{
"input": "91 89",
"output": "0"
},
{
"input": "109 89",
"output": "10"
},
{
"input": "109 91",
"output": "10"
},
{
"input": "20331 11580",
"output": "8732"
},
{
"input": "405487470 255750281",
"output": "149737161"
},
{
"input": "17382 12863",
"output": "4493"
},
{
"input": "19725 14457",
"output": "5246"
},
{
"input": "24848 15384",
"output": "9449"
},
{
"input": "25727 15982",
"output": "9728"
},
{
"input": "109 90",
"output": "10"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "1"
},
{
"input": "1000000000000000000 999999999999999998",
"output": "1"
},
{
"input": "1009 980",
"output": "10"
},
{
"input": "999999999999999999 999999999999999838",
"output": "0"
},
{
"input": "1000000000000000000 99999999999999800",
"output": "900000000000000061"
},
{
"input": "8785369357 3377262261",
"output": "5408107058"
},
{
"input": "110 109",
"output": "0"
},
{
"input": "999 777",
"output": "200"
},
{
"input": "327170000015578 77230000029054",
"output": "249939999986479"
},
{
"input": "12515000022229 1791000022317",
"output": "10723999999880"
},
{
"input": "9999999999999 9999999999882",
"output": "10"
},
{
"input": "213 196",
"output": "14"
},
{
"input": "92 82",
"output": "0"
},
{
"input": "148 136",
"output": "0"
},
{
"input": "8 9",
"output": "0"
},
{
"input": "309 299",
"output": "0"
},
{
"input": "9999 9963",
"output": "10"
},
{
"input": "82 81",
"output": "0"
},
{
"input": "9999999 9999936",
"output": "10"
},
{
"input": "171 155",
"output": "2"
},
{
"input": "999 972",
"output": "10"
},
{
"input": "999999999999 999999999891",
"output": "10"
},
{
"input": "9 9",
"output": "0"
},
{
"input": "6900 6885",
"output": "1"
},
{
"input": "96 57",
"output": "27"
},
{
"input": "5 4",
"output": "0"
},
{
"input": "17386 5814",
"output": "11557"
},
{
"input": "493679757404593 316259583979965",
"output": "177420173424564"
},
{
"input": "18474 9478",
"output": "8975"
},
{
"input": "270091571496186 250931112649966",
"output": "19160458846177"
},
{
"input": "565751690089037 381448507916936",
"output": "184303182172038"
},
{
"input": "19 10",
"output": "0"
}
] | 1,565,798,228 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 109 | 0 | def nine(p) :
s=''
for i in range(p) :
s+='9'
return int(s)
n,k=map(int,input().split())
l=[0]*19
for i in range(18) :
e=nine(18-i)
l[i]=int(k/e)
k-=l[i]*e
if k==0 :
break
if i==17 or k%e>nine(18-i-1)*9 :
l[i]+=1
break
otv=0
for i in range(18) :
otv+=10**(18-i)*l[i]
print(max(n-otv+1,0))
| Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different special properties, he wants to know how rare (or not rare) they are — in fact, he needs to calculate the quantity of really big numbers that are not greater than *n*.
Ivan tried to do the calculations himself, but soon realized that it's too difficult for him. So he asked you to help him in calculations.
Input Specification:
The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018).
Output Specification:
Print one integer — the quantity of really big numbers that are not greater than *n*.
Demo Input:
['12 1\n', '25 20\n', '10 9\n']
Demo Output:
['3\n', '0\n', '1\n']
Note:
In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | ```python
def nine(p) :
s=''
for i in range(p) :
s+='9'
return int(s)
n,k=map(int,input().split())
l=[0]*19
for i in range(18) :
e=nine(18-i)
l[i]=int(k/e)
k-=l[i]*e
if k==0 :
break
if i==17 or k%e>nine(18-i-1)*9 :
l[i]+=1
break
otv=0
for i in range(18) :
otv+=10**(18-i)*l[i]
print(max(n-otv+1,0))
``` | 0 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,692,973,315 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | players = int(input())
def get_max_value(d: dict) -> int:
return max(list(d.values()))
d = {}
l = []
for i in range(players):
player, value = input().split()
value = int(value)
l.append((player, value))
d[player] = d.get(player, 0) + value
max_value = get_max_value(d)
d.clear()
for t in l:
player, value = t
d[player] = d.get(player, 0) + value
if d[player] == max_value:
print(player)
break | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
players = int(input())
def get_max_value(d: dict) -> int:
return max(list(d.values()))
d = {}
l = []
for i in range(players):
player, value = input().split()
value = int(value)
l.append((player, value))
d[player] = d.get(player, 0) + value
max_value = get_max_value(d)
d.clear()
for t in l:
player, value = t
d[player] = d.get(player, 0) + value
if d[player] == max_value:
print(player)
break
``` | 0 |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
"output": "3"
},
{
"input": "10 10\n1 10 1 10 1 1 7 8 6 7",
"output": "8"
},
{
"input": "100 100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52",
"output": "63"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "10"
},
{
"input": "10 2\n2 2 1 1 1 1 1 2 1 2",
"output": "8"
},
{
"input": "10 3\n1 3 1 1 3 2 2 2 3 3",
"output": "9"
},
{
"input": "10 4\n2 1 1 1 3 4 4 4 1 2",
"output": "6"
},
{
"input": "10 5\n2 2 3 4 4 1 5 3 1 2",
"output": "7"
},
{
"input": "100 3\n1 2 3 2 1 2 2 3 1 3 3 2 2 1 1 2 2 1 1 1 1 2 3 3 2 1 1 2 2 2 3 3 3 2 1 3 1 3 3 2 3 1 2 2 2 3 2 1 1 3 3 3 3 2 1 1 2 3 2 2 3 2 3 2 2 3 2 2 2 2 3 3 3 1 3 3 1 1 2 3 2 2 2 2 3 3 3 2 1 2 3 1 1 2 3 3 1 3 3 2",
"output": "83"
},
{
"input": "100 7\n4 7 4 7 7 4 7 3 5 6 3 5 4 3 7 2 7 2 4 1 6 3 3 7 4 4 5 4 3 6 4 3 2 2 1 4 4 1 7 3 7 7 1 3 1 5 4 1 5 3 5 2 2 1 5 5 1 5 2 7 5 5 1 5 5 4 6 5 1 3 5 6 7 4 1 3 3 4 3 2 7 6 5 7 2 7 1 1 2 2 3 1 3 7 1 3 2 1 1 7",
"output": "71"
},
{
"input": "100 10\n3 4 8 10 8 6 4 3 7 7 6 2 3 1 3 10 1 7 9 3 5 5 2 6 2 9 1 7 4 2 4 1 6 1 7 10 2 5 3 7 6 4 6 2 8 8 8 6 6 10 3 7 4 3 4 1 7 9 3 6 3 6 1 4 9 3 8 1 10 1 4 10 7 7 9 5 3 8 10 2 1 10 8 7 10 8 5 3 1 2 1 10 6 1 5 3 3 5 7 2",
"output": "64"
},
{
"input": "100 15\n3 12 8 3 11 14 12 14 1 11 13 3 5 13 4 14 2 11 7 8 12 9 15 7 15 1 4 11 6 12 1 3 8 13 1 8 14 4 3 14 1 3 1 6 10 15 13 11 12 1 14 13 11 14 11 3 12 7 3 15 14 4 5 6 5 14 7 14 6 2 6 12 6 13 13 1 9 13 15 11 6 3 15 11 9 4 15 8 15 12 1 15 10 10 4 1 15 1 4 1",
"output": "71"
},
{
"input": "100 30\n7 14 22 16 11 13 7 29 20 19 22 6 12 16 1 8 27 21 22 3 15 27 20 12 4 19 1 26 26 22 25 17 29 25 16 29 29 28 16 26 25 14 16 20 5 21 5 15 19 13 17 21 17 19 23 13 1 25 6 30 16 19 12 10 28 8 15 13 14 24 19 30 12 19 22 1 3 14 16 3 20 26 15 19 9 10 19 27 2 16 10 22 15 13 19 3 24 9 8 13",
"output": "71"
},
{
"input": "100 40\n39 19 13 36 11 21 32 12 1 2 39 26 32 39 24 1 4 19 10 4 16 39 32 34 13 24 30 35 3 10 8 18 13 12 39 27 31 40 37 20 17 17 37 5 10 12 22 17 7 1 31 13 11 10 2 6 22 16 2 4 9 27 6 35 22 16 22 30 33 2 26 20 35 19 40 37 19 17 21 28 37 28 40 4 5 4 35 19 26 36 19 12 21 20 21 30 9 16 9 32",
"output": "65"
},
{
"input": "100 50\n2 46 4 6 38 19 15 34 10 35 37 30 3 25 5 45 40 45 33 31 6 20 10 44 11 9 2 14 35 5 9 23 20 2 48 22 25 35 38 31 24 33 35 16 4 30 27 10 12 22 6 24 12 30 23 21 14 12 32 21 7 12 25 43 18 34 34 28 47 13 28 43 18 39 44 42 35 26 35 14 8 29 32 20 29 3 20 6 20 9 9 27 8 42 10 37 42 27 8 1",
"output": "60"
},
{
"input": "100 60\n34 21 39 17 48 46 23 56 46 52 50 39 55 48 54 38 32 38 24 26 44 12 28 9 25 26 10 52 42 60 41 3 16 60 44 29 27 55 19 19 19 57 45 59 29 35 5 14 50 47 57 48 16 7 12 36 58 31 37 58 30 50 19 11 10 41 59 57 49 41 33 9 12 11 53 50 60 51 21 9 44 23 1 16 4 15 17 57 15 17 46 50 18 52 43 24 47 50 19 18",
"output": "74"
},
{
"input": "100 90\n74 65 49 41 3 79 61 83 50 40 13 57 90 14 62 77 36 10 3 5 5 40 50 75 32 26 3 71 79 54 88 50 46 20 42 59 30 36 83 86 60 62 82 68 62 80 18 65 28 28 81 74 62 33 61 35 33 83 90 72 6 6 51 4 22 20 29 10 8 3 84 69 12 17 24 16 12 64 80 74 68 59 1 59 15 59 37 58 79 83 51 56 81 14 37 45 19 31 61 90",
"output": "67"
},
{
"input": "100 99\n69 46 76 47 71 9 66 46 78 17 96 83 56 96 29 3 43 48 79 23 93 61 19 9 29 72 15 84 93 46 71 87 11 43 96 44 54 75 3 66 2 95 46 32 69 52 79 38 57 53 37 60 71 82 28 31 84 58 89 40 62 74 22 50 45 38 99 67 24 28 28 12 69 88 33 10 31 71 46 7 42 81 54 81 96 44 8 1 20 24 28 19 54 35 69 32 71 13 66 15",
"output": "68"
},
{
"input": "90 100\n25 52 88 89 36 17 57 64 66 11 89 61 54 92 48 51 18 42 44 92 6 14 67 100 16 21 17 88 85 73 33 11 94 84 56 72 4 80 90 78 96 5 62 70 54 70 94 80 10 91 100 89 98 87 69 74 88 63 53 79 38 94 89 52 21 82 67 79 100 81 2 40 30 69 34 15 12 33 87 52 95 18 51 30 15 39 30 99 46 84",
"output": "67"
},
{
"input": "5 100\n14 67 15 28 21",
"output": "2"
},
{
"input": "10 100\n2 17 53 94 95 57 36 47 68 48",
"output": "7"
},
{
"input": "1 100\n18",
"output": "1"
},
{
"input": "100 1\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": "100"
},
{
"input": "30 100\n56 7 99 83 2 65 35 53 99 36 42 57 13 37 68 52 87 11 50 23 86 24 32 39 97 6 64 1 18 86",
"output": "18"
},
{
"input": "60 100\n18 75 43 88 45 43 20 59 59 79 62 39 53 21 28 46 54 53 97 81 18 15 2 95 84 9 36 70 30 76 17 19 83 40 45 32 31 70 23 14 44 35 79 84 97 96 99 60 3 73 64 83 6 12 67 86 70 89 18 61",
"output": "40"
},
{
"input": "1 73\n24",
"output": "1"
},
{
"input": "4 4\n1 4 4 4",
"output": "4"
},
{
"input": "2 6\n1 4",
"output": "1"
},
{
"input": "2 5\n5 5",
"output": "2"
}
] | 1,590,744,361 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | n , m = map(int , input().split())
groups = list(map(int , input().split()))
i = 0
count = []
if len(groups)==1:
count = [1]
else:
while i+1<len(groups):
temp = groups[i]
i = i + 1
while temp + groups[i]<m and i<len(groups)-1:
temp = temp + groups[i]
i = i + 1
count.append(temp)
if count[-1]+groups[-1]>m:
count.append(5)
print(len(count)) | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue.
Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*).
Output Specification:
Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside.
Demo Input:
['4 3\n2 3 2 1\n', '3 4\n1 2 1\n']
Demo Output:
['3\n', '1\n']
Note:
none | ```python
n , m = map(int , input().split())
groups = list(map(int , input().split()))
i = 0
count = []
if len(groups)==1:
count = [1]
else:
while i+1<len(groups):
temp = groups[i]
i = i + 1
while temp + groups[i]<m and i<len(groups)-1:
temp = temp + groups[i]
i = i + 1
count.append(temp)
if count[-1]+groups[-1]>m:
count.append(5)
print(len(count))
``` | 0 |
|
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card? | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards. | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB",
"output": "BGR"
},
{
"input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "BG"
},
{
"input": "7\nBBBGBRG",
"output": "BGR"
},
{
"input": "5\nGRRGR",
"output": "BGR"
},
{
"input": "3\nGBR",
"output": "BGR"
},
{
"input": "1\nB",
"output": "B"
},
{
"input": "2\nBB",
"output": "B"
},
{
"input": "1\nG",
"output": "G"
},
{
"input": "2\nBG",
"output": "R"
},
{
"input": "3\nBGB",
"output": "GR"
},
{
"input": "2\nGG",
"output": "G"
},
{
"input": "3\nGBG",
"output": "BR"
},
{
"input": "4\nBGBG",
"output": "BGR"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "2\nBR",
"output": "G"
},
{
"input": "3\nBRB",
"output": "GR"
},
{
"input": "2\nRG",
"output": "B"
},
{
"input": "3\nBGR",
"output": "BGR"
},
{
"input": "4\nRBGB",
"output": "BGR"
},
{
"input": "3\nGGR",
"output": "BR"
},
{
"input": "4\nGGRB",
"output": "BGR"
},
{
"input": "5\nBGBGR",
"output": "BGR"
},
{
"input": "2\nRR",
"output": "R"
},
{
"input": "3\nRBR",
"output": "BG"
},
{
"input": "4\nRRBB",
"output": "BGR"
},
{
"input": "3\nRRG",
"output": "BG"
},
{
"input": "4\nBRRG",
"output": "BGR"
},
{
"input": "5\nRBRBG",
"output": "BGR"
},
{
"input": "4\nRGGR",
"output": "BGR"
},
{
"input": "5\nBRGRG",
"output": "BGR"
},
{
"input": "6\nGRRGBB",
"output": "BGR"
},
{
"input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR",
"output": "BGR"
},
{
"input": "16\nRRGRRRRRRGGRGRRR",
"output": "BGR"
},
{
"input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "GR"
},
{
"input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR",
"output": "BGR"
},
{
"input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "G"
},
{
"input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
"output": "BGR"
},
{
"input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB",
"output": "BGR"
},
{
"input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
"output": "BGR"
},
{
"input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG",
"output": "BGR"
},
{
"input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB",
"output": "BGR"
},
{
"input": "3\nGGB",
"output": "BR"
}
] | 1,455,386,779 | 1,879 | Python 3 | WRONG_ANSWER | PRETESTS | 1 | 46 | 204,800 | d = input()
r=d.count('R')
g=d.count('G')
b= d.count('B')
R=0;
G=0;
B=0;
if (r>0 and g>0 and b>0):
print('RGB')
exit(0);
if (r==0 and g==0):
print('B')
exit(0)
if (r==0 and b==0):
print('G')
exit(0)
if (b==0 and g==0):
print('R')
exit(0)
if (b==1 and r ==1):
print ('G')
exit(0)
if (b==1 and g ==1):
print ('R')
exit(0)
if (r==1 and r ==1):
print ('B')
exit(0)
if (b>1 and r ==1):
print ('GR')
exit(0)
if (b>1 and g ==1):
print ('GR')
exit(0)
if (r>1 and g ==1):
print ('GB')
exit(0)
if (r>1 and b ==1):
print ('GB')
exit(0)
if (g>1 and b ==1):
print ('RB')
exit(0)
if (g>1 and r ==1):
print ('RB')
exit(0)
print('RGB') | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.
She repeats this process until there is only one card left. What are the possible colors for the final card?
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Output Specification:
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
Demo Input:
['2\nRB\n', '3\nGRG\n', '5\nBBBBB\n']
Demo Output:
['G\n', 'BR\n', 'B\n']
Note:
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.
In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards. | ```python
d = input()
r=d.count('R')
g=d.count('G')
b= d.count('B')
R=0;
G=0;
B=0;
if (r>0 and g>0 and b>0):
print('RGB')
exit(0);
if (r==0 and g==0):
print('B')
exit(0)
if (r==0 and b==0):
print('G')
exit(0)
if (b==0 and g==0):
print('R')
exit(0)
if (b==1 and r ==1):
print ('G')
exit(0)
if (b==1 and g ==1):
print ('R')
exit(0)
if (r==1 and r ==1):
print ('B')
exit(0)
if (b>1 and r ==1):
print ('GR')
exit(0)
if (b>1 and g ==1):
print ('GR')
exit(0)
if (r>1 and g ==1):
print ('GB')
exit(0)
if (r>1 and b ==1):
print ('GB')
exit(0)
if (g>1 and b ==1):
print ('RB')
exit(0)
if (g>1 and r ==1):
print ('RB')
exit(0)
print('RGB')
``` | 0 |
|
142 | A | Help Farmer | PROGRAMMING | 1,600 | [
"brute force",
"math"
] | null | null | Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*.
Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks. | The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109). | Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator. | [
"4\n",
"7\n",
"12\n"
] | [
"28 41\n",
"47 65\n",
"48 105\n"
] | Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | 500 | [
{
"input": "4",
"output": "28 41"
},
{
"input": "7",
"output": "47 65"
},
{
"input": "12",
"output": "48 105"
},
{
"input": "1",
"output": "17 17"
},
{
"input": "6",
"output": "34 57"
},
{
"input": "8",
"output": "40 73"
},
{
"input": "9",
"output": "41 81"
},
{
"input": "14",
"output": "58 121"
},
{
"input": "15",
"output": "55 129"
},
{
"input": "16",
"output": "56 137"
},
{
"input": "18",
"output": "57 153"
},
{
"input": "20",
"output": "64 169"
},
{
"input": "299999771",
"output": "1499998867 2399998177"
},
{
"input": "54",
"output": "106 441"
},
{
"input": "96",
"output": "144 777"
},
{
"input": "348",
"output": "396 2793"
},
{
"input": "748",
"output": "487 5993"
},
{
"input": "908",
"output": "1840 7273"
},
{
"input": "1026",
"output": "591 8217"
},
{
"input": "1985",
"output": "3601 15889"
},
{
"input": "4472",
"output": "1603 35785"
},
{
"input": "20845",
"output": "8873 166769"
},
{
"input": "50480",
"output": "17884 403849"
},
{
"input": "62497",
"output": "312497 499985"
},
{
"input": "646055",
"output": "140995 5168449"
},
{
"input": "790620",
"output": "316416 6324969"
},
{
"input": "989903",
"output": "1082167 7919233"
},
{
"input": "7033800",
"output": "210976 56270409"
},
{
"input": "7661860",
"output": "546725 61294889"
},
{
"input": "7834243",
"output": "8302235 62673953"
},
{
"input": "45134118",
"output": "19223945 361072953"
},
{
"input": "89054701",
"output": "445273517 712437617"
},
{
"input": "99264891",
"output": "15587889 794119137"
},
{
"input": "127039320",
"output": "1209066 1016314569"
},
{
"input": "206898748",
"output": "1683461 1655189993"
},
{
"input": "231136953",
"output": "539319577 1849095633"
},
{
"input": "257259713",
"output": "2122207 2058077713"
},
{
"input": "286736327",
"output": "290355727 2293890625"
},
{
"input": "311933803",
"output": "1559669027 2495470433"
},
{
"input": "332393619",
"output": "10714371 2659148961"
},
{
"input": "422114561",
"output": "78417139 3376916497"
},
{
"input": "453012754",
"output": "2844347 3624102041"
},
{
"input": "470860680",
"output": "129486993 3766885449"
},
{
"input": "509607936",
"output": "3045276 4076863497"
},
{
"input": "534879507",
"output": "253364145 4279036065"
},
{
"input": "535074941",
"output": "647722381 4280599537"
},
{
"input": "536870912",
"output": "3151876 4294967305"
},
{
"input": "573308928",
"output": "3301020 4586471433"
},
{
"input": "603979776",
"output": "3414276 4831838217"
},
{
"input": "605404800",
"output": "3414952 4843238409"
},
{
"input": "615716902",
"output": "10508698 4925735225"
},
{
"input": "628464178",
"output": "3574502 5027713433"
},
{
"input": "631243141",
"output": "634644469 5049945137"
},
{
"input": "644972544",
"output": "3573148 5159780361"
},
{
"input": "659274082",
"output": "1977822262 5274192665"
},
{
"input": "679477248",
"output": "3693060 5435817993"
},
{
"input": "735134400",
"output": "3886608 5881075209"
},
{
"input": "764411904",
"output": "3988228 6115295241"
},
{
"input": "778377600",
"output": "4036708 6227020809"
},
{
"input": "791683200",
"output": "4082888 6333465609"
},
{
"input": "805306368",
"output": "4201476 6442450953"
},
{
"input": "821620800",
"output": "4185636 6572966409"
},
{
"input": "856079286",
"output": "196667409 6848634297"
},
{
"input": "857656800",
"output": "4307008 6861254409"
},
{
"input": "859963392",
"output": "4320292 6879707145"
},
{
"input": "864864000",
"output": "4331048 6918912009"
},
{
"input": "882161280",
"output": "4388720 7057290249"
},
{
"input": "884822400",
"output": "4396766 7078579209"
},
{
"input": "905969664",
"output": "4529412 7247757321"
},
{
"input": "908107200",
"output": "4474050 7264857609"
},
{
"input": "918918000",
"output": "4511288 7351344009"
},
{
"input": "931170240",
"output": "4548514 7449361929"
},
{
"input": "935625600",
"output": "4563150 7485004809"
},
{
"input": "936354996",
"output": "40069269 7490839977"
},
{
"input": "951350400",
"output": "4614600 7610803209"
},
{
"input": "958557600",
"output": "4637398 7668460809"
},
{
"input": "972972000",
"output": "4685478 7783776009"
},
{
"input": "980179200",
"output": "4707050 7841433609"
},
{
"input": "985944960",
"output": "4725040 7887559689"
},
{
"input": "994593600",
"output": "4752650 7956748809"
},
{
"input": "999893227",
"output": "1000183267 7999145825"
},
{
"input": "999893387",
"output": "1000724227 7999147105"
},
{
"input": "999905161",
"output": "1000161721 7999241297"
},
{
"input": "999942949",
"output": "1000368197 7999543601"
},
{
"input": "999996583",
"output": "1022096687 7999972673"
},
{
"input": "999999797",
"output": "4999998997 7999998385"
},
{
"input": "999999883",
"output": "4999999427 7999999073"
},
{
"input": "999999893",
"output": "4999999477 7999999153"
},
{
"input": "999999929",
"output": "4999999657 7999999441"
},
{
"input": "999999937",
"output": "4999999697 7999999505"
},
{
"input": "999999991",
"output": "1059701759 7999999937"
},
{
"input": "999999992",
"output": "129518035 7999999945"
},
{
"input": "999999993",
"output": "490196227 7999999953"
},
{
"input": "999999994",
"output": "928571477 7999999961"
},
{
"input": "999999995",
"output": "4924975 7999999969"
},
{
"input": "999999996",
"output": "1000000044 7999999977"
},
{
"input": "999999997",
"output": "15309947 7999999985"
},
{
"input": "999999998",
"output": "504345691 7999999993"
},
{
"input": "999999999",
"output": "52392027 8000000001"
},
{
"input": "1000000000",
"output": "4770064 8000000009"
}
] | 1,619,033,970 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 69 | 109 | 1,331,200 | n=int(input())
if n==1:
print(17,17)
else:
c1=c2=c=max(1,int((n/4)**(1/3)))
c2+=1
while n%c1!=0:
c1-=1
while n%c2!=0 and c2<=2*c:
c2+=1
if c2>2*c:
c2=n
n1=n//c1
n2=n//c2
d1=d2=d3=d4=float('inf')
for i in range(1,int(n1**0.5)+1):
if n1%i==0:
c,a,b=sorted([c1,i,n1//i])
if (c+1)*(a+2)*(b+2)<d1:
d1=(c+1)*(a+2)*(b+2)
a11,a21,c11=a,b,c
for i in range(1,int(n2**0.5)+1):
if n2%i==0:
c,a,b=sorted([c2,i,n2//i])
if (c+1)*(a+2)*(b+2)<d2:
d2=(c+1)*(a+2)*(b+2)
a31,a41,c21=a,b,c
c1,a1,a2,c2,a3,a4=c11,a11,a21,c21,a31,a41
c3=a2
c4=a4
n3=n//c3
n4=n//c4
for i in range(1,int(n3**0.5)+1):
if n3%i==0:
c,a,b=sorted([c3,i,n3//i])
if (c+1)*(a+2)*(b+2)<d3:
d3=(c+1)*(a+2)*(b+2)
a51,a61,c31=a,b,c
for i in range(1,int(n4**0.5)+1):
if n4%i==0:
c,a,b=sorted([c4,i,n4//i])
if (c+1)*(a+2)*(b+2)<d4:
d4=(c+1)*(a+2)*(b+2)
a71,a81,c41=a,b,c
c1,a1,a2,c2,a3,a4,c3,a5,a6,c4,a7,a8=c11,a11,a21,c21,a31,a41,c31,a51,a61,c41,a71,a81
print(min((c2+1)*(a3+2)*(a4+2),(c1+1)*(a1+2)*(a2+2),(c3+1)*(a5+2)*(a6+2),(c4+1)*(a7+2)*(a8+2))-n,8*n+9) | Title: Help Farmer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simpler and more convenient to use. He collected the hay into cubical hay blocks of the same size. Then he stored the blocks in his barn. After a summer spent in hard toil Sam stored *A*·*B*·*C* hay blocks and stored them in a barn as a rectangular parallelepiped *A* layers high. Each layer had *B* rows and each row had *C* blocks.
At the end of the autumn Sam came into the barn to admire one more time the hay he'd been stacking during this hard summer. Unfortunately, Sam was horrified to see that the hay blocks had been carelessly scattered around the barn. The place was a complete mess. As it turned out, thieves had sneaked into the barn. They completely dissembled and took away a layer of blocks from the parallelepiped's front, back, top and sides. As a result, the barn only had a parallelepiped containing (*A*<=-<=1)<=×<=(*B*<=-<=2)<=×<=(*C*<=-<=2) hay blocks. To hide the evidence of the crime, the thieves had dissembled the parallelepiped into single 1<=×<=1<=×<=1 blocks and scattered them around the barn. After the theft Sam counted *n* hay blocks in the barn but he forgot numbers *A*, *B* и *C*.
Given number *n*, find the minimally possible and maximally possible number of stolen hay blocks.
Input Specification:
The only line contains integer *n* from the problem's statement (1<=≤<=*n*<=≤<=109).
Output Specification:
Print space-separated minimum and maximum number of hay blocks that could have been stolen by the thieves.
Note that the answer to the problem can be large enough, so you must use the 64-bit integer type for calculations. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.
Demo Input:
['4\n', '7\n', '12\n']
Demo Output:
['28 41\n', '47 65\n', '48 105\n']
Note:
Let's consider the first sample test. If initially Sam has a parallelepiped consisting of 32 = 2 × 4 × 4 hay blocks in his barn, then after the theft the barn has 4 = (2 - 1) × (4 - 2) × (4 - 2) hay blocks left. Thus, the thieves could have stolen 32 - 4 = 28 hay blocks. If Sam initially had a parallelepiped consisting of 45 = 5 × 3 × 3 hay blocks in his barn, then after the theft the barn has 4 = (5 - 1) × (3 - 2) × (3 - 2) hay blocks left. Thus, the thieves could have stolen 45 - 4 = 41 hay blocks. No other variants of the blocks' initial arrangement (that leave Sam with exactly 4 blocks after the theft) can permit the thieves to steal less than 28 or more than 41 blocks. | ```python
n=int(input())
if n==1:
print(17,17)
else:
c1=c2=c=max(1,int((n/4)**(1/3)))
c2+=1
while n%c1!=0:
c1-=1
while n%c2!=0 and c2<=2*c:
c2+=1
if c2>2*c:
c2=n
n1=n//c1
n2=n//c2
d1=d2=d3=d4=float('inf')
for i in range(1,int(n1**0.5)+1):
if n1%i==0:
c,a,b=sorted([c1,i,n1//i])
if (c+1)*(a+2)*(b+2)<d1:
d1=(c+1)*(a+2)*(b+2)
a11,a21,c11=a,b,c
for i in range(1,int(n2**0.5)+1):
if n2%i==0:
c,a,b=sorted([c2,i,n2//i])
if (c+1)*(a+2)*(b+2)<d2:
d2=(c+1)*(a+2)*(b+2)
a31,a41,c21=a,b,c
c1,a1,a2,c2,a3,a4=c11,a11,a21,c21,a31,a41
c3=a2
c4=a4
n3=n//c3
n4=n//c4
for i in range(1,int(n3**0.5)+1):
if n3%i==0:
c,a,b=sorted([c3,i,n3//i])
if (c+1)*(a+2)*(b+2)<d3:
d3=(c+1)*(a+2)*(b+2)
a51,a61,c31=a,b,c
for i in range(1,int(n4**0.5)+1):
if n4%i==0:
c,a,b=sorted([c4,i,n4//i])
if (c+1)*(a+2)*(b+2)<d4:
d4=(c+1)*(a+2)*(b+2)
a71,a81,c41=a,b,c
c1,a1,a2,c2,a3,a4,c3,a5,a6,c4,a7,a8=c11,a11,a21,c21,a31,a41,c31,a51,a61,c41,a71,a81
print(min((c2+1)*(a3+2)*(a4+2),(c1+1)*(a1+2)*(a2+2),(c3+1)*(a5+2)*(a6+2),(c4+1)*(a7+2)*(a8+2))-n,8*n+9)
``` | 0 |
|
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "10000220"
},
{
"input": ".",
"output": "0"
},
{
"input": "-.",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "..",
"output": "00"
},
{
"input": "--.",
"output": "20"
},
{
"input": ".--.",
"output": "020"
},
{
"input": ".-.-..",
"output": "0110"
},
{
"input": "----.-.",
"output": "2201"
},
{
"input": "-..--.-.",
"output": "10201"
},
{
"input": "..--..--.",
"output": "0020020"
},
{
"input": "-.-.---.--..-..-.-.-..-..-.--.",
"output": "112120010111010120"
},
{
"input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.",
"output": "21112220010101011012011011221011"
},
{
"input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------",
"output": "11020111110111222212021020002022111100201121222020012022110010222"
},
{
"input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..",
"output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110"
},
{
"input": ".-..-.-.---.-----.--.---...-.--.-.-....-..",
"output": "01011212212021001201100010"
},
{
"input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..",
"output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210"
},
{
"input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.",
"output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220"
},
{
"input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----",
"output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122"
},
{
"input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..",
"output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110"
},
{
"input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.",
"output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020"
},
{
"input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..",
"output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200"
},
{
"input": "-.---...----...--.--...-.--.----",
"output": "121002200020200012022"
},
{
"input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.",
"output": "202020212012111010201021100001021221200011222112012201012220"
}
] | 1,684,775,233 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s=input()
ls=[]
def b(s):
if len(s)==0:
return ''
if s[0]=='.':
return '0'+ b(s[1:])
if s[0]=='-' and s[1]=='.':
return '1'+ b(s[2:])
if s[0]=='-' and s[1]=='-':
return '2'+ b(s[2:])
print(b(s)) | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
Input Specification:
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output Specification:
Output the decoded ternary number. It can have leading zeroes.
Demo Input:
['.-.--\n', '--.\n', '-..-.--\n']
Demo Output:
['012', '20', '1012']
Note:
none | ```python
s=input()
ls=[]
def b(s):
if len(s)==0:
return ''
if s[0]=='.':
return '0'+ b(s[1:])
if s[0]=='-' and s[1]=='.':
return '1'+ b(s[2:])
if s[0]=='-' and s[1]=='-':
return '2'+ b(s[2:])
print(b(s))
``` | 3.977 |
777 | A | Shell Game | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball? | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements. | Print one integer from 0 to 2 — the index of the shell where the ball was initially placed. | [
"4\n2\n",
"1\n1\n"
] | [
"1\n",
"0\n"
] | In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | 500 | [
{
"input": "4\n2",
"output": "1"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "3\n1",
"output": "1"
},
{
"input": "3\n2",
"output": "0"
},
{
"input": "3\n0",
"output": "2"
},
{
"input": "2000000000\n0",
"output": "1"
},
{
"input": "2\n0",
"output": "1"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "4\n0",
"output": "2"
},
{
"input": "4\n1",
"output": "0"
},
{
"input": "5\n0",
"output": "0"
},
{
"input": "5\n1",
"output": "2"
},
{
"input": "5\n2",
"output": "1"
},
{
"input": "6\n0",
"output": "0"
},
{
"input": "6\n1",
"output": "1"
},
{
"input": "6\n2",
"output": "2"
},
{
"input": "7\n0",
"output": "1"
},
{
"input": "7\n1",
"output": "0"
},
{
"input": "7\n2",
"output": "2"
},
{
"input": "100000\n0",
"output": "2"
},
{
"input": "100000\n1",
"output": "0"
},
{
"input": "100000\n2",
"output": "1"
},
{
"input": "99999\n1",
"output": "1"
},
{
"input": "99998\n1",
"output": "2"
},
{
"input": "99997\n1",
"output": "0"
},
{
"input": "99996\n1",
"output": "1"
},
{
"input": "99995\n1",
"output": "2"
},
{
"input": "1999999995\n0",
"output": "2"
},
{
"input": "1999999995\n1",
"output": "1"
},
{
"input": "1999999995\n2",
"output": "0"
},
{
"input": "1999999996\n0",
"output": "2"
},
{
"input": "1999999996\n1",
"output": "0"
},
{
"input": "1999999996\n2",
"output": "1"
},
{
"input": "1999999997\n0",
"output": "0"
},
{
"input": "1999999997\n1",
"output": "2"
},
{
"input": "1999999997\n2",
"output": "1"
},
{
"input": "1999999998\n0",
"output": "0"
},
{
"input": "1999999998\n1",
"output": "1"
},
{
"input": "1999999998\n2",
"output": "2"
},
{
"input": "1999999999\n0",
"output": "1"
},
{
"input": "1999999999\n1",
"output": "0"
},
{
"input": "1999999999\n2",
"output": "2"
},
{
"input": "2000000000\n1",
"output": "2"
},
{
"input": "2000000000\n2",
"output": "0"
},
{
"input": "1234567890\n0",
"output": "0"
},
{
"input": "1234567890\n1",
"output": "1"
},
{
"input": "1234567890\n2",
"output": "2"
},
{
"input": "123456789\n0",
"output": "2"
},
{
"input": "123456789\n1",
"output": "1"
},
{
"input": "123456789\n2",
"output": "0"
},
{
"input": "123456790\n0",
"output": "2"
},
{
"input": "12\n2",
"output": "2"
},
{
"input": "32\n1",
"output": "2"
},
{
"input": "20\n2",
"output": "0"
},
{
"input": "10\n1",
"output": "0"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "76994383\n1",
"output": "0"
},
{
"input": "25\n2",
"output": "2"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "12\n0",
"output": "0"
},
{
"input": "150\n2",
"output": "2"
},
{
"input": "15\n0",
"output": "2"
},
{
"input": "21\n2",
"output": "0"
},
{
"input": "18\n2",
"output": "2"
},
{
"input": "8\n2",
"output": "0"
},
{
"input": "10\n0",
"output": "2"
},
{
"input": "16\n0",
"output": "2"
}
] | 1,654,610,176 | 2,147,483,647 | Python 3 | OK | TESTS | 68 | 46 | 0 | print("012102120210201021"[int(input())%6*3+int(input())])
| Title: Shell Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
Input Specification:
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator.
The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Output Specification:
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
Demo Input:
['4\n2\n', '1\n1\n']
Demo Output:
['1\n', '0\n']
Note:
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell. 1. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle. 1. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell. | ```python
print("012102120210201021"[int(input())%6*3+int(input())])
``` | 3 |
|
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
"output": "18"
},
{
"input": "z\na",
"output": "2"
},
{
"input": "ama\nsama",
"output": "1"
},
{
"input": "aaabc\nbc",
"output": "3"
},
{
"input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa",
"output": "32"
},
{
"input": "ahmedaly\naly",
"output": "5"
},
{
"input": "aa\na",
"output": "1"
},
{
"input": "aa\nba",
"output": "2"
},
{
"input": "cccba\nba",
"output": "3"
},
{
"input": "a\nab",
"output": "3"
},
{
"input": "dadc\ndddc",
"output": "4"
},
{
"input": "aacaaab\nb",
"output": "6"
},
{
"input": "dddc\ncdcde",
"output": "9"
},
{
"input": "bbdab\ndab",
"output": "2"
},
{
"input": "a\naa",
"output": "1"
},
{
"input": "aa\nab",
"output": "4"
},
{
"input": "codeforces\nces",
"output": "7"
}
] | 1,655,409,777 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 2,867,200 | s = input()
t = input()
rs = s[::-1]
rt = t[::-1]
ls = len(s)
lt = len(t)
lst = []
for i in range(min(ls,lt)):
if rs[i] == rt[i]:
lst.append(rs[i])
lst.reverse()
print((ls-len(lst))+(lt-len(lst)))
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "".
You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings.
Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
Input Specification:
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output Specification:
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
Demo Input:
['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n']
Demo Output:
['2\n', '9\n', '7\n', '1\n']
Note:
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es".
In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty.
In the fourth example, the first character of the second string should be deleted. | ```python
s = input()
t = input()
rs = s[::-1]
rt = t[::-1]
ls = len(s)
lt = len(t)
lst = []
for i in range(min(ls,lt)):
if rs[i] == rt[i]:
lst.append(rs[i])
lst.reverse()
print((ls-len(lst))+(lt-len(lst)))
``` | 0 |
|
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"output": "NO"
},
{
"input": "1010010100000000010",
"output": "YES"
},
{
"input": "101010101",
"output": "NO"
},
{
"input": "000000000100000000000110101100000",
"output": "YES"
},
{
"input": "100001000000110101100000",
"output": "NO"
},
{
"input": "100001000011010110000",
"output": "NO"
},
{
"input": "010",
"output": "NO"
},
{
"input": "10101011111111111111111111111100",
"output": "YES"
},
{
"input": "1001101100",
"output": "NO"
},
{
"input": "1001101010",
"output": "NO"
},
{
"input": "1111100111",
"output": "NO"
},
{
"input": "00110110001110001111",
"output": "NO"
},
{
"input": "11110001001111110001",
"output": "NO"
},
{
"input": "10001111001011111101",
"output": "NO"
},
{
"input": "10000010100000001000110001010100001001001010011",
"output": "YES"
},
{
"input": "01111011111010111100101100001011001010111110000010",
"output": "NO"
},
{
"input": "00100000100100101110011001011011101110110110010100",
"output": "NO"
},
{
"input": "10110100110001001011110101110010100010000000000100101010111110111110100011",
"output": "YES"
},
{
"input": "00011101010101111001011011001101101011111101000010100000111000011100101011",
"output": "NO"
},
{
"input": "01110000110100110101110100111000101101011101011110110100100111100001110111",
"output": "NO"
},
{
"input": "11110110011000100111100111101101011111110100010101011011111101110110110111",
"output": "YES"
},
{
"input": "100100010101110010001011001110100011100010011110100101100011010001001010001001101111001100",
"output": "NO"
},
{
"input": "111110010001011010010011111100110110001111000010100011011100111101111101110010101111011110000001010",
"output": "NO"
},
{
"input": "111110111100010100000100001010111011101011000111011011011010110010100010000101011111000011010011110",
"output": "NO"
},
{
"input": "1011110110111010110111111010010010100011111011110000011000110010011110111010110100011010100010111000",
"output": "NO"
},
{
"input": "0010100111100010110110000011100111110100111110001010000100111111111010111100101101010101001011010110",
"output": "YES"
},
{
"input": "1111010100010100101011101100101101110011000010100010000001111100010011100101010001101111000001011000",
"output": "NO"
},
{
"input": "0101100011001110001110100111100011010101011000000000110110010010111100101111010111100011101100100101",
"output": "YES"
},
{
"input": "0001101110011101110000000010011111101001101111100001001010110000110001100000010001111011011110001101",
"output": "YES"
},
{
"input": "1000010000100000100010000100001000010000100001000010000100001000010000100001000010000100001000010000",
"output": "NO"
},
{
"input": "1000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000",
"output": "YES"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
"output": "YES"
},
{
"input": "1111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111111",
"output": "YES"
},
{
"input": "10100101000",
"output": "NO"
},
{
"input": "11110111011101",
"output": "NO"
},
{
"input": "10000000",
"output": "YES"
},
{
"input": "00000001",
"output": "YES"
},
{
"input": "01111111",
"output": "YES"
},
{
"input": "11111110",
"output": "YES"
}
] | 1,671,936,673 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | def dangerous(word):
zero=0
ones=0
for i in range(0, len(word)):
if word[i]=='1':
zero=0
ones+=1
if ones>=7:
return True
else:
ones=0
zero+=1
if zero>=7:
return True
return False
def main():
word = input()
if dangerous(word):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not.
Input Specification:
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Output Specification:
Print "YES" if the situation is dangerous. Otherwise, print "NO".
Demo Input:
['001001\n', '1000000001\n']
Demo Output:
['NO\n', 'YES\n']
Note:
none | ```python
def dangerous(word):
zero=0
ones=0
for i in range(0, len(word)):
if word[i]=='1':
zero=0
ones+=1
if ones>=7:
return True
else:
ones=0
zero+=1
if zero>=7:
return True
return False
def main():
word = input()
if dangerous(word):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
``` | 3.977 |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
},
{
"input": "5\n7 36 53 81 100",
"output": "4"
},
{
"input": "5\n100 81 53 36 7",
"output": "4"
},
{
"input": "10\n8 6 3 4 9 10 7 7 1 3",
"output": "5"
},
{
"input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862",
"output": "6"
},
{
"input": "10\n1 3 3 4 6 7 7 8 9 10",
"output": "7"
},
{
"input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137",
"output": "9"
},
{
"input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198",
"output": "5"
},
{
"input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101",
"output": "5"
},
{
"input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498",
"output": "7"
},
{
"input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679",
"output": "9"
},
{
"input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992",
"output": "57"
},
{
"input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83",
"output": "4"
},
{
"input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901",
"output": "57"
},
{
"input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100",
"output": "99"
},
{
"input": "2\n0 10000",
"output": "1"
},
{
"input": "2\n5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n10 10",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
}
] | 1,674,298,477 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | n=int(input())
l=list(map(int,input().split()))
s=set(l)
p=list(s)
c=0
for i in range(len(p)):
if(p[i]==max(p) or p[i]==min(p)):
c=c+1
print(c) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).
Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Output Specification:
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
Demo Input:
['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n']
Demo Output:
['2\n', '4\n']
Note:
In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | ```python
n=int(input())
l=list(map(int,input().split()))
s=set(l)
p=list(s)
c=0
for i in range(len(p)):
if(p[i]==max(p) or p[i]==min(p)):
c=c+1
print(c)
``` | 0 |
|
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk",
"output": "NO"
},
{
"input": "z\na",
"output": "NO"
},
{
"input": "asd\ndsa",
"output": "YES"
},
{
"input": "abcdef\nfecdba",
"output": "NO"
},
{
"input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu",
"output": "NO"
},
{
"input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf",
"output": "NO"
},
{
"input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp",
"output": "NO"
},
{
"input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb",
"output": "NO"
},
{
"input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh",
"output": "NO"
},
{
"input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy",
"output": "NO"
},
{
"input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko",
"output": "NO"
},
{
"input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv",
"output": "NO"
},
{
"input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd",
"output": "NO"
},
{
"input": "w\nw",
"output": "YES"
},
{
"input": "vz\nzv",
"output": "YES"
},
{
"input": "ry\nyr",
"output": "YES"
},
{
"input": "xou\nuox",
"output": "YES"
},
{
"input": "axg\ngax",
"output": "NO"
},
{
"input": "zdsl\nlsdz",
"output": "YES"
},
{
"input": "kudl\nldku",
"output": "NO"
},
{
"input": "zzlzwnqlcl\nlclqnwzlzz",
"output": "YES"
},
{
"input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv",
"output": "YES"
},
{
"input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar",
"output": "NO"
},
{
"input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn",
"output": "YES"
},
{
"input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum",
"output": "YES"
},
{
"input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv",
"output": "YES"
},
{
"input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm",
"output": "NO"
},
{
"input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd",
"output": "NO"
},
{
"input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg",
"output": "YES"
},
{
"input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis",
"output": "YES"
},
{
"input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy",
"output": "NO"
},
{
"input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw",
"output": "YES"
},
{
"input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi",
"output": "YES"
},
{
"input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib",
"output": "YES"
}
] | 1,674,350,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | a=input();b=input();n=0;r=''
for i in range(-1,len(b)-1):
r='{}{}'.format(r,b[i])
if a==r:
print('YES')
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
Input Specification:
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output Specification:
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
Demo Input:
['code\nedoc\n', 'abb\naba\n', 'code\ncode\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
a=input();b=input();n=0;r=''
for i in range(-1,len(b)-1):
r='{}{}'.format(r,b[i])
if a==r:
print('YES')
else:
print("NO")
``` | 0 |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,634,049,232 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 6,963,200 | n=int(input())
l=list(map(int,input().split()))
p=s=w=0
while p<n-1:
s=s+(p+1)*abs(l[p+1]%2-l[p]%2)
w=w+abs(l[p+1]%2-l[p]%2)
p+=1
if w<2 and s>1:
print(n)
else:
print(int(s/2+1/2)) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split()))
p=s=w=0
while p<n-1:
s=s+(p+1)*abs(l[p+1]%2-l[p]%2)
w=w+abs(l[p+1]%2-l[p]%2)
p+=1
if w<2 and s>1:
print(n)
else:
print(int(s/2+1/2))
``` | 3.95603 |
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"output": "100"
},
{
"input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983",
"output": "9983"
},
{
"input": "10 9\n7 29 35 38 41 47 54 56 73 74",
"output": "74"
},
{
"input": "1 2342\n12345",
"output": "12345"
},
{
"input": "10 5\n15 15 20 28 38 44 46 52 69 94",
"output": "109"
},
{
"input": "10 9\n6 10 10 32 36 38 69 80 82 93",
"output": "93"
},
{
"input": "10 10\n4 19 22 24 25 43 49 56 78 88",
"output": "88"
},
{
"input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946",
"output": "9946"
},
{
"input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986",
"output": "9986"
},
{
"input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927",
"output": "9927"
},
{
"input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970",
"output": "9970"
},
{
"input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993",
"output": "11103"
},
{
"input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983",
"output": "10676"
},
{
"input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866",
"output": "10011"
},
{
"input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804",
"output": "10009"
},
{
"input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934",
"output": "9934"
},
{
"input": "1 50000\n2",
"output": "2"
},
{
"input": "1 40000\n23456",
"output": "23456"
},
{
"input": "1 2\n10",
"output": "10"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "2 2\n2 3",
"output": "3"
},
{
"input": "4 2\n1 2 8 9",
"output": "10"
}
] | 1,594,892,137 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 249 | 30,617,600 | import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
double=n-k
ans=0
for i in range(double):
ans=max(ans,a[i]+a[2*double-1-i])
temp=-math.inf
if(k+k!=n):
temp=max(a[2*double:])
ans=max(ans,temp)
print(ans)
| Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection.
Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=><=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
Input Specification:
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Output Specification:
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
Demo Input:
['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n']
Demo Output:
['7\n', '9\n', '8\n']
Note:
In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | ```python
import math
import time
from collections import defaultdict,deque
from sys import stdin,stdout
from bisect import bisect_left,bisect_right
n,k=map(int,stdin.readline().split())
a=list(map(int,stdin.readline().split()))
double=n-k
ans=0
for i in range(double):
ans=max(ans,a[i]+a[2*double-1-i])
temp=-math.inf
if(k+k!=n):
temp=max(a[2*double:])
ans=max(ans,temp)
print(ans)
``` | 3 |
|
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this. | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has. | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order. | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\n1 2 3 4 "
},
{
"input": "30 38\n9560 64176 75619 53112 54160 68775 12655 13118 99502 89757 78434 42521 19210 1927 34097 5416 56110 44786 59126 44266 79240 65567 54602 25325 37171 2879 89291 89121 39568 28162",
"output": "8\n1 2 3 4 5 6 7 8 "
},
{
"input": "1 999999298\n85187",
"output": "44720\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 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 ..."
},
{
"input": "1 999999119\n34421",
"output": "44720\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 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 ..."
},
{
"input": "1 1000000000\n1",
"output": "44719\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 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 15..."
},
{
"input": "1 1000000000\n44720",
"output": "44720\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 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 ..."
},
{
"input": "1 1000000000\n44719",
"output": "44720\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 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 ..."
},
{
"input": "1 1000000000\n44721",
"output": "44720\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 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 ..."
},
{
"input": "3 1000000000\n123456789 234567891 345678912",
"output": "44720\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 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 ..."
},
{
"input": "2 5\n999999999 1000000000",
"output": "2\n1 2 "
},
{
"input": "2 1000000000\n1 1000000000",
"output": "44719\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 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 15..."
},
{
"input": "3 100000\n1000000000 100000000 1",
"output": "445\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 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 ..."
},
{
"input": "5 5\n100000000 200000000 300000000 400000000 1000000000",
"output": "2\n1 2 "
},
{
"input": "6 3\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "1 1000000000\n1000000000",
"output": "44720\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 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 ..."
},
{
"input": "5 1000000\n1000000000 100000000 10000000 99999999 123456789",
"output": "1413\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 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 1..."
},
{
"input": "2 10000000\n1234567 123456",
"output": "4471\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 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 1..."
},
{
"input": "1 1\n1000000000",
"output": "1\n1 "
},
{
"input": "1 1000000000\n9999999",
"output": "44720\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 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 ..."
},
{
"input": "5 10000\n1000000000 888888888 777777777 666666666 959595959",
"output": "140\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 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 "
},
{
"input": "3 1\n1000000000 999999999 999999998",
"output": "1\n1 "
},
{
"input": "5 100000000\n100000000 999999999 1 2 3",
"output": "14138\n4 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 15..."
},
{
"input": "3 55\n100000000 1000000000 999999999",
"output": "10\n1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "2 10\n5 10000009",
"output": "4\n1 2 3 4 "
},
{
"input": "3 10000000\n999999999 999999998 999999997",
"output": "4471\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 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 1..."
},
{
"input": "1 1100\n1000000000",
"output": "46\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 "
},
{
"input": "1 40\n1000000000",
"output": "8\n1 2 3 4 5 6 7 8 "
}
] | 1,571,652,306 | 2,147,483,647 | PyPy 3 | OK | TESTS | 61 | 326 | 12,902,400 | n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
t = 0
ans = []
i = 0
p = 1
while m > 0:
if i < n and a[i] == p:
i += 1
else:
if m >= p:
m -= p
t += 1
ans.append(p)
else:
break
p += 1
print(t)
for i in ans:
print(i, end=' ') | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection. Today is Tanya's birthday, and her mother decided to spend no more than *m* bourles on the gift to the daughter. Tanya will choose several different types of toys from the new collection as a gift. Of course, she does not want to get a type of toy which she already has.
Tanya wants to have as many distinct types of toys in her collection as possible as the result. The new collection is too diverse, and Tanya is too little, so she asks you to help her in this.
Input Specification:
The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the types of toys that Tanya already has.
Output Specification:
In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated integers *t*1,<=*t*2,<=...,<=*t**k* (1<=≤<=*t**i*<=≤<=109) — the types of toys that Tanya should choose.
If there are multiple answers, you may print any of them. Values of *t**i* can be printed in any order.
Demo Input:
['3 7\n1 3 4\n', '4 14\n4 6 12 8\n']
Demo Output:
['2\n2 5 \n', '4\n7 2 3 1\n']
Note:
In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | ```python
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
t = 0
ans = []
i = 0
p = 1
while m > 0:
if i < n and a[i] == p:
i += 1
else:
if m >= p:
m -= p
t += 1
ans.append(p)
else:
break
p += 1
print(t)
for i in ans:
print(i, end=' ')
``` | 3 |
|
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"output": "6"
},
{
"input": "11 562314608",
"output": "39916800"
},
{
"input": "3 990639260",
"output": "6"
},
{
"input": "11 859155400",
"output": "39916800"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "5 3",
"output": "6"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "5 4",
"output": "24"
},
{
"input": "1 12",
"output": "1"
},
{
"input": "9 7",
"output": "5040"
},
{
"input": "2 3",
"output": "2"
},
{
"input": "6 11",
"output": "720"
},
{
"input": "6 7",
"output": "720"
},
{
"input": "11 11",
"output": "39916800"
},
{
"input": "4 999832660",
"output": "24"
},
{
"input": "7 999228288",
"output": "5040"
},
{
"input": "11 999257105",
"output": "39916800"
},
{
"input": "11 999286606",
"output": "39916800"
},
{
"input": "3 999279109",
"output": "6"
},
{
"input": "999632727 11",
"output": "39916800"
},
{
"input": "999625230 7",
"output": "5040"
},
{
"input": "999617047 3",
"output": "6"
},
{
"input": "999646548 7",
"output": "5040"
},
{
"input": "999639051 3",
"output": "6"
},
{
"input": "12 12",
"output": "479001600"
},
{
"input": "12 1",
"output": "1"
},
{
"input": "1213 5",
"output": "120"
},
{
"input": "8 9",
"output": "40320"
},
{
"input": "12 9",
"output": "362880"
},
{
"input": "12 1000000000",
"output": "479001600"
},
{
"input": "1000000000 1",
"output": "1"
},
{
"input": "12 13",
"output": "479001600"
},
{
"input": "2 29845",
"output": "2"
},
{
"input": "10 21",
"output": "3628800"
},
{
"input": "12 20",
"output": "479001600"
},
{
"input": "15 12",
"output": "479001600"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000 12",
"output": "479001600"
},
{
"input": "11 30",
"output": "39916800"
},
{
"input": "17 12",
"output": "479001600"
},
{
"input": "4 19",
"output": "24"
},
{
"input": "12 15",
"output": "479001600"
},
{
"input": "20 6",
"output": "720"
},
{
"input": "10 20",
"output": "3628800"
},
{
"input": "10 10",
"output": "3628800"
},
{
"input": "22 12",
"output": "479001600"
},
{
"input": "20 12",
"output": "479001600"
},
{
"input": "12 23",
"output": "479001600"
},
{
"input": "12 22",
"output": "479001600"
},
{
"input": "18 3",
"output": "6"
},
{
"input": "14 10",
"output": "3628800"
},
{
"input": "14 12",
"output": "479001600"
},
{
"input": "8 3",
"output": "6"
},
{
"input": "5 5",
"output": "120"
}
] | 1,674,585,201 | 2,147,483,647 | PyPy 3 | OK | TESTS | 59 | 93 | 0 | import math
n,p=map(int,input().split())
z=math.factorial(min(n,p))
print(z) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!
Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*.
Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
Input Specification:
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Output Specification:
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
Demo Input:
['4 3\n']
Demo Output:
['6\n']
Note:
Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | ```python
import math
n,p=map(int,input().split())
z=math.factorial(min(n,p))
print(z)
``` | 3 |
|
78 | D | Archer's Shot | PROGRAMMING | 2,300 | [
"binary search",
"geometry",
"math",
"two pointers"
] | D. Archer's Shot | 2 | 256 | A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archer’s fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as *A*.
Find the number of cells that are under fire for some archer. | The first and only line of input contains a single positive integer *k* — the archer's shot range (1<=≤<=*k*<=≤<=106). | Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator). | [
"3\n",
"4\n",
"5\n"
] | [
"7",
"13",
"19"
] | none | 2,000 | [
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "13"
},
{
"input": "5",
"output": "19"
},
{
"input": "9",
"output": "85"
},
{
"input": "11",
"output": "121"
},
{
"input": "51",
"output": "3037"
},
{
"input": "101",
"output": "12109"
},
{
"input": "911",
"output": "1001425"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "8",
"output": "61"
},
{
"input": "6",
"output": "31"
},
{
"input": "7",
"output": "43"
},
{
"input": "10",
"output": "97"
},
{
"input": "13",
"output": "175"
},
{
"input": "43",
"output": "2137"
},
{
"input": "88",
"output": "9151"
},
{
"input": "217",
"output": "56425"
},
{
"input": "301",
"output": "108847"
},
{
"input": "403",
"output": "195457"
},
{
"input": "1034",
"output": "1290385"
},
{
"input": "1249",
"output": "1883353"
},
{
"input": "2749",
"output": "9131485"
},
{
"input": "5832",
"output": "41114119"
},
{
"input": "6486",
"output": "50854039"
},
{
"input": "6726",
"output": "54687523"
},
{
"input": "8910",
"output": "95975509"
},
{
"input": "9654",
"output": "112674937"
},
{
"input": "9991",
"output": "120678955"
},
{
"input": "10000",
"output": "120896557"
},
{
"input": "10264",
"output": "127364821"
},
{
"input": "21352",
"output": "551234029"
},
{
"input": "40094",
"output": "1943730367"
},
{
"input": "47248",
"output": "2699275123"
},
{
"input": "100000",
"output": "12091764163"
},
{
"input": "225481",
"output": "61477218007"
},
{
"input": "498598",
"output": "300605820001"
},
{
"input": "777777",
"output": "731487842995"
},
{
"input": "999811",
"output": "1208740231393"
},
{
"input": "999998",
"output": "1209192430093"
},
{
"input": "999999",
"output": "1209194850235"
},
{
"input": "1000000",
"output": "1209197264797"
}
] | 1,611,669,069 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a=int(input())
print(6*a-11) | Title: Archer's Shot
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them.
The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite.
Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archer’s fire if and only if all points of this cell, including border points are located inside the circle or on its border.
The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as *A*.
Find the number of cells that are under fire for some archer.
Input Specification:
The first and only line of input contains a single positive integer *k* — the archer's shot range (1<=≤<=*k*<=≤<=106).
Output Specification:
Print the single number, the number of cells that are under fire.
Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator).
Demo Input:
['3\n', '4\n', '5\n']
Demo Output:
['7', '13', '19']
Note:
none | ```python
a=int(input())
print(6*a-11)
``` | 0 |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help. | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "10 10 42",
"output": "YES"
},
{
"input": "-1000000000 1000000000 -1",
"output": "NO"
},
{
"input": "10 16 4",
"output": "NO"
},
{
"input": "-1000000000 1000000000 5",
"output": "YES"
},
{
"input": "1000000000 -1000000000 5",
"output": "NO"
},
{
"input": "1000000000 -1000000000 0",
"output": "NO"
},
{
"input": "1000000000 1000000000 0",
"output": "YES"
},
{
"input": "115078364 -899474523 -1",
"output": "YES"
},
{
"input": "-245436499 416383245 992",
"output": "YES"
},
{
"input": "-719636354 536952440 2",
"output": "YES"
},
{
"input": "-198350539 963391024 68337739",
"output": "YES"
},
{
"input": "-652811055 875986516 1091",
"output": "YES"
},
{
"input": "119057893 -516914539 -39748277",
"output": "YES"
},
{
"input": "989140430 731276607 -36837689",
"output": "YES"
},
{
"input": "677168390 494583489 -985071853",
"output": "NO"
},
{
"input": "58090193 777423708 395693923",
"output": "NO"
},
{
"input": "479823846 -403424770 -653472589",
"output": "NO"
},
{
"input": "-52536829 -132023273 -736287999",
"output": "NO"
},
{
"input": "-198893776 740026818 -547885271",
"output": "NO"
},
{
"input": "-2 -2 -2",
"output": "YES"
},
{
"input": "-2 -2 -1",
"output": "YES"
},
{
"input": "-2 -2 0",
"output": "YES"
},
{
"input": "-2 -2 1",
"output": "YES"
},
{
"input": "-2 -2 2",
"output": "YES"
},
{
"input": "-2 -1 -2",
"output": "NO"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "-2 -1 0",
"output": "NO"
},
{
"input": "-2 -1 1",
"output": "YES"
},
{
"input": "-2 -1 2",
"output": "NO"
},
{
"input": "-2 0 -2",
"output": "NO"
},
{
"input": "-2 0 -1",
"output": "NO"
},
{
"input": "-2 0 0",
"output": "NO"
},
{
"input": "-2 0 1",
"output": "YES"
},
{
"input": "-2 0 2",
"output": "YES"
},
{
"input": "-2 1 -2",
"output": "NO"
},
{
"input": "-2 1 -1",
"output": "NO"
},
{
"input": "-2 1 0",
"output": "NO"
},
{
"input": "-2 1 1",
"output": "YES"
},
{
"input": "-2 1 2",
"output": "NO"
},
{
"input": "-2 2 -2",
"output": "NO"
},
{
"input": "-2 2 -1",
"output": "NO"
},
{
"input": "-2 2 0",
"output": "NO"
},
{
"input": "-2 2 1",
"output": "YES"
},
{
"input": "-2 2 2",
"output": "YES"
},
{
"input": "-1 -2 -2",
"output": "NO"
},
{
"input": "-1 -2 -1",
"output": "YES"
},
{
"input": "-1 -2 0",
"output": "NO"
},
{
"input": "-1 -2 1",
"output": "NO"
},
{
"input": "-1 -2 2",
"output": "NO"
},
{
"input": "-1 -1 -2",
"output": "YES"
},
{
"input": "-1 -1 -1",
"output": "YES"
},
{
"input": "-1 -1 0",
"output": "YES"
},
{
"input": "-1 -1 1",
"output": "YES"
},
{
"input": "-1 -1 2",
"output": "YES"
},
{
"input": "-1 0 -2",
"output": "NO"
},
{
"input": "-1 0 -1",
"output": "NO"
},
{
"input": "-1 0 0",
"output": "NO"
},
{
"input": "-1 0 1",
"output": "YES"
},
{
"input": "-1 0 2",
"output": "NO"
},
{
"input": "-1 1 -2",
"output": "NO"
},
{
"input": "-1 1 -1",
"output": "NO"
},
{
"input": "-1 1 0",
"output": "NO"
},
{
"input": "-1 1 1",
"output": "YES"
},
{
"input": "-1 1 2",
"output": "YES"
},
{
"input": "-1 2 -2",
"output": "NO"
},
{
"input": "-1 2 -1",
"output": "NO"
},
{
"input": "-1 2 0",
"output": "NO"
},
{
"input": "-1 2 1",
"output": "YES"
},
{
"input": "-1 2 2",
"output": "NO"
},
{
"input": "0 -2 -2",
"output": "YES"
},
{
"input": "0 -2 -1",
"output": "YES"
},
{
"input": "0 -2 0",
"output": "NO"
},
{
"input": "0 -2 1",
"output": "NO"
},
{
"input": "0 -2 2",
"output": "NO"
},
{
"input": "0 -1 -2",
"output": "NO"
},
{
"input": "0 -1 -1",
"output": "YES"
},
{
"input": "0 -1 0",
"output": "NO"
},
{
"input": "0 -1 1",
"output": "NO"
},
{
"input": "0 -1 2",
"output": "NO"
},
{
"input": "0 0 -2",
"output": "YES"
},
{
"input": "0 0 -1",
"output": "YES"
},
{
"input": "0 0 0",
"output": "YES"
},
{
"input": "0 0 1",
"output": "YES"
},
{
"input": "0 0 2",
"output": "YES"
},
{
"input": "0 1 -2",
"output": "NO"
},
{
"input": "0 1 -1",
"output": "NO"
},
{
"input": "0 1 0",
"output": "NO"
},
{
"input": "0 1 1",
"output": "YES"
},
{
"input": "0 1 2",
"output": "NO"
},
{
"input": "0 2 -2",
"output": "NO"
},
{
"input": "0 2 -1",
"output": "NO"
},
{
"input": "0 2 0",
"output": "NO"
},
{
"input": "0 2 1",
"output": "YES"
},
{
"input": "0 2 2",
"output": "YES"
},
{
"input": "1 -2 -2",
"output": "NO"
},
{
"input": "1 -2 -1",
"output": "YES"
},
{
"input": "1 -2 0",
"output": "NO"
},
{
"input": "1 -2 1",
"output": "NO"
},
{
"input": "1 -2 2",
"output": "NO"
},
{
"input": "1 -1 -2",
"output": "YES"
},
{
"input": "1 -1 -1",
"output": "YES"
},
{
"input": "1 -1 0",
"output": "NO"
},
{
"input": "1 -1 1",
"output": "NO"
},
{
"input": "1 -1 2",
"output": "NO"
},
{
"input": "1 0 -2",
"output": "NO"
},
{
"input": "1 0 -1",
"output": "YES"
},
{
"input": "1 0 0",
"output": "NO"
},
{
"input": "1 0 1",
"output": "NO"
},
{
"input": "1 0 2",
"output": "NO"
},
{
"input": "1 1 -2",
"output": "YES"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "1 1 0",
"output": "YES"
},
{
"input": "1 1 1",
"output": "YES"
},
{
"input": "1 1 2",
"output": "YES"
},
{
"input": "1 2 -2",
"output": "NO"
},
{
"input": "1 2 -1",
"output": "NO"
},
{
"input": "1 2 0",
"output": "NO"
},
{
"input": "1 2 1",
"output": "YES"
},
{
"input": "1 2 2",
"output": "NO"
},
{
"input": "2 -2 -2",
"output": "YES"
},
{
"input": "2 -2 -1",
"output": "YES"
},
{
"input": "2 -2 0",
"output": "NO"
},
{
"input": "2 -2 1",
"output": "NO"
},
{
"input": "2 -2 2",
"output": "NO"
},
{
"input": "2 -1 -2",
"output": "NO"
},
{
"input": "2 -1 -1",
"output": "YES"
},
{
"input": "2 -1 0",
"output": "NO"
},
{
"input": "2 -1 1",
"output": "NO"
},
{
"input": "2 -1 2",
"output": "NO"
},
{
"input": "2 0 -2",
"output": "YES"
},
{
"input": "2 0 -1",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "2 0 1",
"output": "NO"
},
{
"input": "2 0 2",
"output": "NO"
},
{
"input": "2 1 -2",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "2 1 0",
"output": "NO"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "2 1 2",
"output": "NO"
},
{
"input": "2 2 -2",
"output": "YES"
},
{
"input": "2 2 -1",
"output": "YES"
},
{
"input": "2 2 0",
"output": "YES"
},
{
"input": "2 2 1",
"output": "YES"
},
{
"input": "2 2 2",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 2",
"output": "YES"
},
{
"input": "1000000000 -1000000000 -1",
"output": "YES"
},
{
"input": "5 2 3",
"output": "NO"
},
{
"input": "2 1 -1",
"output": "YES"
},
{
"input": "3 2 1",
"output": "NO"
},
{
"input": "0 -5 -3",
"output": "NO"
},
{
"input": "2 5 5",
"output": "NO"
},
{
"input": "0 10 1",
"output": "YES"
},
{
"input": "15 5 -5",
"output": "YES"
},
{
"input": "2 1 1",
"output": "NO"
},
{
"input": "20 10 0",
"output": "NO"
},
{
"input": "20 15 5",
"output": "NO"
},
{
"input": "1 6 1",
"output": "YES"
},
{
"input": "1000000000 0 -1000000000",
"output": "YES"
},
{
"input": "1 1 -5",
"output": "YES"
},
{
"input": "4 6 1",
"output": "YES"
},
{
"input": "-5 -10 -5",
"output": "YES"
},
{
"input": "2 0 0",
"output": "NO"
},
{
"input": "10 9 -1",
"output": "YES"
},
{
"input": "-2 -1 -1",
"output": "NO"
},
{
"input": "1 13 3",
"output": "YES"
},
{
"input": "2 3 0",
"output": "NO"
},
{
"input": "1 1 -1",
"output": "YES"
},
{
"input": "5 -10 -5",
"output": "YES"
},
{
"input": "5 3 1",
"output": "NO"
},
{
"input": "1 1000000000 1",
"output": "YES"
},
{
"input": "-1000000000 1000000000 1000000000",
"output": "YES"
}
] | 1,689,446,498 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | text = input()
a,b,c = text.split()
a,b,c = int(a),int(b),int(c)
if c==0:
if b==a: print("YES")
else: print("NO")
else:
if (b-a)%c==0 : print("YES")
else: print("NO") | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears in this sequence, that is, there exists a positive integer *i*, such that *s**i*<==<=*b*. Of course, you are the person he asks for a help.
Input Specification:
The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
Output Specification:
If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes).
Demo Input:
['1 7 3\n', '10 10 0\n', '1 -4 5\n', '0 60 50\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n', 'NO\n']
Note:
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer. | ```python
text = input()
a,b,c = text.split()
a,b,c = int(a),int(b),int(c)
if c==0:
if b==a: print("YES")
else: print("NO")
else:
if (b-a)%c==0 : print("YES")
else: print("NO")
``` | 0 |
|
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell. | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters. | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input": "3 2 W\nOO\nWW\nWW",
"output": "1"
},
{
"input": "3 3 U\nUOO\nUVV\nUVV",
"output": "2"
},
{
"input": "4 5 Z\n...ZZ\nUU.ZZ\nUUTT.\n..TT.",
"output": "1"
},
{
"input": "4 4 X\nT..R\nTJJJ\nDJJJ\nXJJJ",
"output": "2"
},
{
"input": "5 5 O\nCQGAV\nIHTUD\nRFPZO\nMYSKX\nJEWBN",
"output": "3"
},
{
"input": "5 4 O\n.O.J\nWOBJ\nWOBJ\nDDBJ\nDD.J",
"output": "3"
},
{
"input": "7 7 Q\n....RRR\nUUUURRR\nUUUUSS.\n....SSB\nPPP.OIB\n.MMTTIB\nQQQTTIB",
"output": "2"
},
{
"input": "8 10 B\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\n..BBBBEEEE\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..\nJJJJYYYY..",
"output": "3"
},
{
"input": "7 13 G\n....GGGGGGXXX\nSSSSGGGGGGXXX\nSSSSJJFFFFFFF\nRRR.JJFFFFFFF\nRRRYYYYYYYAAA\nRRRYYYYYYYAAA\nRRR.......AAA",
"output": "4"
},
{
"input": "10 10 T\nCCEEEKKKHJ\nCCRRRRRRHJ\nCC..XFFOOO\nZZZZZFFOOO\n..PTTFFOOO\nAAATTFFOOO\nAAATTYYYYY\nAAATTYYYYY\nAAAMMYYYYY\nAAA..YYYYY",
"output": "6"
},
{
"input": "15 12 M\n............\n.....L..QQQQ\nNNN..L..QQQQ\nNNN..LJJJJJ.\nNNNEEEEEEEE.\nNNNEEEEEEEE.\nNNNMMMMM.AAA\nNNNMMMMM.AAA\n.RRMMMMM.AAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\n.RRMMMMMYAAA\nZRRMMMMMYAAA\nZRRMMMMM.AAA\nZRRMMMMM.AAA",
"output": "4"
}
] | 1,680,304,295 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 61 | 0 | def checa(x, y):
if x < 0 or x >= n or y < 0 or y >= m or matrix[x][y] == c or matrix[x][y] == '.':
return False
return True
n, m, c = input().split()
n, m = int(n), int(m)
matrix = []
for k in range(n):
matrix.append(input())
x = [-1, 0, 0, 1]
y = [0, 1, -1, 0]
m7 = set([])
for i in range(n):
for j in range(m):
if matrix[i][j] == c:
for k in range(4):
if checa(i + x[k], j + y[k]):
m7.add(matrix[i + x[k]][ j + y[k]])
print(len(m7)) | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all his deputies will be members. Unfortunately, he does not remember the exact amount of his deputies, but he remembers that the desk of each his deputy is adjacent to his own desk, that is to say, the two desks (President's and each deputy's) have a common side of a positive length.
The office-room plan can be viewed as a matrix with *n* rows and *m* columns. Each cell of this matrix is either empty, or contains a part of a desk. An uppercase Latin letter stands for each desk colour. The «period» character («.») stands for an empty cell.
Input Specification:
The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each desk is unique, and each desk represents a continuous subrectangle of the given matrix. All colours are marked by uppercase Latin letters.
Output Specification:
Print the only number — the amount of President's deputies.
Demo Input:
['3 4 R\nG.B.\n.RR.\nTTT.\n', '3 3 Z\n...\n.H.\n..Z\n']
Demo Output:
['2\n', '0\n']
Note:
none | ```python
def checa(x, y):
if x < 0 or x >= n or y < 0 or y >= m or matrix[x][y] == c or matrix[x][y] == '.':
return False
return True
n, m, c = input().split()
n, m = int(n), int(m)
matrix = []
for k in range(n):
matrix.append(input())
x = [-1, 0, 0, 1]
y = [0, 1, -1, 0]
m7 = set([])
for i in range(n):
for j in range(m):
if matrix[i][j] == c:
for k in range(4):
if checa(i + x[k], j + y[k]):
m7.add(matrix[i + x[k]][ j + y[k]])
print(len(m7))
``` | 3.98475 |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus. | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"output": "ypg"
},
{
"input": "3\nexhll\nexhll\narruapexj",
"output": "arruapexj\nexhll"
},
{
"input": "3\nfv\nle\nle",
"output": "le\nfv"
},
{
"input": "8\nm\nm\nm\nm\nm\nm\nm\nm",
"output": "m"
},
{
"input": "10\nr\nr\ni\nw\nk\nr\nb\nu\nu\nr",
"output": "r\nu\nb\nk\nw\ni"
},
{
"input": "7\ne\nfau\ncmk\nnzs\nby\nwx\ntjmok",
"output": "tjmok\nwx\nby\nnzs\ncmk\nfau\ne"
},
{
"input": "6\nklrj\nwe\nklrj\nwe\nwe\nwe",
"output": "we\nklrj"
},
{
"input": "8\nzncybqmh\naeebef\nzncybqmh\nn\naeebef\nzncybqmh\nzncybqmh\nzncybqmh",
"output": "zncybqmh\naeebef\nn"
},
{
"input": "30\nkqqcbs\nvap\nkymomn\nj\nkqqcbs\nfuzlzoum\nkymomn\ndbh\nfuzlzoum\nkymomn\nvap\nvlgzs\ndbh\nvlgzs\nbvy\ndbh\nkymomn\nkymomn\neoqql\nkymomn\nkymomn\nkqqcbs\nvlgzs\nkqqcbs\nkqqcbs\nfuzlzoum\nvlgzs\nrylgdoo\nvlgzs\nrylgdoo",
"output": "rylgdoo\nvlgzs\nfuzlzoum\nkqqcbs\nkymomn\neoqql\ndbh\nbvy\nvap\nj"
},
{
"input": "40\nji\nv\nv\nns\nji\nn\nji\nv\nfvy\nvje\nns\nvje\nv\nhas\nv\nusm\nhas\nfvy\nvje\nkdb\nn\nv\nji\nji\nn\nhas\nv\nji\nkdb\nr\nvje\nns\nv\nusm\nn\nvje\nhas\nns\nhas\nn",
"output": "n\nhas\nns\nvje\nusm\nv\nr\nkdb\nji\nfvy"
},
{
"input": "50\njcg\nvle\njopb\nepdb\nnkef\nfv\nxj\nufe\nfuy\noqta\ngbc\nyuz\nec\nyji\nkuux\ncwm\ntq\nnno\nhp\nzry\nxxpp\ntjvo\ngyz\nkwo\nvwqz\nyaqc\njnj\nwoav\nqcv\ndcu\ngc\nhovn\nop\nevy\ndc\ntrpu\nyb\nuzfa\npca\noq\nnhxy\nsiqu\nde\nhphy\nc\nwovu\nf\nbvv\ndsik\nlwyg",
"output": "lwyg\ndsik\nbvv\nf\nwovu\nc\nhphy\nde\nsiqu\nnhxy\noq\npca\nuzfa\nyb\ntrpu\ndc\nevy\nop\nhovn\ngc\ndcu\nqcv\nwoav\njnj\nyaqc\nvwqz\nkwo\ngyz\ntjvo\nxxpp\nzry\nhp\nnno\ntq\ncwm\nkuux\nyji\nec\nyuz\ngbc\noqta\nfuy\nufe\nxj\nfv\nnkef\nepdb\njopb\nvle\njcg"
},
{
"input": "100\nvhh\nvhh\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nvhh\nvhh\nvhh\nfa\nvhh\nvhh\nfa\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nfa\nfa\nfa\nfa\nfa\nfa\nvhh\nvhh\nfa\nvhh\nfa\nfa\nvhh\nfa\nfa\nvhh\nfa\nvhh\nvhh\nfa\nvhh",
"output": "vhh\nfa"
},
{
"input": "2\naa\nbb",
"output": "bb\naa"
},
{
"input": "2\naa\na",
"output": "a\naa"
},
{
"input": "3\naa\naa\naa",
"output": "aa"
},
{
"input": "5\naa\na\naa\na\naa",
"output": "aa\na"
},
{
"input": "7\naaaa\naaaa\naaa\na\naa\naaaaaaa\naaa",
"output": "aaa\naaaaaaa\naa\na\naaaa"
},
{
"input": "5\na\naa\naaa\naaaa\na",
"output": "a\naaaa\naaa\naa"
},
{
"input": "12\naaaaa\naaaaaa\naaaa\naaaaaa\naa\naaaa\naaaa\naaaaaa\na\naaa\naaaaaaaa\naa",
"output": "aa\naaaaaaaa\naaa\na\naaaaaa\naaaa\naaaaa"
},
{
"input": "3\na\naa\naaa",
"output": "aaa\naa\na"
},
{
"input": "9\nzzz\nzzzzz\nzzz\nzzzz\nzz\nzzzz\nzzzzz\nzzzz\nzzzzzzz",
"output": "zzzzzzz\nzzzz\nzzzzz\nzz\nzzz"
}
] | 1,696,681,423 | 2,147,483,647 | Python 3 | OK | TESTS | 95 | 529 | 31,948,800 | n = int(input())
Dict = {}
arr = list()
for i in range(n):
s = input()
arr.append(s)
for i in range(len(arr)-1,-1,-1):
if arr[i] not in Dict:
Dict[arr[i]] = 1
print(arr[i])
| Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then a new chat is simply inserted to the top of the list.
Assuming that the chat list is initially empty, given the sequence of Polycaprus' messages make a list of chats after all of his messages are processed. Assume that no friend wrote any message to Polycarpus.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10.
Output Specification:
Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom.
Demo Input:
['4\nalex\nivan\nroman\nivan\n', '8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n']
Demo Output:
['ivan\nroman\nalex\n', 'alina\nmaria\nekaterina\ndarya\n']
Note:
In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1. ivan 1. alex
Polycarpus writes the fourth message to friend by name "ivan", to who he has already sent a message, so the list of chats changes as follows:
1. ivan 1. roman 1. alex | ```python
n = int(input())
Dict = {}
arr = list()
for i in range(n):
s = input()
arr.append(s)
for i in range(len(arr)-1,-1,-1):
if arr[i] not in Dict:
Dict[arr[i]] = 1
print(arr[i])
``` | 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,652,261,180 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | n,m,a=map(int,input().split())
t=1
c=0
if n*m < a*a:
print('1')
else:
c=1
a=a*a*t
while n*m > a:
t+=2
a=a*a*t
c=c+t
print(c)
| 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
n,m,a=map(int,input().split())
t=1
c=0
if n*m < a*a:
print('1')
else:
c=1
a=a*a*t
while n*m > a:
t+=2
a=a*a*t
c=c+t
print(c)
``` | 0 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact. | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
"input": "AMVFNFJIAVNQJWIVONQOAOOQSNQSONOASONAONQINAONAOIQONANOIQOANOQINAONOQINAONOXJCOIAQOAOQAQAQAQAQWWWAQQAQ",
"output": "1077"
},
{
"input": "AAQQAXBQQBQQXBNQRJAQKQNAQNQVDQASAGGANQQQQTJFFQQQTQQA",
"output": "568"
},
{
"input": "KAZXAVLPJQBQVQQQQQAPAQQGQTQVZQAAAOYA",
"output": "70"
},
{
"input": "W",
"output": "0"
},
{
"input": "DBA",
"output": "0"
},
{
"input": "RQAWNACASAAKAGAAAAQ",
"output": "10"
},
{
"input": "QJAWZAAOAAGIAAAAAOQATASQAEAAAAQFQQHPA",
"output": "111"
},
{
"input": "QQKWQAQAAAAAAAAGAAVAQUEQQUMQMAQQQNQLAMAAAUAEAAEMAAA",
"output": "411"
},
{
"input": "QQUMQAYAUAAGWAAAQSDAVAAQAAAASKQJJQQQQMAWAYYAAAAAAEAJAXWQQ",
"output": "625"
},
{
"input": "QORZOYAQ",
"output": "1"
},
{
"input": "QCQAQAGAWAQQQAQAVQAQQQQAQAQQQAQAAATQAAVAAAQQQQAAAUUQAQQNQQWQQWAQAAQQKQYAQAAQQQAAQRAQQQWBQQQQAPBAQGQA",
"output": "13174"
},
{
"input": "QQAQQAKQFAQLQAAWAMQAZQAJQAAQQOACQQAAAYANAQAQQAQAAQQAOBQQJQAQAQAQQQAAAAABQQQAVNZAQQQQAMQQAFAAEAQAQHQT",
"output": "10420"
},
{
"input": "AQEGQHQQKQAQQPQKAQQQAAAAQQQAQEQAAQAAQAQFSLAAQQAQOQQAVQAAAPQQAWAQAQAFQAXAQQQQTRLOQAQQJQNQXQQQQSQVDQQQ",
"output": "12488"
},
{
"input": "QNQKQQQLASQBAVQQQQAAQQOQRJQQAQQQEQZUOANAADAAQQJAQAQARAAAQQQEQBHTQAAQAAAAQQMKQQQIAOJJQQAQAAADADQUQQQA",
"output": "9114"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "35937"
},
{
"input": "AMQQAAQAAQAAAAAAQQQBOAAANAAKQJCYQAE",
"output": "254"
},
{
"input": "AYQBAEQGAQEOAKGIXLQJAIAKQAAAQPUAJAKAATFWQQAOQQQUFQYAQQMQHOKAAJXGFCARAQSATHAUQQAATQJJQDQRAANQQAE",
"output": "2174"
},
{
"input": "AAQXAAQAYQAAAAGAQHVQYAGIVACADFAAQAAAAQZAAQMAKZAADQAQDAAQDAAAMQQOXYAQQQAKQBAAQQKAXQBJZDDLAAHQQ",
"output": "2962"
},
{
"input": "AYQQYAVAMNIAUAAKBBQVACWKTQSAQZAAQAAASZJAWBCAALAARHACQAKQQAQAARPAQAAQAQAAZQUSHQAMFVFZQQQQSAQQXAA",
"output": "2482"
},
{
"input": "LQMAQQARQAQBJQQQAGAAZQQXALQQAARQAQQQQAAQQAQQQAQQCAQQAQQAYQQQRAAZATQALYQQAAHHAAQHAAAAAAAAQQMAAQNAKQ",
"output": "7768"
},
{
"input": "MAQQWAQOYQMAAAQAQPQZAOAAQAUAQNAAQAAAITQSAQAKAQKAQQWSQAAQQAGUCDQMQWKQUXKWQQAAQQAAQQZQDQQQAABXQUUXQOA",
"output": "5422"
},
{
"input": "QTAAQDAQXAQQJQQQGAAAQQQQSBQZKAQQAQQQQEAQNUQBZCQLYQZQEQQAAQHQVAORKQVAQYQNASZQAARZAAGAAAAOQDCQ",
"output": "3024"
},
{
"input": "QQWAQQGQQUZQQQLZAAQYQXQVAQFQUAQZUQZZQUKBHSHTQYLQAOQXAQQGAQQTQOAQARQADAJRAAQPQAQQUQAUAMAUVQAAAQQAWQ",
"output": "4527"
},
{
"input": "QQAAQQAQVAQZQQQQAOEAQZPQIBQZACQQAFQQLAAQDATZQANHKYQQAQTAAFQRQAIQAJPWQAQTEIRXAEQQAYWAAAUKQQAQAQQQSQQH",
"output": "6416"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAAAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQ",
"output": "13136"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "14270"
},
{
"input": "AQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQQAA",
"output": "14231"
},
{
"input": "QQQQQAQAAQQAQAQAAAAAAAAAQAQAAAAAQAQAQQQAQQQAAAQQQAAAAAAAQAAAAQQQQQQQAQQQQAQAAAQAAAAAQAQAAAAAQAQAA",
"output": "15296"
},
{
"input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"output": "0"
},
{
"input": "QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ",
"output": "0"
},
{
"input": "QAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQA",
"output": "20825"
},
{
"input": "AQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQAQ",
"output": "20825"
},
{
"input": "Q",
"output": "0"
},
{
"input": "A",
"output": "0"
},
{
"input": "FFF",
"output": "0"
},
{
"input": "AAAAAA",
"output": "0"
}
] | 1,620,908,378 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 109 | 22,118,400 | import sys
input = sys.stdin.readline
s = input()
ans = 0
for i in range(len(s)):
if s[i] == 'Q':
for j in range(i + 1, len(s)):
if s[j] == 'A':
y = 0
for k in range(j + 1, len(s)):
if s[k] == 'Q':
y += 1
ans += y
print(ans) | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.
Input Specification:
The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters.
Output Specification:
Print a single integer — the number of subsequences "QAQ" in the string.
Demo Input:
['QAQAQYSYIOIWIN\n', 'QAQQQZZYNOIWIN\n']
Demo Output:
['4\n', '3\n']
Note:
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | ```python
import sys
input = sys.stdin.readline
s = input()
ans = 0
for i in range(len(s)):
if s[i] == 'Q':
for j in range(i + 1, len(s)):
if s[j] == 'A':
y = 0
for k in range(j + 1, len(s)):
if s[k] == 'Q':
y += 1
ans += y
print(ans)
``` | 3 |
|
719 | A | Vitya in the Countryside | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent. | If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1. | [
"5\n3 4 5 6 7\n",
"7\n12 13 14 15 14 13 12\n",
"1\n8\n"
] | [
"UP\n",
"DOWN\n",
"-1\n"
] | In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | 500 | [
{
"input": "5\n3 4 5 6 7",
"output": "UP"
},
{
"input": "7\n12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "1\n8",
"output": "-1"
},
{
"input": "44\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10",
"output": "DOWN"
},
{
"input": "92\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4",
"output": "UP"
},
{
"input": "6\n10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "27\n11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "6\n8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "27\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "79\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5",
"output": "DOWN"
},
{
"input": "25\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "21\n3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7",
"output": "DOWN"
},
{
"input": "56\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "19\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14",
"output": "UP"
},
{
"input": "79\n5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13",
"output": "UP"
},
{
"input": "87\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10",
"output": "UP"
},
{
"input": "13\n10 9 8 7 6 5 4 3 2 1 0 1 2",
"output": "UP"
},
{
"input": "2\n8 9",
"output": "UP"
},
{
"input": "3\n10 11 12",
"output": "UP"
},
{
"input": "1\n1",
"output": "-1"
},
{
"input": "1\n2",
"output": "-1"
},
{
"input": "1\n3",
"output": "-1"
},
{
"input": "1\n4",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n6",
"output": "-1"
},
{
"input": "1\n7",
"output": "-1"
},
{
"input": "1\n9",
"output": "-1"
},
{
"input": "1\n10",
"output": "-1"
},
{
"input": "1\n11",
"output": "-1"
},
{
"input": "1\n12",
"output": "-1"
},
{
"input": "1\n13",
"output": "-1"
},
{
"input": "1\n14",
"output": "-1"
},
{
"input": "1\n15",
"output": "DOWN"
},
{
"input": "1\n0",
"output": "UP"
},
{
"input": "3\n11 12 13",
"output": "UP"
},
{
"input": "2\n10 9",
"output": "DOWN"
},
{
"input": "92\n10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11",
"output": "UP"
},
{
"input": "92\n7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6",
"output": "DOWN"
},
{
"input": "2\n14 15",
"output": "DOWN"
},
{
"input": "2\n1 0",
"output": "UP"
},
{
"input": "2\n15 14",
"output": "DOWN"
},
{
"input": "92\n7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8",
"output": "UP"
},
{
"input": "92\n13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12",
"output": "DOWN"
},
{
"input": "92\n4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3",
"output": "DOWN"
},
{
"input": "92\n14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "DOWN"
},
{
"input": "92\n1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n2 1",
"output": "DOWN"
},
{
"input": "3\n2 1 0",
"output": "UP"
},
{
"input": "5\n4 3 2 1 0",
"output": "UP"
},
{
"input": "2\n5 4",
"output": "DOWN"
},
{
"input": "4\n3 2 1 0",
"output": "UP"
},
{
"input": "3\n13 12 11",
"output": "DOWN"
},
{
"input": "2\n1 2",
"output": "UP"
},
{
"input": "2\n0 1",
"output": "UP"
},
{
"input": "2\n13 14",
"output": "UP"
},
{
"input": "14\n13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "UP"
}
] | 1,479,821,374 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 77 | 0 | n = int(input())
lst = [int(x) for x in input().split()]
if lst[-1] is 15:
print("DOWN")
elif lst[-1] is 0:
print("UP")
elif n is 1:
print("-1")
elif lst[-1] > lst[-2]:
print("UP")
else:
print("DOWN") | Title: Vitya in the Countryside
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.
Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.
As there is no internet in the countryside, Vitya has been watching the moon for *n* consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.
Input Specification:
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=15) — Vitya's records.
It's guaranteed that the input data is consistent.
Output Specification:
If Vitya can be sure that the size of visible part of the moon on day *n*<=+<=1 will be less than the size of the visible part on day *n*, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.
Demo Input:
['5\n3 4 5 6 7\n', '7\n12 13 14 15 14 13 12\n', '1\n8\n']
Demo Output:
['UP\n', 'DOWN\n', '-1\n']
Note:
In the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".
In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".
In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1. | ```python
n = int(input())
lst = [int(x) for x in input().split()]
if lst[-1] is 15:
print("DOWN")
elif lst[-1] is 0:
print("UP")
elif n is 1:
print("-1")
elif lst[-1] > lst[-2]:
print("UP")
else:
print("DOWN")
``` | 3 |
|
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,589,097,244 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 216 | 6,860,800 | n, m = map(int,input().split())
a = []
s = []
k = 0
l = []
for x in range(n):
a.append(list(input()))
for x in range(len(a)):
for y in range(len(a[x])):
if a[x][y] == "*":
s.append([x + 1,y + 1])
print(s)
for x in s:
l.append(x[0])
c = 0
d = 0
e =[]
for x in l:
if l.count(x) == 1:
c = x
if l.count(x) == 2:
d = x
print(c)
print(d)
for x in s:
if x[0] != c:
e.append(x[-1])
print(e)
if d in e:
e.remove(d)
print(str(c) + " " + str(e[0]))
| 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
n, m = map(int,input().split())
a = []
s = []
k = 0
l = []
for x in range(n):
a.append(list(input()))
for x in range(len(a)):
for y in range(len(a[x])):
if a[x][y] == "*":
s.append([x + 1,y + 1])
print(s)
for x in s:
l.append(x[0])
c = 0
d = 0
e =[]
for x in l:
if l.count(x) == 1:
c = x
if l.count(x) == 2:
d = x
print(c)
print(d)
for x in s:
if x[0] != c:
e.append(x[-1])
print(e)
if d in e:
e.remove(d)
print(str(c) + " " + str(e[0]))
``` | 0 |
|
991 | E | Bus Number | PROGRAMMING | 1,800 | [
"brute force",
"combinatorics",
"math"
] | null | null | This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all.
In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$.
In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too.
Given $n$, determine the total number of possible bus number variants. | The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$. | Output a single integer — the amount of possible variants of the real bus number. | [
"97\n",
"2028\n"
] | [
"2\n",
"13\n"
] | In the first sample, only variants $97$ and $79$ are possible.
In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$. | 2,000 | [
{
"input": "97",
"output": "2"
},
{
"input": "2028",
"output": "13"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "1"
},
{
"input": "168",
"output": "6"
},
{
"input": "999999",
"output": "6"
},
{
"input": "987654320023456789",
"output": "29340299842560"
},
{
"input": "1000000000000000000",
"output": "18"
},
{
"input": "74774",
"output": "28"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "1"
},
{
"input": "5",
"output": "1"
},
{
"input": "6",
"output": "1"
},
{
"input": "7",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "101010101",
"output": "246"
},
{
"input": "1010101010",
"output": "456"
},
{
"input": "707070707070707070",
"output": "92368"
},
{
"input": "19293",
"output": "84"
},
{
"input": "987650",
"output": "600"
},
{
"input": "123456",
"output": "720"
},
{
"input": "900008",
"output": "28"
},
{
"input": "1000000",
"output": "6"
},
{
"input": "9900111",
"output": "404"
},
{
"input": "11112222",
"output": "242"
},
{
"input": "88888880",
"output": "28"
},
{
"input": "100000009",
"output": "70"
},
{
"input": "203456799",
"output": "196560"
},
{
"input": "890009800",
"output": "1120"
},
{
"input": "900000000",
"output": "8"
},
{
"input": "987654321",
"output": "362880"
},
{
"input": "999999999",
"output": "9"
},
{
"input": "1000000000",
"output": "9"
},
{
"input": "999999999999999999",
"output": "18"
},
{
"input": "987654321123456789",
"output": "33007837322880"
},
{
"input": "987654321123456780",
"output": "55657759288320"
},
{
"input": "888888888888888888",
"output": "18"
},
{
"input": "888884444444448888",
"output": "184736"
},
{
"input": "880000000008888888",
"output": "92368"
},
{
"input": "122661170586643693",
"output": "4205605773600"
},
{
"input": "166187867387753706",
"output": "224244425700"
},
{
"input": "54405428089931205",
"output": "417074011200"
},
{
"input": "96517150587709082",
"output": "417074011200"
},
{
"input": "234906817379759421",
"output": "22773236965920"
},
{
"input": "470038695054731020",
"output": "5099960335680"
},
{
"input": "888413836884649324",
"output": "76835760120"
},
{
"input": "978691308972024154",
"output": "33638772575520"
},
{
"input": "484211136976275613",
"output": "6471643862880"
},
{
"input": "824250067279351651",
"output": "21519859273920"
},
{
"input": "269041787841325833",
"output": "22773236965920"
},
{
"input": "462534182594129378",
"output": "13498126800480"
},
{
"input": "79318880250640214",
"output": "2075276790720"
},
{
"input": "58577142509378476",
"output": "1126629393120"
},
{
"input": "973088698775609061",
"output": "1646603038080"
},
{
"input": "529916324588161451",
"output": "3614537707200"
},
{
"input": "406105326393716536",
"output": "2760291011520"
},
{
"input": "490977896148785607",
"output": "2054415328560"
},
{
"input": "547694365350162078",
"output": "21519859273920"
},
{
"input": "868572419889505545",
"output": "1124978369760"
}
] | 1,610,054,525 | 4,625 | PyPy 3 | OK | TESTS | 61 | 156 | 1,536,000 | fact = [0 for _ in range(35)]
fact[0] = 1
for q in range(1,35):
fact[q] = fact[q-1]*q
amts = []
ans = 0
def multinom():
tot = 0
for i in amts:
tot = tot + i
ret = fact[tot]
for i in amts:
ret = ret / fact[i]
return ret
t = int(input())
digct = []
for i in range(10):
digct.append(0)
tcpy = t
while tcpy > 0:
digct[int(tcpy%10)] = digct[int(tcpy%10)]+1
tcpy = tcpy // 10
def dfs(place):
global ans
if place == 10:
ans = ans + multinom()
if amts[0] > 0:
amts[0] = amts[0]-1
ans = ans - multinom()
amts[0] = amts[0]+1
return
if digct[place] == 0:
amts.append(0)
dfs(place+1)
amts.pop()
else:
for q in range(1, digct[place]+1):
amts.append(q)
dfs(place+1)
amts.pop()
dfs(0)
print(int(ans))
| Title: Bus Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This night wasn't easy on Vasya. His favorite team lost, and he didn't find himself victorious either — although he played perfectly, his teammates let him down every time. He had to win at least one more time, but the losestreak only grew longer and longer... It's no wonder he didn't get any sleep this night at all.
In the morning, Vasya was waiting the bus to the university on the bus stop. Vasya's thoughts were hazy and so he couldn't remember the right bus' number quite right and got onto the bus with the number $n$.
In the bus, Vasya thought that he could get the order of the digits in the number of the bus wrong. Futhermore, he could "see" some digits several times, but the digits he saw were definitely in the real number of the bus. For example, if Vasya saw the number 2028, it could mean that the real bus number could be 2028, 8022, 2820 or just 820. However, numbers 80, 22208, 52 definitely couldn't be the number of the bus. Also, real bus number couldn't start with the digit 0, this meaning that, for example, number 082 couldn't be the real bus number too.
Given $n$, determine the total number of possible bus number variants.
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^{18}$) — the number of the bus that was seen by Vasya. It is guaranteed that this number does not start with $0$.
Output Specification:
Output a single integer — the amount of possible variants of the real bus number.
Demo Input:
['97\n', '2028\n']
Demo Output:
['2\n', '13\n']
Note:
In the first sample, only variants $97$ and $79$ are possible.
In the second sample, the variants (in the increasing order) are the following: $208$, $280$, $802$, $820$, $2028$, $2082$, $2208$, $2280$, $2802$, $2820$, $8022$, $8202$, $8220$. | ```python
fact = [0 for _ in range(35)]
fact[0] = 1
for q in range(1,35):
fact[q] = fact[q-1]*q
amts = []
ans = 0
def multinom():
tot = 0
for i in amts:
tot = tot + i
ret = fact[tot]
for i in amts:
ret = ret / fact[i]
return ret
t = int(input())
digct = []
for i in range(10):
digct.append(0)
tcpy = t
while tcpy > 0:
digct[int(tcpy%10)] = digct[int(tcpy%10)]+1
tcpy = tcpy // 10
def dfs(place):
global ans
if place == 10:
ans = ans + multinom()
if amts[0] > 0:
amts[0] = amts[0]-1
ans = ans - multinom()
amts[0] = amts[0]+1
return
if digct[place] == 0:
amts.append(0)
dfs(place+1)
amts.pop()
else:
for q in range(1, digct[place]+1):
amts.append(q)
dfs(place+1)
amts.pop()
dfs(0)
print(int(ans))
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,631,363,460 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 6,963,200 | n1=input()
n2=input()
a=[]
a1=[]
a2=[]
a1=list(map(int ,str(n1)))
a2=list(map(int ,str(n2)))
for i,j in zip(a1,a2):
if i==j:
a.append(0)
else:
a.append(1)
for k in a:
print(k,end="") | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
n1=input()
n2=input()
a=[]
a1=[]
a2=[]
a1=list(map(int ,str(n1)))
a2=list(map(int ,str(n2)))
for i,j in zip(a1,a2):
if i==j:
a.append(0)
else:
a.append(1)
for k in a:
print(k,end="")
``` | 3.96778 |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other? | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*. | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output": "I become the guy."
},
{
"input": "10\n9 6 1 8 3 9 7 5 10 4\n7 1 3 2 7 6 9 5",
"output": "I become the guy."
},
{
"input": "100\n75 83 69 73 30 76 37 48 14 41 42 21 35 15 50 61 86 85 46 3 31 13 78 10 2 44 80 95 56 82 38 75 77 4 99 9 84 53 12 11 36 74 39 72 43 89 57 28 54 1 51 66 27 22 93 59 68 88 91 29 7 20 63 8 52 23 64 58 100 79 65 49 96 71 33 45\n83 50 89 73 34 28 99 67 77 44 19 60 68 42 8 27 94 85 14 39 17 78 24 21 29 63 92 32 86 22 71 81 31 82 65 48 80 59 98 3 70 55 37 12 15 72 47 9 11 33 16 7 91 74 13 64 38 84 6 61 93 90 45 69 1 54 52 100 57 10 35 49 53 75 76 43 62 5 4 18 36 96 79 23",
"output": "Oh, my keyboard!"
},
{
"input": "1\n1 1\n1 1",
"output": "I become the guy."
},
{
"input": "1\n0\n1 1",
"output": "I become the guy."
},
{
"input": "1\n1 1\n0",
"output": "I become the guy."
},
{
"input": "1\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n0\n0",
"output": "Oh, my keyboard!"
},
{
"input": "100\n44 71 70 55 49 43 16 53 7 95 58 56 38 76 67 94 20 73 29 90 25 30 8 84 5 14 77 52 99 91 66 24 39 37 22 44 78 12 63 59 32 51 15 82 34\n56 17 10 96 80 69 13 81 31 57 4 48 68 89 50 45 3 33 36 2 72 100 64 87 21 75 54 74 92 65 23 40 97 61 18 28 98 93 35 83 9 79 46 27 41 62 88 6 47 60 86 26 42 85 19 1 11",
"output": "I become the guy."
},
{
"input": "100\n78 63 59 39 11 58 4 2 80 69 22 95 90 26 65 16 30 100 66 99 67 79 54 12 23 28 45 56 70 74 60 82 73 91 68 43 92 75 51 21 17 97 86 44 62 47 85 78 72 64 50 81 71 5 57 13 31 76 87 9 49 96 25 42 19 35 88 53 7 83 38 27 29 41 89 93 10 84 18\n78 1 16 53 72 99 9 36 59 49 75 77 94 79 35 4 92 42 82 83 76 97 20 68 55 47 65 50 14 30 13 67 98 8 7 40 64 32 87 10 33 90 93 18 26 71 17 46 24 28 89 58 37 91 39 34 25 48 84 31 96 95 80 88 3 51 62 52 85 61 12 15 27 6 45 38 2 22 60",
"output": "I become the guy."
},
{
"input": "2\n2 2 1\n0",
"output": "I become the guy."
},
{
"input": "2\n1 2\n2 1 2",
"output": "I become the guy."
},
{
"input": "80\n57 40 1 47 36 69 24 76 5 72 26 4 29 62 6 60 3 70 8 64 18 37 16 14 13 21 25 7 66 68 44 74 61 39 38 33 15 63 34 65 10 23 56 51 80 58 49 75 71 12 50 57 2 30 54 27 17 52\n61 22 67 15 28 41 26 1 80 44 3 38 18 37 79 57 11 7 65 34 9 36 40 5 48 29 64 31 51 63 27 4 50 13 24 32 58 23 19 46 8 73 39 2 21 56 77 53 59 78 43 12 55 45 30 74 33 68 42 47 17 54",
"output": "Oh, my keyboard!"
},
{
"input": "100\n78 87 96 18 73 32 38 44 29 64 40 70 47 91 60 69 24 1 5 34 92 94 99 22 83 65 14 68 15 20 74 31 39 100 42 4 97 46 25 6 8 56 79 9 71 35 54 19 59 93 58 62 10 85 57 45 33 7 86 81 30 98 26 61 84 41 23 28 88 36 66 51 80 53 37 63 43 95 75\n76 81 53 15 26 37 31 62 24 87 41 39 75 86 46 76 34 4 51 5 45 65 67 48 68 23 71 27 94 47 16 17 9 96 84 89 88 100 18 52 69 42 6 92 7 64 49 12 98 28 21 99 25 55 44 40 82 19 36 30 77 90 14 43 50 3 13 95 78 35 20 54 58 11 2 1 33",
"output": "Oh, my keyboard!"
},
{
"input": "100\n77 55 26 98 13 91 78 60 23 76 12 11 36 62 84 80 18 1 68 92 81 67 19 4 2 10 17 77 96 63 15 69 46 97 82 42 83 59 50 72 14 40 89 9 52 29 56 31 74 39 45 85 22 99 44 65 95 6 90 38 54 32 49 34 3 70 75 33 94 53 21 71 5 66 73 41 100 24\n69 76 93 5 24 57 59 6 81 4 30 12 44 15 67 45 73 3 16 8 47 95 20 64 68 85 54 17 90 86 66 58 13 37 42 51 35 32 1 28 43 80 7 14 48 19 62 55 2 91 25 49 27 26 38 79 89 99 22 60 75 53 88 82 34 21 87 71 72 61",
"output": "I become the guy."
},
{
"input": "100\n74 96 32 63 12 69 72 99 15 22 1 41 79 77 71 31 20 28 75 73 85 37 38 59 42 100 86 89 55 87 68 4 24 57 52 8 92 27 56 98 95 58 34 9 45 14 11 36 66 76 61 19 25 23 78 49 90 26 80 43 70 13 65 10 5 74 81 21 44 60 97 3 47 93 6\n64 68 21 27 16 91 23 22 33 12 71 88 90 50 62 43 28 29 57 59 5 74 10 95 35 1 67 93 36 32 86 40 6 64 78 46 89 15 84 53 18 30 17 85 2 3 47 92 25 48 76 51 20 82 52 83 99 63 80 11 94 54 39 7 58",
"output": "I become the guy."
},
{
"input": "100\n75 11 98 44 47 88 94 23 78 59 70 2 43 39 34 63 71 19 42 61 30 74 14 77 97 53 92 60 67 36 37 13 6 86 62 46 41 3 25 93 7 12 27 48 55 49 31 35 51 10 57 54 95 82 28 90 73 26 17 50 81 56 20 87 40 85 72 64 99 29 91 5 80 18 24 52\n72 93 59 5 88 47 9 58 48 1 43 50 100 87 61 91 45 98 99 56 25 84 53 73 78 54 63 38 37 2 77 95 89 85 4 90 10 33 12 22 74 32 34 70 71 52 96 57 15 66 31 27 75 8 21 39 62 44 67 94 81 68 14 19 36 28 11 79 16 65 46 83 76",
"output": "Oh, my keyboard!"
},
{
"input": "3\n1 2\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "4\n1 2\n3 1 3 4",
"output": "I become the guy."
},
{
"input": "6\n2 1 2\n3 4 5 6",
"output": "Oh, my keyboard!"
}
] | 1,696,391,336 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 |
newlist=[]
j=int(input())
k=list(map(int,input().split()))
i=list(map(int,input().split()))
k.pop(0)
i.pop(0)
for x in k:
newlist.append(x)
for y in i:
newlist.append(y)
newlist=set(newlist)
newlist=list(newlist)
e=len(newlist)
if e>=j:
print("I become the guy.")
else:
print('Oh, my keyboard!') | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?
Input Specification:
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to *n*.
Output Specification:
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
Demo Input:
['4\n3 1 2 3\n2 2 4\n', '4\n3 1 2 3\n2 2 3\n']
Demo Output:
['I become the guy.\n', 'Oh, my keyboard!\n']
Note:
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | ```python
newlist=[]
j=int(input())
k=list(map(int,input().split()))
i=list(map(int,input().split()))
k.pop(0)
i.pop(0)
for x in k:
newlist.append(x)
for y in i:
newlist.append(y)
newlist=set(newlist)
newlist=list(newlist)
e=len(newlist)
if e>=j:
print("I become the guy.")
else:
print('Oh, my keyboard!')
``` | 3 |
|
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "52"
},
{
"input": "2\nAA",
"output": "1"
},
{
"input": "4\nqqqE",
"output": "2"
},
{
"input": "10\nrrrrroooro",
"output": "2"
},
{
"input": "15\nOCOCCCCiCOCCCOi",
"output": "3"
},
{
"input": "20\nVEVnVVnWnVEVVnEVBEWn",
"output": "5"
},
{
"input": "25\ncpcyPPjPPcPPPPcppPcPpppcP",
"output": "6"
},
{
"input": "30\nsssssAsesssssssssssssessssssss",
"output": "3"
},
{
"input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb",
"output": "4"
},
{
"input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi",
"output": "9"
},
{
"input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae",
"output": "9"
},
{
"input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl",
"output": "3"
},
{
"input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA",
"output": "2"
},
{
"input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR",
"output": "3"
},
{
"input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh",
"output": "5"
},
{
"input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww",
"output": "2"
},
{
"input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX",
"output": "4"
},
{
"input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr",
"output": "2"
},
{
"input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM",
"output": "6"
},
{
"input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl",
"output": "5"
},
{
"input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu",
"output": "39"
},
{
"input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN",
"output": "4"
},
{
"input": "7\nabcbbab",
"output": "3"
},
{
"input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk",
"output": "3"
},
{
"input": "9\nbcdddbddc",
"output": "3"
},
{
"input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco",
"output": "36"
},
{
"input": "8\nabbbbbbc",
"output": "8"
}
] | 1,680,819,653 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 93 | 7,782,400 | import sys
from collections import Counter
read = sys.stdin.readline
write = sys.stdout.write
n = int(read())
s = read().strip()
types = len(set(s))
ans = len(s)
frequencies = Counter()
matches = 0
l = 0
for r in range(len(s)):
frequencies[s[r]] += 1
if frequencies[s[r]] == 1:
matches += 1
while l < len(s) and matches == types:
if matches == types:
ans = min(ans, r - l + 1)
frequencies[s[l]] -= 1
if frequencies[s[l]] == 0:
matches -= 1
l += 1
write(f"{ans}") | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Output Specification:
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
Demo Input:
['3\nAaA\n', '7\nbcAAcbc\n', '6\naaBCCe\n']
Demo Output:
['2\n', '3\n', '5\n']
Note:
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | ```python
import sys
from collections import Counter
read = sys.stdin.readline
write = sys.stdout.write
n = int(read())
s = read().strip()
types = len(set(s))
ans = len(s)
frequencies = Counter()
matches = 0
l = 0
for r in range(len(s)):
frequencies[s[r]] += 1
if frequencies[s[r]] == 1:
matches += 1
while l < len(s) and matches == types:
if matches == types:
ans = min(ans, r - l + 1)
frequencies[s[l]] -= 1
if frequencies[s[l]] == 0:
matches -= 1
l += 1
write(f"{ans}")
``` | 3 |
|
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 586975278",
"output": "1"
},
{
"input": "259504825 377489979 588153796 377489979",
"output": "1"
},
{
"input": "652588203 931100304 931100304 652588203",
"output": "2"
},
{
"input": "391958720 651507265 391958720 651507265",
"output": "2"
},
{
"input": "90793237 90793237 90793237 90793237",
"output": "3"
},
{
"input": "551651653 551651653 551651653 551651653",
"output": "3"
},
{
"input": "156630260 609654355 668943582 973622757",
"output": "0"
},
{
"input": "17061017 110313588 434481173 796661222",
"output": "0"
},
{
"input": "24975422 256716298 337790533 690960249",
"output": "0"
},
{
"input": "255635360 732742923 798648949 883146723",
"output": "0"
},
{
"input": "133315691 265159773 734556507 265159773",
"output": "1"
},
{
"input": "28442865 741657755 978106882 978106882",
"output": "1"
},
{
"input": "131245479 174845575 497483467 131245479",
"output": "1"
},
{
"input": "139159884 616215581 958341883 616215581",
"output": "1"
},
{
"input": "147784432 947653080 947653080 947653080",
"output": "2"
},
{
"input": "94055790 756126496 756126496 94055790",
"output": "2"
},
{
"input": "240458500 511952208 240458500 511952208",
"output": "2"
},
{
"input": "681828506 972810624 972810624 681828506",
"output": "2"
},
{
"input": "454961014 454961014 454961014 454961014",
"output": "3"
},
{
"input": "915819430 915819430 915819430 915819430",
"output": "3"
},
{
"input": "671645142 671645142 671645142 671645142",
"output": "3"
},
{
"input": "132503558 132503558 132503558 132503558",
"output": "3"
},
{
"input": "5 5 999999 6",
"output": "1"
},
{
"input": "1 1 2 5",
"output": "1"
},
{
"input": "2 1 2 3",
"output": "1"
},
{
"input": "1 1 3 5",
"output": "1"
},
{
"input": "1 1 3 3",
"output": "2"
},
{
"input": "2 2 2 1",
"output": "2"
},
{
"input": "3 1 1 1",
"output": "2"
},
{
"input": "1 2 2 2",
"output": "2"
}
] | 1,693,481,594 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | h = list(map(int,input().split()))
u_c = len(set(h))
a_need = 4 - u_c
print(a_need) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to the store and buy some few more horseshoes, not to lose face in front of his stylish comrades.
Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
Input Specification:
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers.
Output Specification:
Print a single integer — the minimum number of horseshoes Valera needs to buy.
Demo Input:
['1 7 3 3\n', '7 7 7 7\n']
Demo Output:
['1\n', '3\n']
Note:
none | ```python
h = list(map(int,input().split()))
u_c = len(set(h))
a_need = 4 - u_c
print(a_need)
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,660,633,150 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 62 | 0 | m, n = [int(i) for i in input().split()]
x = 2
S = n * m
s = 0
print(S // x) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
m, n = [int(i) for i in input().split()]
x = 2
S = n * m
s = 0
print(S // x)
``` | 3.9845 |
1,011 | B | Planning The Expedition | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above? | The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package. | Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. | [
"4 10\n1 5 2 1 1 1 2 5 7 2\n",
"100 1\n1\n",
"2 5\n5 4 3 2 1\n",
"3 9\n42 42 42 42 42 42 42 42 42\n"
] | [
"2\n",
"0\n",
"1\n",
"3\n"
] | In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | 1,000 | [
{
"input": "4 10\n1 5 2 1 1 1 2 5 7 2",
"output": "2"
},
{
"input": "100 1\n1",
"output": "0"
},
{
"input": "2 5\n5 4 3 2 1",
"output": "1"
},
{
"input": "3 9\n42 42 42 42 42 42 42 42 42",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "4 100\n84 99 66 69 86 94 89 96 98 93 93 82 87 93 91 100 69 99 93 81 99 84 75 100 86 88 98 100 84 96 44 70 94 91 85 78 86 79 45 88 91 78 98 94 81 87 93 72 96 88 96 97 96 62 86 72 94 84 80 98 88 90 93 73 73 98 78 50 91 96 97 82 85 90 87 41 97 82 97 77 100 100 92 83 98 81 70 81 74 78 84 79 98 98 55 99 97 99 79 98",
"output": "5"
},
{
"input": "100 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": "1"
},
{
"input": "1 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": "100"
},
{
"input": "6 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 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 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "15"
},
{
"input": "1 1\n59",
"output": "1"
},
{
"input": "1 50\n39 1 46 21 23 28 100 32 63 63 18 15 40 29 34 49 56 74 47 42 96 97 59 62 76 62 69 61 36 21 66 18 92 58 63 85 5 6 77 75 91 66 38 10 66 43 20 74 37 83",
"output": "3"
},
{
"input": "1 100\n83 72 21 55 49 5 61 60 87 21 89 88 3 75 49 81 36 25 50 61 96 19 36 55 48 8 97 69 50 24 23 39 26 25 41 90 69 20 19 62 38 52 60 6 66 31 9 45 36 12 69 94 22 60 91 65 35 58 13 85 33 87 83 11 95 20 20 85 13 21 57 69 17 94 78 37 59 45 60 7 64 51 60 89 91 22 6 58 95 96 51 53 89 22 28 16 27 56 1 54",
"output": "5"
},
{
"input": "50 1\n75",
"output": "0"
},
{
"input": "50 50\n85 20 12 73 52 78 70 95 88 43 31 88 81 41 80 99 16 11 97 11 21 44 2 34 47 38 87 2 32 47 97 93 52 14 35 37 97 48 58 19 52 55 97 72 17 25 16 85 90 58",
"output": "1"
},
{
"input": "50 100\n2 37 74 32 99 75 73 86 67 33 62 30 15 21 51 41 73 75 67 39 90 10 56 74 72 26 38 65 75 55 46 99 34 49 92 82 11 100 15 71 75 12 22 56 47 74 20 98 59 65 14 76 1 40 89 36 43 93 83 73 75 100 50 95 27 10 72 51 25 69 15 3 57 60 84 99 31 44 12 61 69 95 51 31 28 36 57 35 31 52 44 19 79 12 27 27 7 81 68 1",
"output": "1"
},
{
"input": "100 1\n26",
"output": "0"
},
{
"input": "100 50\n8 82 62 11 85 57 5 32 99 92 77 2 61 86 8 88 10 28 83 4 68 79 8 64 56 98 4 88 22 54 30 60 62 79 72 38 17 28 32 16 62 26 56 44 72 33 22 84 77 45",
"output": "0"
},
{
"input": "100 100\n13 88 64 65 78 10 61 97 16 32 76 9 60 1 40 35 90 61 60 85 26 16 38 36 33 95 24 55 82 88 13 9 47 34 94 2 90 74 11 81 46 70 94 11 55 32 19 36 97 16 17 35 38 82 89 16 74 94 97 79 9 94 88 12 28 2 4 25 72 95 49 31 88 82 6 77 70 98 90 57 57 33 38 61 26 75 2 66 22 44 13 35 16 4 33 16 12 66 32 86",
"output": "1"
},
{
"input": "34 64\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",
"output": "1"
},
{
"input": "53 98\n1 1 2 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 2 2 2 1 1 2 1 2 1 1 1 1 2 2 2 2 2 1 1 2 2 2 1 1",
"output": "1"
},
{
"input": "17 8\n2 5 3 4 3 2 2 2",
"output": "0"
},
{
"input": "24 77\n8 6 10 4 6 6 4 10 9 7 7 5 5 4 6 7 10 6 3 4 6 6 4 9 4 6 2 5 3 4 4 1 4 6 6 8 1 1 6 4 6 2 5 7 7 2 4 4 10 1 10 9 2 3 8 1 10 4 3 9 3 8 3 5 6 3 4 9 5 3 4 1 1 6 1 2 1",
"output": "2"
},
{
"input": "65 74\n7 19 2 38 28 44 34 49 14 13 30 22 11 4 4 12 8 1 40 8 34 31 44 38 21 35 13 7 19 32 37 5 36 26 7 2 15 11 47 45 48 2 49 10 10 42 42 31 50 24 29 34 31 38 39 48 43 47 32 46 10 1 33 21 12 50 13 44 38 11 41 41 10 7",
"output": "1"
},
{
"input": "37 71\n50 93 15 80 82 23 35 90 70 73 55 23 23 6 86 63 38 70 38 52 88 34 25 75 32 19 6 98 31 38 21 8 66 8 59 71 7 80 69 23 17 70 6 40 72 5 48 59 18 1 48 91 17 41 11 27 53 95 87 31 62 94 94 60 38 99 70 50 81 86 44",
"output": "1"
},
{
"input": "35 4\n100 100 100 100",
"output": "0"
},
{
"input": "68 12\n100 100 100 99 99 100 100 100 99 99 99 99",
"output": "0"
},
{
"input": "91 33\n97 100 96 96 97 100 97 97 96 96 99 99 98 97 97 99 99 98 100 96 96 99 100 96 97 100 97 97 99 98 96 98 97",
"output": "0"
},
{
"input": "59 72\n99 96 96 93 94 97 93 96 100 99 93 99 96 92 92 97 93 100 92 100 91 96 99 100 97 98 93 93 96 100 97 99 100 100 91 93 96 91 93 100 95 96 92 97 91 91 99 100 91 95 95 100 92 93 98 93 95 92 95 100 91 95 99 95 92 91 100 93 98 98 96 99",
"output": "1"
},
{
"input": "9 35\n95 54 78 94 56 63 68 73 61 85 73 62 61 94 67 91 66 54 89 69 92 60 91 87 63 62 85 70 62 68 97 88 96 55 62",
"output": "2"
},
{
"input": "99 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": "1"
},
{
"input": "1 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": "50"
}
] | 1,532,801,374 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | n,m=map(int,input().split())
a=list(map(int,input().split()))
y=set (a)
y=list(y)
l=len(y)
t=[]
if (n>m ):
exit(print("0"))
for i in y :
t.append (a.count(i))
t.sort()
#print(t)
ans=t[0]
sum=n+1
for i in range(l+1):
print(sum,ans)
if (sum>=n) :
if (i==0):
ans=t[0]
#print("yes")
else :
ans=t[i-1]
#print("no")
else :
exit (print(ans))
sum=0
for j in range(i,l):
sum+=t[j]//t[i]
| Title: Planning The Expedition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant.
The warehouse has $m$ daily food packages. Each package has some food type $a_i$.
Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.
Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different.
What is the maximum possible number of days the expedition can last, following the requirements above?
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available.
The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package.
Output Specification:
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.
Demo Input:
['4 10\n1 5 2 1 1 1 2 5 7 2\n', '100 1\n1\n', '2 5\n5 4 3 2 1\n', '3 9\n42 42 42 42 42 42 42 42 42\n']
Demo Output:
['2\n', '0\n', '1\n', '3\n']
Note:
In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$).
In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
y=set (a)
y=list(y)
l=len(y)
t=[]
if (n>m ):
exit(print("0"))
for i in y :
t.append (a.count(i))
t.sort()
#print(t)
ans=t[0]
sum=n+1
for i in range(l+1):
print(sum,ans)
if (sum>=n) :
if (i==0):
ans=t[0]
#print("yes")
else :
ans=t[i-1]
#print("no")
else :
exit (print(ans))
sum=0
for j in range(i,l):
sum+=t[j]//t[i]
``` | 0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.