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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so. | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"output": "-1"
},
{
"input": "2 2 4\n5 5\n5 5",
"output": "0"
},
{
"input": "7 4 5\n7 7 7 12\n7 12 12 7\n7 7 7 7\n7 7 12 7\n7 7 12 12\n12 12 7 12\n7 7 7 7",
"output": "9"
},
{
"input": "7 7 47\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91\n91 91 91 91 91 91 91",
"output": "0"
},
{
"input": "7 7 47\n47 47 47 47 47 47 47\n47 47 47 47 77 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 47 47\n47 47 47 47 47 127 47",
"output": "-1"
},
{
"input": "7 5 47\n9583 1734 4601 5353 2110\n3802 5165 7985 6293 324\n7045 653 9160 7891 4930\n1781 3520 4178 2298 3943\n1405 2956 5447 5494 6528\n3097 1640 7750 4883 8032\n4225 8455 1875 4789 4366",
"output": "1508"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 1 8\n12",
"output": "0"
}
] | 1,604,290,524 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 340 | 1,740,800 | n,m,d=map(int,input().split())
ans=True
hehe=-1
mat=[]
for i in range(n):
row=list(map(int,input().split()))
for k in row:
mat.append(k)
for j in range(m):
if i==0 and j==0:
hehe=row[j]%d
continue
if row[j]%d!=hehe:
ans=False
if not ans:
print(-1)
else:
maxxx=-1
mat.sort()
l=len(mat)//2
mid=mat[l]
summ=0
for h in mat:
summ+=abs(mid-h)//d
print(summ)
| Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add or subtract number *d* from some matrix element. Find the minimum number of moves needed to make all matrix elements equal. If the described plan is impossible to carry out, say so.
Input Specification:
The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104).
Output Specification:
In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
Demo Input:
['2 2 2\n2 4\n6 8\n', '1 2 7\n6 7\n']
Demo Output:
['4\n', '-1\n']
Note:
none | ```python
n,m,d=map(int,input().split())
ans=True
hehe=-1
mat=[]
for i in range(n):
row=list(map(int,input().split()))
for k in row:
mat.append(k)
for j in range(m):
if i==0 and j==0:
hehe=row[j]%d
continue
if row[j]%d!=hehe:
ans=False
if not ans:
print(-1)
else:
maxxx=-1
mat.sort()
l=len(mat)//2
mid=mat[l]
summ=0
for h in mat:
summ+=abs(mid-h)//d
print(summ)
``` | 3 |
|
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 91",
"output": "-48"
},
{
"input": "20\n-72 -9 -86 80 7 -10 40 -27 -94 92 96 56 28 -19 79 36 -3 -73 -63 -49",
"output": "-86"
},
{
"input": "49\n-74 -100 -80 23 -8 -83 -41 -20 48 17 46 -73 -55 67 85 4 40 -60 -69 -75 56 -74 -42 93 74 -95 64 -46 97 -47 55 0 -78 -34 -31 40 -63 -49 -76 48 21 -1 -49 -29 -98 -11 76 26 94",
"output": "-98"
},
{
"input": "88\n63 48 1 -53 -89 -49 64 -70 -49 71 -17 -16 76 81 -26 -50 67 -59 -56 97 2 100 14 18 -91 -80 42 92 -25 -88 59 8 -56 38 48 -71 -78 24 -14 48 -1 69 73 -76 54 16 -92 44 47 33 -34 -17 -81 21 -59 -61 53 26 10 -76 67 35 -29 70 65 -13 -29 81 80 32 74 -6 34 46 57 1 -45 -55 69 79 -58 11 -2 22 -18 -16 -89 -46",
"output": "-91"
},
{
"input": "100\n34 32 88 20 76 53 -71 -39 -98 -10 57 37 63 -3 -54 -64 -78 -82 73 20 -30 -4 22 75 51 -64 -91 29 -52 -48 83 19 18 -47 46 57 -44 95 89 89 -30 84 -83 67 58 -99 -90 -53 92 -60 -5 -56 -61 27 68 -48 52 -95 64 -48 -30 -67 66 89 14 -33 -31 -91 39 7 -94 -54 92 -96 -99 -83 -16 91 -28 -66 81 44 14 -85 -21 18 40 16 -13 -82 -33 47 -10 -40 -19 10 25 60 -34 -89",
"output": "-98"
},
{
"input": "2\n-1 -1",
"output": "NO"
},
{
"input": "3\n-2 -2 -2",
"output": "NO"
},
{
"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": "NO"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 -100 100 100 100 100 -100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100"
},
{
"input": "10\n40 71 -85 -85 40 -85 -85 64 -85 47",
"output": "40"
},
{
"input": "23\n-90 -90 -41 -64 -64 -90 -15 10 -43 -90 -64 -64 89 -64 36 47 38 -90 -64 -90 -90 68 -90",
"output": "-64"
},
{
"input": "39\n-97 -93 -42 -93 -97 -93 56 -97 -97 -97 76 -33 -60 91 7 82 17 47 -97 -97 -93 73 -97 12 -97 -97 -97 -97 56 -92 -83 -93 -93 49 -93 -97 -97 -17 -93",
"output": "-93"
},
{
"input": "51\n-21 6 -35 -98 -86 -98 -86 -43 -65 32 -98 -40 96 -98 -98 -98 -98 -86 -86 -98 56 -86 -98 -98 -30 -98 -86 -31 -98 -86 -86 -86 -86 -30 96 -86 -86 -86 -60 25 88 -86 -86 58 31 -47 57 -86 37 44 -83",
"output": "-86"
},
{
"input": "66\n-14 -95 65 -95 -95 -97 -90 -71 -97 -97 70 -95 -95 -97 -95 -27 35 -87 -95 -5 -97 -97 87 34 -49 -95 -97 -95 -97 -95 -30 -95 -97 47 -95 -17 -97 -95 -97 -69 51 -97 -97 -95 -75 87 59 21 63 56 76 -91 98 -97 6 -97 -95 -95 -97 -73 11 -97 -35 -95 -95 -43",
"output": "-95"
},
{
"input": "77\n-67 -93 -93 -92 97 29 93 -93 -93 -5 -93 -7 60 -92 -93 44 -84 68 -92 -93 69 -92 -37 56 43 -93 35 -92 -93 19 -79 18 -92 -93 -93 -37 -93 -47 -93 -92 -92 74 67 19 40 -92 -92 -92 -92 -93 -93 -41 -93 -92 -93 -93 -92 -93 51 -80 6 -42 -92 -92 -66 -12 -92 -92 -3 93 -92 -49 -93 40 62 -92 -92",
"output": "-92"
},
{
"input": "89\n-98 40 16 -87 -98 63 -100 55 -96 -98 -21 -100 -93 26 -98 -98 -100 -89 -98 -5 -65 -28 -100 -6 -66 67 -100 -98 -98 10 -98 -98 -70 7 -98 2 -100 -100 -98 25 -100 -100 -98 23 -68 -100 -98 3 98 -100 -98 -98 -98 -98 -24 -100 -100 -9 -98 35 -100 99 -5 -98 -100 -100 37 -100 -84 57 -98 40 -47 -100 -1 -92 -76 -98 -98 -100 -100 -100 -63 30 21 -100 -100 -100 -12",
"output": "-98"
},
{
"input": "99\n10 -84 -100 -100 73 -64 -100 -94 33 -100 -100 -100 -100 71 64 24 7 -100 -32 -100 -100 77 -100 62 -12 55 45 -100 -100 -80 -100 -100 -100 -100 -100 -100 -100 -100 -100 -39 -48 -100 -34 47 -100 -100 -100 -100 -100 -77 -100 -100 -100 -100 -100 -100 -52 40 -55 -100 -44 -100 72 33 70 -100 -100 -78 -100 -3 100 -77 22 -100 95 -30 -100 10 -69 -100 -100 -100 -100 52 -39 -100 -100 -100 7 -100 -98 -66 95 -17 -100 52 -100 68 -100",
"output": "-98"
},
{
"input": "100\n-99 -98 -64 89 53 57 -99 29 -78 18 -3 -54 76 -98 -99 -98 37 -98 19 -47 89 73 -98 -91 -99 -99 -98 -48 -99 22 -99 -98 -99 -99 -98 -60 84 67 -99 -98 20 -98 88 -98 46 -98 -99 -98 -99 -71 -99 -98 -98 -39 83 95 -98 63 -98 -99 32 -98 -99 -64 57 -30 -53 -83 -4 -99 58 20 -98 -10 -99 -44 -99 -99 -99 -99 75 34 -98 -52 -98 -30 -98 -99 -98 -98 51 -99 -99 -99 -98 -99 -99 -82 -90 92",
"output": "-98"
},
{
"input": "3\n1 2 3",
"output": "2"
},
{
"input": "3\n1 3 2",
"output": "2"
},
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 3 1",
"output": "2"
},
{
"input": "3\n3 1 2",
"output": "2"
},
{
"input": "3\n3 2 1",
"output": "2"
},
{
"input": "9\n99 99 99 99 100 100 100 100 100",
"output": "100"
},
{
"input": "5\n-100 -100 -100 -100 -100",
"output": "NO"
}
] | 1,609,833,241 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n=int(input())
l=list(map(int,input().split()))
l.sort()
print(min(l),max(l),sum(l))
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
Input Specification:
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
Output Specification:
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
Demo Input:
['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n']
Demo Output:
['1\n', '2\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort()
print(min(l),max(l),sum(l))
``` | 0 |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888",
"output": "NO"
},
{
"input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555",
"output": "NO"
},
{
"input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333",
"output": "NO"
},
{
"input": "5 5\n88888\n44444\n66666\n55555\n88888",
"output": "YES"
},
{
"input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222",
"output": "YES"
},
{
"input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888",
"output": "YES"
},
{
"input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4",
"output": "YES"
},
{
"input": "1 1\n2",
"output": "YES"
},
{
"input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111",
"output": "NO"
},
{
"input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0",
"output": "YES"
}
] | 1,645,228,197 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | from pickle import TRUE
tamaño = input().split(' ')
n = int(tamaño[0]) #filas
m = int(tamaño[1]) #columnas
matriz = list()
count = 0
if((n >= 1 and n <= 100) and (m >= 1 and m <= 100)):
for i in range(n):
matriz.append(list())
cadena = input()
if(len(cadena) <= m):
for j in cadena:
matriz[count].append(int(j))
count += 1
igualPorFila = True
igualPorCol = True
auxNumeroPorFila = -1
for i in range(n):
if(matriz[i][0] != auxNumeroPorFila):
auxNumero = matriz[i][0]
for j in matriz[i]:
if(j == auxNumero):
igualPorFila = True
else:
igualPorFila = False
auxNumero = j
igualPorCol = True
else:
igualPorCol = False
auxNumeroPorFila = matriz[i][0]
if(igualPorFila == True and igualPorCol == True):
print('YES')
else:
print('NO') | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
Input Specification:
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output Specification:
Output YES, if the flag meets the new ISO standard, and NO otherwise.
Demo Input:
['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n']
Note:
none | ```python
from pickle import TRUE
tamaño = input().split(' ')
n = int(tamaño[0]) #filas
m = int(tamaño[1]) #columnas
matriz = list()
count = 0
if((n >= 1 and n <= 100) and (m >= 1 and m <= 100)):
for i in range(n):
matriz.append(list())
cadena = input()
if(len(cadena) <= m):
for j in cadena:
matriz[count].append(int(j))
count += 1
igualPorFila = True
igualPorCol = True
auxNumeroPorFila = -1
for i in range(n):
if(matriz[i][0] != auxNumeroPorFila):
auxNumero = matriz[i][0]
for j in matriz[i]:
if(j == auxNumero):
igualPorFila = True
else:
igualPorFila = False
auxNumero = j
igualPorCol = True
else:
igualPorCol = False
auxNumeroPorFila = matriz[i][0]
if(igualPorFila == True and igualPorCol == True):
print('YES')
else:
print('NO')
``` | -1 |
487 | C | Prefix Product Sequence | PROGRAMMING | 2,300 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | Consider a sequence [*a*1,<=*a*2,<=... ,<=*a**n*]. Define its prefix product sequence .
Now given *n*, find a permutation of [1,<=2,<=...,<=*n*], such that its prefix product sequence is a permutation of [0,<=1,<=...,<=*n*<=-<=1]. | The only input line contains an integer *n* (1<=≤<=*n*<=≤<=105). | In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output *n* more lines. *i*-th line contains only an integer *a**i*. The elements of the sequence should be different positive integers no larger than *n*.
If there are multiple solutions, you are allowed to print any of them. | [
"7\n",
"6\n"
] | [
"YES\n1\n4\n3\n6\n5\n2\n7\n",
"NO\n"
] | For the second sample, there are no valid sequences. | 1,500 | [
{
"input": "7",
"output": "YES\n1\n2\n5\n6\n3\n4\n7"
},
{
"input": "6",
"output": "NO"
},
{
"input": "7137",
"output": "NO"
},
{
"input": "10529",
"output": "YES\n1\n2\n5266\n3511\n7898\n2107\n1756\n9026\n9214\n1171\n1054\n4787\n6143\n811\n9778\n703\n9872\n8672\n586\n3326\n5792\n6519\n2394\n6410\n3072\n2528\n406\n391\n10154\n5084\n352\n5775\n10201\n5106\n9601\n1806\n5558\n1993\n6928\n271\n8161\n9246\n3260\n8816\n6462\n235\n8470\n10306\n6801\n8811\n6529\n6401\n5468\n597\n196\n3064\n10342\n4619\n7807\n4284\n5441\n4834\n2888\n9193\n5101\n163\n7818\n3144\n4801\n5647\n6168\n4005\n8044\n4328\n997\n4353\n8729\n3693\n136\n8131\n4081\n131\n9888\n889\n6895\n3841\n9673\n5..."
},
{
"input": "34211",
"output": "YES\n1\n2\n17107\n11405\n8554\n27370\n5703\n14663\n21383\n15206\n30791\n31102\n2852\n21054\n7332\n9124\n10692\n24150\n24709\n21608\n15396\n16292\n32657\n23800\n18532\n12317\n27633\n16473\n20772\n15337\n21668\n13244\n22452\n10368\n29181\n23460\n12355\n7398\n27910\n29826\n24804\n10014\n25252\n30234\n16329\n3042\n29006\n13831\n26372\n26532\n6159\n30858\n13817\n1292\n8237\n33590\n27492\n18607\n7669\n26674\n27940\n30847\n23728\n16835\n28332\n17896\n22290\n25021\n14591\n7934\n28836\n6265\n6178\n27651\n20805\n155..."
},
{
"input": "1941",
"output": "NO"
},
{
"input": "55004",
"output": "NO"
},
{
"input": "21341",
"output": "YES\n1\n2\n10672\n7115\n16007\n17074\n3558\n12196\n8004\n9486\n19208\n19402\n12450\n13134\n16769\n5692\n14673\n17576\n15414\n15726\n20275\n4066\n20372\n7424\n16896\n11952\n17238\n17390\n8385\n7360\n13517\n13081\n7337\n6468\n19459\n2440\n18378\n8076\n18534\n18606\n10138\n20301\n12704\n16379\n20857\n1898\n14383\n14077\n19119\n13938\n16647\n12973\n19290\n1209\n19366\n20954\n4193\n19470\n14351\n2533\n6759\n11896\n6541\n1356\n3669\n11164\n13905\n14016\n9730\n9589\n11891\n13527\n19860\n10233\n14709\n18212\n19938..."
},
{
"input": "61333",
"output": "YES\n1\n2\n30668\n40890\n46001\n36801\n51112\n8763\n23001\n34075\n18401\n22304\n56223\n4719\n4382\n32712\n11501\n21648\n17038\n58106\n9201\n23366\n41819\n8001\n28112\n7361\n2360\n11359\n32858\n31725\n47023\n3958\n5751\n48324\n41491\n14020\n39186\n33154\n59720\n22018\n4601\n20944\n42350\n28528\n20910\n31349\n4001\n31320\n44723\n45062\n3681\n27661\n31847\n25460\n5680\n53528\n47096\n60258\n15863\n36385\n23512\n37203\n32646\n48678\n2876\n50011\n54829\n50349\n20746\n23112\n37677\n11231\n50260\n23526\n47244\n433..."
},
{
"input": "77617",
"output": "YES\n1\n2\n38810\n51746\n58214\n31048\n64682\n66530\n67916\n68994\n54333\n70562\n71150\n65677\n72074\n10350\n72767\n31961\n73306\n36767\n27167\n73922\n74090\n10125\n74384\n68304\n32839\n48871\n74846\n53530\n43984\n22535\n36384\n75266\n15981\n59877\n75462\n69227\n18384\n21893\n13584\n18932\n75770\n37907\n75854\n29323\n5063\n11561\n76001\n76034\n72961\n62399\n16420\n52722\n24436\n45160\n76232\n64001\n65574\n46045\n60801\n49625\n11268\n76386\n57001\n44183\n76442\n62558\n7991\n29248\n29939\n5467\n76540\n4254\n..."
},
{
"input": "44633",
"output": "YES\n1\n2\n22318\n14879\n33476\n26781\n7440\n38258\n39055\n19838\n13391\n36519\n26037\n10301\n41446\n38683\n19528\n5252\n32236\n21143\n6696\n27631\n18260\n13585\n13019\n5357\n5151\n21491\n43040\n21548\n19342\n12959\n32081\n41929\n24943\n16579\n38435\n12064\n10572\n18312\n25665\n19596\n13816\n1039\n31447\n12895\n6793\n34188\n6510\n37347\n2679\n16629\n2576\n12633\n10746\n43011\n43837\n21926\n33091\n1514\n31988\n32927\n6480\n9211\n16041\n2061\n20965\n3998\n12472\n4529\n8290\n25775\n19218\n10395\n28349\n16664\n..."
},
{
"input": "18047",
"output": "YES\n1\n2\n9025\n6017\n4513\n7220\n3009\n15470\n2257\n8022\n12634\n4923\n1505\n5554\n16759\n8423\n1129\n5309\n13035\n12349\n15341\n11173\n2462\n2355\n753\n12273\n11801\n14706\n8380\n9958\n4212\n3494\n565\n13673\n2655\n13923\n6518\n16097\n6175\n1852\n7671\n15407\n5587\n4198\n10255\n8824\n1178\n385\n377\n4789\n6137\n7786\n5901\n17367\n16377\n15423\n13214\n4117\n14003\n5201\n11130\n10060\n10771\n3725\n283\n4721\n6837\n14277\n1328\n12817\n6962\n15252\n12283\n10137\n8049\n16123\n3088\n16173\n9950\n2057\n3836\n1..."
},
{
"input": "78137",
"output": "YES\n1\n2\n39070\n26047\n58604\n31256\n13024\n22326\n68371\n8683\n54697\n56828\n45581\n66117\n50232\n36465\n34186\n45964\n4342\n8226\n27349\n59534\n67483\n64549\n22791\n6252\n33059\n2895\n64185\n56583\n18233\n50412\n56162\n44989\n62051\n4466\n41240\n33790\n43182\n74131\n13675\n60986\n68836\n12721\n33742\n64247\n32275\n3326\n11396\n47840\n42195\n15322\n16530\n10321\n1448\n73876\n32093\n54834\n28292\n18542\n9117\n58924\n64275\n45891\n67150\n44479\n22495\n67642\n31026\n21517\n41302\n25313\n59689\n28901\n55964..."
},
{
"input": "2647",
"output": "YES\n1\n2\n1325\n1766\n663\n1060\n2207\n2270\n332\n2354\n1854\n723\n1104\n1630\n2459\n354\n1490\n1091\n2501\n419\n2251\n2522\n362\n1267\n1876\n1801\n2139\n2550\n1230\n1644\n1501\n1538\n2069\n1124\n546\n2043\n1251\n1718\n210\n544\n1126\n1034\n2585\n2094\n1505\n1001\n634\n1409\n2262\n2594\n901\n2129\n1070\n900\n2599\n2263\n1939\n1905\n2146\n1661\n751\n1433\n2093\n2606\n1035\n1915\n1886\n2569\n1597\n423\n1022\n1455\n626\n835\n2183\n601\n1429\n2373\n1596\n2581\n1887\n1733\n1841\n1181\n1293\n219\n2371\n1431\n75..."
},
{
"input": "6577",
"output": "YES\n1\n2\n3290\n4386\n4934\n2632\n5482\n4699\n5756\n3655\n4605\n599\n6030\n507\n2350\n878\n6167\n3483\n1828\n2078\n2303\n1567\n300\n287\n6304\n3158\n254\n1219\n4464\n1135\n3728\n1274\n3084\n4585\n1742\n2256\n4203\n5867\n4328\n2362\n1152\n1926\n784\n3366\n3439\n4678\n144\n2240\n6441\n5370\n4868\n3354\n3416\n2607\n610\n1436\n5521\n5078\n568\n4460\n5153\n5392\n3926\n523\n4831\n2733\n2293\n590\n4160\n4481\n4417\n3799\n2102\n4686\n2934\n5438\n5453\n1026\n4470\n6245\n3865\n407\n4252\n2299\n3681\n5959\n4972\n379..."
},
{
"input": "87511",
"output": "YES\n1\n2\n43757\n58342\n21879\n70010\n72927\n62509\n10940\n19448\n78761\n71601\n36464\n53854\n31255\n81678\n49226\n36035\n53480\n59877\n39381\n20837\n35801\n22830\n61988\n31505\n70683\n64824\n15628\n24142\n84595\n45168\n68369\n53038\n18018\n47507\n70496\n14192\n29939\n17952\n19691\n25614\n10419\n14247\n17901\n56397\n55171\n29792\n74750\n58937\n15753\n70353\n35342\n54489\n76168\n14321\n51570\n49130\n55827\n31149\n42298\n40170\n66340\n65287\n34185\n45776\n70275\n67920\n52765\n36781\n23754\n24652\n79004\n383..."
},
{
"input": "87299",
"output": "YES\n1\n2\n43651\n29101\n21826\n17461\n14551\n37415\n54563\n9701\n8731\n55555\n7276\n20147\n18708\n5821\n27282\n20542\n4851\n73516\n4366\n41572\n27778\n68322\n47288\n3493\n10074\n32334\n53004\n48166\n2911\n28162\n57291\n18519\n53921\n77323\n2426\n70784\n80408\n35816\n45833\n8518\n64436\n38575\n57539\n1941\n77811\n13003\n67294\n55231\n1747\n6848\n48687\n54357\n59817\n80951\n70152\n24506\n67733\n66585\n1456\n54384\n57731\n13858\n28646\n21490\n9260\n44302\n26961\n80974\n38662\n67627\n44863\n77733\n79042\n1165..."
},
{
"input": "49069",
"output": "YES\n1\n2\n24536\n32714\n36803\n9815\n40892\n7011\n18402\n43618\n4908\n26766\n44981\n41521\n3506\n35985\n33736\n34638\n46344\n30992\n26989\n18694\n37918\n34136\n22491\n41219\n20761\n14540\n26288\n47378\n17993\n12664\n41403\n25279\n41854\n1403\n47707\n27851\n40031\n13841\n13495\n43086\n33882\n7989\n43494\n28352\n41603\n48026\n11246\n22032\n20610\n27903\n10381\n5556\n31805\n5354\n37679\n43044\n48224\n23288\n8997\n31373\n30867\n6232\n20702\n8305\n12640\n5860\n45462\n44092\n702\n42850\n23854\n18822\n13926\n464..."
},
{
"input": "16553",
"output": "YES\n1\n2\n8278\n5519\n12416\n9933\n2760\n9460\n14485\n7358\n4967\n9030\n9657\n3821\n13007\n14347\n7243\n6817\n11956\n12198\n2484\n3154\n12792\n7198\n4829\n5298\n1911\n7971\n6504\n2855\n7174\n535\n3622\n14046\n3409\n8514\n14255\n12975\n14376\n6792\n9519\n6057\n9854\n8470\n14673\n4783\n11876\n9158\n2415\n3717\n10926\n2273\n956\n8746\n3986\n8428\n11529\n15102\n1428\n7015\n11864\n9770\n268\n1052\n10088\n765\n15300\n12354\n1705\n2400\n12534\n1633\n7128\n15647\n6488\n12802\n15465\n8385\n11673\n9849\n4760\n13693..."
},
{
"input": "19333",
"output": "YES\n1\n2\n9668\n12890\n14501\n11601\n16112\n2763\n7251\n17186\n5801\n15819\n17723\n8924\n1382\n10312\n3626\n4550\n18260\n17299\n2901\n7366\n7910\n5885\n8862\n2321\n14129\n18618\n10358\n2001\n14823\n10603\n11480\n11718\n11942\n4420\n18797\n18289\n8650\n15864\n1451\n6131\n13350\n17086\n13622\n3438\n2943\n18100\n14098\n11443\n1161\n14406\n7065\n11309\n18976\n18631\n14846\n5767\n1001\n9176\n7412\n14580\n5302\n2456\n15407\n17252\n15526\n10966\n15638\n14851\n11877\n7353\n9399\n17745\n9145\n13663\n13992\n16070\n..."
},
{
"input": "8677",
"output": "YES\n1\n2\n4340\n5786\n6509\n3472\n7232\n6199\n3255\n7714\n6075\n4734\n7955\n1336\n3100\n1158\n1628\n6126\n8196\n7308\n3038\n2067\n6706\n7169\n3978\n4166\n5007\n2572\n5889\n7182\n4918\n5879\n5153\n4471\n7402\n2976\n8437\n8209\n7993\n446\n5858\n2329\n1034\n4844\n7692\n3279\n3585\n6278\n6328\n2126\n6422\n4935\n2504\n7532\n5625\n2683\n2945\n5329\n7930\n6472\n6798\n570\n2940\n3582\n2577\n268\n2236\n8419\n8040\n8175\n5827\n6356\n4219\n2616\n4105\n7174\n3997\n6875\n4562\n8019\n7268\n858\n1165\n6169\n4856\n1226\n..."
},
{
"input": "83203",
"output": "YES\n1\n2\n41603\n55470\n20802\n49923\n69337\n71318\n52003\n46225\n24962\n7565\n34669\n25602\n77261\n44376\n26002\n48944\n23113\n39413\n54083\n79242\n3783\n75969\n17335\n26626\n54403\n15409\n38631\n40168\n63790\n2685\n54603\n57991\n66074\n30905\n11557\n58468\n19707\n36269\n27042\n77116\n81223\n42570\n1892\n42527\n37985\n31866\n8668\n81506\n54915\n71784\n27202\n59656\n7705\n34795\n19316\n68607\n61686\n12693\n73497\n1365\n1343\n54149\n27302\n55043\n28996\n75753\n74639\n53058\n15453\n9376\n5779\n49011\n70836\n..."
},
{
"input": "31513",
"output": "YES\n1\n2\n15758\n21010\n23636\n18909\n26262\n4503\n27575\n7004\n9455\n17190\n28888\n29090\n2252\n16808\n13788\n12977\n19259\n19904\n4728\n12006\n24352\n20553\n30201\n28993\n30302\n23344\n16883\n3261\n24161\n20332\n22651\n16235\n6489\n7204\n9630\n22997\n25709\n30706\n18121\n13836\n21760\n26384\n27933\n26612\n10277\n1342\n15101\n5146\n14497\n25335\n30908\n24379\n27429\n16044\n8442\n27644\n1631\n22434\n12081\n14466\n25923\n14507\n11326\n18424\n8118\n15052\n3245\n17356\n19359\n5771\n20572\n23312\n11499\n9665\n..."
},
{
"input": "60811",
"output": "YES\n1\n2\n30407\n40542\n15204\n48650\n50677\n26063\n38008\n33785\n54731\n38699\n25339\n42101\n13032\n56758\n49410\n28618\n16893\n38408\n27366\n49229\n19350\n2645\n12670\n21893\n21051\n51803\n36922\n31455\n58785\n33349\n55111\n53441\n44715\n41700\n8447\n39446\n49610\n54575\n44089\n7417\n24615\n26871\n40081\n18920\n1323\n34935\n36741\n29786\n10947\n9540\n10526\n51633\n25902\n32065\n48867\n53344\n15728\n23707\n29393\n50843\n16675\n56951\n27556\n8421\n26721\n53551\n22358\n41423\n51256\n1714\n4224\n29990\n5012..."
},
{
"input": "71821",
"output": "YES\n1\n2\n35912\n47882\n53867\n57458\n59852\n61562\n26934\n63842\n64640\n32647\n65837\n55248\n66692\n67034\n49378\n54923\n67832\n68042\n68231\n68402\n16324\n9369\n32919\n54585\n63535\n69162\n69257\n42103\n69428\n60238\n60600\n10883\n27462\n69770\n69827\n17471\n69932\n42357\n34116\n26277\n70112\n65141\n44073\n70226\n4685\n42788\n16460\n49836\n27293\n66189\n31768\n59626\n70492\n63987\n34629\n70562\n21052\n43824\n70625\n38855\n66030\n70682\n66211\n54143\n5442\n48239\n49642\n27064\n70796\n55637\n34914\n19678\n..."
},
{
"input": "1",
"output": "YES\n1"
},
{
"input": "2",
"output": "YES\n1\n2"
},
{
"input": "3",
"output": "YES\n1\n2\n3"
},
{
"input": "4",
"output": "YES\n1\n3\n2\n4"
},
{
"input": "5",
"output": "YES\n1\n2\n4\n3\n5"
},
{
"input": "99989",
"output": "YES\n1\n2\n49996\n33331\n74993\n19999\n16666\n85706\n37497\n11111\n10000\n9091\n58328\n15384\n92848\n6667\n18749\n41173\n5556\n63152\n54995\n61899\n4546\n86948\n79159\n63994\n57687\n37034\n96419\n34480\n3334\n35481\n9375\n3031\n20587\n17142\n52773\n86478\n81571\n71788\n27498\n90235\n30950\n6977\n52268\n2223\n93469\n14893\n39580\n55097\n81992\n13725\n28844\n77351\n68512\n1819\n48210\n54381\n67235\n81348\n51662\n9836\n17741\n87293\n4688\n63071\n1516\n11940\n10294\n62313\n58566\n38025\n26387\n9589\n93234\n213..."
}
] | 1,445,204,387 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 842 | 102,400 | def comp(x):
for i in range(2, x):
if x % i == 0:
return True
return False
N = int(input())
if N == 4:
print('YES', '1', '3', '2', '4', sep = '\n')
elif comp(N):
print('NO')
else:
print('YES', '1', sep = '\n')
if N > 1:
for i in range(2, N):
print((i - 1) * pow(i, N - 2, N) % N)
print(N)
| Title: Prefix Product Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider a sequence [*a*1,<=*a*2,<=... ,<=*a**n*]. Define its prefix product sequence .
Now given *n*, find a permutation of [1,<=2,<=...,<=*n*], such that its prefix product sequence is a permutation of [0,<=1,<=...,<=*n*<=-<=1].
Input Specification:
The only input line contains an integer *n* (1<=≤<=*n*<=≤<=105).
Output Specification:
In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output *n* more lines. *i*-th line contains only an integer *a**i*. The elements of the sequence should be different positive integers no larger than *n*.
If there are multiple solutions, you are allowed to print any of them.
Demo Input:
['7\n', '6\n']
Demo Output:
['YES\n1\n4\n3\n6\n5\n2\n7\n', 'NO\n']
Note:
For the second sample, there are no valid sequences. | ```python
def comp(x):
for i in range(2, x):
if x % i == 0:
return True
return False
N = int(input())
if N == 4:
print('YES', '1', '3', '2', '4', sep = '\n')
elif comp(N):
print('NO')
else:
print('YES', '1', sep = '\n')
if N > 1:
for i in range(2, N):
print((i - 1) * pow(i, N - 2, N) % N)
print(N)
``` | 3 |
|
489 | C | Given Length and Sum of Digits... | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes. | The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers. | In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes). | [
"2 15\n",
"3 0\n"
] | [
"69 96\n",
"-1 -1\n"
] | none | 1,500 | [
{
"input": "2 15",
"output": "69 96"
},
{
"input": "3 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "100 100",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000099999999999 9999999999910000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "1 900",
"output": "-1 -1"
},
{
"input": "1 9",
"output": "9 9"
},
{
"input": "1 0",
"output": "0 0"
},
{
"input": "1 1",
"output": "1 1"
},
{
"input": "1 2",
"output": "2 2"
},
{
"input": "1 8",
"output": "8 8"
},
{
"input": "1 10",
"output": "-1 -1"
},
{
"input": "1 11",
"output": "-1 -1"
},
{
"input": "2 0",
"output": "-1 -1"
},
{
"input": "2 1",
"output": "10 10"
},
{
"input": "2 2",
"output": "11 20"
},
{
"input": "2 8",
"output": "17 80"
},
{
"input": "2 10",
"output": "19 91"
},
{
"input": "2 11",
"output": "29 92"
},
{
"input": "2 16",
"output": "79 97"
},
{
"input": "2 17",
"output": "89 98"
},
{
"input": "2 18",
"output": "99 99"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "2 20",
"output": "-1 -1"
},
{
"input": "2 900",
"output": "-1 -1"
},
{
"input": "3 1",
"output": "100 100"
},
{
"input": "3 2",
"output": "101 200"
},
{
"input": "3 3",
"output": "102 300"
},
{
"input": "3 9",
"output": "108 900"
},
{
"input": "3 10",
"output": "109 910"
},
{
"input": "3 20",
"output": "299 992"
},
{
"input": "3 21",
"output": "399 993"
},
{
"input": "3 26",
"output": "899 998"
},
{
"input": "3 27",
"output": "999 999"
},
{
"input": "3 28",
"output": "-1 -1"
},
{
"input": "3 100",
"output": "-1 -1"
},
{
"input": "100 0",
"output": "-1 -1"
},
{
"input": "100 1",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 2",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 9",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008 9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 10",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009 9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 11",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019 9200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 296",
"output": "1000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999999999999 9999999999999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 297",
"output": "1000000000000000000000000000000000000000000000000000000000000000000899999999999999999999999999999999 9999999999999999999999999999999990000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 298",
"output": "1000000000000000000000000000000000000000000000000000000000000000000999999999999999999999999999999999 9999999999999999999999999999999991000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 299",
"output": "1000000000000000000000000000000000000000000000000000000000000000001999999999999999999999999999999999 9999999999999999999999999999999992000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 300",
"output": "1000000000000000000000000000000000000000000000000000000000000000002999999999999999999999999999999999 9999999999999999999999999999999993000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 301",
"output": "1000000000000000000000000000000000000000000000000000000000000000003999999999999999999999999999999999 9999999999999999999999999999999994000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 895",
"output": "4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999994"
},
{
"input": "100 896",
"output": "5999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995"
},
{
"input": "100 897",
"output": "6999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999996"
},
{
"input": "100 898",
"output": "7999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999997"
},
{
"input": "100 899",
"output": "8999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998"
},
{
"input": "100 900",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 900",
"output": "-1 -1"
},
{
"input": "99 891",
"output": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "99 892",
"output": "-1 -1"
},
{
"input": "96 364",
"output": "100000000000000000000000000000000000000000000000000000039999999999999999999999999999999999999999 999999999999999999999999999999999999999940000000000000000000000000000000000000000000000000000000"
},
{
"input": "97 206",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000079999999999999999999999 9999999999999999999999800000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "98 250",
"output": "10000000000000000000000000000000000000000000000000000000000000000000006999999999999999999999999999 99999999999999999999999999970000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "99 96",
"output": "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000059999999999 999999999960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "100 215",
"output": "1000000000000000000000000000000000000000000000000000000000000000000000000000799999999999999999999999 9999999999999999999999980000000000000000000000000000000000000000000000000000000000000000000000000000"
},
{
"input": "5 18",
"output": "10089 99000"
},
{
"input": "2 19",
"output": "-1 -1"
},
{
"input": "3 3",
"output": "102 300"
}
] | 1,683,403,117 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 93 | 0 | n,m = tuple(map(int,input().split()))
s = [1] + [0]*(n-1)
l = [9]*(n)
ss = 1
ls = 9*n
if(n == 1 and m <= 9):
print(m,m)
elif(ss > m or ls < m):
print(-1,-1)
else:
for i in range(n-1):
if(m - ss >= 9):
s[n-1-i] = 9
ss += 9
else:
s[n-1-i] = m - ss
ss = m
if(ss != m and m - ss <= 8):
s[0] += m - ss
for i in range(n-1):
if(ls -m >= 9):
l[n-1-i] = 0
ls -=9
else:
l[n-1-i] =9 - (ls - m)
ls = m
if(ls != m and ls - m <= 8):
l[0] -= ls - m
for i in range(n):
print(s[i],end = '')
print('',end = ' ')
for i in range(n):
print(l[i],end = '')
print() | Title: Given Length and Sum of Digits...
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
Input Specification:
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
Output Specification:
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
Demo Input:
['2 15\n', '3 0\n']
Demo Output:
['69 96\n', '-1 -1\n']
Note:
none | ```python
n,m = tuple(map(int,input().split()))
s = [1] + [0]*(n-1)
l = [9]*(n)
ss = 1
ls = 9*n
if(n == 1 and m <= 9):
print(m,m)
elif(ss > m or ls < m):
print(-1,-1)
else:
for i in range(n-1):
if(m - ss >= 9):
s[n-1-i] = 9
ss += 9
else:
s[n-1-i] = m - ss
ss = m
if(ss != m and m - ss <= 8):
s[0] += m - ss
for i in range(n-1):
if(ls -m >= 9):
l[n-1-i] = 0
ls -=9
else:
l[n-1-i] =9 - (ls - m)
ls = m
if(ls != m and ls - m <= 8):
l[0] -= ls - m
for i in range(n):
print(s[i],end = '')
print('',end = ' ')
for i in range(n):
print(l[i],end = '')
print()
``` | 3 |
|
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole? | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes. | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 96",
"output": "8"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "2 2 2\n1 10000",
"output": "1"
},
{
"input": "2 10000 1\n1 9999",
"output": "0"
}
] | 1,669,073,429 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | n, a, b = [int(c) for c in input().split()]
pesos = [int(k) for k in input().split()]
first = pesos[0]
pesos.sort()
i = 0
soma = sum(pesos[i:n])
v = (first*a)/soma
while (v < b):
i += 1
soma = sum(pesos[i:n])
v = (first*a)/soma
print(i)
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After that, the water will flow out from the non-blocked holes proportionally to their sizes $s_1, s_2, \ldots, s_n$. In other words, if the sum of sizes of non-blocked holes is $S$, and the $i$-th hole is not blocked, $\frac{s_i \cdot A}{S}$ liters of water will flow out of it.
What is the minimum number of holes Arkady should block to make at least $B$ liters of water flow out of the first hole?
Input Specification:
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$) — the sizes of the holes.
Output Specification:
Print a single integer — the number of holes Arkady should block.
Demo Input:
['4 10 3\n2 2 2 2\n', '4 80 20\n3 2 1 4\n', '5 10 10\n1000 1 1 1 1\n']
Demo Output:
['1\n', '0\n', '4\n']
Note:
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not less than $20$.
In the third example Arkady has to block all holes except the first to make all water flow out of the first hole. | ```python
n, a, b = [int(c) for c in input().split()]
pesos = [int(k) for k in input().split()]
first = pesos[0]
pesos.sort()
i = 0
soma = sum(pesos[i:n])
v = (first*a)/soma
while (v < b):
i += 1
soma = sum(pesos[i:n])
v = (first*a)/soma
print(i)
``` | 0 |
|
556 | A | Case of the Zeros and Ones | PROGRAMMING | 900 | [
"greedy"
] | null | null | Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones. | Output the minimum length of the string that may remain after applying the described operations several times. | [
"4\n1100\n",
"5\n01010\n",
"8\n11101111\n"
] | [
"0\n",
"1\n",
"6\n"
] | In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | 250 | [
{
"input": "4\n1100",
"output": "0"
},
{
"input": "5\n01010",
"output": "1"
},
{
"input": "8\n11101111",
"output": "6"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "2"
},
{
"input": "2\n01",
"output": "0"
},
{
"input": "2\n10",
"output": "0"
},
{
"input": "2\n11",
"output": "2"
},
{
"input": "3\n001",
"output": "1"
},
{
"input": "6\n110110",
"output": "2"
},
{
"input": "7\n0000011",
"output": "3"
},
{
"input": "6\n110010",
"output": "0"
},
{
"input": "6\n110100",
"output": "0"
},
{
"input": "3\n100",
"output": "1"
},
{
"input": "6\n010111",
"output": "2"
},
{
"input": "8\n01011100",
"output": "0"
},
{
"input": "6\n001011",
"output": "0"
},
{
"input": "7\n1110000",
"output": "1"
},
{
"input": "9\n011111101",
"output": "5"
}
] | 1,685,215,835 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 93 | 409,600 | n = int(input())
num = input()
zeroes = num.count('0')
ones = num.count('1')
pairs = min(zeroes, ones)
print(n - pairs * 2) | Title: Case of the Zeros and Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.
Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result.
Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.
Input Specification:
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has.
The second line contains the string of length *n* consisting only from zeros and ones.
Output Specification:
Output the minimum length of the string that may remain after applying the described operations several times.
Demo Input:
['4\n1100\n', '5\n01010\n', '8\n11101111\n']
Demo Output:
['0\n', '1\n', '6\n']
Note:
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/19ec5dcd85f0b5cf757aa076ace72df39634de2d.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the third sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/dc34a159e4230375fa325555527ebc748811f188.png" style="max-width: 100.0%;max-height: 100.0%;"/>. | ```python
n = int(input())
num = input()
zeroes = num.count('0')
ones = num.count('1')
pairs = min(zeroes, ones)
print(n - pairs * 2)
``` | 3 |
|
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input": "2",
"output": "1 2"
},
{
"input": "3",
"output": "1 3"
},
{
"input": "4",
"output": "2 2"
},
{
"input": "6",
"output": "2 3"
},
{
"input": "7",
"output": "1 7"
},
{
"input": "9",
"output": "3 3"
},
{
"input": "10",
"output": "2 5"
},
{
"input": "11",
"output": "1 11"
},
{
"input": "12",
"output": "3 4"
},
{
"input": "15",
"output": "3 5"
},
{
"input": "100",
"output": "10 10"
},
{
"input": "101",
"output": "1 101"
},
{
"input": "169",
"output": "13 13"
},
{
"input": "179",
"output": "1 179"
},
{
"input": "190",
"output": "10 19"
},
{
"input": "1000",
"output": "25 40"
},
{
"input": "10000",
"output": "100 100"
},
{
"input": "10001",
"output": "73 137"
},
{
"input": "100000",
"output": "250 400"
},
{
"input": "100001",
"output": "11 9091"
},
{
"input": "1000000",
"output": "1000 1000"
},
{
"input": "999983",
"output": "1 999983"
},
{
"input": "524288",
"output": "512 1024"
},
{
"input": "954493",
"output": "971 983"
},
{
"input": "966289",
"output": "983 983"
},
{
"input": "944663",
"output": "961 983"
},
{
"input": "912673",
"output": "97 9409"
},
{
"input": "732641",
"output": "679 1079"
},
{
"input": "232897",
"output": "343 679"
},
{
"input": "16807",
"output": "49 343"
},
{
"input": "999958",
"output": "2 499979"
},
{
"input": "990151",
"output": "1 990151"
},
{
"input": "997002",
"output": "998 999"
},
{
"input": "20",
"output": "4 5"
},
{
"input": "20261",
"output": "1 20261"
},
{
"input": "999123",
"output": "3 333041"
},
{
"input": "901841",
"output": "1 901841"
}
] | 1,543,998,294 | 294 | Python 3 | OK | TESTS | 43 | 109 | 0 | #import sys
#sys.stdin = open('in', 'r')
n = int(input())
#a = [int(x) for x in input().split()]
#n,m = map(int, input().split())
import math
a = 1
b = n
r = n-1
ra = 1
rb = n
while a <= (math.sqrt(n) + 1):
a += 1
if n % a == 0:
b = n // a
if b >= a and (b-a) < r:
r = b - a
ra = a
rb = b
print(ra, rb)
| Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
Input Specification:
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Output Specification:
Print two integers — the number of rows and columns on the display.
Demo Input:
['8\n', '64\n', '5\n', '999999\n']
Demo Output:
['2 4\n', '8 8\n', '1 5\n', '999 1001\n']
Note:
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels. | ```python
#import sys
#sys.stdin = open('in', 'r')
n = int(input())
#a = [int(x) for x in input().split()]
#n,m = map(int, input().split())
import math
a = 1
b = n
r = n-1
ra = 1
rb = n
while a <= (math.sqrt(n) + 1):
a += 1
if n % a == 0:
b = n // a
if b >= a and (b-a) < r:
r = b - a
ra = a
rb = b
print(ra, rb)
``` | 3 |
|
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round. | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1). | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0",
"output": "14"
},
{
"input": "5 5\n3 2 1 0 0",
"output": "3"
},
{
"input": "8 6\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 7\n10 9 8 7 7 7 5 5",
"output": "8"
},
{
"input": "8 4\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "8 3\n10 9 8 7 7 7 5 5",
"output": "3"
},
{
"input": "8 1\n10 9 8 7 7 7 5 5",
"output": "1"
},
{
"input": "8 2\n10 9 8 7 7 7 5 5",
"output": "2"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "50 25\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"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 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": "25"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 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": "26"
},
{
"input": "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "50"
},
{
"input": "11 5\n100 99 98 97 96 95 94 93 92 91 90",
"output": "5"
},
{
"input": "10 4\n100 81 70 69 64 43 34 29 15 3",
"output": "4"
},
{
"input": "11 6\n87 71 62 52 46 46 43 35 32 25 12",
"output": "6"
},
{
"input": "17 12\n99 88 86 82 75 75 74 65 58 52 45 30 21 16 7 2 2",
"output": "12"
},
{
"input": "20 3\n98 98 96 89 87 82 82 80 76 74 74 68 61 60 43 32 30 22 4 2",
"output": "3"
},
{
"input": "36 12\n90 87 86 85 83 80 79 78 76 70 69 69 61 61 59 58 56 48 45 44 42 41 33 31 27 25 23 21 20 19 15 14 12 7 5 5",
"output": "12"
},
{
"input": "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 3 1",
"output": "9"
},
{
"input": "49 29\n100 98 98 96 96 96 95 87 85 84 81 76 74 70 63 63 63 62 57 57 56 54 53 52 50 47 45 41 41 39 38 31 30 28 27 26 23 22 20 15 15 11 7 6 6 4 2 1 0",
"output": "29"
},
{
"input": "49 34\n99 98 96 96 93 92 90 89 88 86 85 85 82 76 73 69 66 64 63 63 60 59 57 57 56 55 54 54 51 48 47 44 42 42 40 39 38 36 33 26 24 23 19 17 17 14 12 7 4",
"output": "34"
},
{
"input": "50 44\n100 100 99 97 95 91 91 84 83 83 79 71 70 69 69 62 61 60 59 59 58 58 58 55 55 54 52 48 47 45 44 44 38 36 32 31 28 28 25 25 24 24 24 22 17 15 14 13 12 4",
"output": "44"
},
{
"input": "50 13\n99 95 94 94 88 87 81 79 78 76 74 72 72 69 68 67 67 67 66 63 62 61 58 57 55 55 54 51 50 50 48 48 42 41 38 35 34 32 31 30 26 24 13 13 12 6 5 4 3 3",
"output": "13"
},
{
"input": "50 30\n100 98 96 94 91 89 88 81 81 81 81 81 76 73 72 71 70 69 66 64 61 59 59 56 52 50 49 48 43 39 36 35 34 34 31 29 27 26 24 22 16 16 15 14 14 14 9 7 4 3",
"output": "30"
},
{
"input": "2 1\n10 10",
"output": "2"
},
{
"input": "2 2\n10 10",
"output": "2"
},
{
"input": "2 2\n10 0",
"output": "1"
},
{
"input": "2 2\n10 1",
"output": "2"
},
{
"input": "2 1\n10 0",
"output": "1"
},
{
"input": "2 1\n10 2",
"output": "1"
},
{
"input": "50 13\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",
"output": "0"
},
{
"input": "50 1\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",
"output": "0"
},
{
"input": "50 50\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",
"output": "0"
},
{
"input": "10 1\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 2\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 3\n5 5 5 3 3 3 0 0 0 0",
"output": "3"
},
{
"input": "10 4\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 5\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 6\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 7\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 8\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 9\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
},
{
"input": "10 10\n5 5 5 3 3 3 0 0 0 0",
"output": "6"
}
] | 1,697,171,130 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def shert(num):
return num>k
n,k=map(int,input().split(' '))
tt=list(map(int,input().strip().split()))[:n]
t1=list(map(int,filter(shert,tt)))
print(len(t1))
print(len(t1)) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate how many participants will advance to the next round.
Input Specification:
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence is non-increasing (that is, for all *i* from 1 to *n*<=-<=1 the following condition is fulfilled: *a**i*<=≥<=*a**i*<=+<=1).
Output Specification:
Output the number of participants who advance to the next round.
Demo Input:
['8 5\n10 9 8 7 7 7 5 5\n', '4 2\n0 0 0 0\n']
Demo Output:
['6\n', '0\n']
Note:
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | ```python
def shert(num):
return num>k
n,k=map(int,input().split(' '))
tt=list(map(int,input().strip().split()))[:n]
t1=list(map(int,filter(shert,tt)))
print(len(t1))
print(len(t1))
``` | 0 |
|
99 | B | Help Chef Gerasim | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | B. Help Chef Gerasim | 0 | 256 | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.
To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice. | The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104. | If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes). | [
"5\n270\n250\n250\n230\n250\n",
"5\n250\n250\n250\n250\n250\n",
"5\n270\n250\n249\n230\n250\n"
] | [
"20 ml. from cup #4 to cup #1.\n",
"Exemplary pages.\n",
"Unrecoverable configuration.\n"
] | none | 1,000 | [
{
"input": "5\n270\n250\n250\n230\n250",
"output": "20 ml. from cup #4 to cup #1."
},
{
"input": "5\n250\n250\n250\n250\n250",
"output": "Exemplary pages."
},
{
"input": "5\n270\n250\n249\n230\n250",
"output": "Unrecoverable configuration."
},
{
"input": "4\n200\n190\n210\n200",
"output": "10 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n2\n3\n4",
"output": "Unrecoverable configuration."
},
{
"input": "1\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n0",
"output": "Exemplary pages."
},
{
"input": "2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n0\n2",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "2\n1\n1",
"output": "Exemplary pages."
},
{
"input": "2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n0",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "3\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n1\n2",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "3\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n0\n2\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "3\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n0\n2",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "3\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "3\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n0",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "3\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n0\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "3\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n0",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "3\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "3\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n0",
"output": "Exemplary pages."
},
{
"input": "4\n0\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n1\n2",
"output": "1 ml. from cup #1 to cup #4."
},
{
"input": "4\n0\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n1\n2\n1",
"output": "1 ml. from cup #1 to cup #3."
},
{
"input": "4\n0\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n1\n1",
"output": "1 ml. from cup #1 to cup #2."
},
{
"input": "4\n0\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n0\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n1\n2",
"output": "1 ml. from cup #2 to cup #4."
},
{
"input": "4\n1\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n0\n2\n1",
"output": "1 ml. from cup #2 to cup #3."
},
{
"input": "4\n1\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n0\n2",
"output": "1 ml. from cup #3 to cup #4."
},
{
"input": "4\n1\n1\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n1\n1",
"output": "Exemplary pages."
},
{
"input": "4\n1\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n0",
"output": "1 ml. from cup #4 to cup #3."
},
{
"input": "4\n1\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n0\n1",
"output": "1 ml. from cup #3 to cup #2."
},
{
"input": "4\n1\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n0",
"output": "1 ml. from cup #4 to cup #2."
},
{
"input": "4\n1\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n1\n2\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n1\n1",
"output": "1 ml. from cup #2 to cup #1."
},
{
"input": "4\n2\n0\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n0\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n0\n1",
"output": "1 ml. from cup #3 to cup #1."
},
{
"input": "4\n2\n1\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n0",
"output": "1 ml. from cup #4 to cup #1."
},
{
"input": "4\n2\n1\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n1\n2\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n0\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n1\n2",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n0",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n1",
"output": "Unrecoverable configuration."
},
{
"input": "4\n2\n2\n2\n2",
"output": "Exemplary pages."
},
{
"input": "27\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n2626\n5599\n5599\n5599\n5599\n5599\n8572\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599\n5599",
"output": "2973 ml. from cup #11 to cup #17."
},
{
"input": "98\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n1204\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n702\n197\n702\n702\n702\n702\n702\n702\n702\n702\n702",
"output": "Unrecoverable configuration."
},
{
"input": "54\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6859\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n5389\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124\n6124",
"output": "735 ml. from cup #37 to cup #29."
},
{
"input": "50\n9636\n9678\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9636\n9596\n9636\n9636\n9636\n9636\n9636\n9636",
"output": "Unrecoverable configuration."
},
{
"input": "19\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n5001\n82\n5001\n9919\n5001\n5001",
"output": "Unrecoverable configuration."
},
{
"input": "74\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n3918\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n5330\n6742\n5330\n5330",
"output": "1412 ml. from cup #36 to cup #72."
}
] | 1,550,045,080 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 |
n = int(input())
l = []
for i in range(n):
a = int(input())
l.append(a)
v = l.copy()
l.sort()
if len(set(l)) == 1:
print('Exemplary pages.')
elif len(set(l)) >3:
print('Unrecoverable configuration.')
else:
k = sorted(list((set(l))))[-1] - sorted(list((set(l))))[0]
x,y = sorted(list((set(l))))[-1],sorted(list((set(l))))[0]
for i in range(n):
if v[i] == y:
a = i+1
if v[i] == x:
b = i+1
ans = str(k)+' ml.' + ' from ' + '#' + str(a) + ' to ' + '#' + str(b)
print(ans)
| Title: Help Chef Gerasim
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup to another. Now Gerasim wants to check his hypothesis. The good thing is that chef Gerasim always pour the same number of milliliters of juice to all cups in the royal kitchen. Having thoroughly measured the juice in each cup, Gerasim asked you to write a program that will determine from which cup juice was poured to which one; otherwise, the program should determine that this time the pages set the table diligently.
To simplify your task we shall consider the cups to be bottomless so that the juice never overfills a cup and pours out, however much it can be. Besides, by some strange reason in a far away kingdom one can only pour to a cup or from one cup to another an integer number of milliliters of juice.
Input Specification:
The first line contains integer *n* — the number of cups on the royal table (1<=≤<=*n*<=≤<=1000). Next *n* lines contain volumes of juice in each cup — non-negative integers, not exceeding 104.
Output Specification:
If the pages didn't pour the juice, print "Exemplary pages." (without the quotes). If you can determine the volume of juice poured during exactly one juice pouring, print "*v* ml. from cup #*a* to cup #*b*." (without the quotes), where *v* represents the volume of poured juice, *a* represents the number of the cup from which the juice was poured (the cups are numbered with consecutive positive integers starting from one in the order in which the cups are described in the input data), *b* represents the number of the cup into which the juice was poured. Finally, if the given juice's volumes cannot be obtained using no more than one pouring (for example, the pages poured the juice from one cup to another more than once or the royal kitchen maids poured the juice into the cups incorrectly), print "Unrecoverable configuration." (without the quotes).
Demo Input:
['5\n270\n250\n250\n230\n250\n', '5\n250\n250\n250\n250\n250\n', '5\n270\n250\n249\n230\n250\n']
Demo Output:
['20 ml. from cup #4 to cup #1.\n', 'Exemplary pages.\n', 'Unrecoverable configuration.\n']
Note:
none | ```python
n = int(input())
l = []
for i in range(n):
a = int(input())
l.append(a)
v = l.copy()
l.sort()
if len(set(l)) == 1:
print('Exemplary pages.')
elif len(set(l)) >3:
print('Unrecoverable configuration.')
else:
k = sorted(list((set(l))))[-1] - sorted(list((set(l))))[0]
x,y = sorted(list((set(l))))[-1],sorted(list((set(l))))[0]
for i in range(n):
if v[i] == y:
a = i+1
if v[i] == x:
b = i+1
ans = str(k)+' ml.' + ' from ' + '#' + str(a) + ' to ' + '#' + str(b)
print(ans)
``` | 0 |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment. | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 100000",
"output": "Yes"
},
{
"input": "1 99989",
"output": "No"
},
{
"input": "512 2",
"output": "Yes"
},
{
"input": "100 24",
"output": "No"
},
{
"input": "1 100000",
"output": "No"
},
{
"input": "100000 1",
"output": "Yes"
},
{
"input": "3 99929",
"output": "No"
},
{
"input": "99961 99971",
"output": "No"
},
{
"input": "1 65536",
"output": "Yes"
},
{
"input": "4 65536",
"output": "Yes"
},
{
"input": "3 65536",
"output": "Yes"
},
{
"input": "32768 65536",
"output": "Yes"
},
{
"input": "65535 65536",
"output": "Yes"
},
{
"input": "1 65535",
"output": "No"
},
{
"input": "98812 100000",
"output": "No"
},
{
"input": "10 5",
"output": "Yes"
},
{
"input": "6 8",
"output": "Yes"
}
] | 1,415,206,456 | 1,456 | Python 3 | OK | TESTS | 23 | 109 | 5,017,600 | a, m = map(int, input().split())
s = set()
while True:
a %= m
if a in s:
print('Yes' if 0 in s else 'No')
break
s.add(a)
a *= 2
| Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment.
Input Specification:
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Output Specification:
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Demo Input:
['1 5\n', '3 6\n']
Demo Output:
['No\n', 'Yes\n']
Note:
none | ```python
a, m = map(int, input().split())
s = set()
while True:
a %= m
if a in s:
print('Yes' if 0 in s else 'No')
break
s.add(a)
a *= 2
``` | 3 |
|
742 | B | Arpa’s obvious problem and Mehrdad’s terrible solution | PROGRAMMING | 1,500 | [
"brute force",
"math",
"number theory"
] | null | null | There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem. | First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer: the answer to the problem. | [
"2 3\n1 2\n",
"6 1\n5 1 2 3 4 1\n"
] | [
"1",
"2"
] | In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1.
In the second sample the only two pairs are *i* = 3, *j* = 4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i* = 1, *j* = 5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). | 1,000 | [
{
"input": "2 3\n1 2",
"output": "1"
},
{
"input": "6 1\n5 1 2 3 4 1",
"output": "2"
},
{
"input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423",
"output": "0"
},
{
"input": "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 135 519 174 147 201 564 182 359 41 465 162 125 378 342 144 549 363 309",
"output": "1"
},
{
"input": "27 41\n156 148 86 161 113 80 185 15 204 185 205 95 147 146 133 187 114 8 11 120 117 167 100 171 140 102 174",
"output": "1"
},
{
"input": "10 208\n399 912 747 631 510 622 234 707 483 496",
"output": "0"
},
{
"input": "64 43\n78 90 211 205 198 4 172 43 163 21 58 145 28 66 210 68 79 90 155 123 9 119 188 151 180 157 44 163 20 71 28 120 163 141 170 206 31 34 21 195 72 194 83 163 140 40 182 208 127 128 110 72 184 157 128 189 146 35 51 206 62 8 117 61",
"output": "8"
},
{
"input": "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 31 27 97 91 49 45 37 92",
"output": "21"
},
{
"input": "64 118\n361 547 410 294 448 377 482 490 13 116 346 50 251 330 443 128 543 580 370 489 337 509 414 291 228 71 245 308 319 314 154 39 317 288 145 248 547 152 262 278 89 108 522 238 128 575 112 469 86 230 310 492 127 270 475 25 179 72 345 444 17 332 544 338",
"output": "3"
},
{
"input": "52 231\n229 492 1005 498 786 274 773 573 316 774 977 110 709 49 131 81 1146 1028 451 451 776 470 996 363 581 484 1023 858 1115 273 1105 4 445 509 428 125 432 131 360 404 280 808 649 4 499 1097 831 512 208 996 430 1010",
"output": "0"
},
{
"input": "4 0\n1 2 3 4",
"output": "0"
},
{
"input": "3 0\n2 2 2",
"output": "3"
},
{
"input": "5 0\n1 1 1 1 1",
"output": "10"
},
{
"input": "3 0\n1 1 1",
"output": "3"
},
{
"input": "4 0\n2 2 2 2",
"output": "6"
},
{
"input": "3 0\n10 10 10",
"output": "3"
},
{
"input": "3 0\n3 3 3",
"output": "3"
},
{
"input": "4 0\n1 1 1 1",
"output": "6"
},
{
"input": "3 0\n4 4 4",
"output": "3"
},
{
"input": "2 0\n2 2",
"output": "1"
},
{
"input": "2 0\n2 3",
"output": "0"
},
{
"input": "2 0\n1 2",
"output": "0"
},
{
"input": "5 0\n5 5 5 5 5",
"output": "10"
},
{
"input": "6 0\n1 1 1 1 1 1",
"output": "15"
},
{
"input": "2 0\n1 1",
"output": "1"
},
{
"input": "4 0\n1 1 3 3",
"output": "2"
},
{
"input": "2 0\n10 10",
"output": "1"
},
{
"input": "4 0\n3 3 3 3",
"output": "6"
},
{
"input": "5 0\n1 1 1 2 2",
"output": "4"
},
{
"input": "5 0\n1 1 2 2 3",
"output": "2"
},
{
"input": "10 0\n1 1 1 1 1 1 1 1 1 1",
"output": "45"
},
{
"input": "2 0\n3 3",
"output": "1"
}
] | 1,699,287,599 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 10 | 93 | 4,505,600 | l=[0 for j in range(10**5+1)]
n, k = ([int(x) for x in input().split()])
l1=list(map(int,input().split()))
for j in l1:
l[j]+=1
ans=0
for j in l1:
a=j^k
if l[a]>0 and l[j]>0:
ans += l[a] * l[j]
l[a]=0
l[j]=0
# print (a,j,l[a],l[j])
print(ans) | Title: Arpa’s obvious problem and Mehrdad’s terrible solution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=<<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation).
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
Input Specification:
First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*.
Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array.
Output Specification:
Print a single integer: the answer to the problem.
Demo Input:
['2 3\n1 2\n', '6 1\n5 1 2 3 4 1\n']
Demo Output:
['1', '2']
Note:
In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1.
In the second sample the only two pairs are *i* = 3, *j* = 4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i* = 1, *j* = 5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR). | ```python
l=[0 for j in range(10**5+1)]
n, k = ([int(x) for x in input().split()])
l1=list(map(int,input().split()))
for j in l1:
l[j]+=1
ans=0
for j in l1:
a=j^k
if l[a]>0 and l[j]>0:
ans += l[a] * l[j]
l[a]=0
l[j]=0
# print (a,j,l[a],l[j])
print(ans)
``` | -1 |
|
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
},
{
"input": "1024",
"output": "10"
},
{
"input": "99999",
"output": "11"
},
{
"input": "10007",
"output": "1"
},
{
"input": "4096",
"output": "12"
},
{
"input": "65536",
"output": "16"
},
{
"input": "40320",
"output": "95"
},
{
"input": "30030",
"output": "63"
},
{
"input": "161",
"output": "3"
},
{
"input": "1000",
"output": "15"
},
{
"input": "10000",
"output": "24"
},
{
"input": "777",
"output": "7"
},
{
"input": "121",
"output": "2"
},
{
"input": "25",
"output": "2"
},
{
"input": "40000",
"output": "34"
},
{
"input": "99990",
"output": "47"
},
{
"input": "98765",
"output": "3"
},
{
"input": "56789",
"output": "3"
},
{
"input": "13579",
"output": "3"
},
{
"input": "97531",
"output": "3"
},
{
"input": "12345",
"output": "7"
},
{
"input": "54321",
"output": "7"
},
{
"input": "83160",
"output": "127"
},
{
"input": "9",
"output": "2"
},
{
"input": "21",
"output": "3"
},
{
"input": "11",
"output": "1"
},
{
"input": "15",
"output": "3"
}
] | 1,675,237,233 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 93 | 1,331,200 | t = int(input())
s = 1
for i in range(2, t):
if t % i == 0:
s += 1
print(s)
| Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader.
Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly.
Input Specification:
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Output Specification:
Print a single integer representing the answer to the problem.
Demo Input:
['2\n', '10\n']
Demo Output:
['1\n', '3\n']
Note:
In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | ```python
t = int(input())
s = 1
for i in range(2, t):
if t % i == 0:
s += 1
print(s)
``` | 3 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,694,076,171 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m=list(map(int,input().split()))
min_num=min(n,m)
count=min_num
c=abs(n-m)
if c<=1:
pass
else:
if c%2==0:
d=c/2
print(count,d,end="")
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
n,m=list(map(int,input().split()))
min_num=min(n,m)
count=min_num
c=abs(n-m)
if c<=1:
pass
else:
if c%2==0:
d=c/2
print(count,d,end="")
``` | 0 |
|
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymedasloqbq",
"output": "NO"
},
{
"input": "yehluhlkwo",
"output": "NO"
},
{
"input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello",
"output": "YES"
},
{
"input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq",
"output": "YES"
},
{
"input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi",
"output": "YES"
},
{
"input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo",
"output": "YES"
},
{
"input": "lqllcolohwflhfhlnaow",
"output": "NO"
},
{
"input": "heheeellollvoo",
"output": "YES"
},
{
"input": "hellooo",
"output": "YES"
},
{
"input": "o",
"output": "NO"
},
{
"input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv",
"output": "YES"
},
{
"input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk",
"output": "YES"
},
{
"input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry",
"output": "NO"
},
{
"input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq",
"output": "NO"
},
{
"input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi",
"output": "YES"
},
{
"input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm",
"output": "YES"
},
{
"input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac",
"output": "NO"
},
{
"input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok",
"output": "YES"
},
{
"input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz",
"output": "YES"
},
{
"input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb",
"output": "YES"
},
{
"input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla",
"output": "YES"
},
{
"input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz",
"output": "YES"
},
{
"input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti",
"output": "YES"
},
{
"input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli",
"output": "YES"
},
{
"input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo",
"output": "YES"
},
{
"input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk",
"output": "NO"
},
{
"input": "loee",
"output": "NO"
},
{
"input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo",
"output": "NO"
},
{
"input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi",
"output": "YES"
},
{
"input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv",
"output": "NO"
},
{
"input": "hello",
"output": "YES"
},
{
"input": "oohell",
"output": "NO"
},
{
"input": "hell",
"output": "NO"
},
{
"input": "eloellohoelo",
"output": "NO"
},
{
"input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo",
"output": "YES"
}
] | 1,600,079,655 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | a= input().lower()
o=list(a)
the_list=[]
for l in o:
if l not in the_list :
the_list.append(l)
x=""
for i in the_list :
x=x+i
if "ell" in a or "llo" in a:
if "helo" in x:
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
a= input().lower()
o=list(a)
the_list=[]
for l in o:
if l not in the_list :
the_list.append(l)
x=""
for i in the_list :
x=x+i
if "ell" in a or "llo" in a:
if "helo" in x:
print("YES")
else:
print("NO")
``` | 0 |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them are connected by a cable. The computers are indexed by integers from 1 to *n*. It's known that any two computers connected by cable directly or through other computers
Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.
Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.
Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture.
You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown. | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the numbers of nodes that are connected by the *i*-the edge.
It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself. | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes). | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"input": "5 4\n1 2\n3 5\n1 4\n5 4",
"output": "bus topology"
},
{
"input": "5 5\n3 4\n5 2\n2 1\n5 4\n3 1",
"output": "ring topology"
},
{
"input": "5 4\n4 2\n5 2\n1 2\n2 3",
"output": "star topology"
},
{
"input": "5 9\n5 3\n4 5\n3 1\n3 2\n2 1\n2 5\n1 5\n1 4\n4 2",
"output": "unknown topology"
},
{
"input": "4 3\n2 4\n1 3\n4 1",
"output": "bus topology"
},
{
"input": "4 4\n2 4\n4 1\n1 3\n2 3",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n2 4\n3 2",
"output": "star topology"
},
{
"input": "4 4\n3 2\n2 4\n4 1\n1 2",
"output": "unknown topology"
},
{
"input": "10 9\n10 6\n3 4\n8 9\n8 4\n6 1\n2 9\n5 1\n7 5\n10 3",
"output": "bus topology"
},
{
"input": "10 10\n1 4\n3 6\n10 7\n5 8\n2 10\n3 4\n7 5\n9 6\n8 1\n2 9",
"output": "ring topology"
},
{
"input": "10 9\n1 4\n4 10\n4 9\n8 4\n4 7\n4 5\n4 2\n4 6\n4 3",
"output": "star topology"
},
{
"input": "10 14\n3 2\n7 2\n6 4\n8 1\n3 9\n5 6\n6 3\n4 1\n2 5\n7 10\n9 5\n7 1\n8 10\n3 4",
"output": "unknown topology"
},
{
"input": "4 4\n1 2\n2 3\n2 4\n3 4",
"output": "unknown topology"
},
{
"input": "5 4\n1 2\n1 3\n1 4\n4 5",
"output": "unknown topology"
},
{
"input": "10 9\n10 1\n10 2\n10 3\n10 4\n10 5\n10 6\n10 7\n10 8\n10 9",
"output": "star topology"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 1",
"output": "unknown topology"
},
{
"input": "6 5\n1 2\n1 3\n1 4\n4 5\n4 6",
"output": "unknown topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 2",
"output": "unknown topology"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "unknown topology"
}
] | 1,612,355,930 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 1,808 | 14,848,000 | n,m = map(int, input().split())
db = [[0] for i in range(n)]
for i in range(m):
x,y = map(int, input().split())
db[x-1].append(y)
db[y-1].append(x)
db[x-1][0] += 1
db[y-1][0] += 1
one = 0
two = 0
mx = 0
for i in range(n):
if db[i][0] == 1:
one += 1
elif db[i][0] == 2:
two += 1
mx = max(mx,db[i][0])
if one == 2 and two == n-2:
print("bus topology")
elif two == n:
print("ring topology")
elif one == n-1 and mx == n-1:
print("star topology")
else:
print("unknown topology") | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them are connected by a cable. The computers are indexed by integers from 1 to *n*. It's known that any two computers connected by cable directly or through other computers
Polycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.
Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.
Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture.
You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown.
Input Specification:
The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*) — the numbers of nodes that are connected by the *i*-the edge.
It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself.
Output Specification:
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes).
Demo Input:
['4 3\n1 2\n2 3\n3 4\n', '4 4\n1 2\n2 3\n3 4\n4 1\n', '4 3\n1 2\n1 3\n1 4\n', '4 4\n1 2\n2 3\n3 1\n1 4\n']
Demo Output:
['bus topology\n', 'ring topology\n', 'star topology\n', 'unknown topology\n']
Note:
none | ```python
n,m = map(int, input().split())
db = [[0] for i in range(n)]
for i in range(m):
x,y = map(int, input().split())
db[x-1].append(y)
db[y-1].append(x)
db[x-1][0] += 1
db[y-1][0] += 1
one = 0
two = 0
mx = 0
for i in range(n):
if db[i][0] == 1:
one += 1
elif db[i][0] == 2:
two += 1
mx = max(mx,db[i][0])
if one == 2 and two == n-2:
print("bus topology")
elif two == n:
print("ring topology")
elif one == n-1 and mx == n-1:
print("star topology")
else:
print("unknown topology")
``` | 3 |
|
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,687,690,851 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 92 | 0 | s1 = input()
c = 1
for i in range(1, len(s1)-1):
if s1[i] == s1[i-1]:
c += 1
if c == 7:
print("YES\n")
exit(0)
else:
c = 1
print("NO\n")
| 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
s1 = input()
c = 1
for i in range(1, len(s1)-1):
if s1[i] == s1[i-1]:
c += 1
if c == 7:
print("YES\n")
exit(0)
else:
c = 1
print("NO\n")
``` | 0 |
899 | C | Dividing the numbers | PROGRAMMING | 1,300 | [
"constructive algorithms",
"graphs",
"math"
] | null | null | Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has. | Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them. | [
"4\n",
"2\n"
] | [
"0\n2 1 4 \n",
"1\n1 1 \n"
] | In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | 1,500 | [
{
"input": "4",
"output": "0\n2 1 4 "
},
{
"input": "2",
"output": "1\n1 1 "
},
{
"input": "3",
"output": "0\n1\n3 "
},
{
"input": "5",
"output": "1\n3\n1 2 5 "
},
{
"input": "59998",
"output": "1\n29999 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "60000",
"output": "0\n30000 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59991",
"output": "0\n29995\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 1..."
},
{
"input": "59989",
"output": "1\n29995\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 1..."
},
{
"input": "6",
"output": "1\n3 1 4 5 "
},
{
"input": "7",
"output": "0\n3\n1 6 7 "
},
{
"input": "8",
"output": "0\n4 1 4 5 8 "
},
{
"input": "9",
"output": "1\n5\n1 2 3 8 9 "
},
{
"input": "10",
"output": "1\n5 1 4 5 8 9 "
},
{
"input": "11",
"output": "0\n5\n1 2 9 10 11 "
},
{
"input": "12",
"output": "0\n6 1 4 5 8 9 12 "
},
{
"input": "13",
"output": "1\n7\n1 2 3 4 11 12 13 "
},
{
"input": "14",
"output": "1\n7 1 4 5 8 9 12 13 "
},
{
"input": "15",
"output": "0\n7\n1 2 3 12 13 14 15 "
},
{
"input": "16",
"output": "0\n8 1 4 5 8 9 12 13 16 "
},
{
"input": "17",
"output": "1\n9\n1 2 3 4 5 14 15 16 17 "
},
{
"input": "18",
"output": "1\n9 1 4 5 8 9 12 13 16 17 "
},
{
"input": "19",
"output": "0\n9\n1 2 3 4 15 16 17 18 19 "
},
{
"input": "20",
"output": "0\n10 1 4 5 8 9 12 13 16 17 20 "
},
{
"input": "21",
"output": "1\n11\n1 2 3 4 5 6 17 18 19 20 21 "
},
{
"input": "22",
"output": "1\n11 1 4 5 8 9 12 13 16 17 20 21 "
},
{
"input": "23",
"output": "0\n11\n1 2 3 4 5 18 19 20 21 22 23 "
},
{
"input": "24",
"output": "0\n12 1 4 5 8 9 12 13 16 17 20 21 24 "
},
{
"input": "59999",
"output": "0\n29999\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 1..."
},
{
"input": "59997",
"output": "1\n29999\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 1..."
},
{
"input": "59996",
"output": "0\n29998 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59995",
"output": "0\n29997\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 1..."
},
{
"input": "59994",
"output": "1\n29997 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59993",
"output": "1\n29997\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 1..."
},
{
"input": "59992",
"output": "0\n29996 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "59990",
"output": "1\n29995 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "100",
"output": "0\n50 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 "
},
{
"input": "1000",
"output": "0\n500 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "10001",
"output": "1\n5001\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 15..."
},
{
"input": "103",
"output": "0\n51\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 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 "
},
{
"input": "1002",
"output": "1\n501 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 28..."
},
{
"input": "31724",
"output": "0\n15862 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "2032",
"output": "0\n1016 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "42620",
"output": "0\n21310 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "18076",
"output": "0\n9038 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "53520",
"output": "0\n26760 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "37193",
"output": "1\n18597\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 1..."
},
{
"input": "12645",
"output": "1\n6323\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 15..."
},
{
"input": "53237",
"output": "1\n26619\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 1..."
},
{
"input": "28693",
"output": "1\n14347\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 1..."
},
{
"input": "4145",
"output": "1\n2073\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 15..."
},
{
"input": "36042",
"output": "1\n18021 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "16646",
"output": "1\n8323 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "57238",
"output": "1\n28619 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "27542",
"output": "1\n13771 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 ..."
},
{
"input": "8146",
"output": "1\n4073 1 4 5 8 9 12 13 16 17 20 21 24 25 28 29 32 33 36 37 40 41 44 45 48 49 52 53 56 57 60 61 64 65 68 69 72 73 76 77 80 81 84 85 88 89 92 93 96 97 100 101 104 105 108 109 112 113 116 117 120 121 124 125 128 129 132 133 136 137 140 141 144 145 148 149 152 153 156 157 160 161 164 165 168 169 172 173 176 177 180 181 184 185 188 189 192 193 196 197 200 201 204 205 208 209 212 213 216 217 220 221 224 225 228 229 232 233 236 237 240 241 244 245 248 249 252 253 256 257 260 261 264 265 268 269 272 273 276 277 2..."
},
{
"input": "46659",
"output": "0\n23329\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 1..."
},
{
"input": "27259",
"output": "0\n13629\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 1..."
},
{
"input": "2715",
"output": "0\n1357\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 15..."
},
{
"input": "38159",
"output": "0\n19079\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 1..."
},
{
"input": "18759",
"output": "0\n9379\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 15..."
}
] | 1,677,926,085 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | #899C
n=int(input())
a=0;b=0;l=[]
for i in range(n):
if a>b:
b+=i
l.append(i)
else:
a+=i
if n%2!=0:print(1)
else:print(abs(a-b))
print(len(l),*l)
| Title: Dividing the numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *n* integers: 1,<=2,<=3,<=...,<=*n*. He wants to split these integers in two non-empty groups in such a way that the absolute difference of sums of integers in each group is as small as possible.
Help Petya to split the integers. Each of *n* integers should be exactly in one group.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of integers Petya has.
Output Specification:
Print the smallest possible absolute difference in the first line.
In the second line print the size of the first group, followed by the integers in that group. You can print these integers in arbitrary order. If there are multiple answers, print any of them.
Demo Input:
['4\n', '2\n']
Demo Output:
['0\n2 1 4 \n', '1\n1 1 \n']
Note:
In the first example you have to put integers 1 and 4 in the first group, and 2 and 3 in the second. This way the sum in each group is 5, and the absolute difference is 0.
In the second example there are only two integers, and since both groups should be non-empty, you have to put one integer in the first group and one in the second. This way the absolute difference of sums of integers in each group is 1. | ```python
#899C
n=int(input())
a=0;b=0;l=[]
for i in range(n):
if a>b:
b+=i
l.append(i)
else:
a+=i
if n%2!=0:print(1)
else:print(abs(a-b))
print(len(l),*l)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.
After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!
She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.
Lexicographical order is defined in following way. When we compare *s* and *t*, first we find the leftmost position with differing characters: *s**i*<=≠<=*t**i*. If there is no such position (i. e. *s* is a prefix of *t* or vice versa) the shortest string is less. Otherwise, we compare characters *s**i* and *t**i* according to their order in alphabet. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100): number of names.
Each of the following *n* lines contain one string *name**i* (1<=≤<=|*name**i*|<=≤<=100), the *i*-th name. Each name contains only lowercase Latin letters. All names are different. | If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).
Otherwise output a single word "Impossible" (without quotes). | [
"3\nrivest\nshamir\nadleman\n",
"10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer\n",
"10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever\n",
"7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck\n"
] | [
"bcdefghijklmnopqrsatuvwxyz\n",
"Impossible\n",
"aghjlnopefikdmbcqrstuvwxyz\n",
"acbdefhijklmnogpqrstuvwxyz\n"
] | none | 0 | [
{
"input": "3\nrivest\nshamir\nadleman",
"output": "bcdefghijklmnopqrsatuvwxyz"
},
{
"input": "10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer",
"output": "Impossible"
},
{
"input": "10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever",
"output": "aghjlnopefikdmbcqrstuvwxyz"
},
{
"input": "7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck",
"output": "acbdefhijklmnogpqrstuvwxyz"
},
{
"input": "2\na\naa",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "6\nax\nay\nby\nbz\ncz\ncx",
"output": "Impossible"
},
{
"input": "4\nax\nay\nby\nbx",
"output": "Impossible"
},
{
"input": "4\nax\nay\nby\nbz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\na",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "1\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "2\naa\na",
"output": "Impossible"
},
{
"input": "5\naaaaa\naaaa\naaa\naa\na",
"output": "Impossible"
},
{
"input": "2\nanud\nanu",
"output": "Impossible"
},
{
"input": "8\nwa\nwb\nxc\nxd\nyb\nyc\nzd\nza",
"output": "Impossible"
}
] | 1,498,773,158 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 62 | 5,529,600 | a=int(input())
n=[]
pairs=[set() for i in range(26)]
for i in range(a):
n.append(input())
lets=set()
for i in n[::-1]:
lets.add(i[0])
for j in lets:
if j!=i[0]:
pairs[ord(i[0])-97].add(j)
for i in range(1,a):
x=n[i]
y=n[i-1]
if y not in x:
count=0
while x[count]==y[count]:
count+=1
pairs[ord(y[count])-97].add(x[count])
'''for i in range(26):
print(pairs[i],chr(i+97))'''
string=''
left=[]
for i in range(26):
if pairs[i]==set():
string+=chr(i+97)
else:
left.append(i)
for k in range(26):
for i in left:
if len(set(string)|pairs[i])==len(string):
left.pop(left.index(i))
string+=chr(i+97)
if left!=[]:
print('Impossible')
else:
print(string[::-1]) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order.
After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical!
She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order.
Lexicographical order is defined in following way. When we compare *s* and *t*, first we find the leftmost position with differing characters: *s**i*<=≠<=*t**i*. If there is no such position (i. e. *s* is a prefix of *t* or vice versa) the shortest string is less. Otherwise, we compare characters *s**i* and *t**i* according to their order in alphabet.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100): number of names.
Each of the following *n* lines contain one string *name**i* (1<=≤<=|*name**i*|<=≤<=100), the *i*-th name. Each name contains only lowercase Latin letters. All names are different.
Output Specification:
If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on).
Otherwise output a single word "Impossible" (without quotes).
Demo Input:
['3\nrivest\nshamir\nadleman\n', '10\ntourist\npetr\nwjmzbmr\nyeputons\nvepifanov\nscottwu\noooooooooooooooo\nsubscriber\nrowdark\ntankengineer\n', '10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever\n', '7\ncar\ncare\ncareful\ncarefully\nbecarefuldontforgetsomething\notherwiseyouwillbehacked\ngoodluck\n']
Demo Output:
['bcdefghijklmnopqrsatuvwxyz\n', 'Impossible\n', 'aghjlnopefikdmbcqrstuvwxyz\n', 'acbdefhijklmnogpqrstuvwxyz\n']
Note:
none | ```python
a=int(input())
n=[]
pairs=[set() for i in range(26)]
for i in range(a):
n.append(input())
lets=set()
for i in n[::-1]:
lets.add(i[0])
for j in lets:
if j!=i[0]:
pairs[ord(i[0])-97].add(j)
for i in range(1,a):
x=n[i]
y=n[i-1]
if y not in x:
count=0
while x[count]==y[count]:
count+=1
pairs[ord(y[count])-97].add(x[count])
'''for i in range(26):
print(pairs[i],chr(i+97))'''
string=''
left=[]
for i in range(26):
if pairs[i]==set():
string+=chr(i+97)
else:
left.append(i)
for k in range(26):
for i in left:
if len(set(string)|pairs[i])==len(string):
left.pop(left.index(i))
string+=chr(i+97)
if left!=[]:
print('Impossible')
else:
print(string[::-1])
``` | -1 |
|
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"
},
{
"input": "599 97 54 992",
"output": "YES"
},
{
"input": "11 22 18 17",
"output": "NO"
},
{
"input": "1 13 22 11",
"output": "NO"
},
{
"input": "1 1 1 1",
"output": "NO"
},
{
"input": "3 1 1 1",
"output": "YES"
},
{
"input": "1000 1000 1000 1000",
"output": "NO"
},
{
"input": "1000 1000 1 1",
"output": "YES"
},
{
"input": "1000 1000 1 400",
"output": "YES"
},
{
"input": "1000 1000 1 1000",
"output": "YES"
},
{
"input": "1000 1000 1 999",
"output": "YES"
},
{
"input": "53 11 3 166",
"output": "YES"
},
{
"input": "313 2 3 385",
"output": "NO"
},
{
"input": "214 9 9 412",
"output": "NO"
},
{
"input": "349 9 5 268",
"output": "YES"
},
{
"input": "611 16 8 153",
"output": "YES"
},
{
"input": "877 13 3 191",
"output": "YES"
},
{
"input": "340 9 9 10",
"output": "YES"
},
{
"input": "31 8 2 205",
"output": "NO"
},
{
"input": "519 3 2 148",
"output": "YES"
},
{
"input": "882 2 21 219",
"output": "NO"
},
{
"input": "982 13 5 198",
"output": "YES"
},
{
"input": "428 13 6 272",
"output": "YES"
},
{
"input": "436 16 14 26",
"output": "YES"
},
{
"input": "628 10 9 386",
"output": "YES"
},
{
"input": "77 33 18 31",
"output": "YES"
},
{
"input": "527 36 4 8",
"output": "YES"
},
{
"input": "128 18 2 169",
"output": "YES"
},
{
"input": "904 4 2 288",
"output": "YES"
},
{
"input": "986 4 3 25",
"output": "YES"
},
{
"input": "134 8 22 162",
"output": "NO"
},
{
"input": "942 42 3 69",
"output": "YES"
},
{
"input": "894 4 9 4",
"output": "YES"
},
{
"input": "953 8 10 312",
"output": "YES"
},
{
"input": "43 8 1 121",
"output": "YES"
},
{
"input": "12 13 19 273",
"output": "NO"
},
{
"input": "204 45 10 871",
"output": "YES"
},
{
"input": "342 69 50 425",
"output": "NO"
},
{
"input": "982 93 99 875",
"output": "NO"
},
{
"input": "283 21 39 132",
"output": "YES"
},
{
"input": "1000 45 83 686",
"output": "NO"
},
{
"input": "246 69 36 432",
"output": "NO"
},
{
"input": "607 93 76 689",
"output": "NO"
},
{
"input": "503 21 24 435",
"output": "NO"
},
{
"input": "1000 45 65 989",
"output": "NO"
},
{
"input": "30 21 2 250",
"output": "YES"
},
{
"input": "1000 49 50 995",
"output": "NO"
},
{
"input": "383 69 95 253",
"output": "YES"
},
{
"input": "393 98 35 999",
"output": "YES"
},
{
"input": "1000 22 79 552",
"output": "NO"
},
{
"input": "268 294 268 154",
"output": "NO"
},
{
"input": "963 465 706 146",
"output": "YES"
},
{
"input": "304 635 304 257",
"output": "NO"
},
{
"input": "4 2 1 6",
"output": "NO"
},
{
"input": "1 51 10 50",
"output": "NO"
},
{
"input": "5 5 4 4",
"output": "YES"
},
{
"input": "3 2 1 1",
"output": "YES"
},
{
"input": "3 4 3 3",
"output": "NO"
},
{
"input": "7 3 4 1",
"output": "YES"
},
{
"input": "101 10 1 1000",
"output": "NO"
},
{
"input": "5 1 1 1",
"output": "YES"
},
{
"input": "5 10 5 5",
"output": "NO"
},
{
"input": "19 1 7 1",
"output": "YES"
},
{
"input": "763 572 745 262",
"output": "YES"
},
{
"input": "1 2 1 1",
"output": "NO"
},
{
"input": "5 1 1 3",
"output": "YES"
},
{
"input": "170 725 479 359",
"output": "NO"
},
{
"input": "6 2 1 7",
"output": "YES"
},
{
"input": "6 2 5 1",
"output": "YES"
},
{
"input": "1 2 2 1",
"output": "NO"
},
{
"input": "24 2 8 3",
"output": "YES"
},
{
"input": "7 3 3 3",
"output": "YES"
},
{
"input": "5 2 2 2",
"output": "YES"
},
{
"input": "3 2 1 2",
"output": "YES"
},
{
"input": "1000 2 200 8",
"output": "NO"
},
{
"input": "3 100 2 100",
"output": "NO"
},
{
"input": "2 999 1 1000",
"output": "NO"
},
{
"input": "2 1 1 1",
"output": "NO"
},
{
"input": "2 3 5 1",
"output": "NO"
},
{
"input": "100 1 5 1",
"output": "YES"
},
{
"input": "7 2 3 3",
"output": "YES"
},
{
"input": "4 1 1 3",
"output": "NO"
},
{
"input": "3 2 2 1",
"output": "YES"
},
{
"input": "1 1 1 2",
"output": "NO"
},
{
"input": "91 8 7 13",
"output": "YES"
},
{
"input": "3 1 2 1",
"output": "NO"
},
{
"input": "5 3 2 3",
"output": "YES"
},
{
"input": "9 6 6 3",
"output": "YES"
}
] | 1,681,509,217 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import math
def should_build_second_oven(n, t, k, d):
single_oven_time= math.ceil(n / k )* t
double_oven_time= d + math.ceil((n -k)/ k )* t
return double_oven_time < single_oven_time
# Read input
n, t, k, d = map(int, input().split())
# Determine if it's reasonable to build the second oven
if should_build_second_oven(n, t, k, d):
print("YES")
else:
print("NO") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.
Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
Input Specification:
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
Output Specification:
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
Demo Input:
['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n']
Demo Output:
['YES\n', 'NO\n', 'NO\n', 'YES\n']
Note:
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.
In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven. | ```python
import math
def should_build_second_oven(n, t, k, d):
single_oven_time= math.ceil(n / k )* t
double_oven_time= d + math.ceil((n -k)/ k )* t
return double_oven_time < single_oven_time
# Read input
n, t, k, d = map(int, input().split())
# Determine if it's reasonable to build the second oven
if should_build_second_oven(n, t, k, d):
print("YES")
else:
print("NO")
``` | 0 |
|
234 | A | Lefthanders and Righthanders | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists. | The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander. | Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them. | [
"6\nLLRLLL\n",
"4\nRRLL\n"
] | [
"1 4\n2 5\n6 3\n",
"3 1\n4 2\n"
] | none | 0 | [
{
"input": "6\nLLRLLL",
"output": "1 4\n2 5\n6 3"
},
{
"input": "4\nRRLL",
"output": "3 1\n4 2"
},
{
"input": "4\nLLRR",
"output": "1 3\n2 4"
},
{
"input": "6\nRLLRRL",
"output": "1 4\n2 5\n3 6"
},
{
"input": "8\nLRLRLLLR",
"output": "1 5\n6 2\n3 7\n4 8"
},
{
"input": "10\nRLLRLRRRLL",
"output": "1 6\n2 7\n3 8\n9 4\n5 10"
},
{
"input": "12\nLRRRRRLRRRRL",
"output": "1 7\n2 8\n3 9\n4 10\n5 11\n12 6"
},
{
"input": "14\nRLLRLLLLRLLLRL",
"output": "8 1\n2 9\n3 10\n11 4\n5 12\n6 13\n7 14"
},
{
"input": "16\nLLLRRRLRRLLRRLLL",
"output": "1 9\n2 10\n3 11\n4 12\n5 13\n14 6\n7 15\n16 8"
},
{
"input": "18\nRRRLLLLRRRLRLRLLRL",
"output": "1 10\n11 2\n3 12\n4 13\n5 14\n6 15\n7 16\n8 17\n18 9"
},
{
"input": "20\nRLRLLRLRRLLRRRRRRLRL",
"output": "11 1\n2 12\n3 13\n4 14\n5 15\n6 16\n7 17\n18 8\n9 19\n10 20"
},
{
"input": "22\nRLLLRLLLRRLRRRLRLLLLLL",
"output": "1 12\n2 13\n3 14\n4 15\n5 16\n6 17\n7 18\n8 19\n20 9\n21 10\n11 22"
},
{
"input": "24\nLRRRLRLLRLRRRRLLLLRRLRLR",
"output": "1 13\n2 14\n15 3\n16 4\n5 17\n18 6\n7 19\n8 20\n21 9\n10 22\n23 11\n12 24"
},
{
"input": "26\nRLRRLLRRLLRLRRLLRLLRRLRLRR",
"output": "1 14\n2 15\n16 3\n4 17\n5 18\n6 19\n7 20\n8 21\n9 22\n10 23\n24 11\n12 25\n13 26"
},
{
"input": "28\nLLLRRRRRLRRLRRRLRLRLRRLRLRRL",
"output": "1 15\n2 16\n3 17\n18 4\n5 19\n20 6\n7 21\n8 22\n9 23\n10 24\n25 11\n12 26\n13 27\n28 14"
},
{
"input": "30\nLRLLRLRRLLRLRLLRRRRRLRLRLRLLLL",
"output": "1 16\n2 17\n3 18\n4 19\n5 20\n6 21\n7 22\n23 8\n9 24\n10 25\n11 26\n12 27\n28 13\n14 29\n15 30"
},
{
"input": "32\nRLRLLRRLLRRLRLLRLRLRLLRLRRRLLRRR",
"output": "17 1\n2 18\n19 3\n4 20\n5 21\n22 6\n7 23\n8 24\n9 25\n10 26\n11 27\n12 28\n29 13\n14 30\n15 31\n16 32"
},
{
"input": "34\nLRRLRLRLLRRRRLLRLRRLRRLRLRRLRRRLLR",
"output": "1 18\n2 19\n20 3\n4 21\n5 22\n6 23\n7 24\n8 25\n9 26\n10 27\n28 11\n12 29\n13 30\n14 31\n15 32\n33 16\n17 34"
},
{
"input": "36\nRRLLLRRRLLLRRLLLRRLLRLLRLRLLRLRLRLLL",
"output": "19 1\n20 2\n3 21\n4 22\n5 23\n6 24\n25 7\n8 26\n9 27\n10 28\n11 29\n30 12\n13 31\n14 32\n15 33\n16 34\n35 17\n36 18"
},
{
"input": "38\nLLRRRLLRRRLRRLRLRRLRRLRLRLLRRRRLLLLRLL",
"output": "1 20\n2 21\n22 3\n4 23\n24 5\n6 25\n7 26\n27 8\n9 28\n10 29\n11 30\n12 31\n32 13\n14 33\n34 15\n16 35\n17 36\n37 18\n19 38"
},
{
"input": "40\nLRRRRRLRLLRRRLLRRLRLLRLRRLRRLLLRRLRRRLLL",
"output": "1 21\n2 22\n23 3\n4 24\n5 25\n26 6\n7 27\n8 28\n9 29\n10 30\n31 11\n12 32\n13 33\n14 34\n15 35\n16 36\n17 37\n18 38\n39 19\n20 40"
},
{
"input": "42\nRLRRLLLLLLLRRRLRLLLRRRLRLLLRLRLRLLLRLRLRRR",
"output": "1 22\n2 23\n3 24\n25 4\n5 26\n6 27\n7 28\n8 29\n9 30\n10 31\n11 32\n33 12\n34 13\n35 14\n15 36\n37 16\n17 38\n18 39\n19 40\n20 41\n21 42"
},
{
"input": "44\nLLLLRRLLRRLLRRLRLLRRRLRLRLLRLRLRRLLRLRRLLLRR",
"output": "1 23\n2 24\n3 25\n4 26\n27 5\n6 28\n7 29\n8 30\n31 9\n10 32\n11 33\n12 34\n35 13\n14 36\n15 37\n16 38\n17 39\n18 40\n41 19\n42 20\n21 43\n22 44"
},
{
"input": "46\nRRRLLLLRRLRLRRRRRLRLLRLRRLRLLLLLLLLRRLRLRLRLLL",
"output": "1 24\n2 25\n26 3\n4 27\n5 28\n6 29\n7 30\n31 8\n32 9\n10 33\n34 11\n12 35\n13 36\n14 37\n38 15\n16 39\n40 17\n18 41\n42 19\n20 43\n21 44\n45 22\n23 46"
},
{
"input": "48\nLLLLRRLRRRRLRRRLRLLLLLRRLLRLLRLLRRLRRLLRLRLRRRRL",
"output": "1 25\n2 26\n3 27\n4 28\n29 5\n6 30\n7 31\n32 8\n9 33\n10 34\n35 11\n12 36\n13 37\n38 14\n39 15\n16 40\n41 17\n18 42\n19 43\n20 44\n21 45\n22 46\n23 47\n48 24"
},
{
"input": "50\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 26\n2 27\n3 28\n4 29\n5 30\n6 31\n7 32\n8 33\n9 34\n10 35\n11 36\n12 37\n13 38\n14 39\n15 40\n16 41\n17 42\n18 43\n19 44\n20 45\n21 46\n22 47\n23 48\n24 49\n25 50"
},
{
"input": "52\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 27\n2 28\n3 29\n4 30\n5 31\n6 32\n7 33\n8 34\n9 35\n10 36\n11 37\n12 38\n13 39\n14 40\n15 41\n16 42\n17 43\n18 44\n19 45\n20 46\n21 47\n22 48\n23 49\n24 50\n25 51\n26 52"
},
{
"input": "54\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 28\n2 29\n3 30\n4 31\n5 32\n6 33\n7 34\n8 35\n9 36\n10 37\n11 38\n12 39\n13 40\n14 41\n15 42\n16 43\n17 44\n18 45\n19 46\n20 47\n21 48\n22 49\n23 50\n24 51\n25 52\n26 53\n27 54"
},
{
"input": "56\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 29\n2 30\n3 31\n4 32\n5 33\n6 34\n7 35\n8 36\n9 37\n10 38\n11 39\n12 40\n13 41\n14 42\n15 43\n16 44\n17 45\n18 46\n19 47\n20 48\n21 49\n22 50\n23 51\n24 52\n25 53\n26 54\n27 55\n28 56"
},
{
"input": "58\nRRRLLLRLLLLRRLRRRLLRLLRLRLLRLRRRRLLLLLLRLRRLRLRRRLRLRRLRRL",
"output": "1 30\n2 31\n3 32\n4 33\n5 34\n6 35\n36 7\n8 37\n9 38\n10 39\n11 40\n41 12\n13 42\n14 43\n44 15\n16 45\n46 17\n18 47\n19 48\n20 49\n21 50\n22 51\n52 23\n24 53\n25 54\n26 55\n27 56\n28 57\n29 58"
},
{
"input": "60\nRLLLLRRLLRRRLLLLRRRRRLRRRLRRRLLLRLLLRLRRRLRLLLRLLRRLLRRRRRLL",
"output": "31 1\n2 32\n3 33\n4 34\n5 35\n36 6\n7 37\n8 38\n9 39\n10 40\n11 41\n42 12\n13 43\n14 44\n15 45\n16 46\n17 47\n48 18\n49 19\n20 50\n21 51\n22 52\n53 23\n24 54\n25 55\n26 56\n27 57\n28 58\n59 29\n30 60"
},
{
"input": "62\nLRRLRLRLLLLRRLLLLRRRLRLLLLRRRLLLLLLRRRLLLLRRLRRLRLLLLLLLLRRLRR",
"output": "1 32\n33 2\n34 3\n4 35\n5 36\n6 37\n7 38\n8 39\n9 40\n10 41\n11 42\n12 43\n13 44\n14 45\n15 46\n16 47\n17 48\n18 49\n50 19\n51 20\n21 52\n53 22\n23 54\n24 55\n25 56\n26 57\n27 58\n28 59\n60 29\n30 61\n31 62"
},
{
"input": "64\nRLLLLRRRLRLLRRRRLRLLLRRRLLLRRRLLRLLRLRLRRRLLRRRRLRLRRRLLLLRRLLLL",
"output": "1 33\n2 34\n3 35\n4 36\n5 37\n6 38\n39 7\n8 40\n9 41\n10 42\n11 43\n12 44\n13 45\n14 46\n15 47\n16 48\n17 49\n18 50\n19 51\n20 52\n21 53\n22 54\n55 23\n56 24\n25 57\n26 58\n27 59\n28 60\n61 29\n62 30\n31 63\n32 64"
},
{
"input": "66\nLLRRRLLRLRLLRRRRRRRLLLLRRLLLLLLRLLLRLLLLLLRRRLRRLLRRRRRLRLLRLLLLRR",
"output": "1 34\n2 35\n3 36\n37 4\n38 5\n6 39\n7 40\n41 8\n9 42\n10 43\n11 44\n12 45\n46 13\n14 47\n15 48\n49 16\n50 17\n18 51\n19 52\n20 53\n21 54\n22 55\n23 56\n24 57\n58 25\n26 59\n27 60\n28 61\n29 62\n30 63\n31 64\n32 65\n33 66"
},
{
"input": "68\nRRLRLRLLRLRLRRRRRRLRRRLLLLRLLRLRLRLRRRRLRLRLLRRRRLRRLLRLRRLLRLRRLRRL",
"output": "35 1\n2 36\n3 37\n4 38\n5 39\n40 6\n7 41\n8 42\n9 43\n10 44\n45 11\n12 46\n13 47\n14 48\n15 49\n50 16\n17 51\n18 52\n19 53\n54 20\n21 55\n56 22\n23 57\n24 58\n25 59\n26 60\n27 61\n28 62\n29 63\n30 64\n31 65\n32 66\n33 67\n68 34"
},
{
"input": "70\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 36\n2 37\n3 38\n4 39\n5 40\n6 41\n7 42\n8 43\n9 44\n10 45\n11 46\n12 47\n13 48\n14 49\n15 50\n16 51\n17 52\n18 53\n19 54\n20 55\n21 56\n22 57\n23 58\n24 59\n25 60\n26 61\n27 62\n28 63\n29 64\n30 65\n31 66\n32 67\n33 68\n34 69\n35 70"
},
{
"input": "72\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 37\n2 38\n3 39\n4 40\n5 41\n6 42\n7 43\n8 44\n9 45\n10 46\n11 47\n12 48\n13 49\n14 50\n15 51\n16 52\n17 53\n18 54\n19 55\n20 56\n21 57\n22 58\n23 59\n24 60\n25 61\n26 62\n27 63\n28 64\n29 65\n30 66\n31 67\n32 68\n33 69\n34 70\n35 71\n36 72"
},
{
"input": "74\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 38\n2 39\n3 40\n4 41\n5 42\n6 43\n7 44\n8 45\n9 46\n10 47\n11 48\n12 49\n13 50\n14 51\n15 52\n16 53\n17 54\n18 55\n19 56\n20 57\n21 58\n22 59\n23 60\n24 61\n25 62\n26 63\n27 64\n28 65\n29 66\n30 67\n31 68\n32 69\n33 70\n34 71\n35 72\n36 73\n37 74"
},
{
"input": "76\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 39\n2 40\n3 41\n4 42\n5 43\n6 44\n7 45\n8 46\n9 47\n10 48\n11 49\n12 50\n13 51\n14 52\n15 53\n16 54\n17 55\n18 56\n19 57\n20 58\n21 59\n22 60\n23 61\n24 62\n25 63\n26 64\n27 65\n28 66\n29 67\n30 68\n31 69\n32 70\n33 71\n34 72\n35 73\n36 74\n37 75\n38 76"
},
{
"input": "78\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"output": "1 40\n2 41\n3 42\n4 43\n5 44\n6 45\n7 46\n8 47\n9 48\n10 49\n11 50\n12 51\n13 52\n14 53\n15 54\n16 55\n17 56\n18 57\n19 58\n20 59\n21 60\n22 61\n23 62\n24 63\n25 64\n26 65\n27 66\n28 67\n29 68\n30 69\n31 70\n32 71\n33 72\n34 73\n35 74\n36 75\n37 76\n38 77\n39 78"
},
{
"input": "80\nLRLRRRRLRRRRLLLLRLLRLRLLRRLRLLLRRLLLLRLLLRLRLLRRRLRRRLRLRRRRRLRLLRLLRRLLLRLRRRLL",
"output": "1 41\n2 42\n3 43\n4 44\n45 5\n46 6\n7 47\n8 48\n9 49\n50 10\n11 51\n12 52\n13 53\n14 54\n15 55\n16 56\n17 57\n18 58\n19 59\n20 60\n21 61\n62 22\n23 63\n24 64\n65 25\n26 66\n27 67\n68 28\n29 69\n30 70\n31 71\n72 32\n73 33\n34 74\n35 75\n36 76\n37 77\n38 78\n39 79\n40 80"
},
{
"input": "82\nRLRRLLRLRLRLLLRLLLRRLLRRLRRRRLLRLLLLRRRRRLLLRRRLLLLRLRRLRRRLRLLLLRRRLRLRLLLRLLLLLR",
"output": "42 1\n2 43\n44 3\n4 45\n5 46\n6 47\n48 7\n8 49\n50 9\n10 51\n11 52\n12 53\n13 54\n14 55\n56 15\n16 57\n17 58\n18 59\n60 19\n20 61\n21 62\n22 63\n64 23\n65 24\n25 66\n26 67\n27 68\n69 28\n29 70\n30 71\n31 72\n73 32\n33 74\n34 75\n35 76\n36 77\n78 37\n79 38\n80 39\n81 40\n41 82"
},
{
"input": "84\nLRLRRRRRRLLLRLRLLLLLRRLRLRLRRRLLRLLLRLRLLLRRRLRLRRLRLRLLLLLLLLRRRRRRLLLRRLRLRLLLRLRR",
"output": "1 43\n2 44\n3 45\n46 4\n5 47\n48 6\n7 49\n8 50\n51 9\n10 52\n11 53\n12 54\n55 13\n14 56\n57 15\n16 58\n17 59\n18 60\n19 61\n20 62\n21 63\n22 64\n23 65\n24 66\n25 67\n26 68\n27 69\n70 28\n71 29\n30 72\n31 73\n32 74\n33 75\n34 76\n35 77\n36 78\n79 37\n38 80\n39 81\n40 82\n41 83\n42 84"
},
{
"input": "86\nRRRLLLRLLRLLRLRLRLLLRLRLRRLLRLLLRLLLLLLRRRLRLLRLLLRRRLRLLLLRLLRLRRLLRLLLRRRLLRLRLLRLLR",
"output": "1 44\n45 2\n46 3\n4 47\n5 48\n6 49\n50 7\n8 51\n9 52\n10 53\n11 54\n12 55\n56 13\n14 57\n58 15\n16 59\n17 60\n18 61\n19 62\n20 63\n64 21\n22 65\n23 66\n24 67\n68 25\n26 69\n27 70\n28 71\n72 29\n30 73\n31 74\n32 75\n76 33\n34 77\n35 78\n36 79\n37 80\n38 81\n39 82\n40 83\n84 41\n85 42\n43 86"
},
{
"input": "88\nLLRLRLRLLLLRRRRRRLRRLLLLLRRLRRLLLLLRLRLRLLLLLRLRLRRLRLRRLRLLRRLRLLLRLLLLRRLLRRLRLRLRRLRR",
"output": "1 45\n2 46\n47 3\n4 48\n49 5\n6 50\n7 51\n8 52\n9 53\n10 54\n11 55\n12 56\n57 13\n14 58\n59 15\n60 16\n17 61\n18 62\n63 19\n20 64\n21 65\n22 66\n23 67\n24 68\n25 69\n70 26\n71 27\n28 72\n29 73\n30 74\n31 75\n32 76\n33 77\n34 78\n35 79\n36 80\n37 81\n38 82\n39 83\n40 84\n41 85\n42 86\n43 87\n44 88"
},
{
"input": "90\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 46\n2 47\n3 48\n4 49\n5 50\n6 51\n7 52\n8 53\n9 54\n10 55\n11 56\n12 57\n13 58\n14 59\n15 60\n16 61\n17 62\n18 63\n19 64\n20 65\n21 66\n22 67\n23 68\n24 69\n25 70\n26 71\n27 72\n28 73\n29 74\n30 75\n31 76\n32 77\n33 78\n34 79\n35 80\n36 81\n37 82\n38 83\n39 84\n40 85\n41 86\n42 87\n43 88\n44 89\n45 90"
},
{
"input": "92\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 47\n2 48\n3 49\n4 50\n5 51\n6 52\n7 53\n8 54\n9 55\n10 56\n11 57\n12 58\n13 59\n14 60\n15 61\n16 62\n17 63\n18 64\n19 65\n20 66\n21 67\n22 68\n23 69\n24 70\n25 71\n26 72\n27 73\n28 74\n29 75\n30 76\n31 77\n32 78\n33 79\n34 80\n35 81\n36 82\n37 83\n38 84\n39 85\n40 86\n41 87\n42 88\n43 89\n44 90\n45 91\n46 92"
},
{
"input": "94\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 48\n2 49\n3 50\n4 51\n5 52\n6 53\n7 54\n8 55\n9 56\n10 57\n11 58\n12 59\n13 60\n14 61\n15 62\n16 63\n17 64\n18 65\n19 66\n20 67\n21 68\n22 69\n23 70\n24 71\n25 72\n26 73\n27 74\n28 75\n29 76\n30 77\n31 78\n32 79\n33 80\n34 81\n35 82\n36 83\n37 84\n38 85\n39 86\n40 87\n41 88\n42 89\n43 90\n44 91\n45 92\n46 93\n47 94"
},
{
"input": "96\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 49\n2 50\n3 51\n4 52\n5 53\n6 54\n7 55\n8 56\n9 57\n10 58\n11 59\n12 60\n13 61\n14 62\n15 63\n16 64\n17 65\n18 66\n19 67\n20 68\n21 69\n22 70\n23 71\n24 72\n25 73\n26 74\n27 75\n28 76\n29 77\n30 78\n31 79\n32 80\n33 81\n34 82\n35 83\n36 84\n37 85\n38 86\n39 87\n40 88\n41 89\n42 90\n43 91\n44 92\n45 93\n46 94\n47 95\n48 96"
},
{
"input": "98\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL",
"output": "1 50\n2 51\n3 52\n4 53\n5 54\n6 55\n7 56\n8 57\n9 58\n10 59\n11 60\n12 61\n13 62\n14 63\n15 64\n16 65\n17 66\n18 67\n19 68\n20 69\n21 70\n22 71\n23 72\n24 73\n25 74\n26 75\n27 76\n28 77\n29 78\n30 79\n31 80\n32 81\n33 82\n34 83\n35 84\n36 85\n37 86\n38 87\n39 88\n40 89\n41 90\n42 91\n43 92\n44 93\n45 94\n46 95\n47 96\n48 97\n49 98"
},
{
"input": "100\nRLRRRRLLLLRRRRLRRRRRRRRLRLRRLLRRRRRRRRLRRRRLLLLRRRRLRRLRLRRRLLRRLRRLLLRLRRLLLLLLRLRLRLRRLRLRLRRRLLLR",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n14 64\n15 65\n16 66\n17 67\n68 18\n69 19\n70 20\n21 71\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n78 28\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n86 36\n37 87\n38 88\n39 89\n40 90\n91 41\n42 92\n93 43\n44 94\n45 95\n46 96\n47 97\n98 48\n99 49\n50 100"
},
{
"input": "100\nLRLLLLRLLLLRRRRRLRRRRLRRLRRLRLLRRLRRRRLLRRRLLLRLLLRRRRLLRLRLRRLRLLRRLLRRLRRLRRRRRLRRLRLRLRLLLLLLLLRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n6 56\n7 57\n8 58\n9 59\n10 60\n11 61\n12 62\n63 13\n14 64\n65 15\n66 16\n17 67\n18 68\n69 19\n70 20\n21 71\n22 72\n73 23\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n91 41\n92 42\n93 43\n44 94\n45 95\n46 96\n97 47\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLLRRLLRLRLLLRLLLRLRLLRRRLRRLLLRLRLRRLLRLRRRLLLRRLLRLLRRLLRRRRRLRLRRLRLRRLRLRRLLRLRLLRLLLRLLRLLLLRLL",
"output": "1 51\n2 52\n3 53\n54 4\n5 55\n6 56\n7 57\n58 8\n9 59\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n74 24\n25 75\n26 76\n27 77\n28 78\n29 79\n30 80\n31 81\n82 32\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n99 49\n50 100"
},
{
"input": "100\nRLLLLRRLLLLRRRRLLRLRRRLLLRLLRLLLLLRRLLLLLLRRLRRRRRLRLLRLRRRLLLRLRLRLLLRRRLLLLLRRRRRLRRLLLLRLLLRRLLLL",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n11 61\n62 12\n13 63\n64 14\n15 65\n16 66\n17 67\n68 18\n19 69\n70 20\n21 71\n22 72\n23 73\n24 74\n25 75\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n93 43\n94 44\n45 95\n46 96\n97 47\n98 48\n99 49\n100 50"
},
{
"input": "100\nRLRRLRLRRLRLLRLLRRRLRRLLLLLRLRLRRRRRRRLLRRRLLRLRLLLRRRLLRRRLLRLRLLLLRRLRLLRLLRLLLLRRLRLRRLRLLLLRLRRR",
"output": "51 1\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n23 73\n24 74\n25 75\n26 76\n27 77\n28 78\n29 79\n80 30\n31 81\n82 32\n33 83\n34 84\n85 35\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n92 42\n93 43\n44 94\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLRRLRLRRRRRRLRRLRRLLLLLLRRLLRRLLRLLLLLLRRRLLRLRRRLLRLLRRLRRRLLRLRLLRRLRRRLLLRRRRLLRRRLLLRRRRRLLLLLLR",
"output": "1 51\n2 52\n53 3\n4 54\n5 55\n6 56\n57 7\n8 58\n9 59\n10 60\n61 11\n62 12\n13 63\n64 14\n15 65\n16 66\n67 17\n18 68\n19 69\n20 70\n21 71\n22 72\n23 73\n24 74\n75 25\n76 26\n27 77\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n99 49\n50 100"
},
{
"input": "100\nRRLRRLRLRLRRRRLLRRLLRLRRLLRRRLLRLRRLRLRRLLLRRLLRRRRRRLLLRRRLLRRLLLLLLRLLLLLLRLLLRRRLRLLRRRRRLLRLLRRR",
"output": "1 51\n2 52\n3 53\n54 4\n55 5\n6 56\n7 57\n8 58\n9 59\n10 60\n61 11\n12 62\n13 63\n64 14\n15 65\n16 66\n67 17\n68 18\n19 69\n20 70\n71 21\n22 72\n73 23\n74 24\n25 75\n26 76\n27 77\n78 28\n79 29\n30 80\n31 81\n32 82\n33 83\n84 34\n35 85\n36 86\n87 37\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n94 44\n45 95\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nRRLLLRLRRLRLLRRLRRRLLRRRLRRLLLLLLLLLRRRLLRLRRLRRLRRLRRLRLLLLRLLRRRLLLLRLRRRLLRRRRLRRLLRRRRLRRRLRLLLR",
"output": "1 51\n52 2\n3 53\n4 54\n5 55\n6 56\n7 57\n58 8\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n67 17\n68 18\n69 19\n20 70\n21 71\n72 22\n23 73\n24 74\n25 75\n76 26\n77 27\n28 78\n29 79\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n40 90\n41 91\n42 92\n43 93\n44 94\n95 45\n46 96\n97 47\n98 48\n49 99\n50 100"
},
{
"input": "100\nLLLLLRRLRRRRRRRLLRRRRRLRRLRLRLLRLRRLLLRRRRLLRRLRLLRLLLRLRLLRRRRRRRRRLRLLLRLRLLLLLRLRRRRLRLLRLRLRLRRL",
"output": "1 51\n2 52\n3 53\n4 54\n5 55\n56 6\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n14 64\n15 65\n16 66\n17 67\n18 68\n69 19\n20 70\n71 21\n72 22\n23 73\n24 74\n75 25\n26 76\n77 27\n28 78\n79 29\n30 80\n31 81\n32 82\n33 83\n34 84\n35 85\n36 86\n37 87\n38 88\n39 89\n90 40\n91 41\n42 92\n43 93\n44 94\n95 45\n46 96\n47 97\n48 98\n49 99\n50 100"
},
{
"input": "100\nLLRRRLLLRLLLLRLRLRLRRRLLLRRRLRLLRLLLRRRRRLRRLRRLRRRLRRLRRLLLRLRLLRRRRLRLRRRRRLRRLRLLRRRRLLLRRRRRLLLL",
"output": "1 51\n2 52\n3 53\n4 54\n55 5\n6 56\n7 57\n8 58\n59 9\n10 60\n11 61\n12 62\n13 63\n64 14\n15 65\n16 66\n17 67\n18 68\n19 69\n70 20\n21 71\n72 22\n23 73\n24 74\n25 75\n26 76\n27 77\n78 28\n29 79\n30 80\n31 81\n32 82\n83 33\n34 84\n35 85\n36 86\n37 87\n38 88\n89 39\n90 40\n91 41\n42 92\n43 93\n44 94\n45 95\n46 96\n97 47\n48 98\n99 49\n100 50"
}
] | 1,621,902,864 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import random
s = int(input())
s_list = [num for num in range(3, s)]
count = 0
for num in s_list:
| Title: Lefthanders and Righthanders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*.
But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.
On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.
Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.
Input Specification:
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Output Specification:
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.
Demo Input:
['6\nLLRLLL\n', '4\nRRLL\n']
Demo Output:
['1 4\n2 5\n6 3\n', '3 1\n4 2\n']
Note:
none | ```python
import random
s = int(input())
s_list = [num for num in range(3, s)]
count = 0
for num in s_list:
``` | -1 |
|
354 | C | Vasya and Beautiful Arrays | PROGRAMMING | 2,100 | [
"brute force",
"dp",
"number theory"
] | null | null | Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array *a* left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by *k* for each number).
The seller can obtain array *b* from array *a* if the following conditions hold: *b**i*<=><=0; 0<=≤<=*a**i*<=-<=*b**i*<=≤<=*k* for all 1<=≤<=*i*<=≤<=*n*.
Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105;<=1<=≤<=*k*<=≤<=106). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — array *a*. | In the single line print a single number — the maximum possible beauty of the resulting array. | [
"6 1\n3 6 10 12 13 16\n",
"5 3\n8 21 52 15 77\n"
] | [
"3\n",
"7\n"
] | In the first sample we can obtain the array:
3 6 9 12 12 15
In the second sample we can obtain the next array:
7 21 49 14 77 | 1,500 | [
{
"input": "6 1\n3 6 10 12 13 16",
"output": "3"
},
{
"input": "5 3\n8 21 52 15 77",
"output": "7"
},
{
"input": "13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58",
"output": "16"
},
{
"input": "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68",
"output": "13"
},
{
"input": "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64",
"output": "16"
},
{
"input": "7 1\n12 84 21 60 33 21 45",
"output": "4"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "10 10\n40141 53368 66538 64507 78114 34253 73242 42141 37430 6",
"output": "6"
},
{
"input": "10 7\n869 1293 12421 1 90901 120214 12403 6543 591870 124",
"output": "1"
},
{
"input": "2 84794\n1000000 1000000",
"output": "1000000"
}
] | 1,503,802,883 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 358 | 21,606,400 | n, k = map(int, input().split())
t = set(map(int, input().split()))
y = x = min(t)
t = list(t)
while True:
for i in t:
if i % x > k: x = i // (i // x + 1)
if y == x: break
y = x
print(y)
| Title: Vasya and Beautiful Arrays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*.
Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array *a* left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by *k* for each number).
The seller can obtain array *b* from array *a* if the following conditions hold: *b**i*<=><=0; 0<=≤<=*a**i*<=-<=*b**i*<=≤<=*k* for all 1<=≤<=*i*<=≤<=*n*.
Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain).
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105;<=1<=≤<=*k*<=≤<=106). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — array *a*.
Output Specification:
In the single line print a single number — the maximum possible beauty of the resulting array.
Demo Input:
['6 1\n3 6 10 12 13 16\n', '5 3\n8 21 52 15 77\n']
Demo Output:
['3\n', '7\n']
Note:
In the first sample we can obtain the array:
3 6 9 12 12 15
In the second sample we can obtain the next array:
7 21 49 14 77 | ```python
n, k = map(int, input().split())
t = set(map(int, input().split()))
y = x = min(t)
t = list(t)
while True:
for i in t:
if i % x > k: x = i // (i // x + 1)
if y == x: break
y = x
print(y)
``` | 3 |
|
492 | B | Vanya and Lanterns | PROGRAMMING | 1,200 | [
"binary search",
"implementation",
"math",
"sortings"
] | null | null | Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street? | The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street. | Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9. | [
"7 15\n15 5 3 7 9 14 0\n",
"2 5\n2 5\n"
] | [
"2.5000000000\n",
"2.0000000000\n"
] | Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | 1,000 | [
{
"input": "7 15\n15 5 3 7 9 14 0",
"output": "2.5000000000"
},
{
"input": "2 5\n2 5",
"output": "2.0000000000"
},
{
"input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 173675329 473068378 356306865 311731938 192959832 321180686 141984626 578985584 512026637 175885185 590844074 47103801 212211134 330150 509886963 565955809 315640375 612907074 500474373 524310737 568681652 315339618 478782781 518873818 271322031 74600969 539099112 85129347 222068995 106014720 77282307",
"output": "22258199.5000000000"
},
{
"input": "2 1000000000\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "2 555\n200 300",
"output": "255.0000000000"
},
{
"input": "1 1\n1",
"output": "1.0000000000"
},
{
"input": "1 1\n0",
"output": "1.0000000000"
},
{
"input": "1 1000000000\n0",
"output": "1000000000.0000000000"
},
{
"input": "1 1000000000\n1000000000",
"output": "1000000000.0000000000"
},
{
"input": "1 999999999\n499999999",
"output": "500000000.0000000000"
},
{
"input": "4 700\n0 250 475 700",
"output": "125.0000000000"
},
{
"input": "4 700\n0 225 450 700",
"output": "125.0000000000"
},
{
"input": "5 1000\n0 250 500 750 1000",
"output": "125.0000000000"
},
{
"input": "5 2000\n1001 1001 1001 1001 1001",
"output": "1001.0000000000"
},
{
"input": "1 999\n501",
"output": "501.0000000000"
},
{
"input": "2 1000\n400 600",
"output": "400.0000000000"
},
{
"input": "4 15\n1 3 9 11",
"output": "4.0000000000"
},
{
"input": "1 5\n2",
"output": "3.0000000000"
}
] | 1,696,655,660 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 31 | 0 | import sys
import math
def min_light_radius(n, l, lanterns):
lanterns.sort()
max_distance = 0
for i in range(n - 1):
max_distance = max(max_distance, lanterns[i + 1] - lanterns[i])
max_distance /= 2 # Divide by 2 to get the radius
# Check the distance from the first lantern to the beginning of the street
max_distance = max(max_distance, lanterns[0])
# Check the distance from the last lantern to the end of the street
max_distance = max(max_distance, l - lanterns[-1])
return max_distance
n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
result = min_light_radius(n, l, lanterns)
print("{:.10f}".format(result))
| Title: Vanya and Lanterns
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that are at the distance of at most *d* from it, where *d* is some positive number, common for all lanterns.
Vanya wonders: what is the minimum light radius *d* should the lanterns have to light the whole street?
Input Specification:
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively.
The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.
Output Specification:
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
Demo Input:
['7 15\n15 5 3 7 9 14 0\n', '2 5\n2 5\n']
Demo Output:
['2.5000000000\n', '2.0000000000\n']
Note:
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit. | ```python
import sys
import math
def min_light_radius(n, l, lanterns):
lanterns.sort()
max_distance = 0
for i in range(n - 1):
max_distance = max(max_distance, lanterns[i + 1] - lanterns[i])
max_distance /= 2 # Divide by 2 to get the radius
# Check the distance from the first lantern to the beginning of the street
max_distance = max(max_distance, lanterns[0])
# Check the distance from the last lantern to the end of the street
max_distance = max(max_distance, l - lanterns[-1])
return max_distance
n, l = map(int, input().split())
lanterns = list(map(int, input().split()))
result = min_light_radius(n, l, lanterns)
print("{:.10f}".format(result))
``` | 3 |
|
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form. | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "/a//aa/a//",
"output": "/a/aa/a"
},
{
"input": "/aa//b/aa",
"output": "/aa/b/aa"
},
{
"input": "////////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/"
},
{
"input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/",
"output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb"
},
{
"input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test"
},
{
"input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt",
"output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt"
},
{
"input": "///a//a////a/a//a//a//a/////",
"output": "/a/a/a/a/a/a/a"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/",
"output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
},
{
"input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a",
"output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a"
},
{
"input": "///////////////////////////////////////////////////////////////////////////////////////////////////z",
"output": "/z"
},
{
"input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////",
"output": "/z"
}
] | 1,642,074,660 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | a=input("Enter the directory")
b=[]
count=0
for i in a:
b.append(i)
for j in range(len(b)):
if (b[j]=="\\"):
count+=1
if count==2:
b.pop(j)
for k in b:
print(k,end="")
| Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'.
A path called normalized if it contains the smallest possible number of characters '/'.
Your task is to transform a given path to the normalized form.
Input Specification:
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
Output Specification:
The path in normalized form.
Demo Input:
['//usr///local//nginx/sbin\n']
Demo Output:
['/usr/local/nginx/sbin\n']
Note:
none | ```python
a=input("Enter the directory")
b=[]
count=0
for i in a:
b.append(i)
for j in range(len(b)):
if (b[j]=="\\"):
count+=1
if count==2:
b.pop(j)
for k in b:
print(k,end="")
``` | 0 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
{
"input": "2 7\n1 1",
"output": "1"
},
{
"input": "3 3\n18 1 9",
"output": "10"
},
{
"input": "3 3\n15 17 9",
"output": "3"
},
{
"input": "3 3\n10 9 12",
"output": "2"
},
{
"input": "10 3\n2 1 17 10 5 16 8 4 15 17",
"output": "31"
},
{
"input": "10 3\n6 11 4 12 22 15 23 26 24 26",
"output": "13"
},
{
"input": "10 3\n10 24 13 15 18 14 15 26 33 35",
"output": "29"
},
{
"input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580",
"output": "15717"
},
{
"input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327",
"output": "16133"
}
] | 1,653,575,467 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n, d = input().split()
number_input = input().split()[:int(n)]
s = 0
for i in number_input:
s+=int(i)
print(int(int(s) / (int(d) + 1)))
| Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
Input Specification:
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output Specification:
Output the minimal number of moves needed to make the sequence increasing.
Demo Input:
['4 2\n1 3 3 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n, d = input().split()
number_input = input().split()[:int(n)]
s = 0
for i in number_input:
s+=int(i)
print(int(int(s) / (int(d) + 1)))
``` | 0 |
997 | A | Convert to Ones | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones? | The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones. | Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. | [
"5 1 10\n01000\n",
"5 10 1\n01000\n",
"7 2 3\n1111111\n"
] | [
"11\n",
"2\n",
"0\n"
] | In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | 500 | [
{
"input": "5 1 10\n01000",
"output": "11"
},
{
"input": "5 10 1\n01000",
"output": "2"
},
{
"input": "7 2 3\n1111111",
"output": "0"
},
{
"input": "1 60754033 959739508\n0",
"output": "959739508"
},
{
"input": "1 431963980 493041212\n1",
"output": "0"
},
{
"input": "1 314253869 261764879\n0",
"output": "261764879"
},
{
"input": "1 491511050 399084767\n1",
"output": "0"
},
{
"input": "2 163093925 214567542\n00",
"output": "214567542"
},
{
"input": "2 340351106 646854722\n10",
"output": "646854722"
},
{
"input": "2 222640995 489207317\n01",
"output": "489207317"
},
{
"input": "2 399898176 552898277\n11",
"output": "0"
},
{
"input": "2 690218164 577155357\n00",
"output": "577155357"
},
{
"input": "2 827538051 754412538\n10",
"output": "754412538"
},
{
"input": "2 636702427 259825230\n01",
"output": "259825230"
},
{
"input": "2 108926899 102177825\n11",
"output": "0"
},
{
"input": "3 368381052 440077270\n000",
"output": "440077270"
},
{
"input": "3 505700940 617334451\n100",
"output": "617334451"
},
{
"input": "3 499624340 643020827\n010",
"output": "1142645167"
},
{
"input": "3 75308005 971848814\n110",
"output": "971848814"
},
{
"input": "3 212627893 854138703\n001",
"output": "854138703"
},
{
"input": "3 31395883 981351561\n101",
"output": "981351561"
},
{
"input": "3 118671447 913685773\n011",
"output": "913685773"
},
{
"input": "3 255991335 385910245\n111",
"output": "0"
},
{
"input": "3 688278514 268200134\n000",
"output": "268200134"
},
{
"input": "3 825598402 445457315\n100",
"output": "445457315"
},
{
"input": "3 300751942 45676507\n010",
"output": "91353014"
},
{
"input": "3 517900980 438071829\n110",
"output": "438071829"
},
{
"input": "3 400190869 280424424\n001",
"output": "280424424"
},
{
"input": "3 577448050 344115384\n101",
"output": "344115384"
},
{
"input": "3 481435271 459737939\n011",
"output": "459737939"
},
{
"input": "3 931962412 913722450\n111",
"output": "0"
},
{
"input": "4 522194562 717060616\n0000",
"output": "717060616"
},
{
"input": "4 659514449 894317797\n1000",
"output": "894317797"
},
{
"input": "4 71574977 796834337\n0100",
"output": "868409314"
},
{
"input": "4 248832158 934154224\n1100",
"output": "934154224"
},
{
"input": "4 71474110 131122047\n0010",
"output": "202596157"
},
{
"input": "4 308379228 503761290\n1010",
"output": "812140518"
},
{
"input": "4 272484957 485636409\n0110",
"output": "758121366"
},
{
"input": "4 662893590 704772137\n1110",
"output": "704772137"
},
{
"input": "4 545183479 547124732\n0001",
"output": "547124732"
},
{
"input": "4 684444619 722440661\n1001",
"output": "722440661"
},
{
"input": "4 477963686 636258459\n0101",
"output": "1114222145"
},
{
"input": "4 360253575 773578347\n1101",
"output": "773578347"
},
{
"input": "4 832478048 910898234\n0011",
"output": "910898234"
},
{
"input": "4 343185412 714767937\n1011",
"output": "714767937"
},
{
"input": "4 480505300 892025118\n0111",
"output": "892025118"
},
{
"input": "4 322857895 774315007\n1111",
"output": "0"
},
{
"input": "4 386548854 246539479\n0000",
"output": "246539479"
},
{
"input": "4 523868742 128829368\n1000",
"output": "128829368"
},
{
"input": "4 956155921 11119257\n0100",
"output": "22238514"
},
{
"input": "4 188376438 93475808\n1100",
"output": "93475808"
},
{
"input": "4 754947032 158668188\n0010",
"output": "317336376"
},
{
"input": "4 927391856 637236921\n1010",
"output": "1274473842"
},
{
"input": "4 359679035 109461393\n0110",
"output": "218922786"
},
{
"input": "4 991751283 202031630\n1110",
"output": "202031630"
},
{
"input": "4 339351517 169008463\n0001",
"output": "169008463"
},
{
"input": "4 771638697 346265644\n1001",
"output": "346265644"
},
{
"input": "4 908958584 523522825\n0101",
"output": "1047045650"
},
{
"input": "4 677682252 405812714\n1101",
"output": "405812714"
},
{
"input": "4 815002139 288102603\n0011",
"output": "288102603"
},
{
"input": "4 952322026 760327076\n1011",
"output": "760327076"
},
{
"input": "4 663334158 312481698\n0111",
"output": "312481698"
},
{
"input": "4 840591339 154834293\n1111",
"output": "0"
},
{
"input": "14 3 11\n10110100011001",
"output": "20"
},
{
"input": "19 1 1\n1010101010101010101",
"output": "9"
},
{
"input": "1 10 1\n1",
"output": "0"
},
{
"input": "1 100 1\n1",
"output": "0"
},
{
"input": "5 1000 1\n11111",
"output": "0"
},
{
"input": "5 10 1\n11111",
"output": "0"
},
{
"input": "7 3 2\n1111111",
"output": "0"
},
{
"input": "5 1 10\n10101",
"output": "11"
},
{
"input": "1 3 2\n1",
"output": "0"
},
{
"input": "2 10 1\n11",
"output": "0"
},
{
"input": "4 148823922 302792601\n1010",
"output": "451616523"
},
{
"input": "1 2 1\n1",
"output": "0"
},
{
"input": "5 2 3\n00011",
"output": "3"
},
{
"input": "1 5 0\n1",
"output": "0"
},
{
"input": "7 2 3\n1001001",
"output": "5"
},
{
"input": "10 1 1000000000\n1111010111",
"output": "1000000001"
},
{
"input": "25 999999998 999999999\n1011001110101010100111001",
"output": "7999999985"
},
{
"input": "2 0 1\n00",
"output": "1"
},
{
"input": "2 1 100\n10",
"output": "100"
},
{
"input": "7 20 3\n1111111",
"output": "0"
},
{
"input": "1 1 0\n1",
"output": "0"
},
{
"input": "3 1 10\n010",
"output": "11"
},
{
"input": "2 1 0\n11",
"output": "0"
},
{
"input": "7 100 3\n1111111",
"output": "0"
},
{
"input": "5 1 1000\n10101",
"output": "1001"
},
{
"input": "5 2 1\n11111",
"output": "0"
},
{
"input": "1 1000 1\n1",
"output": "0"
},
{
"input": "1 799543940 488239239\n1",
"output": "0"
},
{
"input": "6 1 1000\n010101",
"output": "1002"
},
{
"input": "5 11 1\n11111",
"output": "0"
},
{
"input": "5 2 3\n10101",
"output": "5"
},
{
"input": "3 10 1\n111",
"output": "0"
},
{
"input": "7 9 10\n1001011",
"output": "19"
},
{
"input": "5 5 6\n10101",
"output": "11"
},
{
"input": "1 1000000000 0\n1",
"output": "0"
},
{
"input": "4 0 1\n0101",
"output": "1"
},
{
"input": "8 2 3\n10101010",
"output": "9"
},
{
"input": "6 3 100\n010101",
"output": "106"
},
{
"input": "3 3 2\n111",
"output": "0"
},
{
"input": "1 20 1\n1",
"output": "0"
},
{
"input": "2 1 2\n01",
"output": "2"
}
] | 1,697,221,236 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n, a, b = [int(x) for x in input().split(" ")]
seats = list(input())
res = 0
prev = "*"
for i in range(n):
if seats[i] == "*":
prev = "*"
elif prev == "*":
if a >= b and a > 0:
a -= 1
res += 1
prev = "a"
elif a < b and b > 0:
b -= 1
res += 1
prev = "b"
elif prev == "a":
if b > 0:
b -= 1
res += 1
prev = "b"
elif prev == "b":
if a > 0:
a -= 1
res += 1
prev = "a"
if a == 0 or b == 0:
break
print(res) | Title: Convert to Ones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones.
Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$.
You can apply the following operations any number of times:
- Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»).
You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring.
What is the minimum number of coins you need to spend to get a string consisting only of ones?
Input Specification:
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring).
The second line contains the string $a$ of length $n$, consisting of zeros and ones.
Output Specification:
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
Demo Input:
['5 1 10\n01000\n', '5 10 1\n01000\n', '7 2 3\n1111111\n']
Demo Output:
['11\n', '2\n', '0\n']
Note:
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «10000» $\to$ «11111».
The total cost of operations is $1 + 10 = 11$.
In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$.
Then the string was changed as follows:
«01000» $\to$ «11000» $\to$ «11111».
The overall cost is $1 + 1 = 2$.
In the third example, string already consists only of ones, so the answer is $0$. | ```python
n, a, b = [int(x) for x in input().split(" ")]
seats = list(input())
res = 0
prev = "*"
for i in range(n):
if seats[i] == "*":
prev = "*"
elif prev == "*":
if a >= b and a > 0:
a -= 1
res += 1
prev = "a"
elif a < b and b > 0:
b -= 1
res += 1
prev = "b"
elif prev == "a":
if b > 0:
b -= 1
res += 1
prev = "b"
elif prev == "b":
if a > 0:
a -= 1
res += 1
prev = "a"
if a == 0 or b == 0:
break
print(res)
``` | 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,596,863,839 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 3,000 | 60,108,800 | n,m,k = map(int,input().split())
a = []
rows = {} # get actual row from symbolic row
cols = {}
for i in range(n):
rows[i] = i
for i in range(m):
cols[i] = i
for i in range(n):
a.append(input().split())
for i in range(k):
s,x,y = input().split()
x,y=int(x)-1,int(y)-1
if s == 'g':
print(a[rows[x]][cols[y]])
elif s == 'r':
rows[x], rows[y] = rows[y], rows[x]
else:
cols[x], cols[y] = cols[y], cols[x]
| 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 = map(int,input().split())
a = []
rows = {} # get actual row from symbolic row
cols = {}
for i in range(n):
rows[i] = i
for i in range(m):
cols[i] = i
for i in range(n):
a.append(input().split())
for i in range(k):
s,x,y = input().split()
x,y=int(x)-1,int(y)-1
if s == 'g':
print(a[rows[x]][cols[y]])
elif s == 'r':
rows[x], rows[y] = rows[y], rows[x]
else:
cols[x], cols[y] = cols[y], cols[x]
``` | 0 |
|
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. | The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n2 2 1 1 1",
"output": "2"
},
{
"input": "7\n1 1 2 2 1 2 1",
"output": "3"
},
{
"input": "10\n1 2 2 1 2 2 1 2 1 1",
"output": "5"
},
{
"input": "5\n2 2 2 1 2",
"output": "1"
},
{
"input": "43\n1 2 2 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2",
"output": "10"
},
{
"input": "72\n1 2 1 2 2 1 2 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 1 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 2 1 1 1 1 2 2 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 2 2",
"output": "34"
},
{
"input": "64\n2 2 1 1 1 2 1 1 1 2 2 1 2 2 2 1 2 2 2 1 1 1 1 2 1 2 1 2 1 1 2 2 1 1 2 2 1 1 1 1 2 2 1 1 1 2 1 2 2 2 2 2 2 2 1 1 2 1 1 1 2 2 1 2",
"output": "32"
},
{
"input": "20\n1 1 1 1 2 1 2 2 2 1 2 1 2 1 2 1 1 2 1 2",
"output": "9"
},
{
"input": "23\n1 1 1 1 2 1 2 1 1 1 2 2 2 2 2 2 1 2 1 2 2 1 1",
"output": "11"
},
{
"input": "201\n1 1 2 2 2 2 1 1 1 2 2 1 2 1 2 1 2 2 2 1 1 2 1 1 1 2 1 2 1 1 1 2 1 1 2 1 2 2 1 1 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 1 2 2 2 2 2 2 1 1 1 2 2 1 1 1 1 2 2 1 2 1 1 2 2 1 1 2 2 2 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 1 1 1 2 1 2 2 2 2 2 1 2 1 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 1 2 1 1 1 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 1 1 1 2",
"output": "100"
},
{
"input": "247\n2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 1 2 1 1 1 2 1 1 1 1 2 1 1 2 2 1 2 1 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 1 1 1 1 1 1 2 1 2 2 1 2 1 2 2 2 1 2 2 2 1 1 2 2 1 1 1 2 1 1 1 1 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 1 2 2 2 2 2 1 2 2 2 1 1 1 2 1 2 1 1 2 2 2 2 1 1 2 2 2 1 2 2 2 1 2 1 1 2 2 2 2 1 2 2 1 1 1 2 1 2 1 1 1 2 2 1 1 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 1 1 2 2 2",
"output": "123"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "4\n1 1 1 1",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "1"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "3\n2 1 2",
"output": "1"
},
{
"input": "3\n2 2 1",
"output": "1"
},
{
"input": "4\n1 1 1 2",
"output": "1"
},
{
"input": "4\n1 1 2 2",
"output": "2"
},
{
"input": "4\n1 2 2 2",
"output": "1"
},
{
"input": "4\n2 1 1 1",
"output": "1"
},
{
"input": "5\n1 1 1 1 2",
"output": "2"
},
{
"input": "14\n1 2 2 2 2 2 2 2 2 2 2 2 2 2",
"output": "1"
},
{
"input": "38\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "30\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1",
"output": "1"
},
{
"input": "26\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2",
"output": "1"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "3"
},
{
"input": "5\n2 1 1 1 1",
"output": "2"
},
{
"input": "9\n1 1 1 1 1 1 2 2 2",
"output": "4"
},
{
"input": "10\n2 2 1 1 1 1 1 1 1 1",
"output": "4"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "2"
}
] | 1,513,536,214 | 2,147,483,647 | PyPy 3 | OK | TESTS | 67 | 202 | 34,816,000 | n = int(input())
a = [int(z) for z in input().split()]
cnt1 = 0
cnt2 = 0
ans = 0
for i in range(n):
if a[i] == 1:
cnt1 += 1
else:
cnt2 += 1
if cnt1 > cnt2:
ans += cnt2
ans += (cnt1 - cnt2) // 3
else:
ans += cnt1
print(ans) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
Input Specification:
The first line contains single integer *n* (2<=≤<=*n*<=≤<=2·105) — the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2), where *a**i* is the number of people in group *i*.
Output Specification:
Print the maximum number of teams of three people the coach can form.
Demo Input:
['4\n1 1 2 1\n', '2\n2 2\n', '7\n2 2 2 1 1 1 1\n', '3\n1 1 1\n']
Demo Output:
['1\n', '0\n', '3\n', '1\n']
Note:
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person), - The second group (of two people) and the sixth group (of one person), - The third group (of two people) and the fourth group (of one person). | ```python
n = int(input())
a = [int(z) for z in input().split()]
cnt1 = 0
cnt2 = 0
ans = 0
for i in range(n):
if a[i] == 1:
cnt1 += 1
else:
cnt2 += 1
if cnt1 > cnt2:
ans += cnt2
ans += (cnt1 - cnt2) // 3
else:
ans += cnt1
print(ans)
``` | 3 |
|
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ. | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000",
"output": "22"
},
{
"input": "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035",
"output": "6"
},
{
"input": "700\n9307216756404590162143344901558545760612901767837570518638460182990196397856220673189163417019781185",
"output": "32"
},
{
"input": "900\n7570423817272967027553082464863962024635217372307919506594193055572300657732661146354209508997483330",
"output": "91"
},
{
"input": "18\n900",
"output": "1"
},
{
"input": "23\n12138",
"output": "1"
},
{
"input": "16\n333",
"output": "2"
},
{
"input": "3\n12",
"output": "0"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "17\n89",
"output": "0"
},
{
"input": "18\n99",
"output": "0"
},
{
"input": "42\n97779",
"output": "2"
},
{
"input": "2\n11",
"output": "0"
},
{
"input": "6\n33",
"output": "0"
},
{
"input": "45\n23456",
"output": "5"
},
{
"input": "3\n21",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "108\n199999899899",
"output": "3"
},
{
"input": "6\n222",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "9\n9",
"output": "0"
},
{
"input": "5\n5",
"output": "0"
},
{
"input": "27\n888",
"output": "3"
}
] | 1,591,763,882 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 155 | 1,945,600 | k = int(input())
n = input()
a = dict()
ans = 0
for i in range(10):
a[i] = 0
for i in n:
a[int(i)] += 1
ans += int(i)
x = 0
for i in range(10):
while a[i] > 0 and ans < k:
x += 1
a[i] -= 1
ans += 9 - i
print(x)
| Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input Specification:
The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Output Specification:
Print the minimum number of digits in which the initial number and *n* can differ.
Demo Input:
['3\n11\n', '3\n99\n']
Demo Output:
['1\n', '0\n']
Note:
In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | ```python
k = int(input())
n = input()
a = dict()
ans = 0
for i in range(10):
a[i] = 0
for i in n:
a[int(i)] += 1
ans += int(i)
x = 0
for i in range(10):
while a[i] > 0 and ans < k:
x += 1
a[i] -= 1
ans += 9 - i
print(x)
``` | 3 |
|
620 | C | Pearls in a Row | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl. | On the first line print integer *k* — the maximal number of segments in a partition of the row.
Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1". | [
"5\n1 2 3 4 1\n",
"5\n1 2 3 4 5\n",
"7\n1 2 1 3 1 2 1\n"
] | [
"1\n1 5\n",
"-1\n",
"2\n1 3\n4 7\n"
] | none | 0 | [
{
"input": "5\n1 2 3 4 1",
"output": "1\n1 5"
},
{
"input": "5\n1 2 3 4 5",
"output": "-1"
},
{
"input": "7\n1 2 1 3 1 2 1",
"output": "2\n1 3\n4 7"
},
{
"input": "9\n1 2 1 2 1 2 1 2 1",
"output": "3\n1 3\n4 6\n7 9"
},
{
"input": "11\n1 1 2 1 2 1 2 1 2 1 1",
"output": "4\n1 2\n3 5\n6 8\n9 11"
},
{
"input": "1\n576560149",
"output": "-1"
},
{
"input": "10\n460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451 460626451",
"output": "5\n1 2\n3 4\n5 6\n7 8\n9 10"
},
{
"input": "10\n933677171 80672280 80672280 933677171 933677171 933677171 933677171 80672280 80672280 933677171",
"output": "4\n1 3\n4 5\n6 7\n8 10"
},
{
"input": "10\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597",
"output": "2\n1 3\n4 10"
},
{
"input": "7\n13 9 19 13 3 13 12",
"output": "1\n1 7"
},
{
"input": "3\n1 1 1",
"output": "1\n1 3"
},
{
"input": "5\n1 2 2 2 3",
"output": "1\n1 5"
},
{
"input": "5\n1 2 2 2 1",
"output": "1\n1 5"
},
{
"input": "13\n1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "6\n1 2\n3 4\n5 6\n7 8\n9 10\n11 13"
},
{
"input": "4\n1 2 1 2",
"output": "1\n1 4"
}
] | 1,453,458,697 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 1,169 | 23,961,600 | n = int(input())
li = list(map(int,input().split()))
s=set()
otv=[]
l=0
r=-1
for i in range(n):
if li[i] in s:
otv.append([l+1,i+1])
s = set()
l = i+1
r=1
else:
s.add(li[i])
if r==-1:
print(-1)
else:
print(len(otv))
otv[len(otv)-1][1]=n
for i in otv:
print(*i)
| Title: Pearls in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pearls in a row. Let's enumerate them with integers from 1 to *n* from the left to the right. The pearl number *i* has the type *a**i*.
Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type.
Split the row of the pearls to the maximal number of good segments. Note that each pearl should appear in exactly one segment of the partition.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the number of pearls in a row.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) – the type of the *i*-th pearl.
Output Specification:
On the first line print integer *k* — the maximal number of segments in a partition of the row.
Each of the next *k* lines should contain two integers *l**j*,<=*r**j* (1<=≤<=*l**j*<=≤<=*r**j*<=≤<=*n*) — the number of the leftmost and the rightmost pearls in the *j*-th segment.
Note you should print the correct partition of the row of the pearls, so each pearl should be in exactly one segment and all segments should contain two pearls of the same type.
If there are several optimal solutions print any of them. You can print the segments in any order.
If there are no correct partitions of the row print the number "-1".
Demo Input:
['5\n1 2 3 4 1\n', '5\n1 2 3 4 5\n', '7\n1 2 1 3 1 2 1\n']
Demo Output:
['1\n1 5\n', '-1\n', '2\n1 3\n4 7\n']
Note:
none | ```python
n = int(input())
li = list(map(int,input().split()))
s=set()
otv=[]
l=0
r=-1
for i in range(n):
if li[i] in s:
otv.append([l+1,i+1])
s = set()
l = i+1
r=1
else:
s.add(li[i])
if r==-1:
print(-1)
else:
print(len(otv))
otv[len(otv)-1][1]=n
for i in otv:
print(*i)
``` | 3 |
|
601 | A | The Two Routes | PROGRAMMING | 1,600 | [
"graphs",
"shortest paths"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns. | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | 500 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "-1"
},
{
"input": "2 1\n1 2",
"output": "-1"
},
{
"input": "2 0",
"output": "-1"
},
{
"input": "20 0",
"output": "-1"
},
{
"input": "381 0",
"output": "-1"
},
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "3 0",
"output": "-1"
},
{
"input": "3 1\n1 3",
"output": "2"
},
{
"input": "3 2\n2 3\n3 1",
"output": "-1"
},
{
"input": "4 1\n1 4",
"output": "2"
},
{
"input": "4 5\n1 3\n2 1\n3 4\n4 2\n2 3",
"output": "2"
},
{
"input": "20 1\n20 1",
"output": "2"
},
{
"input": "21 1\n21 1",
"output": "2"
},
{
"input": "100 1\n100 1",
"output": "2"
},
{
"input": "400 1\n1 400",
"output": "2"
},
{
"input": "5 5\n2 5\n1 2\n1 4\n1 3\n3 2",
"output": "2"
}
] | 1,537,682,710 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 140 | 102,400 | def dij(g,n):
t=[-1]*(n+1)
t[1]=0
stack=[1]
while stack:
q=stack.pop()
for val in g[q]:
if(t[val]==-1 ):
t[val]=t[q]+1
stack.append(val)
return t[n]
from collections import defaultdict
g1=defaultdict(list)
g2=defaultdict(list)
f=lambda:map(int,input().split())
n,m=f()
k=n+1
for i in range(1,m+1):
a,b=f()
g1[a].append(b)
g1[b].append(a)
for i in range(1,k):
for j in range(1,k):
if j not in g1[i]:
g2[i].append(j)
t1=dij(g1,n)
t2=dij(g2,n)
if(t1==-1 or t2==-1):
print(-1)
else:
print(max(t1,t2))
| Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.
A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads.
You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously.
Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so.
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*).
You may assume that there is at most one railway connecting any two towns.
Output Specification:
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
Demo Input:
['4 2\n1 3\n3 4\n', '4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n', '5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n']
Demo Output:
['2\n', '-1\n', '3\n']
Note:
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a26c2f3e93c9d9be6c21cb5d2bd6ac1f99f4ff55.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Note that they can arrive at town 4 at the same time.
In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4. | ```python
def dij(g,n):
t=[-1]*(n+1)
t[1]=0
stack=[1]
while stack:
q=stack.pop()
for val in g[q]:
if(t[val]==-1 ):
t[val]=t[q]+1
stack.append(val)
return t[n]
from collections import defaultdict
g1=defaultdict(list)
g2=defaultdict(list)
f=lambda:map(int,input().split())
n,m=f()
k=n+1
for i in range(1,m+1):
a,b=f()
g1[a].append(b)
g1[b].append(a)
for i in range(1,k):
for j in range(1,k):
if j not in g1[i]:
g2[i].append(j)
t1=dij(g1,n)
t2=dij(g2,n)
if(t1==-1 or t2==-1):
print(-1)
else:
print(max(t1,t2))
``` | 0 |
|
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start. | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12326 6163 2",
"output": "1"
},
{
"input": "10000 2500 4",
"output": "1"
},
{
"input": "100000 99999 4",
"output": "1"
},
{
"input": "12351 1223 6",
"output": "2"
},
{
"input": "100000 1 10000",
"output": "2"
},
{
"input": "10028 13 10000",
"output": "1"
},
{
"input": "100000 99999 2",
"output": "1"
},
{
"input": "100000 99999 3",
"output": "1"
},
{
"input": "100000 1 2",
"output": "17"
},
{
"input": "100000 1 3",
"output": "11"
},
{
"input": "100000 1 4",
"output": "9"
},
{
"input": "100000 1 5",
"output": "8"
},
{
"input": "100000 3125 2",
"output": "5"
},
{
"input": "12628 1804 7",
"output": "1"
},
{
"input": "100000 45 13",
"output": "4"
},
{
"input": "100000 500 3",
"output": "5"
},
{
"input": "356 2 3",
"output": "5"
},
{
"input": "50 2 2",
"output": "5"
},
{
"input": "65465 12 3",
"output": "8"
},
{
"input": "10033 3 8",
"output": "4"
},
{
"input": "100000 3 2",
"output": "16"
},
{
"input": "64 1 8",
"output": "2"
},
{
"input": "10000 9 2",
"output": "11"
},
{
"input": "25 2 2",
"output": "4"
},
{
"input": "129 2 2",
"output": "7"
},
{
"input": "6562 1 3",
"output": "9"
},
{
"input": "100000 1 10",
"output": "5"
}
] | 1,495,715,651 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | t=int(input())
s=int(input())
q=int(input())
cnt=0
while(s<t):
cnt=cnt+1
s=s*q
print (cnt)
| Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track.
Tell Lesha, for how many times he will start the song, including the very first start.
Input Specification:
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105).
Output Specification:
Print a single integer — the number of times the song will be restarted.
Demo Input:
['5 2 2\n', '5 4 7\n', '6 2 3\n']
Demo Output:
['2\n', '1\n', '1\n']
Note:
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test, the song is almost downloaded, and Lesha will start it only once.
In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. | ```python
t=int(input())
s=int(input())
q=int(input())
cnt=0
while(s<t):
cnt=cnt+1
s=s*q
print (cnt)
``` | -1 |
|
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,680,090,620 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | n=int(input())
m=int(input())
a=int(input())
if a!=0 and n!=0 and m!=0 and n<=10**9:
print(((n // a) + 1) * ((m // a) + 1)) | 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=int(input())
m=int(input())
a=int(input())
if a!=0 and n!=0 and m!=0 and n<=10**9:
print(((n // a) + 1) * ((m // a) + 1))
``` | -1 |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39 75",
"output": "48.142857142857"
},
{
"input": "13\n2 22 7 0 1 17 3 17 11 2 21 26 22",
"output": "11.615384615385"
},
{
"input": "21\n5 4 11 7 0 5 45 21 0 14 51 6 0 16 10 19 8 9 7 12 18",
"output": "12.761904761905"
},
{
"input": "26\n95 70 93 74 94 70 91 70 39 79 80 57 87 75 37 93 48 67 51 90 85 26 23 64 66 84",
"output": "69.538461538462"
},
{
"input": "29\n84 99 72 96 83 92 95 98 97 93 76 84 99 93 81 76 93 99 99 100 95 100 96 95 97 100 71 98 94",
"output": "91.551724137931"
},
{
"input": "33\n100 99 100 100 99 99 99 100 100 100 99 99 99 100 100 100 100 99 100 99 100 100 97 100 100 100 100 100 100 100 98 98 100",
"output": "99.515151515152"
},
{
"input": "34\n14 9 10 5 4 26 18 23 0 1 0 20 18 15 2 2 3 5 14 1 9 4 2 15 7 1 7 19 10 0 0 11 0 2",
"output": "8.147058823529"
},
{
"input": "38\n99 98 100 100 99 92 99 99 98 84 88 94 86 99 93 100 98 99 65 98 85 84 64 97 96 89 79 96 91 84 99 93 72 96 94 97 96 93",
"output": "91.921052631579"
},
{
"input": "52\n100 94 99 98 99 99 99 95 97 97 98 100 100 98 97 100 98 90 100 99 97 94 90 98 100 100 90 99 100 95 98 95 94 85 97 94 96 94 99 99 99 98 100 100 94 99 99 100 98 87 100 100",
"output": "97.019230769231"
},
{
"input": "58\n10 70 12 89 1 82 100 53 40 100 21 69 92 91 67 66 99 77 25 48 8 63 93 39 46 79 82 14 44 42 1 79 0 69 56 73 67 17 59 4 65 80 20 60 77 52 3 61 16 76 33 18 46 100 28 59 9 6",
"output": "50.965517241379"
},
{
"input": "85\n7 8 1 16 0 15 1 7 0 11 15 6 2 12 2 8 9 8 2 0 3 7 15 7 1 8 5 7 2 26 0 3 11 1 8 10 31 0 7 6 1 8 1 0 9 14 4 8 7 16 9 1 0 16 10 9 6 1 1 4 2 7 4 5 4 1 20 6 16 16 1 1 10 17 8 12 14 19 3 8 1 7 10 23 10",
"output": "7.505882352941"
},
{
"input": "74\n5 3 0 7 13 10 12 10 18 5 0 18 2 13 7 17 2 7 5 2 40 19 0 2 2 3 0 45 4 20 0 4 2 8 1 19 3 9 17 1 15 0 16 1 9 4 0 9 32 2 6 18 11 18 1 15 16 12 7 19 5 3 9 28 26 8 3 10 33 29 4 13 28 6",
"output": "10.418918918919"
},
{
"input": "98\n42 9 21 11 9 11 22 12 52 20 10 6 56 9 26 27 1 29 29 14 38 17 41 21 7 45 15 5 29 4 51 20 6 8 34 17 13 53 30 45 0 10 16 41 4 5 6 4 14 2 31 6 0 11 13 3 3 43 13 36 51 0 7 16 28 23 8 36 30 22 8 54 21 45 39 4 50 15 1 30 17 8 18 10 2 20 16 50 6 68 15 6 38 7 28 8 29 41",
"output": "20.928571428571"
},
{
"input": "99\n60 65 40 63 57 44 30 84 3 10 39 53 40 45 72 20 76 11 61 32 4 26 97 55 14 57 86 96 34 69 52 22 26 79 31 4 21 35 82 47 81 28 72 70 93 84 40 4 69 39 83 58 30 7 32 73 74 12 92 23 61 88 9 58 70 32 75 40 63 71 46 55 39 36 14 97 32 16 95 41 28 20 85 40 5 50 50 50 75 6 10 64 38 19 77 91 50 72 96",
"output": "49.191919191919"
},
{
"input": "99\n100 88 40 30 81 80 91 98 69 73 88 96 79 58 14 100 87 84 52 91 83 88 72 83 99 35 54 80 46 79 52 72 85 32 99 39 79 79 45 83 88 50 75 75 50 59 65 75 97 63 92 58 89 46 93 80 89 33 69 86 99 99 66 85 72 74 79 98 85 95 46 63 77 97 49 81 89 39 70 76 68 91 90 56 31 93 51 87 73 95 74 69 87 95 57 68 49 95 92",
"output": "73.484848484848"
},
{
"input": "100\n18 15 17 0 3 3 0 4 1 8 2 22 7 21 5 0 0 8 3 16 1 0 2 9 9 3 10 8 17 20 5 4 8 12 2 3 1 1 3 2 23 0 1 0 5 7 4 0 1 3 3 4 25 2 2 14 8 4 9 3 0 11 0 3 12 3 14 16 7 7 14 1 17 9 0 35 42 12 3 1 25 9 3 8 5 3 2 8 22 14 11 6 3 9 6 8 7 7 4 6",
"output": "7.640000000000"
},
{
"input": "100\n88 77 65 87 100 63 91 96 92 89 77 95 76 80 84 83 100 71 85 98 26 54 74 78 69 59 96 86 88 91 95 26 52 88 64 70 84 81 76 84 94 82 100 66 97 98 43 94 59 94 100 80 98 73 69 83 94 70 74 79 91 31 62 88 69 55 62 97 40 64 62 83 87 85 50 90 69 72 67 49 100 51 69 96 81 90 83 91 86 34 79 69 100 66 97 98 47 97 74 100",
"output": "77.660000000000"
},
{
"input": "100\n91 92 90 91 98 84 85 96 83 98 99 87 94 70 87 75 86 90 89 88 82 83 91 94 88 86 90 99 100 98 97 75 95 99 95 100 91 92 76 93 95 97 88 93 95 81 96 89 88 100 98 87 90 96 100 99 58 90 96 77 92 82 100 100 93 93 98 99 79 88 97 95 98 66 96 83 96 100 99 92 98 98 92 93 100 97 98 100 98 97 100 100 94 90 99 100 98 79 80 81",
"output": "91.480000000000"
},
{
"input": "1\n0",
"output": "0.000000000000"
},
{
"input": "1\n100",
"output": "100.000000000000"
},
{
"input": "1\n78",
"output": "78.000000000000"
},
{
"input": "2\n0 100",
"output": "50.000000000000"
},
{
"input": "2\n100 100",
"output": "100.000000000000"
},
{
"input": "5\n0 0 0 0 1",
"output": "0.200000000000"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "99.990000000000"
},
{
"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 1",
"output": "0.010000000000"
},
{
"input": "5\n100 100 100 100 100",
"output": "100.000000000000"
}
] | 1,681,932,187 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 156 | 0 | n = int(input())
k = input().split()
s = 0
for i in range(n):
k[i] = int(k[i])
s += k[i]
n = n*100
print((s/n)*100)
| Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportions of each of the *n* drinks and mixed them. Then he wondered, how much orange juice the cocktail has.
Find the volume fraction of orange juice in the final drink.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Output Specification:
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
Demo Input:
['3\n50 50 100\n', '4\n0 25 50 75\n']
Demo Output:
['66.666666666667\n', '37.500000000000\n']
Note:
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: 100.0%;"/> milliliters. The total cocktail's volume equals 3·*x* milliliters, so the volume fraction of the juice in the cocktail equals <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ceb0664e55a1f9f5fa1243ec74680a4665a4d58d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, that is, 66.(6) percent. | ```python
n = int(input())
k = input().split()
s = 0
for i in range(n):
k[i] = int(k[i])
s += k[i]
n = n*100
print((s/n)*100)
``` | 3 |
|
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "1+2+1+2+2+2+2+1+3+3",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2",
"output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3",
"output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3"
},
{
"input": "3",
"output": "3"
},
{
"input": "1+1",
"output": "1+1"
},
{
"input": "1+2",
"output": "1+2"
},
{
"input": "1+3",
"output": "1+3"
},
{
"input": "2+1",
"output": "1+2"
},
{
"input": "2+2",
"output": "2+2"
},
{
"input": "2+3",
"output": "2+3"
},
{
"input": "3+1",
"output": "1+3"
},
{
"input": "3+2",
"output": "2+3"
},
{
"input": "3+3",
"output": "3+3"
}
] | 1,696,783,277 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,969,600 | nums = input().split()
print(sorted(nums).join('+')) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input Specification:
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Output Specification:
Print the new sum that Xenia can count.
Demo Input:
['3+2+1\n', '1+1+3+1+3\n', '2\n']
Demo Output:
['1+2+3\n', '1+1+1+3+3\n', '2\n']
Note:
none | ```python
nums = input().split()
print(sorted(nums).join('+'))
``` | -1 |
|
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
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 or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output": "7"
},
{
"input": "1000000000000 500000000001",
"output": "2"
},
{
"input": "999999999997 499999999999",
"output": "999999999997"
},
{
"input": "999999999999 999999999999",
"output": "999999999998"
},
{
"input": "1000000000000 1",
"output": "1"
},
{
"input": "999999999999 1",
"output": "1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1000000000000 1000000000000",
"output": "1000000000000"
},
{
"input": "1000000000000 500000000000",
"output": "999999999999"
},
{
"input": "1000000000000 499999999999",
"output": "999999999997"
},
{
"input": "999999999997 499999999998",
"output": "999999999995"
},
{
"input": "619234238 556154835",
"output": "493075432"
},
{
"input": "38151981 36650624",
"output": "35149266"
},
{
"input": "680402465 442571217",
"output": "204739968"
},
{
"input": "109135284 9408714",
"output": "18817427"
},
{
"input": "603701841 56038951",
"output": "112077901"
},
{
"input": "356764822 321510177",
"output": "286255532"
},
{
"input": "284911189 142190783",
"output": "284381565"
},
{
"input": "91028405 61435545",
"output": "31842684"
}
] | 1,694,506,151 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 268,390,400 | info=input().split()
n=int(info[0])
k=int(info[1])
num_1=[i for i in range(1,n+1,2)]
num_2=[i for i in range(2,n+1,2)]
for num in num_2:
num_1.append(num)
print(num_1[k-1]) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
Input Specification:
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
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 or the %I64d specifier.
Output Specification:
Print the number that will stand at the position number *k* after Volodya's manipulations.
Demo Input:
['10 3\n', '7 7\n']
Demo Output:
['5', '6']
Note:
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | ```python
info=input().split()
n=int(info[0])
k=int(info[1])
num_1=[i for i in range(1,n+1,2)]
num_2=[i for i in range(2,n+1,2)]
for num in num_2:
num_1.append(num)
print(num_1[k-1])
``` | 0 |
|
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,620,751,556 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 7,065,600 | n = int(input())
num = list(map(int,input().split()))
maxnum = max(num)
default = (maxnum+1)*[0]
for j in range(len(num)):
default[num[j]] = 1
# print(default)
flag = 0
for j in range(1,len(default)):
if default[j] == 0:
flag = 1
ans = j
break
if flag == 1:
print(ans)
else:
print(n+1) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n = int(input())
num = list(map(int,input().split()))
maxnum = max(num)
default = (maxnum+1)*[0]
for j in range(len(num)):
default[num[j]] = 1
# print(default)
flag = 0
for j in range(1,len(default)):
if default[j] == 0:
flag = 1
ans = j
break
if flag == 1:
print(ans)
else:
print(n+1)
``` | 3.948339 |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 1",
"output": "Still Rozdil"
},
{
"input": "4\n1000000000 100000000 1000000 1000000",
"output": "Still Rozdil"
},
{
"input": "20\n7 1 1 2 1 1 8 7 7 8 4 3 7 10 5 3 10 5 10 6",
"output": "Still Rozdil"
},
{
"input": "20\n3 3 6 9 8 2 4 1 7 3 2 9 7 7 9 7 2 6 2 7",
"output": "8"
},
{
"input": "47\n35 79 84 56 67 95 80 34 77 68 14 55 95 32 40 89 58 79 96 66 50 79 35 86 31 74 91 35 22 72 84 38 11 59 73 51 65 11 11 62 30 12 32 71 69 15 11",
"output": "Still Rozdil"
},
{
"input": "47\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3",
"output": "32"
},
{
"input": "25\n73 56 65 70 57 57 49 50 65 68 54 48 66 55 55 66 60 70 47 62 63 70 62 70 63",
"output": "19"
},
{
"input": "100\n922 938 103 689 526 118 314 496 373 47 224 544 495 656 804 754 269 356 354 536 817 597 787 178 516 659 790 993 786 169 866 779 997 350 674 437 219 546 564 893 402 449 751 628 238 686 392 951 716 439 332 563 215 146 746 311 866 773 548 675 731 183 890 802 488 944 473 25 662 559 732 534 777 144 502 593 839 692 84 337 679 718 1005 663 709 940 86 469 310 960 902 233 606 761 116 231 662 903 68 622",
"output": "68"
},
{
"input": "5\n5 5 2 3 1",
"output": "5"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "3\n7 7 4",
"output": "3"
},
{
"input": "3\n2 2 1",
"output": "3"
},
{
"input": "3\n4 4 3",
"output": "3"
},
{
"input": "2\n10000001 10000002",
"output": "1"
},
{
"input": "4\n3 3 2 1",
"output": "4"
},
{
"input": "3\n1 2 3",
"output": "1"
},
{
"input": "2\n1000000000 100000000",
"output": "2"
},
{
"input": "1\n99999999",
"output": "1"
},
{
"input": "3\n5 5 3",
"output": "3"
},
{
"input": "3\n7 7 5",
"output": "3"
},
{
"input": "3\n3 3 1",
"output": "3"
},
{
"input": "4\n10 10 10 1",
"output": "4"
}
] | 1,590,757,283 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 310 | 8,704,000 | n = int(input())
arr = list(map(int,input().split()))
mini = arr[0]
index = 0
for i in range(1, n):
if(arr[i]<mini):
mini = arr[i]
index= i
if(arr.count(mini)>1):
print("Still Rozdil")
else:
print(index+1)
| Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere.
For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities.
Output Specification:
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
Demo Input:
['2\n7 4\n', '7\n7 4 47 100 4 9 12\n']
Demo Output:
['2\n', 'Still Rozdil\n']
Note:
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling time to both of them equals 4, so the answer is "Still Rozdil". | ```python
n = int(input())
arr = list(map(int,input().split()))
mini = arr[0]
index = 0
for i in range(1, n):
if(arr[i]<mini):
mini = arr[i]
index= i
if(arr.count(mini)>1):
print("Still Rozdil")
else:
print(index+1)
``` | 3 |
|
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting. | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
{
"input": "10 3 4 5",
"output": "3"
},
{
"input": "100 23 15 50",
"output": "2"
},
{
"input": "3119 3515 1021 7",
"output": "11"
},
{
"input": "918 102 1327 1733",
"output": "9"
},
{
"input": "3164 42 430 1309",
"output": "15"
},
{
"input": "3043 317 1141 2438",
"output": "7"
},
{
"input": "26 1 772 2683",
"output": "26"
},
{
"input": "370 2 1 15",
"output": "370"
},
{
"input": "734 12 6 2",
"output": "367"
},
{
"input": "418 18 14 17",
"output": "29"
},
{
"input": "18 16 28 9",
"output": "2"
},
{
"input": "14 6 2 17",
"output": "7"
},
{
"input": "29 27 18 2",
"output": "2"
},
{
"input": "29 12 7 10",
"output": "3"
},
{
"input": "27 23 4 3",
"output": "9"
},
{
"input": "5 14 5 2",
"output": "1"
},
{
"input": "5 17 26 5",
"output": "1"
},
{
"input": "9 1 10 3",
"output": "9"
},
{
"input": "2 19 15 1",
"output": "2"
},
{
"input": "4 6 4 9",
"output": "1"
},
{
"input": "10 6 2 9",
"output": "5"
},
{
"input": "2 2 9 6",
"output": "1"
},
{
"input": "6 2 4 1",
"output": "6"
},
{
"input": "27 24 5 27",
"output": "1"
},
{
"input": "2683 83 26 2709",
"output": "101"
},
{
"input": "728 412 789 158",
"output": "3"
},
{
"input": "3964 4 2916 176",
"output": "991"
},
{
"input": "3399 2035 2 3334",
"output": "683"
},
{
"input": "3455 244 3301 3",
"output": "991"
},
{
"input": "595 2263 3625 1",
"output": "595"
},
{
"input": "4000 1 1 1",
"output": "4000"
},
{
"input": "3999 2 2 3999",
"output": "1"
},
{
"input": "25 6 8 11",
"output": "3"
},
{
"input": "4000 500 1000 2000",
"output": "8"
},
{
"input": "53 10 11 23",
"output": "5"
},
{
"input": "100 100 1 1",
"output": "100"
},
{
"input": "17 3 4 10",
"output": "5"
},
{
"input": "413 101 102 105",
"output": "4"
},
{
"input": "490 4 49 50",
"output": "111"
},
{
"input": "3999 2 3 3",
"output": "1999"
},
{
"input": "8 3 8 4",
"output": "2"
},
{
"input": "5 1 3 3",
"output": "5"
},
{
"input": "100 3 17 22",
"output": "27"
},
{
"input": "4000 2 3 4",
"output": "2000"
},
{
"input": "4000 3 3 5",
"output": "1332"
},
{
"input": "13 4 6 7",
"output": "2"
},
{
"input": "4000 5 2 2",
"output": "2000"
},
{
"input": "3999 2 2 3",
"output": "1999"
},
{
"input": "4000 33 7 3333",
"output": "564"
},
{
"input": "60 33 20 9",
"output": "4"
},
{
"input": "100 9 11 99",
"output": "10"
},
{
"input": "2009 6 8 9",
"output": "334"
}
] | 1,674,561,358 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 342 | 0 | n , a , b , c = map(int,input().split())
x = min(a,b,c)
z = max(a,b,c)
y = a+b+c - x - z
ans = 0
for i in range(n):
c = i*z
if(c>n):
break
else:
for j in range(n):
b = j*y
if(b+c>n):
break
else:
if((n-b-c)%x==0):
ans = max(ans,i+j+((n-b-c)//x))
break
print(ans) | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
Input Specification:
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Output Specification:
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
Demo Input:
['5 5 3 2\n', '7 5 5 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | ```python
n , a , b , c = map(int,input().split())
x = min(a,b,c)
z = max(a,b,c)
y = a+b+c - x - z
ans = 0
for i in range(n):
c = i*z
if(c>n):
break
else:
for j in range(n):
b = j*y
if(b+c>n):
break
else:
if((n-b-c)%x==0):
ans = max(ans,i+j+((n-b-c)//x))
break
print(ans)
``` | 3 |
|
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. | The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
"input": "3 5\n1 10 20",
"output": "1"
},
{
"input": "3 10\n1 2 3",
"output": "3"
},
{
"input": "2 1\n1 100",
"output": "1"
},
{
"input": "3 1\n1 2 10",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
}
] | 1,591,176,708 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 187 | 9,011,200 | a=list(map(int,input().split()))
n=a[0]
c=a[1]
s=list(map(int,input().split()))
t=1
i=1
b=s[0]
while(i<len(s)):
if(s[i]<=b+c):
t=t+1
b=s[i]
else:
t=1
b=s[i]
i=i+1
print(t) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=><=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen.
For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen.
You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
Input Specification:
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Output Specification:
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
Demo Input:
['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n']
Demo Output:
['3', '2']
Note:
The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1. | ```python
a=list(map(int,input().split()))
n=a[0]
c=a[1]
s=list(map(int,input().split()))
t=1
i=1
b=s[0]
while(i<len(s)):
if(s[i]<=b+c):
t=t+1
b=s[i]
else:
t=1
b=s[i]
i=i+1
print(t)
``` | 3 |
|
465 | B | Inbox (100500) | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters? | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read. | Print a single number — the minimum number of operations needed to make all the letters read. | [
"5\n0 1 0 1 0\n",
"5\n1 1 0 0 1\n",
"2\n0 0\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | 1,000 | [
{
"input": "5\n0 1 0 1 0",
"output": "3"
},
{
"input": "5\n1 1 0 0 1",
"output": "4"
},
{
"input": "2\n0 0",
"output": "0"
},
{
"input": "9\n1 0 1 0 1 0 1 0 1",
"output": "9"
},
{
"input": "5\n1 1 1 1 1",
"output": "5"
},
{
"input": "14\n0 0 1 1 1 0 1 1 1 0 1 1 1 0",
"output": "11"
},
{
"input": "23\n1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 1 1 1",
"output": "23"
},
{
"input": "27\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0",
"output": "25"
},
{
"input": "10\n1 0 0 0 0 1 0 0 0 1",
"output": "5"
},
{
"input": "10\n1 0 0 1 0 0 1 1 0 1",
"output": "8"
},
{
"input": "27\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",
"output": "0"
},
{
"input": "39\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "39"
},
{
"input": "48\n1 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 1 0 1 0 1 0 0 1 0 0 1",
"output": "39"
},
{
"input": "71\n0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 0 0",
"output": "59"
},
{
"input": "99\n1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1",
"output": "99"
},
{
"input": "99\n1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1",
"output": "99"
},
{
"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"
},
{
"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 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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": "99"
},
{
"input": "193\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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "1"
},
{
"input": "213\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 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0",
"output": "5"
},
{
"input": "2\n1 0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "5\n0 0 0 0 1",
"output": "1"
},
{
"input": "12\n0 1 1 0 1 1 0 1 1 0 0 0",
"output": "8"
},
{
"input": "3\n1 0 0",
"output": "1"
},
{
"input": "5\n0 0 1 0 0",
"output": "1"
},
{
"input": "3\n0 1 0",
"output": "1"
},
{
"input": "6\n1 1 0 0 0 0",
"output": "2"
},
{
"input": "4\n0 1 0 0",
"output": "1"
},
{
"input": "5\n1 1 1 0 0",
"output": "3"
},
{
"input": "4\n1 0 0 0",
"output": "1"
},
{
"input": "6\n1 1 1 1 0 0",
"output": "4"
}
] | 1,683,696,893 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
a = list(map(int, input().split()))
unread = 0
total = 0
for i in a:
if i == 1:
if unread > 0:
total += 1
unread += 1
else:
if unread > 0:
unread -= 1
print(total + unread)
| Title: Inbox (100500)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.
Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:
- Move from the list of letters to the content of any single letter.- Return to the list of letters from single letter viewing mode.- In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
The program cannot delete the letters from the list or rearrange them.
Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of letters in the mailbox.
The second line contains *n* space-separated integers (zeros and ones) — the state of the letter list. The *i*-th number equals either 1, if the *i*-th number is unread, or 0, if the *i*-th letter is read.
Output Specification:
Print a single number — the minimum number of operations needed to make all the letters read.
Demo Input:
['5\n0 1 0 1 0\n', '5\n1 1 0 0 1\n', '2\n0 0\n']
Demo Output:
['3\n', '4\n', '0\n']
Note:
In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.
In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.
In the third sample all letters are already read. | ```python
n = int(input())
a = list(map(int, input().split()))
unread = 0
total = 0
for i in a:
if i == 1:
if unread > 0:
total += 1
unread += 1
else:
if unread > 0:
unread -= 1
print(total + unread)
``` | 0 |
|
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"input": "ABAXXXAB",
"output": "YES"
},
{
"input": "TESTABAXXABTEST",
"output": "YES"
},
{
"input": "A",
"output": "NO"
},
{
"input": "B",
"output": "NO"
},
{
"input": "X",
"output": "NO"
},
{
"input": "BA",
"output": "NO"
},
{
"input": "AB",
"output": "NO"
},
{
"input": "AA",
"output": "NO"
},
{
"input": "BB",
"output": "NO"
},
{
"input": "BAB",
"output": "NO"
},
{
"input": "AAB",
"output": "NO"
},
{
"input": "BAA",
"output": "NO"
},
{
"input": "ABB",
"output": "NO"
},
{
"input": "BBA",
"output": "NO"
},
{
"input": "AAA",
"output": "NO"
},
{
"input": "BBB",
"output": "NO"
},
{
"input": "AXBXBXA",
"output": "NO"
},
{
"input": "SKDSKDJABSDBADKFJDK",
"output": "YES"
},
{
"input": "ABAXXBBXXAA",
"output": "NO"
},
{
"input": "ABAB",
"output": "NO"
},
{
"input": "BABA",
"output": "NO"
},
{
"input": "AAAB",
"output": "NO"
},
{
"input": "AAAA",
"output": "NO"
},
{
"input": "AABA",
"output": "NO"
},
{
"input": "ABAA",
"output": "NO"
},
{
"input": "BAAA",
"output": "NO"
},
{
"input": "AABB",
"output": "NO"
},
{
"input": "BAAB",
"output": "YES"
},
{
"input": "BBAA",
"output": "NO"
},
{
"input": "BBBA",
"output": "NO"
},
{
"input": "BBAB",
"output": "NO"
},
{
"input": "BABB",
"output": "NO"
},
{
"input": "ABBB",
"output": "NO"
},
{
"input": "BBBB",
"output": "NO"
},
{
"input": "BABAB",
"output": "YES"
},
{
"input": "ABABA",
"output": "YES"
},
{
"input": "AAABAAACBBBC",
"output": "NO"
},
{
"input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC",
"output": "YES"
},
{
"input": "CBBABDDBBADAC",
"output": "YES"
},
{
"input": "ABYFAB",
"output": "NO"
},
{
"input": "BABXXAB",
"output": "YES"
},
{
"input": "ABAXAB",
"output": "YES"
},
{
"input": "ABABXAB",
"output": "YES"
},
{
"input": "ABXABXABXABXABXBAXBAXBAXBA",
"output": "YES"
},
{
"input": "QQQQQQQQQABABQQQQQQQQ",
"output": "NO"
}
] | 1,695,716,458 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a = input().split("AB")
w = []
for i in a:
q = i.split("BA")
w.append(q)
if len(w) > 1 and (len(w[0]) > 1 or len(w[1]) > 1):
print("YES")
else:
print("NO")
| Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Output Specification:
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Demo Input:
['ABA\n', 'BACFAB\n', 'AXBYBXA\n']
Demo Output:
['NO\n', 'YES\n', 'NO\n']
Note:
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | ```python
a = input().split("AB")
w = []
for i in a:
q = i.split("BA")
w.append(q)
if len(w) > 1 and (len(w[0]) > 1 or len(w[1]) > 1):
print("YES")
else:
print("NO")
``` | 0 |
|
7 | C | Line | PROGRAMMING | 1,800 | [
"math",
"number theory"
] | C. Line | 1 | 256 | A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist. | The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0. | If the required point exists, output its coordinates, otherwise output -1. | [
"2 5 3\n"
] | [
"6 -3\n"
] | none | 0 | [
{
"input": "2 5 3",
"output": "6 -3"
},
{
"input": "0 2 3",
"output": "-1"
},
{
"input": "931480234 -1767614767 -320146190",
"output": "-98880374013340920 -52107006370101410"
},
{
"input": "-1548994394 -1586527767 -1203252104",
"output": "-878123061596147680 857348814150663048"
},
{
"input": "296038088 887120955 1338330394",
"output": "2114412129515872 -705593211994286"
},
{
"input": "1906842444 749552572 -1693767003",
"output": "-1"
},
{
"input": "-1638453107 317016895 -430897103",
"output": "-23538272620589909 -121653945000687008"
},
{
"input": "-1183748658 875864960 -1315510852",
"output": "-97498198168399474 -131770725522871624"
},
{
"input": "427055698 738296578 -52640953",
"output": "-1"
},
{
"input": "-1516373701 -584304312 -746376800",
"output": "202167007852295200 -524659372900676000"
},
{
"input": "200000003 200000001 1",
"output": "100000000 -100000001"
},
{
"input": "0 -1 -2",
"output": "0 -2"
},
{
"input": "0 15 -17",
"output": "-1"
},
{
"input": "-13 0 0",
"output": "0 0"
},
{
"input": "-1000 0 -6",
"output": "-1"
},
{
"input": "1233978557 804808375 539283626",
"output": "3168196851074932 -4857661898189602"
},
{
"input": "532430220 -2899704 -328786059",
"output": "-1"
},
{
"input": "546348890 -29226055 -341135185",
"output": "50549411713300 944965544604433"
},
{
"input": "-1061610169 583743042 1503847115",
"output": "-333340893817405 -606222356685680"
},
{
"input": "10273743 174653631 -628469658",
"output": "-1"
},
{
"input": "1 2000000000 -1",
"output": "1 0"
},
{
"input": "592707810 829317963 -753392742",
"output": "-15849808632976 11327748563154"
},
{
"input": "1300000013 0 -800000008",
"output": "-1"
},
{
"input": "853072 -269205 -1778980",
"output": "7238140 22936620"
},
{
"input": "3162 56 674",
"output": "-4381 247358"
},
{
"input": "19 -5 115",
"output": "115 460"
},
{
"input": "7 5 -17",
"output": "-34 51"
},
{
"input": "-1 1 -2",
"output": "-2 0"
},
{
"input": "12453630 -163142553 -74721780",
"output": "-780 -60"
},
{
"input": "-3416750 528845750 -93743375",
"output": "-1"
},
{
"input": "701408733 1134903170 1836311903",
"output": "-796030994547383611 491974210728665288"
},
{
"input": "1000000013 -1 135",
"output": "0 135"
},
{
"input": "-2000000000 1 2000000000",
"output": "0 -2000000000"
},
{
"input": "2000000000 -2000000000 2000000000",
"output": "-1 0"
},
{
"input": "610684570 628836350 933504357",
"output": "-1"
},
{
"input": "827797728 -613880705 854959653",
"output": "60828197453915544 82024802605070757"
},
{
"input": "1044910887 -700497854 -1772517851",
"output": "572270531415215165 853638173436907976"
},
{
"input": "1663473197 -1943214909 -399995353",
"output": "90913128604458086 77825438652462521"
},
{
"input": "1880586355 -177315705 -478540057",
"output": "-1"
},
{
"input": "-957757861 308710346 45337024",
"output": "587450634832960 1822535171726016"
},
{
"input": "19999 -20000 10000",
"output": "10000 10000"
},
{
"input": "1999999 -2000000 1000000",
"output": "1000000 1000000"
},
{
"input": "999999999 -1000000000 500000000",
"output": "500000000 500000000"
},
{
"input": "999999999 -2 1",
"output": "-1 -499999999"
},
{
"input": "999999993 999999991 1",
"output": "499999995 -499999996"
},
{
"input": "999999993 -999999997 1",
"output": "-249999999 -249999998"
},
{
"input": "1999999993 1999999991 -1",
"output": "-999999995 999999996"
},
{
"input": "1999999993 1999999991 -1999999997",
"output": "-1999999987000000015 1999999989000000012"
}
] | 1,629,418,738 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 5e18;
int main()
{
int a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
ll bg = ceil(c / a);
while (bg % b != 0)
{
if (bg >= (INF * b))
{
printf("-1\n");
return 0;
}
bg += a;
}
printf("%lld %lld\n", bg / b, (bg + c));
return 0;
} | Title: Line
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input Specification:
The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=><=0.
Output Specification:
If the required point exists, output its coordinates, otherwise output -1.
Demo Input:
['2 5 3\n']
Demo Output:
['6 -3\n']
Note:
none | ```python
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF = 5e18;
int main()
{
int a, b, c;
scanf("%lld%lld%lld", &a, &b, &c);
ll bg = ceil(c / a);
while (bg % b != 0)
{
if (bg >= (INF * b))
{
printf("-1\n");
return 0;
}
bg += a;
}
printf("%lld %lld\n", bg / b, (bg + c));
return 0;
}
``` | -1 |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect? | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0. | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "300000"
},
{
"input": "1\n-1 1",
"output": "1"
},
{
"input": "27\n-30721 24576\n-6620 92252\n88986 24715\n-94356 10509\n-6543 29234\n-68554 69530\n39176 96911\n67266 99669\n95905 51002\n-94093 92134\n65382 23947\n-6525 79426\n-448 67531\n-70083 26921\n-86333 50029\n48924 8036\n-27228 5349\n6022 10691\n-13840 56735\n50398 58794\n-63258 45557\n-27792 77057\n98295 1203\n-51294 18757\n35037 61941\n-30112 13076\n82334 20463",
"output": "1036452"
},
{
"input": "18\n-18697 44186\n56333 51938\n-75688 49735\n77762 14039\n-43996 81060\n69700 49107\n74532 45568\n-94476 203\n-92347 90745\n58921 44650\n57563 63561\n44630 8486\n35750 5999\n3249 34202\n75358 68110\n-33245 60458\n-88148 2342\n87856 85532",
"output": "632240"
},
{
"input": "28\n49728 91049\n-42863 4175\n-89214 22191\n77977 16965\n-42960 87627\n-84329 97494\n89270 75906\n-13695 28908\n-72279 13607\n-97327 87062\n-58682 32094\n39108 99936\n29304 93784\n-63886 48237\n-77359 57648\n-87013 79017\n-41086 35033\n-60613 83555\n-48955 56816\n-20568 26802\n52113 25160\n-88885 45294\n22601 42971\n62693 65662\n-15985 5357\n86671 8522\n-59921 11271\n-79304 25044",
"output": "891593"
},
{
"input": "25\n5704 67795\n6766 31836\n-41715 89987\n76854 9848\n11648 90020\n-79763 10107\n96971 92636\n-64205 71937\n87997 38273\n-9782 57187\n22186 6905\n-41130 40258\n-28403 66579\n19578 43375\n35735 52929\n-52417 89388\n-89430 1939\n9401 43491\n-11228 10112\n-86859 16024\n-51486 33467\n-80578 65080\n-52820 98445\n-89165 7657\n-97106 79422",
"output": "1109655"
},
{
"input": "16\n-41732 47681\n44295 28942\n-75194 99827\n69982 18020\n-75378 22026\n80032 22908\n-34879 41113\n36257 48574\n-35882 84333\n29646 71151\n-86214 80886\n72724 39364\n-42529 60880\n29150 29921\n-8471 80781\n79387 70834",
"output": "847241"
},
{
"input": "3\n-94146 4473\n28707 99079\n-4153 8857",
"output": "112409"
},
{
"input": "3\n-3 3\n-2 2\n-1 1",
"output": "1"
},
{
"input": "2\n100000 3\n-100000 9",
"output": "12"
},
{
"input": "2\n-100000 100000\n100000 99999",
"output": "199999"
}
] | 1,525,613,072 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 77 | 7,065,600 | n = int(input())
pos = []
neg = []
for i in range(n):
line = input().split()
line = [int(i) for i in line]
if line[0] < 0:
neg.append(line)
else:
pos.append(line)
pos.sort()
neg.sort()
if len(pos) == len(neg):
print(sum(n for _, n in pos) + sum(n for _, n in neg))
elif len(pos) > len(neg):
n = len(neg)
print(sum(i for _, i in neg) + sum(pos[i][1] for i in range(n+1)))
else:
n = len(pos)
print(sum(i for _, i in pos) + sum(neg[i][1] for i in range(n+1)))
| Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from the apple trees. Amr currently stands in *x*<==<=0 position. At the beginning, he can choose whether to go right or left. He'll continue in his direction until he meets an apple tree he didn't visit before. He'll take all of its apples and then reverse his direction, continue walking in this direction until he meets another apple tree he didn't visit before and so on. In the other words, Amr reverses his direction when visiting each new apple tree. Amr will stop collecting apples when there are no more trees he didn't visit in the direction he is facing.
What is the maximum number of apples he can collect?
Input Specification:
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guaranteed that there is at most one apple tree at each coordinate. It's guaranteed that no tree grows in point 0.
Output Specification:
Output the maximum number of apples Amr can collect.
Demo Input:
['2\n-1 5\n1 5\n', '3\n-2 2\n1 4\n-1 3\n', '3\n1 9\n3 5\n7 10\n']
Demo Output:
['10', '9', '9']
Note:
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, then the direction will be reversed and Amr goes to the final tree *x* = - 2.
In the third sample test the optimal solution is to go right to *x* = 1, collect apples from there, then the direction will be reversed and Amr will not be able to collect anymore apples because there are no apple trees to his left. | ```python
n = int(input())
pos = []
neg = []
for i in range(n):
line = input().split()
line = [int(i) for i in line]
if line[0] < 0:
neg.append(line)
else:
pos.append(line)
pos.sort()
neg.sort()
if len(pos) == len(neg):
print(sum(n for _, n in pos) + sum(n for _, n in neg))
elif len(pos) > len(neg):
n = len(neg)
print(sum(i for _, i in neg) + sum(pos[i][1] for i in range(n+1)))
else:
n = len(pos)
print(sum(i for _, i in pos) + sum(neg[i][1] for i in range(n+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,687,774,445 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 2,764,800 | n=int(input(''))
for i in range(n):
a,b,c=int(input()),int(input()),int(input())
d=sum(a+b+c)
if d==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
n=int(input(''))
for i in range(n):
a,b,c=int(input()),int(input()),int(input())
d=sum(a+b+c)
if d==0:
print('YES')
else:
print('NO')
``` | -1 |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "NO"
},
{
"input": "256\n16777217",
"output": "NO"
},
{
"input": "4638\n21511044",
"output": "YES\n1"
},
{
"input": "24\n191102976",
"output": "YES\n5"
},
{
"input": "52010\n557556453",
"output": "NO"
},
{
"input": "61703211\n1750753082",
"output": "NO"
},
{
"input": "137\n2571353",
"output": "YES\n2"
},
{
"input": "8758\n1746157336",
"output": "NO"
},
{
"input": "2\n64",
"output": "YES\n5"
},
{
"input": "96\n884736",
"output": "YES\n2"
},
{
"input": "1094841453\n1656354409",
"output": "NO"
},
{
"input": "1154413\n1229512809",
"output": "NO"
},
{
"input": "2442144\n505226241",
"output": "NO"
},
{
"input": "11548057\n1033418098",
"output": "NO"
},
{
"input": "581\n196122941",
"output": "YES\n2"
},
{
"input": "146\n1913781536",
"output": "NO"
},
{
"input": "945916\n1403881488",
"output": "NO"
},
{
"input": "68269\n365689065",
"output": "NO"
},
{
"input": "30\n900",
"output": "YES\n1"
},
{
"input": "6\n1296",
"output": "YES\n3"
},
{
"input": "1470193122\n1420950405",
"output": "NO"
},
{
"input": "90750\n1793111557",
"output": "NO"
},
{
"input": "1950054\n1664545956",
"output": "NO"
},
{
"input": "6767692\n123762320",
"output": "NO"
},
{
"input": "1437134\n1622348229",
"output": "NO"
},
{
"input": "444103\n1806462642",
"output": "NO"
},
{
"input": "2592\n6718464",
"output": "YES\n1"
},
{
"input": "50141\n366636234",
"output": "NO"
},
{
"input": "835\n582182875",
"output": "YES\n2"
},
{
"input": "156604\n902492689",
"output": "NO"
},
{
"input": "27385965\n1742270058",
"output": "NO"
},
{
"input": "3\n9",
"output": "YES\n1"
},
{
"input": "35\n1838265625",
"output": "YES\n5"
},
{
"input": "8\n4096",
"output": "YES\n3"
},
{
"input": "85955\n945811082",
"output": "NO"
},
{
"input": "54958832\n956670209",
"output": "NO"
},
{
"input": "1475381\n1348159738",
"output": "NO"
},
{
"input": "7313241\n413670642",
"output": "NO"
},
{
"input": "582470\n2116368165",
"output": "NO"
},
{
"input": "26859739\n595086170",
"output": "NO"
},
{
"input": "249766393\n1582130",
"output": "NO"
},
{
"input": "11734\n137686756",
"output": "YES\n1"
},
{
"input": "925093\n1098566745",
"output": "NO"
},
{
"input": "40\n1600",
"output": "YES\n1"
},
{
"input": "2147483647\n2147483647",
"output": "YES\n0"
},
{
"input": "2147483646\n2147483647",
"output": "NO"
},
{
"input": "2147483647\n2147483646",
"output": "NO"
},
{
"input": "2\n2147483647",
"output": "NO"
},
{
"input": "2\n1073741825",
"output": "NO"
},
{
"input": "2\n1073741824",
"output": "YES\n29"
},
{
"input": "10000\n10",
"output": "NO"
},
{
"input": "10\n10000",
"output": "YES\n3"
},
{
"input": "10\n2000000000",
"output": "NO"
},
{
"input": "10\n1000000000",
"output": "YES\n8"
},
{
"input": "5\n1808548329",
"output": "NO"
},
{
"input": "2\n2147483646",
"output": "NO"
},
{
"input": "25\n125",
"output": "NO"
},
{
"input": "6\n18",
"output": "NO"
},
{
"input": "5\n30",
"output": "NO"
}
] | 1,441,620,669 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 122 | 0 | a = int(input())
b = int(input())
c = 1
p = 0
d = 0
while c < b:
c = (a**p)
if c == b:
print("YES")
print(str(p - 1))
d = 1
p = p+1
if d == 0:
print("NO") | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million.
Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.
Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
Input Specification:
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
Output Specification:
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
Demo Input:
['5\n25\n', '3\n8\n']
Demo Output:
['YES\n1\n', 'NO\n']
Note:
none | ```python
a = int(input())
b = int(input())
c = 1
p = 0
d = 0
while c < b:
c = (a**p)
if c == b:
print("YES")
print(str(p - 1))
d = 1
p = p+1
if d == 0:
print("NO")
``` | 3 |
|
584 | A | Olesya and Rodion | PROGRAMMING | 1,000 | [
"math"
] | null | null | Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. | The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. | Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. | [
"3 2\n"
] | [
"712"
] | none | 500 | [
{
"input": "3 2",
"output": "222"
},
{
"input": "2 2",
"output": "22"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 3",
"output": "33333"
},
{
"input": "10 7",
"output": "7777777777"
},
{
"input": "2 9",
"output": "99"
},
{
"input": "18 8",
"output": "888888888888888888"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 10",
"output": "-1"
},
{
"input": "100 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "10 2",
"output": "2222222222"
},
{
"input": "18 10",
"output": "111111111111111110"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "7 6",
"output": "6666666"
},
{
"input": "4 4",
"output": "4444"
},
{
"input": "14 7",
"output": "77777777777777"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "2 8",
"output": "88"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "4 3",
"output": "3333"
},
{
"input": "5 9",
"output": "99999"
},
{
"input": "4 8",
"output": "8888"
},
{
"input": "3 4",
"output": "444"
},
{
"input": "9 4",
"output": "444444444"
},
{
"input": "8 10",
"output": "11111110"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "20 3",
"output": "33333333333333333333"
},
{
"input": "15 10",
"output": "111111111111110"
},
{
"input": "31 4",
"output": "4444444444444444444444444444444"
},
{
"input": "18 9",
"output": "999999999999999999"
},
{
"input": "72 4",
"output": "444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "76 8",
"output": "8888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "12 5",
"output": "555555555555"
},
{
"input": "54 5",
"output": "555555555555555555555555555555555555555555555555555555"
},
{
"input": "96 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "15 9",
"output": "999999999999999"
},
{
"input": "100 2",
"output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222"
},
{
"input": "99 3",
"output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"
},
{
"input": "98 4",
"output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"
},
{
"input": "97 5",
"output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "100 6",
"output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "98 8",
"output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888"
},
{
"input": "97 9",
"output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "3 10",
"output": "110"
},
{
"input": "2 4",
"output": "44"
},
{
"input": "2 10",
"output": "10"
},
{
"input": "10 10",
"output": "1111111110"
},
{
"input": "4 10",
"output": "1110"
},
{
"input": "25 10",
"output": "1111111111111111111111110"
},
{
"input": "50 10",
"output": "11111111111111111111111111111111111111111111111110"
},
{
"input": "5 10",
"output": "11110"
},
{
"input": "99 10",
"output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "100 10",
"output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "20 10",
"output": "11111111111111111110"
},
{
"input": "99 7",
"output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
},
{
"input": "89 5",
"output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555"
},
{
"input": "6 10",
"output": "111110"
},
{
"input": "3 8",
"output": "888"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "100 7",
"output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777"
}
] | 1,660,057,694 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 11 | 46 | 0 | x , y = input().split()
if(len(y) > int(x)):
print(-1)
else:
z = int(x) * y
print(z) | Title: Olesya and Rodion
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them.
Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
Input Specification:
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Output Specification:
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
Demo Input:
['3 2\n']
Demo Output:
['712']
Note:
none | ```python
x , y = input().split()
if(len(y) > int(x)):
print(-1)
else:
z = int(x) * y
print(z)
``` | 0 |
|
407 | A | Triangle | PROGRAMMING | 1,600 | [
"brute force",
"geometry",
"implementation",
"math"
] | null | null | There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices. | The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space. | In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value. | [
"1 1\n",
"5 5\n",
"5 10\n"
] | [
"NO\n",
"YES\n2 1\n5 5\n-2 4\n",
"YES\n-10 4\n-2 -2\n1 2\n"
] | none | 500 | [
{
"input": "1 1",
"output": "NO"
},
{
"input": "5 5",
"output": "YES\n2 1\n5 5\n-2 4"
},
{
"input": "5 10",
"output": "YES\n-10 4\n-2 -2\n1 2"
},
{
"input": "2 2",
"output": "NO"
},
{
"input": "5 6",
"output": "NO"
},
{
"input": "5 11",
"output": "NO"
},
{
"input": "10 15",
"output": "YES\n0 0\n6 8\n-12 9"
},
{
"input": "935 938",
"output": "NO"
},
{
"input": "999 1000",
"output": "NO"
},
{
"input": "1000 1000",
"output": "YES\n0 0\n280 960\n-960 280"
},
{
"input": "15 20",
"output": "YES\n0 0\n12 9\n-12 16"
},
{
"input": "20 15",
"output": "YES\n0 0\n12 16\n-12 9"
},
{
"input": "629 865",
"output": "NO"
},
{
"input": "45 872",
"output": "NO"
},
{
"input": "757 582",
"output": "NO"
},
{
"input": "173 588",
"output": "NO"
},
{
"input": "533 298",
"output": "NO"
},
{
"input": "949 360",
"output": "NO"
},
{
"input": "661 175",
"output": "NO"
},
{
"input": "728 299",
"output": "YES\n0 0\n280 672\n-276 115"
},
{
"input": "575 85",
"output": "YES\n0 0\n345 460\n-68 51"
},
{
"input": "385 505",
"output": "YES\n0 0\n231 308\n-404 303"
},
{
"input": "755 865",
"output": "YES\n0 0\n453 604\n-692 519"
},
{
"input": "395 55",
"output": "YES\n0 0\n237 316\n-44 33"
},
{
"input": "600 175",
"output": "YES\n0 0\n168 576\n-168 49"
},
{
"input": "280 210",
"output": "YES\n0 0\n168 224\n-168 126"
},
{
"input": "180 135",
"output": "YES\n0 0\n108 144\n-108 81"
},
{
"input": "140 105",
"output": "YES\n0 0\n84 112\n-84 63"
},
{
"input": "440 330",
"output": "YES\n0 0\n264 352\n-264 198"
},
{
"input": "130 312",
"output": "YES\n0 0\n120 50\n-120 288"
},
{
"input": "65 156",
"output": "YES\n0 0\n60 25\n-60 144"
},
{
"input": "105 140",
"output": "YES\n0 0\n84 63\n-84 112"
},
{
"input": "408 765",
"output": "YES\n0 0\n360 192\n-360 675"
},
{
"input": "195 468",
"output": "YES\n0 0\n180 75\n-180 432"
},
{
"input": "305 949",
"output": "NO"
},
{
"input": "80 60",
"output": "YES\n0 0\n48 64\n-48 36"
},
{
"input": "15 15",
"output": "YES\n0 0\n9 12\n-12 9"
},
{
"input": "120 90",
"output": "YES\n0 0\n72 96\n-72 54"
},
{
"input": "60 80",
"output": "YES\n0 0\n48 36\n-48 64"
},
{
"input": "5 25",
"output": "YES\n0 0\n3 4\n-20 15"
},
{
"input": "5 1000",
"output": "YES\n0 0\n3 4\n-800 600"
},
{
"input": "25 35",
"output": "YES\n0 0\n15 20\n-28 21"
},
{
"input": "25 5",
"output": "YES\n0 0\n15 20\n-4 3"
},
{
"input": "30 40",
"output": "YES\n0 0\n24 18\n-24 32"
},
{
"input": "65 156",
"output": "YES\n0 0\n60 25\n-60 144"
},
{
"input": "455 470",
"output": "YES\n0 0\n273 364\n-376 282"
},
{
"input": "90 120",
"output": "YES\n0 0\n72 54\n-72 96"
},
{
"input": "5 205",
"output": "YES\n0 0\n3 4\n-164 123"
},
{
"input": "111 111",
"output": "YES\n0 0\n36 105\n-105 36"
},
{
"input": "17 17",
"output": "YES\n0 0\n8 15\n-15 8"
},
{
"input": "1000 5",
"output": "YES\n0 0\n600 800\n-4 3"
}
] | 1,646,957,907 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 3 | 46 | 0 | from math import gcd
a, b = map(int, input().split())
g = gcd(a,b)
if g == 1:
print("NO")
quit()
pair = []
for i in range(1,g):
for j in range(i, g):
d2 = i*i + j*j
if d2 == g*g:
pair.append(i)
pair.append(j)
break
if d2 > g*g:
break
if pair != []:
break
pa = [a//g * pair[1], -a//g * pair[0]]
pb = [-b//g * pair[0], -b//g * pair[1]]
if (pa[0] == pb[0]) or (pa[1] == pb[1]):
pa = [-pa[1], pa[0]]
pb = [pb[1], -pb[0]]
if pair:
print("YES")
print(0,0)
print(*pa)
print(*pb)
else:
print("NO") | Title: Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a right triangle with legs of length *a* and *b*. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
Input Specification:
The first line contains two integers *a*,<=*b* (1<=≤<=*a*,<=*b*<=≤<=1000), separated by a single space.
Output Specification:
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
Demo Input:
['1 1\n', '5 5\n', '5 10\n']
Demo Output:
['NO\n', 'YES\n2 1\n5 5\n-2 4\n', 'YES\n-10 4\n-2 -2\n1 2\n']
Note:
none | ```python
from math import gcd
a, b = map(int, input().split())
g = gcd(a,b)
if g == 1:
print("NO")
quit()
pair = []
for i in range(1,g):
for j in range(i, g):
d2 = i*i + j*j
if d2 == g*g:
pair.append(i)
pair.append(j)
break
if d2 > g*g:
break
if pair != []:
break
pa = [a//g * pair[1], -a//g * pair[0]]
pb = [-b//g * pair[0], -b//g * pair[1]]
if (pa[0] == pb[0]) or (pa[1] == pb[1]):
pa = [-pa[1], pa[0]]
pb = [pb[1], -pb[0]]
if pair:
print("YES")
print(0,0)
print(*pa)
print(*pb)
else:
print("NO")
``` | -1 |
|
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01234567890123456789012345678901234567890123456789",
"output": "25"
},
{
"input": "qwertyuioplkjhgfdsazxcvbnmqwertyuioplkjhgfdsazxcvb",
"output": "10"
},
{
"input": "cjw2dwmr10pku4yxohe0wglktd",
"output": "4"
},
{
"input": "6z2tx805jie8cfybwtfqvmlveec3iak5z5u3lu62vbxyqht6",
"output": "13"
},
{
"input": "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1",
"output": "13"
},
{
"input": "hpwn50zgbmct80k9rizjqg40nycgs0acwikjqt11nr6m61krfs",
"output": "8"
},
{
"input": "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc",
"output": "14"
},
{
"input": "2222",
"output": "0"
},
{
"input": "13579",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "0",
"output": "0"
},
{
"input": "a",
"output": "1"
},
{
"input": "y",
"output": "0"
},
{
"input": "w",
"output": "0"
},
{
"input": "oo",
"output": "2"
},
{
"input": "oy",
"output": "1"
},
{
"input": "yo",
"output": "1"
},
{
"input": "yy",
"output": "0"
},
{
"input": "a0",
"output": "1"
},
{
"input": "a9",
"output": "2"
},
{
"input": "y0",
"output": "0"
},
{
"input": "y7",
"output": "1"
},
{
"input": "0a",
"output": "1"
},
{
"input": "3a",
"output": "2"
},
{
"input": "06",
"output": "0"
},
{
"input": "07",
"output": "1"
},
{
"input": "70",
"output": "1"
},
{
"input": "77",
"output": "2"
},
{
"input": "13570",
"output": "4"
},
{
"input": "0000000000011111",
"output": "5"
},
{
"input": "1357",
"output": "4"
},
{
"input": "uuuuuuuuuuuuuuuuuu",
"output": "18"
},
{
"input": "gabieurat",
"output": "5"
}
] | 1,559,379,829 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 0 | s = input()
ans = 0
d = ['a', 'e', 'i', 'o', 'u']
for i in s:
if i in d or i.isdigit() and int(i) % 2 == 0:
ans += 1
print(ans)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.
For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.
To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.
Input Specification:
The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit.
Output Specification:
Print a single integer, the minimum number of cards you must turn over to verify your claim.
Demo Input:
['ee\n', 'z\n', '0ay1\n']
Demo Output:
['2\n', '0\n', '2\n']
Note:
In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.
In the third sample, we need to flip the second and fourth cards. | ```python
s = input()
ans = 0
d = ['a', 'e', 'i', 'o', 'u']
for i in s:
if i in d or i.isdigit() and int(i) % 2 == 0:
ans += 1
print(ans)
``` | 0 |
|
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location. | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4]. | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n21968 5686",
"output": "5686 21968"
},
{
"input": "5\n241218936 -825949895 -84926813 491336344 -872198236",
"output": "-872198236 -825949895 -84926813 491336344 241218936"
},
{
"input": "42\n-557774624 828320986 -345782722 -62979938 -681259411 -945983652 -139095040 832293378 -82572118 432027535 88438103 568183540 961782904 73543295 615958219 -5050584 322982437 -146046730 759453379 129267920 -819827396 -348156048 805080102 390723009 -771277251 -79011872 -592313207 528489973 656201270 -127795621 17284747 145139617 -565641608 83452176 -223074608 545811186 -657981923 -204657836 154779765 -476867246 180386291 202782486",
"output": "202782486 828320986 -476867246 -62979938 -204657836 -945983652 545811186 832293378 83452176 432027535 145139617 568183540 -127795621 73543295 528489973 -5050584 -79011872 -146046730 390723009 129267920 -348156048 -819827396 805080102 759453379 -771277251 322982437 -592313207 615958219 656201270 961782904 17284747 88438103 -565641608 -82572118 -223074608 -139095040 -657981923 -681259411 154779765 -345782722 180386291 -557774624"
},
{
"input": "2\n1 2",
"output": "2 1"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "6 2 4 3 5 1"
},
{
"input": "4\n0 1 2 3",
"output": "3 1 2 0"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10 2 8 4 6 5 7 3 9 1"
},
{
"input": "2\n4 5",
"output": "5 4"
},
{
"input": "2\n1 5",
"output": "5 1"
},
{
"input": "2\n2 5",
"output": "5 2"
},
{
"input": "2\n3 4",
"output": "4 3"
},
{
"input": "2\n10 0",
"output": "0 10"
},
{
"input": "66\n8229 5299 5562 1259 2258 1126 5026 8796 3497 7111 6680 1180 1426 4821 3322 3502 400 2951 4187 417 5234 1266 7525 7648 417 9297 174 670 1790 4121 9737 938 4616 3402 2009 2461 474 3728 327 3353 9773 6818 8781 874 2209 1260 1647 6126 9287 9638 5049 1256 4459 863 1835 4822 6809 348 5053 7784 6927 2140 9173 7817 5095 4184",
"output": "4184 5299 7817 1259 2140 1126 7784 8796 348 7111 4822 1180 863 4821 1256 3502 9638 2951 6126 417 1260 1266 874 7648 6818 9297 3353 670 3728 4121 2461 938 3402 4616 2009 9737 474 1790 327 174 9773 417 8781 7525 2209 5234 1647 4187 9287 400 5049 3322 4459 1426 1835 6680 6809 3497 5053 5026 6927 2258 9173 5562 5095 8229"
}
] | 1,616,740,068 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 452 | 22,323,200 | n=int(input())
a=list(input().split())
k=n//2
for i in range(0,k,2):
a[i],a[n-i-1]=a[n-i-1],a[i]
print(*a) | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Suppose the cubes are numbered from 1 to *n* in their order. Dima performs several steps, on step *i* he reverses the segment of cubes from *i*-th to (*n*<=-<=*i*<=+<=1)-th. He does this while *i*<=≤<=*n*<=-<=*i*<=+<=1.
After performing the operations Dima went away, being very proud of himself. When Timofey returned to his cubes, he understood that their order was changed. Help Timofey as fast as you can and save the holiday — restore the initial order of the cubes using information of their current location.
Input Specification:
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Output Specification:
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique.
Demo Input:
['7\n4 3 7 6 9 1 2\n', '8\n6 1 4 2 5 6 9 2\n']
Demo Output:
['2 3 9 6 7 1 4', '2 1 6 2 5 4 9 6']
Note:
Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing has changed. The final row is [4, 3, 7, 6, 9, 1, 2]. So the answer for this case is row [2, 3, 9, 6, 7, 1, 4]. | ```python
n=int(input())
a=list(input().split())
k=n//2
for i in range(0,k,2):
a[i],a[n-i-1]=a[n-i-1],a[i]
print(*a)
``` | 3 |
|
157 | B | Trace | PROGRAMMING | 1,000 | [
"geometry",
"sortings"
] | null | null | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. | Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. | [
"1\n1\n",
"3\n1 4 2\n"
] | [
"3.1415926536\n",
"40.8407044967\n"
] | In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | 1,000 | [
{
"input": "1\n1",
"output": "3.1415926536"
},
{
"input": "3\n1 4 2",
"output": "40.8407044967"
},
{
"input": "4\n4 1 3 2",
"output": "31.4159265359"
},
{
"input": "4\n100 10 2 1",
"output": "31111.1920484997"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "172.7875959474"
},
{
"input": "1\n1000",
"output": "3141592.6535897931"
},
{
"input": "8\n8 1 7 2 6 3 5 4",
"output": "113.0973355292"
},
{
"input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901",
"output": "298608.3817237098"
},
{
"input": "6\n109 683 214 392 678 10",
"output": "397266.9574170437"
},
{
"input": "2\n151 400",
"output": "431023.3704798660"
},
{
"input": "6\n258 877 696 425 663 934",
"output": "823521.3902487604"
},
{
"input": "9\n635 707 108 234 52 180 910 203 782",
"output": "1100144.9065826489"
},
{
"input": "8\n885 879 891 428 522 176 135 983",
"output": "895488.9947571954"
},
{
"input": "3\n269 918 721",
"output": "1241695.6467754442"
},
{
"input": "7\n920 570 681 428 866 935 795",
"output": "1469640.1849419588"
},
{
"input": "2\n517 331",
"output": "495517.1260654109"
},
{
"input": "2\n457 898",
"output": "1877274.3981158488"
},
{
"input": "8\n872 704 973 612 183 274 739 253",
"output": "1780774.0965755312"
},
{
"input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456",
"output": "1510006.5089479341"
},
{
"input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903",
"output": "1528494.7817143100"
},
{
"input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758",
"output": "1741821.4892636713"
},
{
"input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650",
"output": "1818821.9252031571"
},
{
"input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298",
"output": "1272941.9273080483"
},
{
"input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534",
"output": "2045673.1891262225"
},
{
"input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116",
"output": "1573959.9105970615"
},
{
"input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772",
"output": "1479184.3434235646"
},
{
"input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450",
"output": "1258248.6984672088"
},
{
"input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637",
"output": "1495219.0323274869"
},
{
"input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937",
"output": "1577239.7333274092"
},
{
"input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677",
"output": "1624269.3753516484"
},
{
"input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905",
"output": "1615601.7212203942"
},
{
"input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692",
"output": "1806742.5014501044"
},
{
"input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415",
"output": "1611115.5269110680"
},
{
"input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804",
"output": "1569819.2914796301"
},
{
"input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741",
"output": "2042921.1539616778"
},
{
"input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501",
"output": "1310703.8710041976"
},
{
"input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688",
"output": "1686117.9099228707"
},
{
"input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89",
"output": "1419726.5608617242"
},
{
"input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744",
"output": "1556458.0979239127"
},
{
"input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50",
"output": "1775109.8050211088"
},
{
"input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317",
"output": "1447969.4788174964"
},
{
"input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339",
"output": "1597889.4218394549"
},
{
"input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822",
"output": "1567230.6191330721"
},
{
"input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000",
"output": "298608.3817237098"
}
] | 1,587,569,508 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 280 | 0 | from math import *
n = int(input())
v = [int(i) for i in input().split()]
if len(v) % 2 != 0:
v.append(0)
v.sort()
res = 0
for i in range(1, n+1, 2):
res += v[i]**2 - v[i-1]**2
print("%.10f" % (res * pi))
| Title: Trace
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.
Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Output Specification:
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
Demo Input:
['1\n1\n', '3\n1 4 2\n']
Demo Output:
['3.1415926536\n', '40.8407044967\n']
Note:
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π.
In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π | ```python
from math import *
n = int(input())
v = [int(i) for i in input().split()]
if len(v) % 2 != 0:
v.append(0)
v.sort()
res = 0
for i in range(1, n+1, 2):
res += v[i]**2 - v[i-1]**2
print("%.10f" % (res * pi))
``` | 3 |
|
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting. | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
{
"input": "10 3 4 5",
"output": "3"
},
{
"input": "100 23 15 50",
"output": "2"
},
{
"input": "3119 3515 1021 7",
"output": "11"
},
{
"input": "918 102 1327 1733",
"output": "9"
},
{
"input": "3164 42 430 1309",
"output": "15"
},
{
"input": "3043 317 1141 2438",
"output": "7"
},
{
"input": "26 1 772 2683",
"output": "26"
},
{
"input": "370 2 1 15",
"output": "370"
},
{
"input": "734 12 6 2",
"output": "367"
},
{
"input": "418 18 14 17",
"output": "29"
},
{
"input": "18 16 28 9",
"output": "2"
},
{
"input": "14 6 2 17",
"output": "7"
},
{
"input": "29 27 18 2",
"output": "2"
},
{
"input": "29 12 7 10",
"output": "3"
},
{
"input": "27 23 4 3",
"output": "9"
},
{
"input": "5 14 5 2",
"output": "1"
},
{
"input": "5 17 26 5",
"output": "1"
},
{
"input": "9 1 10 3",
"output": "9"
},
{
"input": "2 19 15 1",
"output": "2"
},
{
"input": "4 6 4 9",
"output": "1"
},
{
"input": "10 6 2 9",
"output": "5"
},
{
"input": "2 2 9 6",
"output": "1"
},
{
"input": "6 2 4 1",
"output": "6"
},
{
"input": "27 24 5 27",
"output": "1"
},
{
"input": "2683 83 26 2709",
"output": "101"
},
{
"input": "728 412 789 158",
"output": "3"
},
{
"input": "3964 4 2916 176",
"output": "991"
},
{
"input": "3399 2035 2 3334",
"output": "683"
},
{
"input": "3455 244 3301 3",
"output": "991"
},
{
"input": "595 2263 3625 1",
"output": "595"
},
{
"input": "4000 1 1 1",
"output": "4000"
},
{
"input": "3999 2 2 3999",
"output": "1"
},
{
"input": "25 6 8 11",
"output": "3"
},
{
"input": "4000 500 1000 2000",
"output": "8"
},
{
"input": "53 10 11 23",
"output": "5"
},
{
"input": "100 100 1 1",
"output": "100"
},
{
"input": "17 3 4 10",
"output": "5"
},
{
"input": "413 101 102 105",
"output": "4"
},
{
"input": "490 4 49 50",
"output": "111"
},
{
"input": "3999 2 3 3",
"output": "1999"
},
{
"input": "8 3 8 4",
"output": "2"
},
{
"input": "5 1 3 3",
"output": "5"
},
{
"input": "100 3 17 22",
"output": "27"
},
{
"input": "4000 2 3 4",
"output": "2000"
},
{
"input": "4000 3 3 5",
"output": "1332"
},
{
"input": "13 4 6 7",
"output": "2"
},
{
"input": "4000 5 2 2",
"output": "2000"
},
{
"input": "3999 2 2 3",
"output": "1999"
},
{
"input": "4000 33 7 3333",
"output": "564"
},
{
"input": "60 33 20 9",
"output": "4"
},
{
"input": "100 9 11 99",
"output": "10"
},
{
"input": "2009 6 8 9",
"output": "334"
}
] | 1,697,217,095 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 93 | 2,150,400 | n, a, b, c = map(int, input().split())
lst = list(set([a, b, c]))
dp = [0] * (n + 1)
dp[0] = 1
for k in range(n + 1):
for i in range(len(lst)):
if (k + lst[i]) <= n and dp[k] != 0:
dp[k + lst[i]] = max(dp[k + lst[i]], dp[k] + 1)
print(dp[n] - 1)
| Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon pieces after the required cutting.
Input Specification:
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Output Specification:
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
Demo Input:
['5 5 3 2\n', '7 5 5 2\n']
Demo Output:
['2\n', '2\n']
Note:
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | ```python
n, a, b, c = map(int, input().split())
lst = list(set([a, b, c]))
dp = [0] * (n + 1)
dp[0] = 1
for k in range(n + 1):
for i in range(len(lst)):
if (k + lst[i]) <= n and dp[k] != 0:
dp[k + lst[i]] = max(dp[k + lst[i]], dp[k] + 1)
print(dp[n] - 1)
``` | 3 |
|
305 | A | Strange Addition | PROGRAMMING | 1,600 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? | The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100). | In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order. | [
"4\n100 10 1 0\n",
"3\n2 70 3\n"
] | [
"4\n0 1 10 100 ",
"2\n2 70 "
] | none | 500 | [
{
"input": "4\n100 10 1 0",
"output": "4\n0 1 10 100 "
},
{
"input": "3\n2 70 3",
"output": "2\n2 70 "
},
{
"input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29",
"output": "4\n0 6 30 100 "
},
{
"input": "50\n20 67 96 6 75 12 37 46 38 86 83 22 10 8 21 2 93 9 81 49 69 52 63 62 70 92 97 40 47 99 16 85 48 77 39 100 28 5 11 44 89 1 19 42 35 27 7 14 88 33",
"output": "3\n1 10 100 "
},
{
"input": "2\n1 2",
"output": "1\n1 "
},
{
"input": "73\n39 66 3 59 40 93 72 34 95 79 83 65 99 57 48 44 82 76 31 21 64 19 53 75 37 16 43 5 47 24 15 22 20 55 45 74 42 10 61 49 23 80 35 62 2 9 67 97 51 81 1 70 88 63 33 25 68 13 69 71 73 6 18 52 41 38 96 46 92 85 14 36 100",
"output": "3\n1 10 100 "
},
{
"input": "15\n74 90 73 47 36 44 81 21 66 92 2 38 62 72 49",
"output": "2\n2 90 "
},
{
"input": "96\n17 10 0 85 57 78 15 99 55 6 7 88 12 95 58 19 47 18 96 82 21 80 97 77 46 31 54 70 23 60 59 100 66 92 51 14 91 25 16 27 44 4 35 98 8 52 24 5 81 29 73 13 61 56 45 75 49 71 94 48 3 76 32 65 72 1 84 36 86 40 83 50 22 33 41 11 26 93 90 43 39 79 89 9 64 68 42 74 87 2 62 34 20 63 67 37",
"output": "4\n0 1 10 100 "
},
{
"input": "5\n23 75 38 47 70",
"output": "1\n23 "
},
{
"input": "12\n89 61 45 92 22 3 94 66 48 21 54 14",
"output": "1\n3 "
},
{
"input": "1\n99",
"output": "1\n99 "
},
{
"input": "1\n0",
"output": "1\n0 "
},
{
"input": "2\n100 1",
"output": "2\n1 100 "
},
{
"input": "3\n1 100 99",
"output": "2\n1 100 "
},
{
"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": "3\n1 10 100 "
},
{
"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 100 0",
"output": "4\n0 1 10 100 "
},
{
"input": "99\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": "2\n1 10 "
},
{
"input": "2\n5 6",
"output": "1\n5 "
},
{
"input": "81\n11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 49 51 52 53 54 55 56 57 58 59 61 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 78 79 81 82 83 84 85 86 87 88 89 91 92 93 94 95 96 97 98 99",
"output": "1\n11 "
},
{
"input": "3\n99 10 6",
"output": "2\n6 10 "
},
{
"input": "4\n11 10 100 3",
"output": "3\n3 10 100 "
},
{
"input": "2\n99 6",
"output": "1\n6 "
},
{
"input": "3\n23 0 100",
"output": "3\n0 23 100 "
},
{
"input": "2\n43 0",
"output": "2\n0 43 "
},
{
"input": "4\n99 0 100 6",
"output": "3\n0 6 100 "
},
{
"input": "1\n100",
"output": "1\n100 "
},
{
"input": "2\n0 100",
"output": "2\n0 100 "
},
{
"input": "3\n0 100 10",
"output": "3\n0 10 100 "
},
{
"input": "3\n0 100 12",
"output": "3\n0 12 100 "
},
{
"input": "3\n0 100 1",
"output": "3\n0 1 100 "
},
{
"input": "4\n0 100 10 1",
"output": "4\n0 1 10 100 "
},
{
"input": "4\n0 100 10 99",
"output": "3\n0 10 100 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "2\n10 12",
"output": "1\n10 "
},
{
"input": "2\n90 9",
"output": "2\n9 90 "
}
] | 1,512,855,441 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 186 | 23,142,400 | def main():
k = int(input())
d = list(map(int,input().split(' ')))
a = set()
b = set()
c = set()
n = set()
zero = False
for di in d:
s = list(str(di))
if di == 0:
zero = True
continue
f = False
if len(s) > 3 and s[3] == '0':
d.add(di)
f = True
elif len(s) > 2 and s[2] == '0':
c.add(di)
f = True
elif len(s) > 1 and s[1] == '0':
b.add(di)
f = True
elif not f:
n.add(di)
se = set()
if len(a) > 0:
se.add(list(a)[0])
if len(b) > 0:
se.add(list(b)[0])
if len(c) > 0:
se.add(list(c)[0])
if len(n) > 0:
se.add(list(n)[0])
if zero:
se.add(0)
print(len(se))
print(' '.join(list(map(str,sorted(list(se))))))
main()
| Title: Strange Addition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.
Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*.
Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?
Input Specification:
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers.
The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
Output Specification:
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers.
If there are multiple solutions, print any of them. You can print the numbers in any order.
Demo Input:
['4\n100 10 1 0\n', '3\n2 70 3\n']
Demo Output:
['4\n0 1 10 100 ', '2\n2 70 ']
Note:
none | ```python
def main():
k = int(input())
d = list(map(int,input().split(' ')))
a = set()
b = set()
c = set()
n = set()
zero = False
for di in d:
s = list(str(di))
if di == 0:
zero = True
continue
f = False
if len(s) > 3 and s[3] == '0':
d.add(di)
f = True
elif len(s) > 2 and s[2] == '0':
c.add(di)
f = True
elif len(s) > 1 and s[1] == '0':
b.add(di)
f = True
elif not f:
n.add(di)
se = set()
if len(a) > 0:
se.add(list(a)[0])
if len(b) > 0:
se.add(list(b)[0])
if len(c) > 0:
se.add(list(c)[0])
if len(n) > 0:
se.add(list(n)[0])
if zero:
se.add(0)
print(len(se))
print(' '.join(list(map(str,sorted(list(se))))))
main()
``` | 0 |
|
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
"output": "QCCYXL"
},
{
"input": "3\nAZID\nEERWBC\nEERWBC",
"output": "EERWBC"
},
{
"input": "3\nHNCGYL\nHNCGYL\nHNCGYL",
"output": "HNCGYL"
},
{
"input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG",
"output": "ZZWZTG"
},
{
"input": "4\nA\nA\nKUDLJMXCSE\nA",
"output": "A"
},
{
"input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW",
"output": "PHBTW"
},
{
"input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN",
"output": "PKUZYTFYWN"
},
{
"input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH",
"output": "HH"
},
{
"input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW",
"output": "W"
},
{
"input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP",
"output": "XBCP"
},
{
"input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS",
"output": "PYPAS"
},
{
"input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC",
"output": "NC"
},
{
"input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI",
"output": "VOCI"
},
{
"input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA",
"output": "HA"
},
{
"input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS",
"output": "G"
},
{
"input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL",
"output": "WL"
}
] | 1,667,455,112 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n=int(input())
has={}
for i in range(n):
x=input()
if x in has:
has[x]=has[x]+1
else:
has[x]=1
x=max(has.values())
for i in has.keys():
if has[i]==x:
print(i)
| Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Output Specification:
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
Demo Input:
['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n']
Demo Output:
['ABC\n', 'A\n']
Note:
none | ```python
n=int(input())
has={}
for i in range(n):
x=input()
if x in has:
has[x]=has[x]+1
else:
has[x]=1
x=max(has.values())
for i in has.keys():
if has[i]==x:
print(i)
``` | 3.9845 |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day. | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\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": "12"
},
{
"input": "1 1\n86399",
"output": "1"
},
{
"input": "6 1200\n86400 86400 86000 86000 86000 86400",
"output": "5"
},
{
"input": "6 1200\n86400 86400 86000 86000 86001 86399",
"output": "6"
},
{
"input": "4 172799\n1 1 86400 0",
"output": "4"
},
{
"input": "4 172799\n0 86400 86399 0",
"output": "4"
},
{
"input": "6 1\n1 1 86400 1 86399 1",
"output": "1"
},
{
"input": "4 1\n86400 86399 86400 86400",
"output": "2"
},
{
"input": "4 1\n86400 86400 0 86400",
"output": "3"
}
] | 1,525,126,027 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 7,065,600 | n, t = map(int,input().split())
l = list(map(int,input().split()))
x = c = y = 0
for i in range(1,n+1):
x = x + 86400 - l[i-1]
y = 86400 * i
if (x > y):
c += 1
print(c)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading.
Help Luba to determine the minimum number of day when she finishes reading.
It is guaranteed that the answer doesn't exceed *n*.
Remember that there are 86400 seconds in a day.
Input Specification:
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Output Specification:
Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*.
Demo Input:
['2 2\n86400 86398\n', '2 86400\n0 86400\n']
Demo Output:
['2\n', '1\n']
Note:
none | ```python
n, t = map(int,input().split())
l = list(map(int,input().split()))
x = c = y = 0
for i in range(1,n+1):
x = x + 86400 - l[i-1]
y = 86400 * i
if (x > y):
c += 1
print(c)
``` | 0 |
|
358 | D | Dima and Hares | PROGRAMMING | 1,800 | [
"dp",
"greedy"
] | null | null | Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to *n* from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?
Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and *n* don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.
Help Inna maximize the total joy the hares radiate. :) | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=3000) — the number of hares. Then three lines follow, each line has *n* integers. The first line contains integers *a*1 *a*2 ... *a**n*. The second line contains *b*1,<=*b*2,<=...,<=*b**n*. The third line contains *c*1,<=*c*2,<=...,<=*c**n*. The following limits are fulfilled: 0<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=105.
Number *a**i* in the first line shows the joy that hare number *i* gets if his adjacent hares are both hungry. Number *b**i* in the second line shows the joy that hare number *i* radiates if he has exactly one full adjacent hare. Number *с**i* in the third line shows the joy that hare number *i* radiates if both his adjacent hares are full. | In a single line, print the maximum possible total joy of the hares Inna can get by feeding them. | [
"4\n1 2 3 4\n4 3 2 1\n0 1 1 0\n",
"7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3\n",
"3\n1 1 1\n1 2 1\n1 1 1\n"
] | [
"13\n",
"44\n",
"4\n"
] | none | 2,000 | [
{
"input": "4\n1 2 3 4\n4 3 2 1\n0 1 1 0",
"output": "13"
},
{
"input": "7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3",
"output": "44"
},
{
"input": "3\n1 1 1\n1 2 1\n1 1 1",
"output": "4"
},
{
"input": "7\n1 3 8 9 3 4 4\n6 0 6 6 1 8 4\n9 6 3 7 8 8 2",
"output": "42"
},
{
"input": "2\n3 5\n9 8\n4 0",
"output": "14"
},
{
"input": "7\n3 6 1 5 4 2 0\n9 7 3 7 2 6 0\n1 6 5 7 5 4 1",
"output": "37"
},
{
"input": "1\n0\n1\n4",
"output": "0"
},
{
"input": "1\n7\n1\n7",
"output": "7"
},
{
"input": "8\n7 3 3 5 9 9 8 1\n8 2 6 6 0 3 8 0\n1 2 5 0 9 4 7 8",
"output": "49"
},
{
"input": "6\n1 2 0 1 6 4\n0 6 1 8 9 8\n4 1 4 3 9 8",
"output": "33"
},
{
"input": "1\n0\n0\n0",
"output": "0"
},
{
"input": "1\n100000\n100000\n100000",
"output": "100000"
}
] | 1,547,795,454 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 614,400 | """
Created on Fri Jan 18 12:23:03 2019
@author: nm57315
"""
n = int(input())
a,b,c = (list(map(int,input().strip().split())) for x in range(3))
d,e = a[0],b[0]
for x in range(1,n):
d,e = max(e+a[x],d+b[x]),max(e+b[x],d+c[x])
print(d) | Title: Dima and Hares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima liked the present he got from Inna very much. He liked the present he got from Seryozha even more.
Dima felt so grateful to Inna about the present that he decided to buy her *n* hares. Inna was very happy. She lined up the hares in a row, numbered them from 1 to *n* from left to right and started feeding them with carrots. Inna was determined to feed each hare exactly once. But in what order should she feed them?
Inna noticed that each hare radiates joy when she feeds it. And the joy of the specific hare depends on whether Inna fed its adjacent hares before feeding it. Inna knows how much joy a hare radiates if it eats when either both of his adjacent hares are hungry, or one of the adjacent hares is full (that is, has been fed), or both of the adjacent hares are full. Please note that hares number 1 and *n* don't have a left and a right-adjacent hare correspondingly, so they can never have two full adjacent hares.
Help Inna maximize the total joy the hares radiate. :)
Input Specification:
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=3000) — the number of hares. Then three lines follow, each line has *n* integers. The first line contains integers *a*1 *a*2 ... *a**n*. The second line contains *b*1,<=*b*2,<=...,<=*b**n*. The third line contains *c*1,<=*c*2,<=...,<=*c**n*. The following limits are fulfilled: 0<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=105.
Number *a**i* in the first line shows the joy that hare number *i* gets if his adjacent hares are both hungry. Number *b**i* in the second line shows the joy that hare number *i* radiates if he has exactly one full adjacent hare. Number *с**i* in the third line shows the joy that hare number *i* radiates if both his adjacent hares are full.
Output Specification:
In a single line, print the maximum possible total joy of the hares Inna can get by feeding them.
Demo Input:
['4\n1 2 3 4\n4 3 2 1\n0 1 1 0\n', '7\n8 5 7 6 1 8 9\n2 7 9 5 4 3 1\n2 3 3 4 1 1 3\n', '3\n1 1 1\n1 2 1\n1 1 1\n']
Demo Output:
['13\n', '44\n', '4\n']
Note:
none | ```python
"""
Created on Fri Jan 18 12:23:03 2019
@author: nm57315
"""
n = int(input())
a,b,c = (list(map(int,input().strip().split())) for x in range(3))
d,e = a[0],b[0]
for x in range(1,n):
d,e = max(e+a[x],d+b[x]),max(e+b[x],d+c[x])
print(d)
``` | 3 |
|
509 | B | Painting Pebbles | PROGRAMMING | 1,300 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one.
In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero. | The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles. | If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .
Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them. | [
"4 4\n1 2 3 4\n",
"5 2\n3 2 4 1 3\n",
"5 4\n3 2 4 3 5\n"
] | [
"YES\n1\n1 4\n1 2 4\n1 2 3 4\n",
"NO\n",
"YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n"
] | none | 0 | [
{
"input": "4 4\n1 2 3 4",
"output": "YES\n1 \n1 1 \n1 1 2 \n1 1 2 3 "
},
{
"input": "5 2\n3 2 4 1 3",
"output": "NO"
},
{
"input": "5 4\n3 2 4 3 5",
"output": "YES\n1 1 1 \n1 1 \n1 1 1 2 \n1 1 1 \n1 1 1 2 3 "
},
{
"input": "4 3\n5 6 7 8",
"output": "YES\n1 1 1 1 1 \n1 1 1 1 1 1 \n1 1 1 1 1 1 2 \n1 1 1 1 1 1 2 3 "
},
{
"input": "5 6\n3 7 2 1 2",
"output": "YES\n1 1 2 \n1 1 2 3 4 5 6 \n1 1 \n1 \n1 1 "
},
{
"input": "9 5\n5 8 7 3 10 1 4 6 3",
"output": "NO"
},
{
"input": "2 1\n7 2",
"output": "NO"
},
{
"input": "87 99\n90 28 93 18 80 94 68 58 72 45 93 72 11 54 54 48 74 63 73 7 4 54 42 67 8 13 89 32 2 26 13 94 28 46 77 95 94 63 60 7 16 55 90 91 97 80 7 97 8 12 1 32 43 20 79 38 48 22 97 11 92 97 100 41 72 2 93 68 26 2 79 36 19 96 31 47 52 21 12 86 90 83 57 1 4 81 87",
"output": "YES\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 5..."
},
{
"input": "5 92\n95 10 4 28 56",
"output": "YES\n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 \n1 1 1 1 1 2 3 4 5 6 \n1 1 1 1 \n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 \n1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43..."
},
{
"input": "96 99\n54 72 100 93 68 36 73 98 79 31 51 88 53 65 69 84 19 65 52 19 62 12 80 45 100 45 78 93 70 56 57 97 21 70 55 15 95 100 51 44 93 1 67 29 4 39 57 82 81 66 66 89 42 18 48 70 81 67 17 62 70 76 79 82 70 26 66 22 16 8 49 23 16 30 46 71 36 20 96 18 53 5 45 5 96 66 95 20 87 3 45 4 47 22 24 7",
"output": "YES\n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 \n1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 5..."
},
{
"input": "56 97\n96 81 39 97 2 75 85 17 9 90 2 31 32 10 42 87 71 100 39 81 2 38 90 81 96 7 57 23 2 25 5 62 22 61 47 94 63 83 91 51 8 93 33 65 38 50 5 64 76 57 96 19 13 100 56 39",
"output": "NO"
},
{
"input": "86 98\n27 94 18 86 16 11 74 59 62 64 37 84 100 4 48 6 37 11 50 73 11 30 87 14 89 55 35 8 99 63 54 16 99 20 40 91 75 18 28 36 31 76 98 40 90 41 83 32 81 61 81 43 5 36 33 35 63 15 86 38 63 27 21 2 68 67 12 55 36 79 93 93 29 5 22 52 100 17 81 50 6 42 59 57 83 20",
"output": "YES\n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 \n1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 4..."
},
{
"input": "21 85\n83 25 85 96 23 80 54 14 71 57 44 88 30 92 90 61 17 80 59 85 12",
"output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 6..."
},
{
"input": "87 71\n44 88 67 57 57 80 69 69 40 32 92 54 64 51 69 54 31 53 29 42 32 85 100 90 46 56 40 46 68 81 60 42 99 89 61 96 48 42 78 95 71 67 30 42 57 82 41 76 29 79 32 62 100 89 81 55 88 90 86 54 54 31 28 67 69 49 45 54 68 77 64 32 60 60 66 66 83 57 56 89 57 82 73 86 60 61 62",
"output": "NO"
},
{
"input": "63 87\n12 63 17 38 52 19 27 26 24 40 43 12 84 99 59 37 37 12 36 88 22 56 55 57 33 64 45 71 85 73 84 38 51 36 14 15 98 68 50 33 92 97 44 79 40 60 43 15 52 58 38 95 74 64 77 79 85 41 59 55 43 29 27",
"output": "YES\n1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \n1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 \n1 ..."
},
{
"input": "39 39\n87 88 86 86 96 70 79 64 85 80 81 74 64 65 90 64 83 78 96 63 78 80 62 62 76 89 69 73 100 100 99 69 69 89 97 64 94 94 71",
"output": "YES\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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \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 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 \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..."
},
{
"input": "100 67\n82 34 100 55 38 32 97 34 100 49 49 41 48 100 74 51 53 50 46 38 35 69 93 61 96 86 43 59 90 45 52 100 48 45 63 60 52 66 83 46 66 47 74 37 56 48 42 88 39 68 38 66 77 40 60 60 92 38 45 57 63 91 85 85 89 53 64 66 99 89 49 54 48 58 94 65 78 34 78 62 95 47 64 50 84 52 98 79 57 69 39 61 92 46 63 45 90 51 79 39",
"output": "NO"
},
{
"input": "100 35\n99 90 67 85 68 67 76 75 77 78 81 85 98 88 70 77 89 87 68 91 83 74 70 65 74 86 82 79 81 93 80 66 93 72 100 99 96 66 89 71 93 80 74 97 73 80 93 81 70 68 80 72 75 70 78 67 73 79 76 75 77 78 85 96 72 84 100 68 77 71 79 91 75 100 67 94 73 79 88 73 92 71 68 66 81 68 81 73 69 75 76 84 70 82 66 83 89 90 79 91",
"output": "YES\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 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 \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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 \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..."
},
{
"input": "100 15\n92 87 87 99 91 87 94 94 97 90 98 90 91 95 99 97 95 100 93 95 92 100 87 87 94 89 90 99 89 99 95 90 89 88 92 97 88 86 86 95 96 92 89 89 86 92 89 89 100 100 95 86 86 97 97 98 89 88 97 89 93 100 99 99 93 92 87 97 91 90 96 86 99 86 87 95 99 100 88 86 86 93 100 88 88 89 94 88 88 95 89 86 99 98 91 97 87 88 100 94",
"output": "YES\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 2 3 4 5 6 \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 \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 ..."
},
{
"input": "17 1\n79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79 79",
"output": "YES\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 \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 \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 \n1 1 1 1 1 1 1 1 1 1 1 1 1 ..."
},
{
"input": "27 2\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53",
"output": "YES\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 \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 \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 \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 \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 ..."
},
{
"input": "48 3\n85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85 85",
"output": "YES\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 \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 \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 ..."
},
{
"input": "1 1\n1",
"output": "YES\n1 "
},
{
"input": "1 100\n1",
"output": "YES\n1 "
}
] | 1,604,160,579 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 109 | 0 | num_pilhas, c_cores = map(int, input().split())
pilhas = list(map(int, input().split()))
# |bi, c - bj, c| ≤ 1
if max(pilhas) - min(pilhas) > c_cores:
print('NO')
else:
print('YES')
for i in range(num_pilhas):
pilhas_colorida = []
for j in range(pilhas[i]):
cor = j % c_cores + 1
pilhas_colorida.append(str(cor))
print(' '.join(pilhas_colorida)) | Title: Painting Pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* piles of pebbles on the table, the *i*-th pile contains *a**i* pebbles. Your task is to paint each pebble using one of the *k* given colors so that for each color *c* and any two piles *i* and *j* the difference between the number of pebbles of color *c* in pile *i* and number of pebbles of color *c* in pile *j* is at most one.
In other words, let's say that *b**i*,<=*c* is the number of pebbles of color *c* in the *i*-th pile. Then for any 1<=≤<=*c*<=≤<=*k*, 1<=≤<=*i*,<=*j*<=≤<=*n* the following condition must be satisfied |*b**i*,<=*c*<=-<=*b**j*,<=*c*|<=≤<=1. It isn't necessary to use all *k* colors: if color *c* hasn't been used in pile *i*, then *b**i*,<=*c* is considered to be zero.
Input Specification:
The first line of the input contains positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100), separated by a space — the number of piles and the number of colors respectively.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) denoting number of pebbles in each of the piles.
Output Specification:
If there is no way to paint the pebbles satisfying the given condition, output "NO" (without quotes) .
Otherwise in the first line output "YES" (without quotes). Then *n* lines should follow, the *i*-th of them should contain *a**i* space-separated integers. *j*-th (1<=≤<=*j*<=≤<=*a**i*) of these integers should be equal to the color of the *j*-th pebble in the *i*-th pile. If there are several possible answers, you may output any of them.
Demo Input:
['4 4\n1 2 3 4\n', '5 2\n3 2 4 1 3\n', '5 4\n3 2 4 3 5\n']
Demo Output:
['YES\n1\n1 4\n1 2 4\n1 2 3 4\n', 'NO\n', 'YES\n1 2 3\n1 3\n1 2 3 4\n1 3 4\n1 1 2 3 4\n']
Note:
none | ```python
num_pilhas, c_cores = map(int, input().split())
pilhas = list(map(int, input().split()))
# |bi, c - bj, c| ≤ 1
if max(pilhas) - min(pilhas) > c_cores:
print('NO')
else:
print('YES')
for i in range(num_pilhas):
pilhas_colorida = []
for j in range(pilhas[i]):
cor = j % c_cores + 1
pilhas_colorida.append(str(cor))
print(' '.join(pilhas_colorida))
``` | 3 |
|
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George. | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98",
"output": "24"
}
] | 1,588,166,507 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 614,400 | n,m = map(int,input().split())
ln = list(map(int,input().split()))
lm = list(set(map(int,input().split())))
used = [0 for i in range(m)]
count = 0
flag = 0
z = 0
for i in ln:
z= 0
flag = 0
for j in lm :
if used[z] == 0 and j>=i:
used[z] = 1
flag = 1
break
z += 1
if flag == 0:
count += 1
print(count) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities.
George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=≥<=*d*), by changing limits on the input data.
However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b*1<=≤<=*b*2...<=≤<=*b**m*<=≤<=106) — the complexities of the problems prepared by George.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['3 5\n1 2 3\n1 2 2 3 3\n', '3 5\n1 2 3\n1 1 1 1 1\n', '3 1\n2 3 4\n1\n']
Demo Output:
['0\n', '2\n', '3\n']
Note:
In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4. | ```python
n,m = map(int,input().split())
ln = list(map(int,input().split()))
lm = list(set(map(int,input().split())))
used = [0 for i in range(m)]
count = 0
flag = 0
z = 0
for i in ln:
z= 0
flag = 0
for j in lm :
if used[z] == 0 and j>=i:
used[z] = 1
flag = 1
break
z += 1
if flag == 0:
count += 1
print(count)
``` | 0 |
|
887 | A | Div. 64 | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. | In the only line given a non-empty binary string *s* with length up to 100. | Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. | [
"100010001\n",
"100\n"
] | [
"yes",
"no"
] | In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | 500 | [
{
"input": "100010001",
"output": "yes"
},
{
"input": "100",
"output": "no"
},
{
"input": "0000001000000",
"output": "yes"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111",
"output": "no"
},
{
"input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
"output": "no"
},
{
"input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111",
"output": "no"
},
{
"input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111",
"output": "yes"
},
{
"input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111",
"output": "yes"
},
{
"input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101",
"output": "yes"
},
{
"input": "000000",
"output": "no"
},
{
"input": "0001000",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "1000000",
"output": "yes"
},
{
"input": "0",
"output": "no"
},
{
"input": "1",
"output": "no"
},
{
"input": "10000000000",
"output": "yes"
},
{
"input": "0000000000",
"output": "no"
},
{
"input": "0010000",
"output": "no"
},
{
"input": "000000011",
"output": "no"
},
{
"input": "000000000",
"output": "no"
},
{
"input": "00000000",
"output": "no"
},
{
"input": "000000000011",
"output": "no"
},
{
"input": "0000000",
"output": "no"
},
{
"input": "00000000011",
"output": "no"
},
{
"input": "000000001",
"output": "no"
},
{
"input": "000000000000000000000000000",
"output": "no"
},
{
"input": "0000001",
"output": "no"
},
{
"input": "00000001",
"output": "no"
},
{
"input": "00000000100",
"output": "no"
},
{
"input": "00000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000",
"output": "no"
},
{
"input": "00001000",
"output": "no"
},
{
"input": "0000000000010",
"output": "no"
},
{
"input": "000000000010",
"output": "no"
},
{
"input": "000000000000010",
"output": "no"
},
{
"input": "0100000",
"output": "no"
},
{
"input": "00010000",
"output": "no"
},
{
"input": "00000000000000000",
"output": "no"
},
{
"input": "00000000000",
"output": "no"
},
{
"input": "000001000",
"output": "no"
},
{
"input": "000000000000",
"output": "no"
},
{
"input": "100000000000000",
"output": "yes"
},
{
"input": "000010000",
"output": "no"
},
{
"input": "00000100",
"output": "no"
},
{
"input": "0001100000",
"output": "no"
},
{
"input": "000000000000000000000000001",
"output": "no"
},
{
"input": "000000100",
"output": "no"
},
{
"input": "0000000000001111111111",
"output": "no"
},
{
"input": "00000010",
"output": "no"
},
{
"input": "0001110000",
"output": "no"
},
{
"input": "0000000000000000000000",
"output": "no"
},
{
"input": "000000010010",
"output": "no"
},
{
"input": "0000100",
"output": "no"
},
{
"input": "0000000001",
"output": "no"
},
{
"input": "000000111",
"output": "no"
},
{
"input": "0000000000000",
"output": "no"
},
{
"input": "000000000000000000",
"output": "no"
},
{
"input": "0000000000000000000000000",
"output": "no"
},
{
"input": "000000000000000",
"output": "no"
},
{
"input": "0010000000000100",
"output": "yes"
},
{
"input": "0000001000",
"output": "no"
},
{
"input": "00000000000000000001",
"output": "no"
},
{
"input": "100000000",
"output": "yes"
},
{
"input": "000000000001",
"output": "no"
},
{
"input": "0000011001",
"output": "no"
},
{
"input": "000",
"output": "no"
},
{
"input": "000000000000000000000",
"output": "no"
},
{
"input": "0000000000011",
"output": "no"
},
{
"input": "0000000000000000",
"output": "no"
},
{
"input": "00000000000000001",
"output": "no"
},
{
"input": "00000000000000",
"output": "no"
},
{
"input": "0000000000000000010",
"output": "no"
},
{
"input": "00000000000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "000011000",
"output": "no"
},
{
"input": "00000011",
"output": "no"
},
{
"input": "0000000000001100",
"output": "no"
},
{
"input": "00000",
"output": "no"
},
{
"input": "000000000000000000000000000111111111111111",
"output": "no"
},
{
"input": "000000010",
"output": "no"
},
{
"input": "00000000111",
"output": "no"
},
{
"input": "000000000000001",
"output": "no"
},
{
"input": "0000000000000011111111111111111",
"output": "no"
},
{
"input": "0000000010",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "00000000010",
"output": "no"
},
{
"input": "101000000000",
"output": "yes"
},
{
"input": "00100000",
"output": "no"
},
{
"input": "00000000000001",
"output": "no"
},
{
"input": "0000000000100",
"output": "no"
},
{
"input": "0000",
"output": "no"
},
{
"input": "00000000000111",
"output": "no"
},
{
"input": "0000000000000011",
"output": "no"
},
{
"input": "0000000000000000000000000000000000000000",
"output": "no"
},
{
"input": "0000000000000010",
"output": "no"
},
{
"input": "0010101010",
"output": "no"
},
{
"input": "0000000000000001",
"output": "no"
},
{
"input": "1010101",
"output": "no"
}
] | 1,573,917,812 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 140 | 0 | arr=input()
if len(arr)>=7:
print('yes')
else:
print('no') | Title: Div. 64
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
Input Specification:
In the only line given a non-empty binary string *s* with length up to 100.
Output Specification:
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
Demo Input:
['100010001\n', '100\n']
Demo Output:
['yes', 'no']
Note:
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: [https://en.wikipedia.org/wiki/Binary_system](https://en.wikipedia.org/wiki/Binary_system) | ```python
arr=input()
if len(arr)>=7:
print('yes')
else:
print('no')
``` | 0 |
|
950 | A | Left-handers, Right-handers and Ambidexters | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. | The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. | Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. | [
"1 4 2\n",
"5 5 5\n",
"0 2 0\n"
] | [
"6\n",
"14\n",
"0\n"
] | In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | 500 | [
{
"input": "1 4 2",
"output": "6"
},
{
"input": "5 5 5",
"output": "14"
},
{
"input": "0 2 0",
"output": "0"
},
{
"input": "30 70 34",
"output": "128"
},
{
"input": "89 32 24",
"output": "112"
},
{
"input": "89 44 77",
"output": "210"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "100 100 100",
"output": "300"
},
{
"input": "1 1 1",
"output": "2"
},
{
"input": "30 70 35",
"output": "130"
},
{
"input": "89 44 76",
"output": "208"
},
{
"input": "0 100 100",
"output": "200"
},
{
"input": "100 0 100",
"output": "200"
},
{
"input": "100 1 100",
"output": "200"
},
{
"input": "1 100 100",
"output": "200"
},
{
"input": "100 100 0",
"output": "200"
},
{
"input": "100 100 1",
"output": "200"
},
{
"input": "1 2 1",
"output": "4"
},
{
"input": "0 0 100",
"output": "100"
},
{
"input": "0 100 0",
"output": "0"
},
{
"input": "100 0 0",
"output": "0"
},
{
"input": "10 8 7",
"output": "24"
},
{
"input": "45 47 16",
"output": "108"
},
{
"input": "59 43 100",
"output": "202"
},
{
"input": "34 1 30",
"output": "62"
},
{
"input": "14 81 1",
"output": "30"
},
{
"input": "53 96 94",
"output": "242"
},
{
"input": "62 81 75",
"output": "218"
},
{
"input": "21 71 97",
"output": "188"
},
{
"input": "49 82 73",
"output": "204"
},
{
"input": "88 19 29",
"output": "96"
},
{
"input": "89 4 62",
"output": "132"
},
{
"input": "58 3 65",
"output": "126"
},
{
"input": "27 86 11",
"output": "76"
},
{
"input": "35 19 80",
"output": "134"
},
{
"input": "4 86 74",
"output": "156"
},
{
"input": "32 61 89",
"output": "182"
},
{
"input": "68 60 98",
"output": "226"
},
{
"input": "37 89 34",
"output": "142"
},
{
"input": "92 9 28",
"output": "74"
},
{
"input": "79 58 98",
"output": "234"
},
{
"input": "35 44 88",
"output": "166"
},
{
"input": "16 24 19",
"output": "58"
},
{
"input": "74 71 75",
"output": "220"
},
{
"input": "83 86 99",
"output": "268"
},
{
"input": "97 73 15",
"output": "176"
},
{
"input": "77 76 73",
"output": "226"
},
{
"input": "48 85 55",
"output": "188"
},
{
"input": "1 2 2",
"output": "4"
},
{
"input": "2 2 2",
"output": "6"
},
{
"input": "2 1 2",
"output": "4"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "3 2 1",
"output": "6"
},
{
"input": "1 2 3",
"output": "6"
},
{
"input": "1 3 2",
"output": "6"
},
{
"input": "2 1 3",
"output": "6"
},
{
"input": "2 3 1",
"output": "6"
},
{
"input": "3 1 2",
"output": "6"
},
{
"input": "99 99 99",
"output": "296"
},
{
"input": "99 99 100",
"output": "298"
},
{
"input": "99 100 99",
"output": "298"
},
{
"input": "99 100 100",
"output": "298"
},
{
"input": "100 99 99",
"output": "298"
},
{
"input": "100 99 100",
"output": "298"
},
{
"input": "100 100 99",
"output": "298"
},
{
"input": "89 32 23",
"output": "110"
},
{
"input": "4 5 0",
"output": "8"
},
{
"input": "3 0 3",
"output": "6"
},
{
"input": "0 0 2",
"output": "2"
},
{
"input": "97 97 0",
"output": "194"
},
{
"input": "1 4 0",
"output": "2"
},
{
"input": "5 2 0",
"output": "4"
},
{
"input": "0 5 10",
"output": "14"
},
{
"input": "0 1 2",
"output": "2"
},
{
"input": "5 2 3",
"output": "10"
},
{
"input": "5 5 0",
"output": "10"
},
{
"input": "0 0 10",
"output": "10"
},
{
"input": "0 1 1",
"output": "2"
},
{
"input": "0 0 1",
"output": "0"
}
] | 1,521,846,466 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 7,065,600 | l, r, a = map(int, input().split())
x = min(l, r)
y = max(l, r)
if (a + x) <= y:
print( ((a+x)*2) )
else:
diff = (a - ((a + x) - y))
if diff == 0:
diff = a // 2
if ((a - diff)//2) > 1 and (( (((x+diff)+((a-diff)//2))*2) )%2) == 0:
print( (((x+diff)+((a-diff)//2))*2) )
else:
print( ((diff+x)*2) )
| Title: Left-handers, Right-handers and Ambidexters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand.
The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.
Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.
Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
Input Specification:
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Output Specification:
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
Demo Input:
['1 4 2\n', '5 5 5\n', '0 2 0\n']
Demo Output:
['6\n', '14\n', '0\n']
Note:
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.
In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand. | ```python
l, r, a = map(int, input().split())
x = min(l, r)
y = max(l, r)
if (a + x) <= y:
print( ((a+x)*2) )
else:
diff = (a - ((a + x) - y))
if diff == 0:
diff = a // 2
if ((a - diff)//2) > 1 and (( (((x+diff)+((a-diff)//2))*2) )%2) == 0:
print( (((x+diff)+((a-diff)//2))*2) )
else:
print( ((diff+x)*2) )
``` | 0 |
|
835 | B | The number on the board | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ. | The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible. | Print the minimum number of digits in which the initial number and *n* can differ. | [
"3\n11\n",
"3\n99\n"
] | [
"1\n",
"0\n"
] | In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | 750 | [
{
"input": "3\n11",
"output": "1"
},
{
"input": "3\n99",
"output": "0"
},
{
"input": "10\n5205602270",
"output": "0"
},
{
"input": "70\n3326631213",
"output": "6"
},
{
"input": "200\n1000000010000000000000000000010000000000000001000001000000000000000000000000000000000000000000000000",
"output": "22"
},
{
"input": "500\n1899337170458531693764539600958943248270674811247191310452938511077656066239840703432499357537079035",
"output": "6"
},
{
"input": "700\n9307216756404590162143344901558545760612901767837570518638460182990196397856220673189163417019781185",
"output": "32"
},
{
"input": "900\n7570423817272967027553082464863962024635217372307919506594193055572300657732661146354209508997483330",
"output": "91"
},
{
"input": "18\n900",
"output": "1"
},
{
"input": "23\n12138",
"output": "1"
},
{
"input": "16\n333",
"output": "2"
},
{
"input": "3\n12",
"output": "0"
},
{
"input": "3\n111",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "17\n89",
"output": "0"
},
{
"input": "18\n99",
"output": "0"
},
{
"input": "42\n97779",
"output": "2"
},
{
"input": "2\n11",
"output": "0"
},
{
"input": "6\n33",
"output": "0"
},
{
"input": "45\n23456",
"output": "5"
},
{
"input": "3\n21",
"output": "0"
},
{
"input": "2\n2",
"output": "0"
},
{
"input": "108\n199999899899",
"output": "3"
},
{
"input": "6\n222",
"output": "0"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "9\n9",
"output": "0"
},
{
"input": "5\n5",
"output": "0"
},
{
"input": "27\n888",
"output": "3"
}
] | 1,684,183,417 | 277 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 0 | k = int(input())
s = input()
z = sum(map(int, s))
ans = 0
ind = 0
while z < k:
x = ord(s[ind]) - ord('0')
ind += 1
if x == 9:
continue
z += 9 - x
ans += 1
print(ans) | Title: The number on the board
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change.
You have to find the minimum number of digits in which these two numbers can differ.
Input Specification:
The first line contains integer *k* (1<=≤<=*k*<=≤<=109).
The second line contains integer *n* (1<=≤<=*n*<=<<=10100000).
There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Output Specification:
Print the minimum number of digits in which the initial number and *n* can differ.
Demo Input:
['3\n11\n', '3\n99\n']
Demo Output:
['1\n', '0\n']
Note:
In the first example, the initial number could be 12.
In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*. | ```python
k = int(input())
s = input()
z = sum(map(int, s))
ans = 0
ind = 0
while z < k:
x = ord(s[ind]) - ord('0')
ind += 1
if x == 9:
continue
z += 9 - x
ans += 1
print(ans)
``` | 0 |
|
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,601,568 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | import math
def inp():
return(int(input()))
def invr():
return(input())
def inlt():
return(list(map(int,input().split())))
def two():
return([int(a) for a in input().split()])
def insr():
s = input()
return(list(s[:len(s) - 1]))
a, b = two()
if a == b:
print(a)
else:
print(1)
| 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
import math
def inp():
return(int(input()))
def invr():
return(input())
def inlt():
return(list(map(int,input().split())))
def two():
return([int(a) for a in input().split()])
def insr():
s = input()
return(list(s[:len(s) - 1]))
a, b = two()
if a == b:
print(a)
else:
print(1)
``` | 3 |
|
964 | A | Splits | PROGRAMMING | 800 | [
"math"
] | null | null | Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits. | The first line contains one integer $n$ ($1 \leq n \leq 10^9$). | Output one integer — the answer to the problem. | [
"7\n",
"8\n",
"9\n"
] | [
"4\n",
"5\n",
"5\n"
] | In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | 500 | [
{
"input": "7",
"output": "4"
},
{
"input": "8",
"output": "5"
},
{
"input": "9",
"output": "5"
},
{
"input": "1",
"output": "1"
},
{
"input": "286",
"output": "144"
},
{
"input": "48",
"output": "25"
},
{
"input": "941",
"output": "471"
},
{
"input": "45154",
"output": "22578"
},
{
"input": "60324",
"output": "30163"
},
{
"input": "91840",
"output": "45921"
},
{
"input": "41909",
"output": "20955"
},
{
"input": "58288",
"output": "29145"
},
{
"input": "91641",
"output": "45821"
},
{
"input": "62258",
"output": "31130"
},
{
"input": "79811",
"output": "39906"
},
{
"input": "88740",
"output": "44371"
},
{
"input": "12351",
"output": "6176"
},
{
"input": "1960",
"output": "981"
},
{
"input": "29239",
"output": "14620"
},
{
"input": "85801",
"output": "42901"
},
{
"input": "43255",
"output": "21628"
},
{
"input": "13439",
"output": "6720"
},
{
"input": "35668",
"output": "17835"
},
{
"input": "19122",
"output": "9562"
},
{
"input": "60169",
"output": "30085"
},
{
"input": "50588",
"output": "25295"
},
{
"input": "2467",
"output": "1234"
},
{
"input": "39315",
"output": "19658"
},
{
"input": "29950",
"output": "14976"
},
{
"input": "17286",
"output": "8644"
},
{
"input": "7359066",
"output": "3679534"
},
{
"input": "1016391",
"output": "508196"
},
{
"input": "7928871",
"output": "3964436"
},
{
"input": "3968891",
"output": "1984446"
},
{
"input": "2636452",
"output": "1318227"
},
{
"input": "5076901",
"output": "2538451"
},
{
"input": "9870265",
"output": "4935133"
},
{
"input": "2453786",
"output": "1226894"
},
{
"input": "7263670",
"output": "3631836"
},
{
"input": "1890845",
"output": "945423"
},
{
"input": "574128507",
"output": "287064254"
},
{
"input": "648476655",
"output": "324238328"
},
{
"input": "97349542",
"output": "48674772"
},
{
"input": "716489761",
"output": "358244881"
},
{
"input": "858771038",
"output": "429385520"
},
{
"input": "520778784",
"output": "260389393"
},
{
"input": "439004204",
"output": "219502103"
},
{
"input": "589992198",
"output": "294996100"
},
{
"input": "371106544",
"output": "185553273"
},
{
"input": "894241590",
"output": "447120796"
},
{
"input": "123957268",
"output": "61978635"
},
{
"input": "234149297",
"output": "117074649"
},
{
"input": "789954052",
"output": "394977027"
},
{
"input": "667978920",
"output": "333989461"
},
{
"input": "154647261",
"output": "77323631"
},
{
"input": "751453521",
"output": "375726761"
},
{
"input": "848862308",
"output": "424431155"
},
{
"input": "323926781",
"output": "161963391"
},
{
"input": "576768825",
"output": "288384413"
},
{
"input": "31293802",
"output": "15646902"
},
{
"input": "2",
"output": "2"
},
{
"input": "1000000000",
"output": "500000001"
},
{
"input": "3",
"output": "2"
}
] | 1,523,975,841 | 1,941 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 77 | 7,065,600 | import math
n = int(input())
s = []
s.append(n)
m = 0
while (m <= n):
m += 2
s.append(math.floor(n/m))
print(len(set(s))) | Title: Splits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a split of $n$ as a nonincreasing sequence of positive integers, the sum of which is $n$.
For example, the following sequences are splits of $8$: $[4, 4]$, $[3, 3, 2]$, $[2, 2, 1, 1, 1, 1]$, $[5, 2, 1]$.
The following sequences aren't splits of $8$: $[1, 7]$, $[5, 4]$, $[11, -3]$, $[1, 1, 4, 1, 1]$.
The weight of a split is the number of elements in the split that are equal to the first element. For example, the weight of the split $[1, 1, 1, 1, 1]$ is $5$, the weight of the split $[5, 5, 3, 3, 3]$ is $2$ and the weight of the split $[9]$ equals $1$.
For a given $n$, find out the number of different weights of its splits.
Input Specification:
The first line contains one integer $n$ ($1 \leq n \leq 10^9$).
Output Specification:
Output one integer — the answer to the problem.
Demo Input:
['7\n', '8\n', '9\n']
Demo Output:
['4\n', '5\n', '5\n']
Note:
In the first sample, there are following possible weights of splits of $7$:
Weight 1: [$\textbf 7$]
Weight 2: [$\textbf 3$, $\textbf 3$, 1]
Weight 3: [$\textbf 2$, $\textbf 2$, $\textbf 2$, 1]
Weight 7: [$\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$, $\textbf 1$] | ```python
import math
n = int(input())
s = []
s.append(n)
m = 0
while (m <= n):
m += 2
s.append(math.floor(n/m))
print(len(set(s)))
``` | 0 |
|
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely. | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once. | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n1000000000",
"output": "1000000000"
},
{
"input": "2 0\n0 0",
"output": "0"
},
{
"input": "2 0\n1000000000 0",
"output": "1000000000"
},
{
"input": "2 0\n0 1000000000",
"output": "1000000000"
},
{
"input": "2 0\n1000000000 1000000000",
"output": "2000000000"
},
{
"input": "2 1\n0 0\n1 2",
"output": "0"
}
] | 1,678,646,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 358 | 8,806,400 | n,m = map(int,input().split())
gold = list(map(int,input().split()))
s = set()
ans = 0
for i in range(m):
a,b = map(int, input().split())
x = min(a,b)
y = max(a,b)
if x not in s:
s.add(x)
ans += gold[x-1]
if y not in s:
s.add(y)
for i in range(1,n+1):
if i not in s:
ans += gold[i-1]
# print(ans)
print(ans) | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.
Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c**i* gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.
The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?
Take a look at the notes if you think you haven't understood the problem completely.
Input Specification:
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
Then *m* lines follow, each containing a pair of numbers (*x**i*,<=*y**i*) which represent that characters *x**i* and *y**i* are friends (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*, *x**i*<=≠<=*y**i*). It is guaranteed that each pair is listed at most once.
Output Specification:
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
Demo Input:
['5 2\n2 5 3 4 8\n1 4\n4 5\n', '10 0\n1 2 3 4 5 6 7 8 9 10\n', '10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n']
Demo Output:
['10\n', '55\n', '15\n']
Note:
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters. | ```python
n,m = map(int,input().split())
gold = list(map(int,input().split()))
s = set()
ans = 0
for i in range(m):
a,b = map(int, input().split())
x = min(a,b)
y = max(a,b)
if x not in s:
s.add(x)
ans += gold[x-1]
if y not in s:
s.add(y)
for i in range(1,n+1):
if i not in s:
ans += gold[i-1]
# print(ans)
print(ans)
``` | 0 |
|
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,635,213,156 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 46,694,400 | n,M = map(int,input().split())
k = list(map(int,input().split()))
k.append(0)
k.append(M)
k.sort()
r = []
l_odd = []
l_even = []
for i in range(1,len(k),2):
s = k[i] - k[i-1]
l_odd.append(s)
for i in range(2,len(k),2):
s = k[i] - k[i-1]
l_even.append(s)
r.append(sum(l_odd))
for i in range(0,len(l_odd)):
s = l_odd[i]
leftlo = l_odd[:i]
rightle = l_even[i:]
l0 = sum(leftlo) + sum(rightle) + s-1
r.append(l0)
for i in range(0,len(l_even)):
s = l_even[i]
leftlo = l_odd[:i]
rightle = l_even[1+i:]
l0 = sum(leftlo) + sum(rightle) + s-1
r.append(l0)
print(max(r))
| 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
n,M = map(int,input().split())
k = list(map(int,input().split()))
k.append(0)
k.append(M)
k.sort()
r = []
l_odd = []
l_even = []
for i in range(1,len(k),2):
s = k[i] - k[i-1]
l_odd.append(s)
for i in range(2,len(k),2):
s = k[i] - k[i-1]
l_even.append(s)
r.append(sum(l_odd))
for i in range(0,len(l_odd)):
s = l_odd[i]
leftlo = l_odd[:i]
rightle = l_even[i:]
l0 = sum(leftlo) + sum(rightle) + s-1
r.append(l0)
for i in range(0,len(l_even)):
s = l_even[i]
leftlo = l_odd[:i]
rightle = l_even[1+i:]
l0 = sum(leftlo) + sum(rightle) + s-1
r.append(l0)
print(max(r))
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,674,030,469 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 31 | 0 |
a,b=map(int,input().split())
if(a>b):
print(b,end=" ")
a=a-b
print(a//2,end=" ")
else:
print(a,end=" ")
b=b-a
print(b//2,end=" ")
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
a,b=map(int,input().split())
if(a>b):
print(b,end=" ")
a=a-b
print(a//2,end=" ")
else:
print(a,end=" ")
b=b-a
print(b//2,end=" ")
``` | 3 |
|
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
{
"input": "1 1000\n1 1000",
"output": "1001"
},
{
"input": "100 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1",
"output": "2"
},
{
"input": "2 7\n6 3\n1 5",
"output": "9"
},
{
"input": "2 100\n99 2\n1 10",
"output": "101"
},
{
"input": "5 5\n1 1\n2 1\n3 1\n4 1\n5 1",
"output": "6"
},
{
"input": "3 7\n1 6\n5 5\n6 1",
"output": "10"
},
{
"input": "2 100\n4 100\n7 99",
"output": "106"
},
{
"input": "2 10\n9 3\n1 4",
"output": "12"
},
{
"input": "2 5\n4 4\n5 4",
"output": "9"
},
{
"input": "2 10\n9 10\n6 11",
"output": "19"
},
{
"input": "2 100\n99 9\n1 10",
"output": "108"
},
{
"input": "2 7\n3 5\n7 4",
"output": "11"
},
{
"input": "4 4\n4 6\n4 8\n1 7\n2 9",
"output": "12"
},
{
"input": "2 1000\n1 2\n1000 1",
"output": "1001"
},
{
"input": "2 20\n1 1\n2 2",
"output": "20"
},
{
"input": "2 20\n10 10\n19 9",
"output": "28"
}
] | 1,578,411,766 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 109 | 512,000 | n,s=map(int,input().split())
t=0
floor=[]
pt=[]
for i in range(0,n):
a,b=map(int,input().split())
floor.append(a)
pt.append(b)
t=s-floor[n-1]
for i in range(n-1,-1,-1):
if i!=n-1:
t += floor[i + 1] - floor[i]
if pt[i]<=t:
continue
elif pt[i]>t:
t=pt[i]
t+=floor[0]
print(t) | Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0.
The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0.
Input Specification:
The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*.
Output Specification:
Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0.
Demo Input:
['3 7\n2 1\n3 8\n5 2\n', '5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n']
Demo Output:
['11\n', '79\n']
Note:
In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: takes 1 second.
7. Pick up passenger 1.
8. Go to floor 0: takes 2 seconds.
This gives a total of 2 + 2 + 4 + 1 + 2 = 11 seconds. | ```python
n,s=map(int,input().split())
t=0
floor=[]
pt=[]
for i in range(0,n):
a,b=map(int,input().split())
floor.append(a)
pt.append(b)
t=s-floor[n-1]
for i in range(n-1,-1,-1):
if i!=n-1:
t += floor[i + 1] - floor[i]
if pt[i]<=t:
continue
elif pt[i]>t:
t=pt[i]
t+=floor[0]
print(t)
``` | 3 |
|
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,594,557,629 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 6,656,000 | s=input()
ans=""
i=0
while(i<len(s)):
if(s[i]=='.'):
ans +=str(0)
i +=1
elif(s[i:i+2]=='-.'):
ans +=str(1)
i +=2
elif(s[i:i+2]=='--'):
ans +=str(2)
i +=2
print(ans) | 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()
ans=""
i=0
while(i<len(s)):
if(s[i]=='.'):
ans +=str(0)
i +=1
elif(s[i:i+2]=='-.'):
ans +=str(1)
i +=2
elif(s[i:i+2]=='--'):
ans +=str(2)
i +=2
print(ans)
``` | 3.925602 |
491 | C | Deciphering | PROGRAMMING | 2,300 | [
"flows",
"graph matchings"
] | null | null | One day Maria Ivanovna found a Sasha's piece of paper with a message dedicated to Olya. Maria Ivanovna wants to know what is there in a message, but unfortunately the message is ciphered. Maria Ivanovna knows that her students usually cipher their messages by replacing each letter of an original message by some another letter. Replacement works in such way that same letters are always replaced with some fixed letter, and different letters are always replaced by different letters.
Maria Ivanovna supposed that the message contains answers to the final exam (since its length is equal to the number of final exam questions). On the other hand she knows that Sasha's answer are not necessary correct. There are *K* possible answers for each questions. Of course, Maria Ivanovna knows correct answers.
Maria Ivanovna decided to decipher message in such way that the number of Sasha's correct answers is maximum possible. She is very busy now, so your task is to help her. | First line contains length of both strings *N* (1<=≤<=*N*<=≤<=2<=000<=000) and an integer *K* — number of possible answers for each of the questions (1<=≤<=*K*<=≤<=52). Answers to the questions are denoted as Latin letters abcde...xyzABCDE...XYZ in the order. For example for *K*<==<=6, possible answers are abcdef and for *K*<==<=30 possible answers are abcde...xyzABCD.
Second line contains a ciphered message string consisting of Latin letters.
Third line contains a correct answers string consisting of Latin letters. | In the first line output maximum possible number of correct Sasha's answers.
In the second line output cipher rule as the string of length *K* where for each letter from the students' cipher (starting from 'a' as mentioned above) there is specified which answer does it correspond to.
If there are several ways to produce maximum answer, output any of them. | [
"10 2\naaabbbaaab\nbbbbabbbbb\n",
"10 2\naaaaaaabbb\nbbbbaaabbb\n",
"9 4\ndacbdacbd\nacbdacbda\n"
] | [
"7\nba\n",
"6\nab\n",
"9\ncdba\n"
] | none | 1,500 | [] | 1,692,341,674 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1692341674.8802922")# 1692341674.880308 | Title: Deciphering
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Maria Ivanovna found a Sasha's piece of paper with a message dedicated to Olya. Maria Ivanovna wants to know what is there in a message, but unfortunately the message is ciphered. Maria Ivanovna knows that her students usually cipher their messages by replacing each letter of an original message by some another letter. Replacement works in such way that same letters are always replaced with some fixed letter, and different letters are always replaced by different letters.
Maria Ivanovna supposed that the message contains answers to the final exam (since its length is equal to the number of final exam questions). On the other hand she knows that Sasha's answer are not necessary correct. There are *K* possible answers for each questions. Of course, Maria Ivanovna knows correct answers.
Maria Ivanovna decided to decipher message in such way that the number of Sasha's correct answers is maximum possible. She is very busy now, so your task is to help her.
Input Specification:
First line contains length of both strings *N* (1<=≤<=*N*<=≤<=2<=000<=000) and an integer *K* — number of possible answers for each of the questions (1<=≤<=*K*<=≤<=52). Answers to the questions are denoted as Latin letters abcde...xyzABCDE...XYZ in the order. For example for *K*<==<=6, possible answers are abcdef and for *K*<==<=30 possible answers are abcde...xyzABCD.
Second line contains a ciphered message string consisting of Latin letters.
Third line contains a correct answers string consisting of Latin letters.
Output Specification:
In the first line output maximum possible number of correct Sasha's answers.
In the second line output cipher rule as the string of length *K* where for each letter from the students' cipher (starting from 'a' as mentioned above) there is specified which answer does it correspond to.
If there are several ways to produce maximum answer, output any of them.
Demo Input:
['10 2\naaabbbaaab\nbbbbabbbbb\n', '10 2\naaaaaaabbb\nbbbbaaabbb\n', '9 4\ndacbdacbd\nacbdacbda\n']
Demo Output:
['7\nba\n', '6\nab\n', '9\ncdba\n']
Note:
none | ```python
print("_RANDOM_GUESS_1692341674.8802922")# 1692341674.880308
``` | 0 |
|
278 | B | New Problem | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is string *s**l**s**l*<=+<=1... *s**r*.
String *x*<==<=*x*1*x*2... *x**p* is lexicographically smaller than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=<<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there exists such number *r* (*r*<=<<=*p*,<=*r*<=<<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=<<=*y**r*<=+<=1. The string characters are compared by their ASCII codes. | The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. | Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title. | [
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n"
] | [
"j\n",
"ab\n"
] | In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,000 | [
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear",
"output": "j"
},
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc",
"output": "ab"
},
{
"input": "1\na",
"output": "b"
},
{
"input": "1\nb",
"output": "a"
},
{
"input": "1\nz",
"output": "a"
},
{
"input": "5\nsplt\nohqykk\nxqpz\nknojbur\npmfm",
"output": "a"
},
{
"input": "2\nrxscdzkkezud\nwjehahqgouqvjienq",
"output": "b"
},
{
"input": "2\nxlaxwpjabtpwddc\ntxwdjmohrrszorrnomc",
"output": "e"
},
{
"input": "1\nepkotfpkkrhhmuipmtdk",
"output": "a"
},
{
"input": "2\nhk\nobsp",
"output": "a"
},
{
"input": "3\nrjnflsbpxqivrcdjptj\nvpojopbwbwbswdu\nrydkiwnugwddcgcrng",
"output": "a"
},
{
"input": "10\nkpmwcdoysw\ngtpr\nkuzoxmiixxbl\ncrgqtuo\njhbplhpklrgwnaugdf\nzuxdaat\naycv\nqwghrkqwkobrgevsjrk\ntdxgc\nlxyzgcmbzulcst",
"output": "ab"
},
{
"input": "30\nwaiphwcqrrinr\no\nqiqehzmgsjdoqd\nkjexeesevrlowxhghq\njudikhzkj\nz\nxo\nlsdzypkfqro\nsshgcxsky\ngecntpcmoojfwp\nsvmytmcfhc\njrsrvsvbaiumlmkptn\ns\nwpcsovfjlyspviflk\nktvyzvddgllht\nszahigtmklglrcocbo\nznligfxkgxzkcfeu\nliryvzmqwhr\nxgrxkgiehxztv\netrjxdczppafly\njrdgajschhwsci\ndoxnxbjwptnimjmsuijx\nzciwkbvrhgsjhrr\nehh\nbzlnmd\nxpbtbpftimnn\nkhbknqbvdkdd\nmldj\nskrvnyz\navptgpjmenfzfxwckmt",
"output": "aa"
},
{
"input": "30\ne\nx\nitaubd\nxcn\nv\nx\ni\nci\naqs\nzbi\nq\ncvdu\na\njos\nqy\nfjf\nnayke\nge\ns\nq\nqwad\ngvz\no\nubn\nnzoc\nh\nwnjwjrf\nt\nbq\nbw",
"output": "l"
},
{
"input": "30\nb\nu\np\nn\nf\nm\nt\ni\nj\nk\np\nh\na\nc\nw\nz\nz\np\nt\nd\no\nw\nu\nq\nl\ny\ni\no\na\nu",
"output": "e"
},
{
"input": "5\nojdfhi\nabcdefghijklmnopqrst\nuvwxyz\nddfhdfhlasjt\nqqq",
"output": "aa"
},
{
"input": "5\ndfijdfhi\nabcdefghijklmnopqrst\nuvwxy\nkopsdfgiopjipw\njty",
"output": "z"
},
{
"input": "5\nzzxpfk\nabcdefghijklmnopqrst\nuvwxz\nsrgkjaskldfkln\nvgnsdfdgfh",
"output": "y"
}
] | 1,591,732,695 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 466 | 2,048,000 | import string
s=' '.join(input()for i in range(int(input())))
alph= string.ascii_lowercase
for i in alph:
if i not in s:print(i);exit()
for i in alph:
for j in alph:
if i+j not in s:print(i+j);exit() | Title: New Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Your task is to find the shortest original title for the new problem. If there are multiple such titles, choose the lexicographically minimum one. Note, that title of the problem can't be an empty string.
A substring *s*[*l*... *r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<==<=*s*1*s*2... *s*|*s*| (where |*s*| is the length of string *s*) is string *s**l**s**l*<=+<=1... *s**r*.
String *x*<==<=*x*1*x*2... *x**p* is lexicographically smaller than string *y*<==<=*y*1*y*2... *y**q*, if either *p*<=<<=*q* and *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**p*<==<=*y**p*, or there exists such number *r* (*r*<=<<=*p*,<=*r*<=<<=*q*), that *x*1<==<=*y*1,<=*x*2<==<=*y*2,<=... ,<=*x**r*<==<=*y**r* and *x**r*<=+<=1<=<<=*y**r*<=+<=1. The string characters are compared by their ASCII codes.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive.
Output Specification:
Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title.
Demo Input:
['5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n', '4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n']
Demo Output:
['j\n', 'ab\n']
Note:
In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | ```python
import string
s=' '.join(input()for i in range(int(input())))
alph= string.ascii_lowercase
for i in alph:
if i not in s:print(i);exit()
for i in alph:
for j in alph:
if i+j not in s:print(i+j);exit()
``` | 3 |
|
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
{
"input": "7\n3 2 1 6 5 7 4",
"output": "8"
},
{
"input": "8\n2 8 3 7 6 9 1 5",
"output": "4"
},
{
"input": "9\n10 5 9 3 8 7 1 2 4",
"output": "6"
},
{
"input": "10\n7 2 3 8 9 6 5 4 1 10",
"output": "11"
},
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n1 2",
"output": "3"
},
{
"input": "3\n2 4 1",
"output": "3"
},
{
"input": "4\n4 2 3 1",
"output": "5"
},
{
"input": "5\n3 1 4 2 5",
"output": "6"
},
{
"input": "6\n1 3 6 7 2 4",
"output": "5"
},
{
"input": "7\n1 5 4 7 2 3 6",
"output": "8"
},
{
"input": "8\n12 1 6 5 2 8 3 4",
"output": "7"
},
{
"input": "9\n3 2 7 5 6 4 1 9 10",
"output": "8"
},
{
"input": "10\n1 7 13 6 5 10 3 8 2 4",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n3",
"output": "1"
},
{
"input": "1\n3000",
"output": "1"
},
{
"input": "2\n2 3",
"output": "1"
},
{
"input": "2\n3000 1",
"output": "2"
}
] | 1,602,926,875 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 1,331,200 | n=int(input())
l=list(map(int,input().split()))
l.sort()
c=1
for i in range(1,max(l)):
if(i not in l):
print(i)
c=0
break
if(c==1):
print(max(l)+1) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.
You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output Specification:
Output the required default value for the next test index.
Demo Input:
['3\n1 7 2\n']
Demo Output:
['3\n']
Note:
none | ```python
n=int(input())
l=list(map(int,input().split()))
l.sort()
c=1
for i in range(1,max(l)):
if(i not in l):
print(i)
c=0
break
if(c==1):
print(max(l)+1)
``` | 3.92752 |
357 | B | Flag Day | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances. | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance. | Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists. | [
"7 3\n1 2 3\n1 4 5\n4 6 7\n",
"9 3\n3 6 9\n2 5 8\n1 4 7\n",
"5 2\n4 1 5\n3 1 2\n"
] | [
"1 2 3 3 2 2 1 \n",
"1 1 1 2 2 2 3 3 3 \n",
"2 3 1 1 3 \n"
] | none | 1,000 | [
{
"input": "7 3\n1 2 3\n1 4 5\n4 6 7",
"output": "1 2 3 3 2 2 1 "
},
{
"input": "9 3\n3 6 9\n2 5 8\n1 4 7",
"output": "1 1 1 2 2 2 3 3 3 "
},
{
"input": "5 2\n4 1 5\n3 1 2",
"output": "2 3 1 1 3 "
},
{
"input": "14 5\n1 5 3\n13 10 11\n6 3 8\n14 9 2\n7 4 12",
"output": "1 3 3 2 2 2 1 1 2 2 3 3 1 1 "
},
{
"input": "14 6\n14 3 13\n10 14 5\n6 2 10\n7 13 9\n12 11 8\n1 4 9",
"output": "2 2 2 3 2 1 2 3 1 3 2 1 3 1 "
},
{
"input": "14 6\n11 13 10\n3 10 14\n2 7 12\n13 1 9\n5 11 4\n8 6 5",
"output": "1 1 2 2 3 2 2 1 3 3 1 3 2 1 "
},
{
"input": "13 5\n13 6 2\n13 3 8\n11 4 7\n10 9 5\n1 12 6",
"output": "3 3 3 2 3 2 3 2 2 1 1 1 1 "
},
{
"input": "14 6\n5 4 8\n5 7 12\n3 6 12\n7 11 14\n10 13 2\n10 1 9",
"output": "3 3 3 2 1 1 3 3 2 1 2 2 2 1 "
},
{
"input": "14 5\n4 13 2\n7 2 11\n6 1 5\n14 12 8\n10 3 9",
"output": "2 3 2 1 3 1 2 3 3 1 1 2 2 1 "
},
{
"input": "14 6\n2 14 5\n3 4 5\n6 13 14\n7 13 12\n8 10 11\n9 6 1",
"output": "1 1 1 2 3 3 3 1 2 2 3 2 1 2 "
},
{
"input": "14 6\n7 14 12\n6 1 12\n13 5 2\n2 3 9\n7 4 11\n5 8 10",
"output": "2 3 2 3 2 1 1 1 1 3 2 3 1 2 "
},
{
"input": "13 6\n8 7 6\n11 7 3\n13 9 3\n12 1 13\n8 10 4\n2 7 5",
"output": "3 1 3 2 3 3 2 1 2 3 1 2 1 "
},
{
"input": "13 5\n8 4 3\n1 9 5\n6 2 11\n12 10 4\n7 10 13",
"output": "1 2 3 2 3 1 3 1 2 1 3 3 2 "
},
{
"input": "20 8\n16 19 12\n13 3 5\n1 5 17\n10 19 7\n8 18 2\n3 11 14\n9 20 12\n4 15 6",
"output": "2 3 2 1 3 3 3 1 1 1 1 3 1 3 2 1 1 2 2 2 "
},
{
"input": "19 7\n10 18 14\n5 9 11\n9 17 7\n3 15 4\n6 8 12\n1 2 18\n13 16 19",
"output": "3 1 1 3 1 1 3 2 2 1 3 3 1 3 2 2 1 2 3 "
},
{
"input": "18 7\n17 4 13\n7 1 6\n16 9 13\n9 2 5\n11 12 17\n14 8 10\n3 15 18",
"output": "2 1 1 2 3 3 1 2 2 3 2 3 3 1 2 1 1 3 "
},
{
"input": "20 7\n8 5 11\n3 19 20\n16 1 17\n9 6 2\n7 18 13\n14 12 18\n10 4 15",
"output": "2 3 1 2 2 2 1 1 1 1 3 1 3 3 3 1 3 2 2 3 "
},
{
"input": "20 7\n6 11 20\n19 5 2\n15 10 12\n3 7 8\n9 1 6\n13 17 18\n14 16 4",
"output": "3 3 1 3 2 1 2 3 2 2 2 3 1 1 1 2 2 3 1 3 "
},
{
"input": "18 7\n15 5 1\n6 11 4\n14 8 17\n11 12 13\n3 8 16\n9 4 7\n2 18 10",
"output": "3 1 1 3 2 1 1 2 2 3 2 1 3 1 1 3 3 2 "
},
{
"input": "19 7\n3 10 8\n17 7 4\n1 19 18\n2 9 5\n12 11 15\n11 14 6\n13 9 16",
"output": "1 1 1 3 3 3 2 3 2 2 2 1 1 1 3 3 1 3 2 "
},
{
"input": "19 7\n18 14 4\n3 11 6\n8 10 7\n10 19 16\n17 13 15\n5 1 14\n12 9 2",
"output": "1 3 1 3 3 3 3 1 2 2 2 1 2 2 3 3 1 1 1 "
},
{
"input": "20 7\n18 7 15\n17 5 20\n9 19 12\n16 13 10\n3 6 1\n3 8 11\n4 2 14",
"output": "3 2 1 1 2 2 2 3 1 3 2 3 2 3 3 1 1 1 2 3 "
},
{
"input": "18 7\n8 4 6\n13 17 3\n9 8 12\n12 16 5\n18 2 7\n11 1 10\n5 15 14",
"output": "2 2 3 2 3 3 3 1 3 3 1 2 1 1 2 1 2 1 "
},
{
"input": "99 37\n40 10 7\n10 3 5\n10 31 37\n87 48 24\n33 47 38\n34 87 2\n2 35 28\n99 28 76\n66 51 97\n72 77 9\n18 17 67\n23 69 98\n58 89 99\n42 44 52\n65 41 80\n70 92 74\n62 88 45\n68 27 61\n6 83 95\n39 85 49\n57 75 77\n59 54 81\n56 20 82\n96 4 53\n90 7 11\n16 43 84\n19 25 59\n68 8 93\n73 94 78\n15 71 79\n26 12 50\n30 32 4\n14 22 29\n46 21 36\n60 55 86\n91 8 63\n13 1 64",
"output": "2 2 1 2 3 1 3 3 3 2 1 2 1 1 1 1 2 1 2 2 2 2 1 3 3 1 2 3 3 3 1 1 1 3 1 3 3 3 1 1 2 1 2 2 3 1 2 2 3 3 2 3 3 2 2 1 3 3 1 1 3 1 1 3 1 1 3 1 2 1 2 1 1 3 1 1 2 3 3 3 3 3 2 3 2 3 1 2 1 2 2 2 2 2 3 1 3 3 2 "
},
{
"input": "99 41\n11 70 20\n57 11 76\n52 11 64\n49 70 15\n19 61 17\n71 77 21\n77 59 39\n37 64 68\n17 84 36\n46 11 90\n35 11 14\n36 25 80\n12 43 48\n18 78 42\n82 94 15\n22 10 84\n63 86 4\n98 86 50\n92 60 9\n73 42 65\n21 5 27\n30 24 23\n7 88 49\n40 97 45\n81 56 17\n79 61 33\n13 3 77\n54 6 28\n99 58 8\n29 95 24\n89 74 32\n51 89 66\n87 91 96\n22 34 38\n1 53 72\n55 97 26\n41 16 44\n2 31 47\n83 67 91\n75 85 69\n93 47 62",
"output": "1 1 1 3 2 2 2 3 3 1 1 1 3 2 3 2 3 1 1 3 3 3 3 2 3 3 1 3 3 1 2 3 3 2 3 1 1 1 3 1 1 3 2 3 3 3 3 3 1 3 3 3 2 1 1 2 3 2 1 2 2 1 1 2 1 2 1 3 3 2 1 3 2 2 1 2 2 2 1 2 1 1 3 2 2 2 1 3 1 2 2 1 2 2 1 3 2 1 1 "
},
{
"input": "99 38\n70 56 92\n61 70 68\n18 92 91\n82 43 55\n37 5 43\n47 27 26\n64 63 40\n20 61 57\n69 80 59\n60 89 50\n33 25 86\n38 15 73\n96 85 90\n3 12 64\n95 23 48\n66 30 9\n38 99 45\n67 88 71\n74 11 81\n28 51 79\n72 92 34\n16 77 31\n65 18 94\n3 41 2\n36 42 81\n22 77 83\n44 24 52\n10 75 97\n54 21 53\n4 29 32\n58 39 98\n46 62 16\n76 5 84\n8 87 13\n6 41 14\n19 21 78\n7 49 93\n17 1 35",
"output": "2 3 2 1 1 3 1 1 3 1 2 3 3 2 2 1 1 2 1 2 2 1 2 2 2 3 2 1 2 2 3 3 1 1 3 1 3 1 2 3 1 2 2 1 2 2 1 3 2 3 2 3 3 1 3 2 1 1 3 1 3 3 2 1 1 1 1 2 1 1 3 2 3 1 2 3 2 3 3 2 3 1 3 2 2 3 2 2 2 3 1 3 3 3 1 1 3 3 3 "
},
{
"input": "98 38\n70 23 73\n73 29 86\n93 82 30\n6 29 10\n7 22 78\n55 61 87\n98 2 12\n11 5 54\n44 56 60\n89 76 50\n37 72 43\n47 41 61\n85 40 38\n48 93 20\n90 64 29\n31 68 25\n83 57 41\n51 90 3\n91 97 66\n96 95 1\n50 84 71\n53 19 5\n45 42 28\n16 17 89\n63 58 15\n26 47 39\n21 24 19\n80 74 38\n14 46 75\n88 65 36\n77 92 33\n17 59 34\n35 69 79\n13 94 39\n8 52 4\n67 27 9\n65 62 18\n81 32 49",
"output": "3 2 1 3 2 1 1 1 3 3 1 3 2 1 3 2 3 3 1 2 2 2 2 3 3 2 2 3 2 3 1 2 3 1 1 3 1 3 1 2 1 2 3 1 1 2 3 3 3 3 2 2 3 3 1 2 3 2 2 3 2 1 1 1 2 3 1 2 2 1 1 2 3 2 3 2 1 3 3 1 1 2 2 2 1 1 3 1 1 3 1 2 1 3 2 1 2 1 "
},
{
"input": "99 42\n61 66 47\n10 47 96\n68 86 67\n21 29 10\n55 44 47\n12 82 4\n45 71 55\n86 3 95\n16 99 93\n14 92 82\n12 59 20\n73 24 8\n79 72 48\n44 87 39\n87 84 97\n47 70 37\n49 77 95\n39 75 28\n75 25 5\n44 41 36\n76 86 78\n73 6 90\n8 22 58\n9 72 63\n81 42 14\n1 21 35\n91 54 15\n30 13 39\n56 89 79\n11 2 76\n19 65 52\n23 85 74\n7 38 24\n57 94 81\n43 34 60\n62 82 27\n69 64 53\n18 32 17\n24 31 88\n51 50 33\n40 80 98\n83 46 26",
"output": "2 3 1 3 3 3 3 3 1 2 2 1 2 3 3 1 3 1 1 2 3 2 1 2 1 3 3 1 1 1 1 2 3 2 1 3 1 1 3 1 1 2 1 2 2 2 3 3 1 2 1 3 3 2 1 2 2 1 3 3 1 1 3 2 2 2 3 1 1 2 3 2 1 3 2 1 2 3 1 2 1 2 1 3 2 2 1 3 3 2 1 1 3 3 3 1 2 3 2 "
}
] | 1,616,218,751 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 623 | 10,240,000 | n , m = list(map (int, input().split()))
cList = [0]*n
for i in range(m) :
x, y, z = list(map (int, input().split()))
r, s, t = cList[x -1], cList[y -1], cList[z -1]
if r > 0 :
s = (r + 1) % 3
t = (r + 2) % 3
if s == 0:
s = 3
elif t == 0:
t = 3
elif s > 0 :
r = (s + 1) % 3
t = (s + 2) % 3
if r == 0:
r = 3
elif t == 0:
t = 3
elif t > 0 :
r = (t + 1) % 3
s = (t + 2) % 3
if s == 0:
s = 3
elif r == 0:
r = 3
elif r == 0 :
r, s, t = 1, 2, 3
cList[x -1], cList[y -1], cList[z -1] = r, s, t
for i in range(n - 1):
print(cList[i], end= " ")
print(cList[n - 1]) | Title: Flag Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland, there is the national holiday coming — the Flag Day. In the honor of this event the president of the country decided to make a big dance party and asked your agency to organize it. He has several conditions:
- overall, there must be *m* dances;- exactly three people must take part in each dance;- each dance must have one dancer in white clothes, one dancer in red clothes and one dancer in blue clothes (these are the colors of the national flag of Berland).
The agency has *n* dancers, and their number can be less than 3*m*. That is, some dancers will probably have to dance in more than one dance. All of your dancers must dance on the party. However, if some dance has two or more dancers from a previous dance, then the current dance stops being spectacular. Your agency cannot allow that to happen, so each dance has at most one dancer who has danced in some previous dance.
You considered all the criteria and made the plan for the *m* dances: each dance had three dancers participating in it. Your task is to determine the clothes color for each of the *n* dancers so that the President's third condition fulfilled: each dance must have a dancer in white, a dancer in red and a dancer in blue. The dancers cannot change clothes between the dances.
Input Specification:
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=105) and *m* (1<=≤<=*m*<=≤<=105) — the number of dancers and the number of dances, correspondingly. Then *m* lines follow, describing the dances in the order of dancing them. The *i*-th line contains three distinct integers — the numbers of the dancers that take part in the *i*-th dance. The dancers are numbered from 1 to *n*. Each dancer takes part in at least one dance.
Output Specification:
Print *n* space-separated integers: the *i*-th number must represent the color of the *i*-th dancer's clothes (1 for white, 2 for red, 3 for blue). If there are multiple valid solutions, print any of them. It is guaranteed that at least one solution exists.
Demo Input:
['7 3\n1 2 3\n1 4 5\n4 6 7\n', '9 3\n3 6 9\n2 5 8\n1 4 7\n', '5 2\n4 1 5\n3 1 2\n']
Demo Output:
['1 2 3 3 2 2 1 \n', '1 1 1 2 2 2 3 3 3 \n', '2 3 1 1 3 \n']
Note:
none | ```python
n , m = list(map (int, input().split()))
cList = [0]*n
for i in range(m) :
x, y, z = list(map (int, input().split()))
r, s, t = cList[x -1], cList[y -1], cList[z -1]
if r > 0 :
s = (r + 1) % 3
t = (r + 2) % 3
if s == 0:
s = 3
elif t == 0:
t = 3
elif s > 0 :
r = (s + 1) % 3
t = (s + 2) % 3
if r == 0:
r = 3
elif t == 0:
t = 3
elif t > 0 :
r = (t + 1) % 3
s = (t + 2) % 3
if s == 0:
s = 3
elif r == 0:
r = 3
elif r == 0 :
r, s, t = 1, 2, 3
cList[x -1], cList[y -1], cList[z -1] = r, s, t
for i in range(n - 1):
print(cList[i], end= " ")
print(cList[n - 1])
``` | 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,634,901,884 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 46 | 4,505,600 | throws = input().split()
player_one = int(throws[0])
player_two = int(throws[1])
def counter(player_one, player_two):
test = []
i = 1
while i <= 6:
if abs(i - player_one) < abs(i - player_two):
test.append(1)
elif abs(i - player_one) > abs(i - player_two):
test.append(2)
elif abs(i - player_one) == abs(i - player_two):
test.append(3)
i += 1
print(' '.join([str(test.count(1)), str(test.count(3)), str(test.count(2))]))
counter(player_one, player_two) | 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
throws = input().split()
player_one = int(throws[0])
player_two = int(throws[1])
def counter(player_one, player_two):
test = []
i = 1
while i <= 6:
if abs(i - player_one) < abs(i - player_two):
test.append(1)
elif abs(i - player_one) > abs(i - player_two):
test.append(2)
elif abs(i - player_one) == abs(i - player_two):
test.append(3)
i += 1
print(' '.join([str(test.count(1)), str(test.count(3)), str(test.count(2))]))
counter(player_one, player_two)
``` | 3 |
|
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 5\n2 6\n2 5\n2 5\n2 4\n2 5",
"output": "Chris"
},
{
"input": "8\n4 1\n2 6\n4 2\n2 5\n5 2\n3 5\n5 2\n1 5",
"output": "Friendship is magic!^^"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "9\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "9\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "10\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "10\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 4\n6 6\n3 2\n1 5\n5 2\n1 5\n1 5\n3 1\n6 5\n4 3\n1 1\n5 1\n3 3\n2 4\n1 5\n3 4\n5 1\n5 5\n2 5\n2 1\n4 3\n6 5\n1 1\n2 1\n1 3\n1 1\n6 4\n4 6\n6 4\n2 1\n2 5\n6 2\n3 4\n5 5\n1 4\n4 6\n3 4\n1 6\n5 1\n4 3\n3 4\n2 2\n1 2\n2 3\n1 3\n4 4\n5 5\n4 5\n4 4\n3 1\n4 5\n2 3\n2 6\n6 5\n6 1\n6 6\n2 3\n6 4\n3 3\n2 5\n4 4\n3 1\n2 4\n6 1\n3 2\n1 3\n5 4\n6 6\n2 5\n5 1\n1 1\n2 5\n6 5\n3 6\n5 6\n4 3\n3 4\n3 4\n6 5\n5 2\n4 2\n1 1\n3 1\n2 6\n1 6\n1 2\n6 1\n3 4\n1 6\n3 1\n5 3\n1 3\n5 6\n2 1\n6 4\n3 1\n1 6\n6 3\n3 3\n4 3",
"output": "Chris"
},
{
"input": "100\n4 1\n3 4\n4 6\n4 5\n6 5\n5 3\n6 2\n6 3\n5 2\n4 5\n1 5\n5 4\n1 4\n4 5\n4 6\n1 6\n4 4\n5 1\n6 4\n6 4\n4 6\n2 3\n6 2\n4 6\n1 4\n2 3\n4 3\n1 3\n6 2\n3 1\n3 4\n2 6\n4 5\n5 4\n2 2\n2 5\n4 1\n2 2\n3 3\n1 4\n5 6\n6 4\n4 2\n6 1\n5 5\n4 1\n2 1\n6 4\n4 4\n4 3\n5 3\n4 5\n5 3\n3 5\n6 3\n1 1\n3 4\n6 3\n6 1\n5 1\n2 4\n4 3\n2 2\n5 5\n1 5\n5 3\n4 6\n1 4\n6 3\n4 3\n2 4\n3 2\n2 4\n3 4\n6 2\n5 6\n1 2\n1 5\n5 5\n2 6\n5 1\n1 6\n5 3\n3 5\n2 6\n4 6\n6 2\n3 1\n5 5\n6 1\n3 6\n4 4\n1 1\n4 6\n5 3\n4 2\n5 1\n3 3\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n6 3\n4 5\n4 3\n5 4\n5 1\n6 3\n4 2\n4 6\n3 1\n2 4\n2 2\n4 6\n5 3\n5 5\n4 2\n6 2\n2 3\n4 4\n6 4\n3 5\n2 4\n2 2\n5 2\n3 5\n2 4\n4 4\n3 5\n6 5\n1 3\n1 6\n2 2\n2 4\n3 2\n5 4\n1 6\n3 4\n4 1\n1 5\n1 4\n5 3\n2 2\n4 5\n6 3\n4 4\n1 1\n4 1\n2 4\n4 1\n4 5\n5 3\n1 1\n1 6\n5 6\n6 6\n4 2\n4 3\n3 4\n3 6\n3 4\n6 5\n3 4\n5 4\n5 1\n5 3\n5 1\n1 2\n2 6\n3 4\n6 5\n4 3\n1 1\n5 5\n5 1\n3 3\n5 2\n1 3\n6 6\n5 6\n1 4\n4 4\n1 4\n3 6\n6 5\n3 3\n3 6\n1 5\n1 2\n3 6\n3 6\n4 1\n5 2\n1 2\n5 2\n3 3\n4 4\n4 2\n6 2\n5 4\n6 1\n6 3",
"output": "Mishka"
},
{
"input": "8\n4 1\n6 2\n4 1\n5 3\n4 1\n5 3\n6 2\n5 3",
"output": "Mishka"
},
{
"input": "5\n3 6\n3 5\n3 5\n1 6\n3 5",
"output": "Chris"
},
{
"input": "4\n4 1\n2 4\n5 3\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "6\n6 3\n5 1\n6 3\n4 3\n4 3\n5 2",
"output": "Mishka"
},
{
"input": "7\n3 4\n1 4\n2 5\n1 6\n1 6\n1 5\n3 4",
"output": "Chris"
},
{
"input": "6\n6 2\n2 5\n5 2\n3 6\n4 3\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "8\n6 1\n5 3\n4 3\n4 1\n5 1\n4 2\n4 2\n4 1",
"output": "Mishka"
},
{
"input": "9\n2 5\n2 5\n1 4\n2 6\n2 4\n2 5\n2 6\n1 5\n2 5",
"output": "Chris"
},
{
"input": "4\n6 2\n2 4\n4 2\n3 6",
"output": "Friendship is magic!^^"
},
{
"input": "9\n5 2\n4 1\n4 1\n5 1\n6 2\n6 1\n5 3\n6 1\n6 2",
"output": "Mishka"
},
{
"input": "8\n2 4\n3 6\n1 6\n1 6\n2 4\n3 4\n3 6\n3 4",
"output": "Chris"
},
{
"input": "6\n5 3\n3 6\n6 2\n1 6\n5 1\n3 5",
"output": "Friendship is magic!^^"
},
{
"input": "6\n5 2\n5 1\n6 1\n5 2\n4 2\n5 1",
"output": "Mishka"
},
{
"input": "5\n1 4\n2 5\n3 4\n2 6\n3 4",
"output": "Chris"
},
{
"input": "4\n6 2\n3 4\n5 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "93\n4 3\n4 1\n4 2\n5 2\n5 3\n6 3\n4 3\n6 2\n6 3\n5 1\n4 2\n4 2\n5 1\n6 2\n6 3\n6 1\n4 1\n6 2\n5 3\n4 3\n4 1\n4 2\n5 2\n6 3\n5 2\n5 2\n6 3\n5 1\n6 2\n5 2\n4 1\n5 2\n5 1\n4 1\n6 1\n5 2\n4 3\n5 3\n5 3\n5 1\n4 3\n4 3\n4 2\n4 1\n6 2\n6 1\n4 1\n5 2\n5 2\n6 2\n5 3\n5 1\n6 2\n5 1\n6 3\n5 2\n6 2\n6 2\n4 2\n5 2\n6 1\n6 3\n6 3\n5 1\n5 1\n4 1\n5 1\n4 3\n5 3\n6 3\n4 1\n4 3\n6 1\n6 1\n4 2\n6 2\n4 2\n5 2\n4 1\n5 2\n4 1\n5 1\n5 2\n5 1\n4 1\n6 3\n6 2\n4 3\n4 1\n5 2\n4 3\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "11\n1 6\n1 6\n2 4\n2 5\n3 4\n1 5\n1 6\n1 5\n1 6\n2 6\n3 4",
"output": "Chris"
},
{
"input": "70\n6 1\n3 6\n4 3\n2 5\n5 2\n1 4\n6 2\n1 6\n4 3\n1 4\n5 3\n2 4\n5 3\n1 6\n5 1\n3 5\n4 2\n2 4\n5 1\n3 5\n6 2\n1 5\n4 2\n2 5\n5 3\n1 5\n4 2\n1 4\n5 2\n2 6\n4 3\n1 5\n6 2\n3 4\n4 2\n3 5\n6 3\n3 4\n5 1\n1 4\n4 2\n1 4\n6 3\n2 6\n5 2\n1 6\n6 1\n2 6\n5 3\n1 5\n5 1\n1 6\n4 1\n1 5\n4 2\n2 4\n5 1\n2 5\n6 3\n1 4\n6 3\n3 6\n5 1\n1 4\n5 3\n3 5\n4 2\n3 4\n6 2\n1 4",
"output": "Friendship is magic!^^"
},
{
"input": "59\n4 1\n5 3\n6 1\n4 2\n5 1\n4 3\n6 1\n5 1\n4 3\n4 3\n5 2\n5 3\n4 1\n6 2\n5 1\n6 3\n6 3\n5 2\n5 2\n6 1\n4 1\n6 1\n4 3\n5 3\n5 3\n4 3\n4 2\n4 2\n6 3\n6 3\n6 1\n4 3\n5 1\n6 2\n6 1\n4 1\n6 1\n5 3\n4 2\n5 1\n6 2\n6 2\n4 3\n5 3\n4 3\n6 3\n5 2\n5 2\n4 3\n5 1\n5 3\n6 1\n6 3\n6 3\n4 3\n5 2\n5 2\n5 2\n4 3",
"output": "Mishka"
},
{
"input": "42\n1 5\n1 6\n1 6\n1 4\n2 5\n3 6\n1 6\n3 4\n2 5\n2 5\n2 4\n1 4\n3 4\n2 4\n2 6\n1 5\n3 6\n2 6\n2 6\n3 5\n1 4\n1 5\n2 6\n3 6\n1 4\n3 4\n2 4\n1 6\n3 4\n2 4\n2 6\n1 6\n1 4\n1 6\n1 6\n2 4\n1 5\n1 6\n2 5\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "78\n4 3\n3 5\n4 3\n1 5\n5 1\n1 5\n4 3\n1 4\n6 3\n1 5\n4 1\n2 4\n4 3\n2 4\n5 1\n3 6\n4 2\n3 6\n6 3\n3 4\n4 3\n3 6\n5 3\n1 5\n4 1\n2 6\n4 2\n2 4\n4 1\n3 5\n5 2\n3 6\n4 3\n2 4\n6 3\n1 6\n4 3\n3 5\n6 3\n2 6\n4 1\n2 4\n6 2\n1 6\n4 2\n1 4\n4 3\n1 4\n4 3\n2 4\n6 2\n3 5\n6 1\n3 6\n5 3\n1 6\n6 1\n2 6\n4 2\n1 5\n6 2\n2 6\n6 3\n2 4\n4 2\n3 5\n6 1\n2 5\n5 3\n2 6\n5 1\n3 6\n4 3\n3 6\n6 3\n2 5\n6 1\n2 6",
"output": "Friendship is magic!^^"
},
{
"input": "76\n4 1\n5 2\n4 3\n5 2\n5 3\n5 2\n6 1\n4 2\n6 2\n5 3\n4 2\n6 2\n4 1\n4 2\n5 1\n5 1\n6 2\n5 2\n5 3\n6 3\n5 2\n4 3\n6 3\n6 1\n4 3\n6 2\n6 1\n4 1\n6 1\n5 3\n4 1\n5 3\n4 2\n5 2\n4 3\n6 1\n6 2\n5 2\n6 1\n5 3\n4 3\n5 1\n5 3\n4 3\n5 1\n5 1\n4 1\n4 1\n4 1\n4 3\n5 3\n6 3\n6 3\n5 2\n6 2\n6 3\n5 1\n6 3\n5 3\n6 1\n5 3\n4 1\n5 3\n6 1\n4 2\n6 2\n4 3\n4 1\n6 2\n4 3\n5 3\n5 2\n5 3\n5 1\n6 3\n5 2",
"output": "Mishka"
},
{
"input": "84\n3 6\n3 4\n2 5\n2 4\n1 6\n3 4\n1 5\n1 6\n3 5\n1 6\n2 4\n2 6\n2 6\n2 4\n3 5\n1 5\n3 6\n3 6\n3 4\n3 4\n2 6\n1 6\n1 6\n3 5\n3 4\n1 6\n3 4\n3 5\n2 4\n2 5\n2 5\n3 5\n1 6\n3 4\n2 6\n2 6\n3 4\n3 4\n2 5\n2 5\n2 4\n3 4\n2 5\n3 4\n3 4\n2 6\n2 6\n1 6\n2 4\n1 5\n3 4\n2 5\n2 5\n3 4\n2 4\n2 6\n2 6\n1 4\n3 5\n3 5\n2 4\n2 5\n3 4\n1 5\n1 5\n2 6\n1 5\n3 5\n2 4\n2 5\n3 4\n2 6\n1 6\n2 5\n3 5\n3 5\n3 4\n2 5\n2 6\n3 4\n1 6\n2 5\n2 6\n1 4",
"output": "Chris"
},
{
"input": "44\n6 1\n1 6\n5 2\n1 4\n6 2\n2 5\n5 3\n3 6\n5 2\n1 6\n4 1\n2 4\n6 1\n3 4\n6 3\n3 6\n4 3\n2 4\n6 1\n3 4\n6 1\n1 6\n4 1\n3 5\n6 1\n3 6\n4 1\n1 4\n4 2\n2 6\n6 1\n2 4\n6 2\n1 4\n6 2\n2 4\n5 2\n3 6\n6 3\n2 6\n5 3\n3 4\n5 3\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "42\n5 3\n5 1\n5 2\n4 1\n6 3\n6 1\n6 2\n4 1\n4 3\n4 1\n5 1\n5 3\n5 1\n4 1\n4 2\n6 1\n6 3\n5 1\n4 1\n4 1\n6 3\n4 3\n6 3\n5 2\n6 1\n4 1\n5 3\n4 3\n5 2\n6 3\n6 1\n5 1\n4 2\n4 3\n5 2\n5 3\n6 3\n5 2\n5 1\n5 3\n6 2\n6 1",
"output": "Mishka"
},
{
"input": "50\n3 6\n2 6\n1 4\n1 4\n1 4\n2 5\n3 4\n3 5\n2 6\n1 6\n3 5\n1 5\n2 6\n2 4\n2 4\n3 5\n1 6\n1 5\n1 5\n1 4\n3 5\n1 6\n3 5\n1 4\n1 5\n1 4\n3 6\n1 6\n1 4\n1 4\n1 4\n1 5\n3 6\n1 6\n1 6\n2 4\n1 5\n2 6\n2 5\n3 5\n3 6\n3 4\n2 4\n2 6\n3 4\n2 5\n3 6\n3 5\n2 4\n2 4",
"output": "Chris"
},
{
"input": "86\n6 3\n2 4\n6 3\n3 5\n6 3\n1 5\n5 2\n2 4\n4 3\n2 6\n4 1\n2 6\n5 2\n1 4\n5 1\n2 4\n4 1\n1 4\n6 2\n3 5\n4 2\n2 4\n6 2\n1 5\n5 3\n2 5\n5 1\n1 6\n6 1\n1 4\n4 3\n3 4\n5 2\n2 4\n5 3\n2 5\n4 3\n3 4\n4 1\n1 5\n6 3\n3 4\n4 3\n3 4\n4 1\n3 4\n5 1\n1 6\n4 2\n1 6\n5 1\n2 4\n5 1\n3 6\n4 1\n1 5\n5 2\n1 4\n4 3\n2 5\n5 1\n1 5\n6 2\n2 6\n4 2\n2 4\n4 1\n2 5\n5 3\n3 4\n5 1\n3 4\n6 3\n3 4\n4 3\n2 6\n6 2\n2 5\n5 2\n3 5\n4 2\n3 6\n6 2\n3 4\n4 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "84\n6 1\n6 3\n6 3\n4 1\n4 3\n4 2\n6 3\n5 3\n6 1\n6 3\n4 3\n5 2\n5 3\n5 1\n6 2\n6 2\n6 1\n4 1\n6 3\n5 2\n4 1\n5 3\n6 3\n4 2\n6 2\n6 3\n4 3\n4 1\n4 3\n5 1\n5 1\n5 1\n4 1\n6 1\n4 3\n6 2\n5 1\n5 1\n6 2\n5 2\n4 1\n6 1\n6 1\n6 3\n6 2\n4 3\n6 3\n6 2\n5 2\n5 1\n4 3\n6 2\n4 1\n6 2\n6 1\n5 2\n5 1\n6 2\n6 1\n5 3\n5 2\n6 1\n6 3\n5 2\n6 1\n6 3\n4 3\n5 1\n6 3\n6 1\n5 3\n4 3\n5 2\n5 1\n6 2\n5 3\n6 1\n5 1\n4 1\n5 1\n5 1\n5 2\n5 2\n5 1",
"output": "Mishka"
},
{
"input": "92\n1 5\n2 4\n3 5\n1 6\n2 5\n1 6\n3 6\n1 6\n2 4\n3 4\n3 4\n3 6\n1 5\n2 5\n1 5\n1 5\n2 6\n2 4\n3 6\n1 4\n1 6\n2 6\n3 4\n2 6\n2 6\n1 4\n3 5\n2 5\n2 6\n1 5\n1 4\n1 5\n3 6\n3 5\n2 5\n1 5\n3 5\n3 6\n2 6\n2 6\n1 5\n3 4\n2 4\n3 6\n2 5\n1 5\n2 4\n1 4\n2 6\n2 6\n2 6\n1 5\n3 6\n3 6\n2 5\n1 4\n2 4\n3 4\n1 5\n2 5\n2 4\n2 5\n3 5\n3 4\n3 6\n2 6\n3 5\n1 4\n3 4\n1 6\n3 6\n2 6\n1 4\n3 6\n3 6\n2 5\n2 6\n1 6\n2 6\n3 5\n2 5\n3 6\n2 5\n2 6\n1 5\n2 4\n1 4\n2 4\n1 5\n2 5\n2 5\n2 6",
"output": "Chris"
},
{
"input": "20\n5 1\n1 4\n4 3\n1 5\n4 2\n3 6\n6 2\n1 6\n4 1\n1 4\n5 2\n3 4\n5 1\n1 6\n5 1\n2 6\n6 3\n2 5\n6 2\n2 4",
"output": "Friendship is magic!^^"
},
{
"input": "100\n4 3\n4 3\n4 2\n4 3\n4 1\n4 3\n5 2\n5 2\n6 2\n4 2\n5 1\n4 2\n5 2\n6 1\n4 1\n6 3\n5 3\n5 1\n5 1\n5 1\n5 3\n6 1\n6 1\n4 1\n5 2\n5 2\n6 1\n6 3\n4 2\n4 1\n5 3\n4 1\n5 3\n5 1\n6 3\n6 3\n6 1\n5 2\n5 3\n5 3\n6 1\n4 1\n6 2\n6 1\n6 2\n6 3\n4 3\n4 3\n6 3\n4 2\n4 2\n5 3\n5 2\n5 2\n4 3\n5 3\n5 2\n4 2\n5 1\n4 2\n5 1\n5 3\n6 3\n5 3\n5 3\n4 2\n4 1\n4 2\n4 3\n6 3\n4 3\n6 2\n6 1\n5 3\n5 2\n4 1\n6 1\n5 2\n6 2\n4 2\n6 3\n4 3\n5 1\n6 3\n5 2\n4 3\n5 3\n5 3\n4 3\n6 3\n4 3\n4 1\n5 1\n6 2\n6 3\n5 3\n6 1\n6 3\n5 3\n6 1",
"output": "Mishka"
},
{
"input": "100\n1 5\n1 4\n1 5\n2 4\n2 6\n3 6\n3 5\n1 5\n2 5\n3 6\n3 5\n1 6\n1 4\n1 5\n1 6\n2 6\n1 5\n3 5\n3 4\n2 6\n2 6\n2 5\n3 4\n1 6\n1 4\n2 4\n1 5\n1 6\n3 5\n1 6\n2 6\n3 5\n1 6\n3 4\n3 5\n1 6\n3 6\n2 4\n2 4\n3 5\n2 6\n1 5\n3 5\n3 6\n2 4\n2 4\n2 6\n3 4\n3 4\n1 5\n1 4\n2 5\n3 4\n1 4\n2 6\n2 5\n2 4\n2 4\n2 5\n1 5\n1 6\n1 5\n1 5\n1 5\n1 6\n3 4\n2 4\n3 5\n3 5\n1 6\n3 5\n1 5\n1 6\n3 6\n3 4\n1 5\n3 5\n3 6\n1 4\n3 6\n1 5\n3 5\n3 6\n3 5\n1 4\n3 4\n2 4\n2 4\n2 5\n3 6\n3 5\n1 5\n2 4\n1 4\n3 4\n1 5\n3 4\n3 6\n3 5\n3 4",
"output": "Chris"
},
{
"input": "100\n4 3\n3 4\n5 1\n2 5\n5 3\n1 5\n6 3\n2 4\n5 2\n2 6\n5 2\n1 5\n6 3\n1 5\n6 3\n3 4\n5 2\n1 5\n6 1\n1 5\n4 2\n3 5\n6 3\n2 6\n6 3\n1 4\n6 2\n3 4\n4 1\n3 6\n5 1\n2 4\n5 1\n3 4\n6 2\n3 5\n4 1\n2 6\n4 3\n2 6\n5 2\n3 6\n6 2\n3 5\n4 3\n1 5\n5 3\n3 6\n4 2\n3 4\n6 1\n3 4\n5 2\n2 6\n5 2\n2 4\n6 2\n3 6\n4 3\n2 4\n4 3\n2 6\n4 2\n3 4\n6 3\n2 4\n6 3\n3 5\n5 2\n1 5\n6 3\n3 6\n4 3\n1 4\n5 2\n1 6\n4 1\n2 5\n4 1\n2 4\n4 2\n2 5\n6 1\n2 4\n6 3\n1 5\n4 3\n2 6\n6 3\n2 6\n5 3\n1 5\n4 1\n1 5\n6 2\n2 5\n5 1\n3 6\n4 3\n3 4",
"output": "Friendship is magic!^^"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n1 3",
"output": "Mishka"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "99\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "99\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n2 1\n2 1\n2 1\n1 4",
"output": "Mishka"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "100\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1\n6 1",
"output": "Chris"
},
{
"input": "100\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6\n1 6",
"output": "Mishka"
},
{
"input": "84\n6 2\n1 5\n6 2\n2 3\n5 5\n1 2\n3 4\n3 4\n6 5\n6 4\n2 5\n4 1\n1 2\n1 1\n1 4\n2 5\n5 6\n6 3\n2 4\n5 5\n2 6\n3 4\n5 1\n3 3\n5 5\n4 6\n4 6\n2 4\n4 1\n5 2\n2 2\n3 6\n3 3\n4 6\n1 1\n2 4\n6 5\n5 2\n6 5\n5 5\n2 5\n6 4\n1 1\n6 2\n3 6\n6 5\n4 4\n1 5\n5 6\n4 4\n3 5\n6 1\n3 4\n1 5\n4 6\n4 6\n4 1\n3 6\n6 2\n1 1\n4 5\n5 4\n5 3\n3 4\n6 4\n1 1\n5 2\n6 5\n6 1\n2 2\n2 4\n3 3\n4 6\n1 3\n6 6\n5 2\n1 6\n6 2\n6 6\n4 1\n3 6\n6 4\n2 3\n3 4",
"output": "Chris"
},
{
"input": "70\n3 4\n2 3\n2 3\n6 5\n6 6\n4 3\n2 3\n3 1\n3 5\n5 6\n1 6\n2 5\n5 3\n2 5\n4 6\n5 1\n6 1\n3 1\n3 3\n5 3\n2 1\n3 3\n6 4\n6 3\n4 3\n4 5\n3 5\n5 5\n5 2\n1 6\n3 4\n5 2\n2 4\n1 6\n4 3\n4 3\n6 2\n1 3\n1 5\n6 1\n3 1\n1 1\n1 3\n2 2\n3 2\n6 4\n1 1\n4 4\n3 1\n4 5\n4 2\n6 3\n4 4\n3 2\n1 2\n2 6\n3 3\n1 5\n1 1\n6 5\n2 2\n3 1\n5 4\n5 2\n6 4\n6 3\n6 6\n6 3\n3 3\n5 4",
"output": "Mishka"
},
{
"input": "56\n6 4\n3 4\n6 1\n3 3\n1 4\n2 3\n1 5\n2 5\n1 5\n5 5\n2 3\n1 1\n3 2\n3 5\n4 6\n4 4\n5 2\n4 3\n3 1\n3 6\n2 3\n3 4\n5 6\n5 2\n5 6\n1 5\n1 5\n4 1\n6 3\n2 2\n2 1\n5 5\n2 1\n4 1\n5 4\n2 5\n4 1\n6 2\n3 4\n4 2\n6 4\n5 4\n4 2\n4 3\n6 2\n6 2\n3 1\n1 4\n3 6\n5 1\n5 5\n3 6\n6 4\n2 3\n6 5\n3 3",
"output": "Mishka"
},
{
"input": "94\n2 4\n6 4\n1 6\n1 4\n5 1\n3 3\n4 3\n6 1\n6 5\n3 2\n2 3\n5 1\n5 3\n1 2\n4 3\n3 2\n2 3\n4 6\n1 3\n6 3\n1 1\n3 2\n4 3\n1 5\n4 6\n3 2\n6 3\n1 6\n1 1\n1 2\n3 5\n1 3\n3 5\n4 4\n4 2\n1 4\n4 5\n1 3\n1 2\n1 1\n5 4\n5 5\n6 1\n2 1\n2 6\n6 6\n4 2\n3 6\n1 6\n6 6\n1 5\n3 2\n1 2\n4 4\n6 4\n4 1\n1 5\n3 3\n1 3\n3 4\n4 4\n1 1\n2 5\n4 5\n3 1\n3 1\n3 6\n3 2\n1 4\n1 6\n6 3\n2 4\n1 1\n2 2\n2 2\n2 1\n5 4\n1 2\n6 6\n2 2\n3 3\n6 3\n6 3\n1 6\n2 3\n2 4\n2 3\n6 6\n2 6\n6 3\n3 5\n1 4\n1 1\n3 5",
"output": "Chris"
},
{
"input": "81\n4 2\n1 2\n2 3\n4 5\n6 2\n1 6\n3 6\n3 4\n4 6\n4 4\n3 5\n4 6\n3 6\n3 5\n3 1\n1 3\n5 3\n3 4\n1 1\n4 1\n1 2\n6 1\n1 3\n6 5\n4 5\n4 2\n4 5\n6 2\n1 2\n2 6\n5 2\n1 5\n2 4\n4 3\n5 4\n1 2\n5 3\n2 6\n6 4\n1 1\n1 3\n3 1\n3 1\n6 5\n5 5\n6 1\n6 6\n5 2\n1 3\n1 4\n2 3\n5 5\n3 1\n3 1\n4 4\n1 6\n6 4\n2 2\n4 6\n4 4\n2 6\n2 4\n2 4\n4 1\n1 6\n1 4\n1 3\n6 5\n5 1\n1 3\n5 1\n1 4\n3 5\n2 6\n1 3\n5 6\n3 5\n4 4\n5 5\n5 6\n4 3",
"output": "Chris"
},
{
"input": "67\n6 5\n3 6\n1 6\n5 3\n5 4\n5 1\n1 6\n1 1\n3 2\n4 4\n3 1\n4 1\n1 5\n5 3\n3 3\n6 4\n2 4\n2 2\n4 3\n1 4\n1 4\n6 1\n1 2\n2 2\n5 1\n6 2\n3 5\n5 5\n2 2\n6 5\n6 2\n4 4\n3 1\n4 2\n6 6\n6 4\n5 1\n2 2\n4 5\n5 5\n4 6\n1 5\n6 3\n4 4\n1 5\n6 4\n3 6\n3 4\n1 6\n2 4\n2 1\n2 5\n6 5\n6 4\n4 1\n3 2\n1 2\n5 1\n5 6\n1 5\n3 5\n3 1\n5 3\n3 2\n5 1\n4 6\n6 6",
"output": "Mishka"
},
{
"input": "55\n6 6\n6 5\n2 2\n2 2\n6 4\n5 5\n6 5\n5 3\n1 3\n2 2\n5 6\n3 3\n3 3\n6 5\n3 5\n5 5\n1 2\n1 1\n4 6\n1 2\n5 5\n6 2\n6 3\n1 2\n5 1\n1 3\n3 3\n4 4\n2 5\n1 1\n5 3\n4 3\n2 2\n4 5\n5 6\n4 5\n6 3\n1 6\n6 4\n3 6\n1 6\n5 2\n6 3\n2 3\n5 5\n4 3\n3 1\n4 2\n1 1\n2 5\n5 3\n2 2\n6 3\n4 5\n2 2",
"output": "Mishka"
},
{
"input": "92\n2 3\n1 3\n2 6\n5 1\n5 5\n3 2\n5 6\n2 5\n3 1\n3 6\n4 5\n2 5\n1 2\n2 3\n6 5\n3 6\n4 4\n6 2\n4 5\n4 4\n5 1\n6 1\n3 4\n3 5\n6 6\n3 2\n6 4\n2 2\n3 5\n6 4\n6 3\n6 6\n3 4\n3 3\n6 1\n5 4\n6 2\n2 6\n5 6\n1 4\n4 6\n6 3\n3 1\n4 1\n6 6\n3 5\n6 3\n6 1\n1 6\n3 2\n6 6\n4 3\n3 4\n1 3\n3 5\n5 3\n6 5\n4 3\n5 5\n4 1\n1 5\n6 4\n2 3\n2 3\n1 5\n1 2\n5 2\n4 3\n3 6\n5 5\n5 4\n1 4\n3 3\n1 6\n5 6\n5 4\n5 3\n1 1\n6 2\n5 5\n2 5\n4 3\n6 6\n5 1\n1 1\n4 6\n4 6\n3 1\n6 4\n2 4\n2 2\n2 1",
"output": "Chris"
},
{
"input": "79\n5 3\n4 6\n3 6\n2 1\n5 2\n2 3\n4 4\n6 2\n2 5\n1 6\n6 6\n2 6\n3 3\n4 5\n6 2\n2 1\n1 5\n5 1\n2 1\n2 6\n5 3\n6 2\n2 6\n2 3\n1 5\n4 4\n6 3\n5 2\n3 2\n1 3\n1 3\n6 3\n2 6\n3 6\n5 3\n4 5\n6 1\n3 5\n3 5\n6 5\n1 5\n4 2\n6 2\n2 3\n4 6\n3 6\n2 5\n4 4\n1 1\n4 6\n2 6\n6 4\n3 2\n4 1\n1 2\n6 4\n5 6\n1 4\n2 2\n5 4\n3 2\n1 2\n2 4\n2 5\n2 1\n3 6\n3 3\n1 1\n2 2\n4 4\n4 5\n3 3\n5 3\n6 2\n4 5\n6 5\n2 5\n5 6\n2 2",
"output": "Chris"
},
{
"input": "65\n1 1\n5 1\n2 2\n5 4\n4 5\n2 5\n3 2\n5 6\n6 3\n1 1\n6 1\n1 5\n1 1\n5 2\n6 4\n1 6\n1 1\n4 3\n2 3\n5 6\n4 4\n6 2\n1 3\n4 3\n1 3\n6 3\n3 5\n4 2\n4 1\n6 1\n3 2\n2 6\n3 2\n3 5\n6 3\n4 3\n1 5\n2 6\n1 3\n4 1\n4 1\n2 5\n2 5\n6 2\n5 3\n3 1\n3 3\n5 1\n2 4\n5 3\n3 3\n1 1\n6 3\n3 3\n5 1\n1 6\n4 5\n6 6\n5 5\n2 5\n4 1\n2 2\n1 4\n1 6\n6 5",
"output": "Mishka"
},
{
"input": "1\n1 1",
"output": "Friendship is magic!^^"
}
] | 1,688,472,801 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 69 | 62 | 0 | q=0
w=0
for _ in range(int(input())):
z,x=map(int,input().split())
if z>x:
q+=1
elif x>z:
w+=1
if q>w:
print("Mishka")
elif w>q:
print("Chris")
else:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner.
In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw.
Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her!
Input Specification:
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively.
Output Specification:
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
Demo Input:
['3\n3 5\n2 1\n4 2\n', '2\n6 1\n1 6\n', '3\n1 5\n3 3\n2 2\n']
Demo Output:
['Mishka', 'Friendship is magic!^^', 'Chris']
Note:
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there is no winner of the next two rounds. The winner of the game is Chris. | ```python
q=0
w=0
for _ in range(int(input())):
z,x=map(int,input().split())
if z>x:
q+=1
elif x>z:
w+=1
if q>w:
print("Mishka")
elif w>q:
print("Chris")
else:
print("Friendship is magic!^^")
``` | 3 |
|
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence. | The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print a single number — the minimum number of moves.
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 or the %I64d specifier. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100\n-77 57 -95 -23 53 -28 82 -83 38 -73 85 28 25 6 -43 4 -10 -30 -9 -92 14 34 -93 61 36 -100 90 -68 28 16 100 -3 97 30 36 -55 62 -62 53 74 -50 -23 67 11 22 -30 -19 83 7 84 43 90 -65 -75 -15 97 90 15 66 2 13 -91 91 -44 46 51 51 -58 95 77 20 30 76 79 91 60 76 2 82 42 -93 94 -57 88 65 -95 -66 100 -9 33 -67 54 -99 97 53 13 54 66 60 -48",
"output": "3459"
}
] | 1,497,428,147 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 998 | 26,009,600 | n_elem = int(input())
numbers = [int(n) for n in input().split()]
numbers.sort()
moves = 0
for x in range(0, n_elem) :
moves += abs((x+1)-numbers[x])
print(moves) | Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You have a sequence of integers *a*1,<=*a*2,<=...,<=*a**n*. In one move, you are allowed to decrease or increase any number by one. Count the minimum number of moves, needed to build a permutation from this sequence.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single number — the minimum number of moves.
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 or the %I64d specifier.
Demo Input:
['2\n3 0\n', '3\n-1 -1 2\n']
Demo Output:
['2\n', '6\n']
Note:
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1).
In the second sample you need 6 moves to build permutation (1, 3, 2). | ```python
n_elem = int(input())
numbers = [int(n) for n in input().split()]
numbers.sort()
moves = 0
for x in range(0, n_elem) :
moves += abs((x+1)-numbers[x])
print(moves)
``` | 3 |
|
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem. | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"output": "11 13"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "10",
"output": "3 7"
},
{
"input": "69",
"output": "34 35"
},
{
"input": "100",
"output": "49 51"
},
{
"input": "57",
"output": "28 29"
},
{
"input": "1000",
"output": "499 501"
},
{
"input": "999",
"output": "499 500"
},
{
"input": "998",
"output": "497 501"
},
{
"input": "997",
"output": "498 499"
},
{
"input": "996",
"output": "497 499"
},
{
"input": "995",
"output": "497 498"
},
{
"input": "994",
"output": "495 499"
},
{
"input": "5",
"output": "2 3"
},
{
"input": "6",
"output": "1 5"
},
{
"input": "8",
"output": "3 5"
},
{
"input": "9",
"output": "4 5"
},
{
"input": "423",
"output": "211 212"
},
{
"input": "876",
"output": "437 439"
},
{
"input": "29",
"output": "14 15"
}
] | 1,594,561,694 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 6,963,200 | n=int(input())
def prime(n):
a=[1]
for i in range(2,n):
for j in range(2,i+1):
if i%j==0:
break
if j==i:
a.append(i)
return a
x=prime(n)
# print(x)
b=[]
for i in range(len(x)):
for j in range(i+1,len(x)):
if x[i]+x[j]==n:
b.append((x[i],x[j]))
print(*max(b)) | Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button (<=+<=) instead of division button (÷) and got sum of numerator and denominator that was equal to *n* instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals *n*. Help Petya deal with this problem.
Input Specification:
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output Specification:
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Demo Input:
['3\n', '4\n', '12\n']
Demo Output:
['1 2\n', '1 3\n', '5 7\n']
Note:
none | ```python
n=int(input())
def prime(n):
a=[1]
for i in range(2,n):
for j in range(2,i+1):
if i%j==0:
break
if j==i:
a.append(i)
return a
x=prime(n)
# print(x)
b=[]
for i in range(len(x)):
for j in range(i+1,len(x)):
if x[i]+x[j]==n:
b.append((x[i],x[j]))
print(*max(b))
``` | 0 |
|
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation. | The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{
"input": "10 6 3",
"output": "<< 3 4 5 (6) 7 8 9 >> "
},
{
"input": "8 5 4",
"output": "1 2 3 4 (5) 6 7 8 "
},
{
"input": "100 10 20",
"output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 >> "
},
{
"input": "100 25 11",
"output": "<< 14 15 16 17 18 19 20 21 22 23 24 (25) 26 27 28 29 30 31 32 33 34 35 36 >> "
},
{
"input": "5 2 1",
"output": "1 (2) 3 >> "
},
{
"input": "5 3 1",
"output": "<< 2 (3) 4 >> "
},
{
"input": "79 35 12",
"output": "<< 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 >> "
},
{
"input": "100 99 5",
"output": "<< 94 95 96 97 98 (99) 100 "
},
{
"input": "100 99 15",
"output": "<< 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 (99) 100 "
},
{
"input": "100 100 17",
"output": "<< 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 (100) "
},
{
"input": "100 35 28",
"output": "<< 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 (35) 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 >> "
},
{
"input": "100 46 38",
"output": "<< 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 >> "
},
{
"input": "100 46 48",
"output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 (46) 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 >> "
},
{
"input": "100 10 100",
"output": "1 2 3 4 5 6 7 8 9 (10) 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 "
},
{
"input": "3 1 1",
"output": "(1) 2 >> "
},
{
"input": "3 2 1",
"output": "1 (2) 3 "
},
{
"input": "17 5 3",
"output": "<< 2 3 4 (5) 6 7 8 >> "
},
{
"input": "3 1 3",
"output": "(1) 2 3 "
},
{
"input": "7 5 1",
"output": "<< 4 (5) 6 >> "
},
{
"input": "5 5 5",
"output": "1 2 3 4 (5) "
},
{
"input": "5 3 5",
"output": "1 2 (3) 4 5 "
}
] | 1,541,174,445 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | def solution(n, p, k):
arr = []
for i in range(1, n+1):
arr.append(i)
string = "(" +str(p) + ")"
if len(arr[:p]) < k:
str1 = ""
for i in range(p-1):
str1 += str(arr[i]) + " "
string = str1 + string
else:
str1 = ""
for i in range(p-k-1, p-1):
str1 += str(arr[i]) + " "
string = str1 + string
if string[0] != '1' and string[0] != '(':
string = "<< " + string
if len(arr[p:]) < k:
str2 = " "
for i in range(arr[p-1], len(arr)):
str2 += str(arr[i]) + " "
string += str2
else:
str2 = " "
for i in range(arr[p-1], p+k):
str2 += str(arr[i]) + " "
string += str2
if string[-2] != str(arr[-1]) and string[-2] != ')':
string += ">>"
print(string)
arr = input().split(" ")
solution(int(arr[0]), int(arr[1]), int(arr[2]))
| Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and when someone clicks the button ">>" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page.
There are some conditions in the navigation:
- If page 1 is in the navigation, the button "<<" must not be printed. - If page *n* is in the navigation, the button ">>" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed.
You can see some examples of the navigations. Make a program that prints the navigation.
Input Specification:
The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*)
Output Specification:
Print the proper navigation. Follow the format of the output from the test samples.
Demo Input:
['17 5 2\n', '6 5 2\n', '6 1 2\n', '6 2 2\n', '9 6 3\n', '10 6 3\n', '8 5 4\n']
Demo Output:
['<< 3 4 (5) 6 7 >> ', '<< 3 4 (5) 6 ', '(1) 2 3 >> ', '1 (2) 3 4 >>', '<< 3 4 5 (6) 7 8 9', '<< 3 4 5 (6) 7 8 9 >>', '1 2 3 4 (5) 6 7 8 ']
Note:
none | ```python
def solution(n, p, k):
arr = []
for i in range(1, n+1):
arr.append(i)
string = "(" +str(p) + ")"
if len(arr[:p]) < k:
str1 = ""
for i in range(p-1):
str1 += str(arr[i]) + " "
string = str1 + string
else:
str1 = ""
for i in range(p-k-1, p-1):
str1 += str(arr[i]) + " "
string = str1 + string
if string[0] != '1' and string[0] != '(':
string = "<< " + string
if len(arr[p:]) < k:
str2 = " "
for i in range(arr[p-1], len(arr)):
str2 += str(arr[i]) + " "
string += str2
else:
str2 = " "
for i in range(arr[p-1], p+k):
str2 += str(arr[i]) + " "
string += str2
if string[-2] != str(arr[-1]) and string[-2] != ')':
string += ">>"
print(string)
arr = input().split(" ")
solution(int(arr[0]), int(arr[1]), int(arr[2]))
``` | 0 |
|
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification. | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n"
] | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000",
"output": "30234919"
},
{
"input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011",
"output": "65264629"
},
{
"input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001",
"output": "98484434"
},
{
"input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001",
"output": "96071437"
},
{
"input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001",
"output": "89787267"
},
{
"input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110",
"output": "88447623"
},
{
"input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001",
"output": "80805519"
},
{
"input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110",
"output": "09250147"
},
{
"input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011",
"output": "40862358"
},
{
"input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001",
"output": "73907059"
},
{
"input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101",
"output": "57680434"
},
{
"input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010",
"output": "93678590"
},
{
"input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000",
"output": "58114879"
},
{
"input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100",
"output": "61146904"
},
{
"input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001",
"output": "23558422"
},
{
"input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111",
"output": "76827631"
},
{
"input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111",
"output": "26240666"
},
{
"input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100",
"output": "21067271"
},
{
"input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010",
"output": "77770029"
},
{
"input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011",
"output": "09448580"
},
{
"input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111",
"output": "99411277"
},
{
"input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110",
"output": "86658594"
},
{
"input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000",
"output": "04536863"
},
{
"input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110",
"output": "21066773"
},
{
"input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111",
"output": "01063858"
},
{
"input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000",
"output": "01599791"
},
{
"input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010",
"output": "40579016"
},
{
"input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001",
"output": "75424967"
},
{
"input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001",
"output": "72259657"
},
{
"input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011",
"output": "22339256"
},
{
"input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110",
"output": "70554591"
},
{
"input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011",
"output": "18124952"
},
{
"input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110",
"output": "33774052"
},
{
"input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000",
"output": "97961250"
},
{
"input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011",
"output": "21954161"
},
{
"input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100",
"output": "78740192"
},
{
"input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111",
"output": "05336882"
},
{
"input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111",
"output": "62020383"
},
{
"input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101",
"output": "24819275"
},
{
"input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001",
"output": "90010504"
},
{
"input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111",
"output": "85948866"
},
{
"input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110",
"output": "77874864"
},
{
"input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011",
"output": "10374003"
},
{
"input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001",
"output": "22955387"
},
{
"input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100",
"output": "25893541"
},
{
"input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010",
"output": "13805878"
},
{
"input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010",
"output": "06369030"
},
{
"input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110",
"output": "46909115"
},
{
"input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100",
"output": "90005541"
}
] | 1,483,183,075 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 186 | 4,608,000 | password = input()
num = []
pas = []
for i in range(10): num.append(input())
while password != '':
item = password[:10]
password = password[10:]
pas.append(num.index(item))
for i in range(8):
print(pas[i], end='')
| Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".
Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.
Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.
Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
Input Specification:
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Output Specification:
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
Demo Input:
['01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n', '10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n']
Demo Output:
['12345678\n', '30234919\n']
Note:
none | ```python
password = input()
num = []
pas = []
for i in range(10): num.append(input())
while password != '':
item = password[:10]
password = password[10:]
pas.append(num.index(item))
for i in range(8):
print(pas[i], end='')
``` | 3.944917 |
934 | B | A Prosperous Lot | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. | The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops. | Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018. | [
"2\n",
"6\n"
] | [
"462",
"8080"
] | none | 1,000 | [
{
"input": "2",
"output": "8"
},
{
"input": "6",
"output": "888"
},
{
"input": "3",
"output": "86"
},
{
"input": "4",
"output": "88"
},
{
"input": "5",
"output": "886"
},
{
"input": "1000000",
"output": "-1"
},
{
"input": "1",
"output": "6"
},
{
"input": "7",
"output": "8886"
},
{
"input": "8",
"output": "8888"
},
{
"input": "9",
"output": "88886"
},
{
"input": "10",
"output": "88888"
},
{
"input": "11",
"output": "888886"
},
{
"input": "12",
"output": "888888"
},
{
"input": "13",
"output": "8888886"
},
{
"input": "14",
"output": "8888888"
},
{
"input": "15",
"output": "88888886"
},
{
"input": "16",
"output": "88888888"
},
{
"input": "17",
"output": "888888886"
},
{
"input": "18",
"output": "888888888"
},
{
"input": "19",
"output": "8888888886"
},
{
"input": "20",
"output": "8888888888"
},
{
"input": "21",
"output": "88888888886"
},
{
"input": "22",
"output": "88888888888"
},
{
"input": "23",
"output": "888888888886"
},
{
"input": "24",
"output": "888888888888"
},
{
"input": "25",
"output": "8888888888886"
},
{
"input": "26",
"output": "8888888888888"
},
{
"input": "27",
"output": "88888888888886"
},
{
"input": "28",
"output": "88888888888888"
},
{
"input": "29",
"output": "888888888888886"
},
{
"input": "30",
"output": "888888888888888"
},
{
"input": "31",
"output": "8888888888888886"
},
{
"input": "32",
"output": "8888888888888888"
},
{
"input": "33",
"output": "88888888888888886"
},
{
"input": "34",
"output": "88888888888888888"
},
{
"input": "35",
"output": "888888888888888886"
},
{
"input": "36",
"output": "888888888888888888"
},
{
"input": "37",
"output": "-1"
},
{
"input": "38",
"output": "-1"
},
{
"input": "39",
"output": "-1"
},
{
"input": "40",
"output": "-1"
},
{
"input": "462",
"output": "-1"
},
{
"input": "1317",
"output": "-1"
},
{
"input": "88",
"output": "-1"
},
{
"input": "87",
"output": "-1"
}
] | 1,690,793,284 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 614,400 | n= int(input())
if n == 1 :
print(0)
elif n% 2 == 0:
x="8" * int(n/2)
if int(x)<10**18:
print( x )
else:
print(-1)
elif n%2==1:
x="8" * int(n/2) + "0"
if int(x)<10**18:
print( x )
else:
print(-1)
| Title: A Prosperous Lot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.
Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.
He would like to find a positive integer *n* not greater than 1018, such that there are exactly *k* loops in the decimal representation of *n*, or determine that such *n* does not exist.
A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms.
Input Specification:
The first and only line contains an integer *k* (1<=≤<=*k*<=≤<=106) — the desired number of loops.
Output Specification:
Output an integer — if no such *n* exists, output -1; otherwise output any such *n*. In the latter case, your output should be a positive decimal integer not exceeding 1018.
Demo Input:
['2\n', '6\n']
Demo Output:
['462', '8080']
Note:
none | ```python
n= int(input())
if n == 1 :
print(0)
elif n% 2 == 0:
x="8" * int(n/2)
if int(x)<10**18:
print( x )
else:
print(-1)
elif n%2==1:
x="8" * int(n/2) + "0"
if int(x)<10**18:
print( x )
else:
print(-1)
``` | 0 |
|
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him? | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input": "6 11",
"output": "6 2"
},
{
"input": "10 40",
"output": "10 15"
},
{
"input": "11 56",
"output": "11 22"
},
{
"input": "34 30",
"output": "30 2"
},
{
"input": "33 33",
"output": "33 0"
},
{
"input": "100 45",
"output": "45 27"
},
{
"input": "100 23",
"output": "23 38"
},
{
"input": "45 12",
"output": "12 16"
},
{
"input": "1 1",
"output": "1 0"
},
{
"input": "1 100",
"output": "1 49"
},
{
"input": "100 1",
"output": "1 49"
},
{
"input": "68 59",
"output": "59 4"
},
{
"input": "45 99",
"output": "45 27"
},
{
"input": "99 100",
"output": "99 0"
},
{
"input": "100 98",
"output": "98 1"
},
{
"input": "59 12",
"output": "12 23"
},
{
"input": "86 4",
"output": "4 41"
},
{
"input": "68 21",
"output": "21 23"
},
{
"input": "100 11",
"output": "11 44"
},
{
"input": "100 10",
"output": "10 45"
},
{
"input": "15 45",
"output": "15 15"
},
{
"input": "11 32",
"output": "11 10"
},
{
"input": "34 96",
"output": "34 31"
},
{
"input": "89 89",
"output": "89 0"
}
] | 1,685,148,724 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 |
x,y=map(int,input().split())
print(min(x,y),end=" ")
print((max(x,y)-min(x,y))//2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.
Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Can you help him?
Input Specification:
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Output Specification:
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.
Demo Input:
['3 1\n', '2 3\n', '7 3\n']
Demo Output:
['1 1\n', '2 0\n', '3 2\n']
Note:
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | ```python
x,y=map(int,input().split())
print(min(x,y),end=" ")
print((max(x,y)-min(x,y))//2)
``` | 3 |
|
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet. | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
},
{
"input": "2 1 2",
"output": "Final!"
},
{
"input": "2 2 1",
"output": "Final!"
},
{
"input": "4 1 3",
"output": "Final!"
},
{
"input": "4 1 4",
"output": "Final!"
},
{
"input": "4 2 1",
"output": "1"
},
{
"input": "4 2 3",
"output": "Final!"
},
{
"input": "4 2 4",
"output": "Final!"
},
{
"input": "4 3 1",
"output": "Final!"
},
{
"input": "4 3 2",
"output": "Final!"
},
{
"input": "4 3 4",
"output": "1"
},
{
"input": "4 4 1",
"output": "Final!"
},
{
"input": "4 4 2",
"output": "Final!"
},
{
"input": "4 4 3",
"output": "1"
},
{
"input": "8 8 7",
"output": "1"
},
{
"input": "8 8 5",
"output": "2"
},
{
"input": "8 8 1",
"output": "Final!"
},
{
"input": "16 4 3",
"output": "1"
},
{
"input": "16 2 4",
"output": "2"
},
{
"input": "16 14 11",
"output": "3"
},
{
"input": "16 3 11",
"output": "Final!"
},
{
"input": "32 10 9",
"output": "1"
},
{
"input": "32 25 28",
"output": "2"
},
{
"input": "32 22 18",
"output": "3"
},
{
"input": "32 17 25",
"output": "4"
},
{
"input": "32 18 3",
"output": "Final!"
},
{
"input": "64 40 39",
"output": "1"
},
{
"input": "64 60 58",
"output": "2"
},
{
"input": "64 34 37",
"output": "3"
},
{
"input": "64 26 24",
"output": "4"
},
{
"input": "64 50 43",
"output": "5"
},
{
"input": "64 17 42",
"output": "Final!"
},
{
"input": "128 116 115",
"output": "1"
},
{
"input": "128 35 33",
"output": "2"
},
{
"input": "128 61 59",
"output": "3"
},
{
"input": "128 116 123",
"output": "4"
},
{
"input": "128 17 15",
"output": "5"
},
{
"input": "128 124 77",
"output": "6"
},
{
"input": "128 4 80",
"output": "Final!"
},
{
"input": "256 224 223",
"output": "1"
},
{
"input": "256 24 22",
"output": "2"
},
{
"input": "256 199 196",
"output": "3"
},
{
"input": "256 148 159",
"output": "4"
},
{
"input": "256 178 166",
"output": "5"
},
{
"input": "256 75 97",
"output": "6"
},
{
"input": "256 185 200",
"output": "7"
},
{
"input": "256 3 238",
"output": "Final!"
},
{
"input": "256 128 129",
"output": "Final!"
},
{
"input": "256 255 129",
"output": "7"
},
{
"input": "256 255 128",
"output": "Final!"
},
{
"input": "256 129 256",
"output": "7"
},
{
"input": "128 98 69",
"output": "6"
},
{
"input": "128 47 83",
"output": "Final!"
},
{
"input": "16 2 3",
"output": "2"
},
{
"input": "64 32 30",
"output": "2"
},
{
"input": "8 4 5",
"output": "Final!"
},
{
"input": "8 7 8",
"output": "1"
},
{
"input": "8 2 3",
"output": "2"
},
{
"input": "8 2 5",
"output": "Final!"
}
] | 1,520,958,394 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 77 | 5,632,000 | x=input().split()
x=[int(i) for i in x]
x.sort()
turn = 1
while(not(x[0]%2==1 and x[1]%2==0 and (x[1]-x[0])==1)):
#print(x[0],x[1])
x[0]=(x[0])//2 + x[0]%2
x[1]=(x[1])//2 + x[1]%2
turn+=1
count = 1
prod=2
while(prod != x[2]):
prod=prod*2
count+=1
if(count==turn):
print("Final!")
else:
print(turn)
| Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.
Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids *a* and *b* can meet.
Input Specification:
The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal.
Output Specification:
In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1.
Demo Input:
['4 1 2\n', '8 2 6\n', '8 7 5\n']
Demo Output:
['1\n', 'Final!\n', '2\n']
Note:
In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round. | ```python
x=input().split()
x=[int(i) for i in x]
x.sort()
turn = 1
while(not(x[0]%2==1 and x[1]%2==0 and (x[1]-x[0])==1)):
#print(x[0],x[1])
x[0]=(x[0])//2 + x[0]%2
x[1]=(x[1])//2 + x[1]%2
turn+=1
count = 1
prod=2
while(prod != x[2]):
prod=prod*2
count+=1
if(count==turn):
print("Final!")
else:
print(turn)
``` | 3 |
|
448 | C | Painting Fence | PROGRAMMING | 1,900 | [
"divide and conquer",
"dp",
"greedy"
] | null | null | Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the *i*-th plank has the width of 1 meter and the height of *a**i* meters.
Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times. | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of fence planks. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the minimum number of strokes needed to paint the whole fence. | [
"5\n2 2 1 2 1\n",
"2\n2 2\n",
"1\n5\n"
] | [
"3\n",
"2\n",
"1\n"
] | In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the fourth plank.
In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes.
In the third sample there is only one plank that can be painted using a single vertical stroke. | 2,500 | [
{
"input": "5\n2 2 1 2 1",
"output": "3"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n2 2 1 2 2",
"output": "3"
},
{
"input": "5\n2 2 1 5 1",
"output": "3"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "2\n999635584 999595693",
"output": "2"
},
{
"input": "10\n3 3 6 4 2 3 2 2 3 3",
"output": "7"
},
{
"input": "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4",
"output": "5"
},
{
"input": "6\n100 100 100 100 100 1",
"output": "6"
},
{
"input": "7\n5 5 1 5 5 4 1",
"output": "6"
},
{
"input": "4\n3 4 5 6",
"output": "4"
},
{
"input": "4\n2 3 4 5",
"output": "4"
},
{
"input": "8\n5000 5000 5 5000 5000 5000 5000 5000",
"output": "8"
},
{
"input": "10\n4 4 4 3 4 4 3 4 4 4",
"output": "6"
},
{
"input": "9\n4 4 4 4 20 4 4 4 4",
"output": "5"
},
{
"input": "30\n1 4 5 3 9 7 8 4 5 9 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4",
"output": "26"
},
{
"input": "6\n3 3 3 3 1 3",
"output": "4"
},
{
"input": "12\n10 10 1 1 1 3 3 3 3 3 3 3",
"output": "5"
},
{
"input": "9\n3 4 5 6 1 9 6 5 3",
"output": "9"
}
] | 1,640,178,624 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 8 | 530 | 819,200 | fence = []
def paint(left, right, height):
if left >= right:
return 0
min_index = left
for i in range(left, right):
# print(min_index, i)
if fence[min_index] > fence[i]:
min_index = i
return min(right - left,
fence[min_index] - height
+ paint(left, min_index, fence[min_index])
+ paint(min_index + 1, right, fence[min_index]))
if __name__ == '__main__':
n = int(input())
fence = list(map(int, input().split()))
res = paint(0, n, 0)
print(res)
| Title: Painting Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion isn't just attentive, he also is very hardworking.
Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as *n* vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one, the *i*-th plank has the width of 1 meter and the height of *a**i* meters.
Bizon the Champion bought a brush in the shop, the brush's width is 1 meter. He can make vertical and horizontal strokes with the brush. During a stroke the brush's full surface must touch the fence at all the time (see the samples for the better understanding). What minimum number of strokes should Bizon the Champion do to fully paint the fence? Note that you are allowed to paint the same area of the fence multiple times.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of fence planks. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Output Specification:
Print a single integer — the minimum number of strokes needed to paint the whole fence.
Demo Input:
['5\n2 2 1 2 1\n', '2\n2 2\n', '1\n5\n']
Demo Output:
['3\n', '2\n', '1\n']
Note:
In the first sample you need to paint the fence in three strokes with the brush: the first stroke goes on height 1 horizontally along all the planks. The second stroke goes on height 2 horizontally and paints the first and second planks and the third stroke (it can be horizontal and vertical) finishes painting the fourth plank.
In the second sample you can paint the fence with two strokes, either two horizontal or two vertical strokes.
In the third sample there is only one plank that can be painted using a single vertical stroke. | ```python
fence = []
def paint(left, right, height):
if left >= right:
return 0
min_index = left
for i in range(left, right):
# print(min_index, i)
if fence[min_index] > fence[i]:
min_index = i
return min(right - left,
fence[min_index] - height
+ paint(left, min_index, fence[min_index])
+ paint(min_index + 1, right, fence[min_index]))
if __name__ == '__main__':
n = int(input())
fence = list(map(int, input().split()))
res = paint(0, n, 0)
print(res)
``` | -1 |
|
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output": "NO"
},
{
"input": "253308697183523656 25332878317796706",
"output": "YES"
},
{
"input": "669038685745448997 501718093668307460",
"output": "YES"
},
{
"input": "116453141993601660 87060381463547965",
"output": "YES"
},
{
"input": "766959657 370931668",
"output": "NO"
},
{
"input": "255787422422806632 146884995820359999",
"output": "YES"
},
{
"input": "502007866464507926 71266379084204128",
"output": "YES"
},
{
"input": "257439908778973480 64157133126869976",
"output": "NO"
},
{
"input": "232709385 91708542",
"output": "NO"
},
{
"input": "252482458300407528 89907711721009125",
"output": "NO"
},
{
"input": "6 2",
"output": "YES"
},
{
"input": "6 3",
"output": "NO"
},
{
"input": "6 4",
"output": "YES"
},
{
"input": "6 5",
"output": "YES"
},
{
"input": "6 6",
"output": "YES"
},
{
"input": "258266151957056904 30153168463725364",
"output": "NO"
},
{
"input": "83504367885565783 52285355047292458",
"output": "YES"
},
{
"input": "545668929424440387 508692735816921376",
"output": "YES"
},
{
"input": "547321411485639939 36665750286082900",
"output": "NO"
},
{
"input": "548973893546839491 183137237979822911",
"output": "NO"
},
{
"input": "544068082 193116851",
"output": "NO"
},
{
"input": "871412474 749817171",
"output": "YES"
},
{
"input": "999999999 1247",
"output": "NO"
},
{
"input": "851941088 712987048",
"output": "YES"
},
{
"input": "559922900 418944886",
"output": "YES"
},
{
"input": "293908937 37520518",
"output": "YES"
},
{
"input": "650075786 130049650",
"output": "NO"
},
{
"input": "1000000000 1000000000",
"output": "YES"
},
{
"input": "548147654663723363 107422751713800746",
"output": "YES"
},
{
"input": "828159210 131819483",
"output": "NO"
},
{
"input": "6242634 4110365",
"output": "YES"
},
{
"input": "458601973 245084155",
"output": "YES"
},
{
"input": "349593257 18089089",
"output": "YES"
},
{
"input": "814768821 312514745",
"output": "NO"
},
{
"input": "697884949 626323363",
"output": "YES"
},
{
"input": "667011589 54866795",
"output": "NO"
},
{
"input": "1000000000000000000 2",
"output": "NO"
},
{
"input": "1000000000000000000 3",
"output": "YES"
},
{
"input": "1000000000000000000 4",
"output": "NO"
},
{
"input": "999999999999999 1",
"output": "YES"
},
{
"input": "17 4",
"output": "NO"
},
{
"input": "2 2",
"output": "YES"
},
{
"input": "1000000000000000 2",
"output": "NO"
},
{
"input": "12 4",
"output": "YES"
},
{
"input": "6 1",
"output": "NO"
},
{
"input": "2 1",
"output": "NO"
},
{
"input": "10000000005 1",
"output": "YES"
},
{
"input": "10000000000000009 2",
"output": "NO"
},
{
"input": "12457895452123 1",
"output": "YES"
},
{
"input": "999999999999999999 9",
"output": "YES"
},
{
"input": "1000000000000 3",
"output": "YES"
},
{
"input": "13099714659575475 6549849616514894",
"output": "NO"
},
{
"input": "100000000000000001 1",
"output": "YES"
},
{
"input": "825175814723458 324",
"output": "YES"
},
{
"input": "20 4",
"output": "YES"
},
{
"input": "100000176877 4",
"output": "YES"
},
{
"input": "100000 3",
"output": "YES"
},
{
"input": "946744073709551614 10",
"output": "YES"
}
] | 1,608,806,159 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n=int(input("enter the number of sticks"))
k=int(input("enter the crossing"))
if((n//k)%2 !=0) or n==k:
print("yes")
else:
print("no")
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
Output Specification:
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower).
Demo Input:
['1 1\n', '10 4\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win. | ```python
n=int(input("enter the number of sticks"))
k=int(input("enter the crossing"))
if((n//k)%2 !=0) or n==k:
print("yes")
else:
print("no")
``` | -1 |
|
67 | A | Partial Teacher | PROGRAMMING | 1,800 | [
"dp",
"graphs",
"greedy",
"implementation"
] | A. Partial Teacher | 1 | 256 | A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum. | The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks. | Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. | [
"5\nLRLR\n",
"5\n=RRR\n"
] | [
"2 1 2 1 2\n",
"1 1 2 3 4\n"
] | none | 500 | [
{
"input": "5\nLRLR",
"output": "2 1 2 1 2"
},
{
"input": "5\n=RRR",
"output": "1 1 2 3 4"
},
{
"input": "6\nRLRL=",
"output": "1 2 1 2 1 1"
},
{
"input": "3\nR=",
"output": "1 2 2"
},
{
"input": "7\nRR==RR",
"output": "1 2 3 3 3 4 5"
},
{
"input": "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==",
"output": "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2 2 1 2 1 2 3 3 3"
},
{
"input": "333\nLL=LR=R=RRR=L=LRR=RLRLLLR=LRL=RRLRRRLLRRLL====RL=L====LLRL=RR==L==RLL==L=R=RLRR==LRRL=LRL=RLRLRR=R=LR=LLR===LRL=RRL====R==LRLR===LLLLL=LLLRLRLLLLLL==RLL=RL==LR=RRLRLL=R=R=R=RLRLRLLRRL==L==LRR=L=R=R===RLR=R=L=LR=LRLRR=RRL=L=RRLR=RRL=RRRL=RLRRRLLLRR=RRRLRLLLR==RR=RL===R=RL=RLL====RRRR=LR=LL=RL==RRLR====R=L=R==L=R=R=RLR=RR=R=LRRRRLLL",
"output": "4 3 2 2 1 2 2 3 3 4 5 6 6 2 2 1 2 3 3 4 1 4 3 2 1 2 2 1 2 1 1 2 3 1 2 3 4 2 1 2 3 2 1 1 1 1 1 5 4 4 3 3 3 3 3 2 1 2 1 1 2 3 3 3 1 1 1 4 3 2 2 2 1 1 2 2 3 1 2 3 3 3 1 2 3 2 2 1 2 1 1 2 1 2 1 2 3 3 4 4 1 3 3 2 1 2 2 2 2 1 2 1 1 2 3 1 1 1 1 1 2 2 2 1 2 1 9 9 9 9 8 7 6 5 4 4 3 2 1 2 1 7 6 5 4 3 2 1 1 1 3 2 1 1 3 2 2 2 1 2 2 3 4 1 3 2 1 1 2 2 3 3 4 4 5 1 2 1 3 2 1 2 4 3 3 3 2 2 2 1 2 3 3 1 1 2 2 3 3 3 3 4 1 2 2 3 3 2 2 1 2 2 1 2 1 2 3 3 4 5 2 2 1 1 2 3 1 2 2 3 4 1 1 2 3 4 1 1 2 1 2 3 4 3 2 1 2 3 3 4 5 6 1 4 3 2..."
},
{
"input": "24\nR=R==RL=RL=RLL=LLL=LLRL",
"output": "1 2 2 3 3 3 4 1 1 2 1 1 8 7 6 6 5 4 3 3 2 1 2 1"
},
{
"input": "438\nLR=RLLLRL=R==LLR=RRLRRR==RLRLRLLRRRRRLRL=RRRRLRR==RR=RR=LLRR=L=LLRRRLLR==RL=L=LLR=L=R==LLR=L=RR==LRL=LLL=RRR=R=LRLLRLLLR==LRRLLL=L==LLR=RL=LLLLR=RR=LR=RL==LRLRR=RRRRRLRLRR==RR=LLLRLR====LRRLL==LR==LL=LLRR=LRL=RRRRLR=RLLR=R=LLLRRRRR===R==LRLLRLR=LLL=L=L=R=RLLR=R=RR=RL=LLRRLLRR=LRRRR==LR==L==R=L=L=R===LLL=LL==L=L=LLLLL==RRRR==R=RLL=RLR=RRRR=R=L=RRRLLRRLRRRLLRLLRRRL=LR=R=LRLRL=R=RLRRLRRL==R=RRR=RLLR=RR=LL=RLR=R==R===RRLR=LLLR=L===LR=L=R",
"output": "2 1 2 2 4 3 2 1 2 1 1 3 3 3 2 1 2 2 3 4 1 2 3 4 4 4 5 1 2 1 3 2 1 2 3 4 5 6 1 2 1 1 2 3 4 5 1 2 3 3 3 4 5 5 6 7 7 2 1 2 4 4 3 3 2 1 2 3 4 2 1 2 2 2 5 4 4 3 3 2 1 2 2 1 1 3 3 3 2 1 2 2 1 1 2 3 3 3 1 5 4 4 3 2 1 1 2 3 4 4 5 5 1 3 2 1 4 3 2 1 2 2 2 1 2 7 6 5 4 4 3 3 3 2 1 2 2 6 5 5 4 3 2 1 2 2 3 4 4 1 2 2 3 2 2 2 1 2 1 2 3 3 4 5 6 7 8 1 2 1 2 3 3 3 4 5 5 3 2 1 2 1 2 2 2 2 2 1 2 4 3 2 2 2 1 5 5 5 4 3 3 2 1 2 3 3 1 2 1 1 2 3 4 5 1 2 2 3 2 1 2 2 4 4 3 2 1 2 3 4 5 6 6 6 6 7 7 7 1 3 2 1 2 1 6 6 5 4 3 3 2 2 1 1 2 2..."
},
{
"input": "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RRLLR=L==LRR=RRLRLLRR=LL==RLRLLRRRL=RRL=R====L=RLRR=RR=RRRL=R=RL=LLR=LR=L=RR=RR====LRRLRRLLR==R==L==RRLLRLR=RLLLLR==L=L=L=RR==L=LRRRL=R==RRL=LRR=RRRRRL===RLRLR=RLRLRLRLRR=RL=LL=RLLRR=LL=RLL=L=LRLLLLLR==RRL=R=L===LRLLL=RRRLR=LR====RR=L===LLLL=R=LLLRRRLL=LL==RLRL=LRLRL=RR=RLR==LLR=LR=RLLRLRRLL==L=LL==L==RLRLRLL=L=RLLR==LLRRLRRL==L=R=RLLRLLLL====L=====",
"output": "1 3 3 3 2 1 1 1 2 3 2 1 2 3 1 3 3 2 2 1 4 3 2 2 1 2 3 4 4 5 5 5 5 5 1 1 2 1 1 1 1 1 1 1 2 3 3 3 4 5 6 7 7 1 2 4 4 3 2 1 2 12 12 11 10 9 8 7 7 7 7 6 5 5 4 3 2 2 1 2 2 3 1 3 2 2 2 2 1 1 1 2 2 1 3 2 2 1 1 2 2 2 3 4 2 1 3 3 2 2 2 1 2 3 3 4 5 1 3 2 1 2 3 3 2 1 1 1 2 1 3 2 1 2 3 4 1 1 2 3 1 1 2 2 2 2 2 1 1 2 1 2 3 3 4 5 5 6 7 8 1 1 2 2 4 3 3 2 1 2 2 1 2 2 1 1 2 3 3 4 5 5 5 5 5 1 2 3 1 2 3 2 1 2 2 2 3 3 3 1 1 1 2 3 2 1 2 1 2 2 5 4 3 2 1 4 4 4 3 3 2 2 1 1 2 3 3 3 2 2 1 2 3 4 1 1 2 2 2 3 4 2 2 1 2 3 3 4 5 6 7 8 1 1..."
},
{
"input": "100\n=L=L=L=R=LR=RRRLRL=LRL=RRLLLLRL=R==R=LLLRR===RR=LR==LRLR===RRLRLLRLLR=LRLRR=L=LRRLLLRR==LLRLLLL==RL",
"output": "4 4 3 3 2 2 1 1 2 2 1 2 2 3 4 5 1 3 2 2 1 2 1 1 2 5 4 3 2 1 2 1 1 2 2 2 4 4 3 2 1 2 3 3 3 3 4 5 5 1 2 2 2 1 2 1 2 2 2 2 3 4 1 3 2 1 3 2 1 2 2 1 2 1 2 3 3 2 2 1 2 4 3 2 1 2 3 3 3 2 1 5 4 3 2 1 1 1 2 1"
},
{
"input": "484\nLLRRRL==RRLRRLR=LRR=RL=LLLRL===RLRRRLRR=RRRL=LLLLRL==RL==R==LLLRL=RLLRLRLLLLLLLRRLL=LLR=LLR==RLL==LLLR=RL==LL=LRRL=LLRRRLR====R=R=LRRRLLL==RLRRLR=LL==LLRLR===RR=LR==RL==L==R====LRL=LR=R=R=R=LL=L=RLR=RL==R==LRLRL==L==LL=LR=L=RRRR=R==RRLRRRLR==R=LL===R===RLRRR===LRRLLRRRRR=L==LLRRRRLRRRLL===L==LR==LR==RRLRRLRLLLL=RRL=L=LLLRLRRLLL=LRRRRLLLR=L=LL=LRLL=R==L=LRR=R=LLLRR=LRRRLR=R=RLLRR=LRL===LL==LR===L=L=L=RLL=LRRL=LL==RL==RRL====RR=L=R==L==RRL=LLRLR=RLLLL==R==RRL=====LR=RRR=LRLRRR=RLR",
"output": "3 2 1 2 3 4 1 1 1 2 3 1 2 3 1 2 2 1 2 3 3 5 4 4 3 2 1 2 1 1 1 1 2 1 2 3 4 1 2 3 3 4 5 6 5 5 4 3 2 1 2 1 1 1 2 1 1 1 4 4 4 3 2 1 2 1 1 3 2 1 2 1 8 7 6 5 4 3 2 1 2 5 4 3 3 2 1 3 3 2 1 2 2 2 6 5 4 4 4 3 2 1 2 2 5 4 4 4 3 2 2 1 2 4 3 3 2 1 2 3 4 1 2 2 2 2 2 3 3 4 4 1 2 3 4 3 2 1 1 1 2 1 2 3 1 5 5 4 3 3 3 2 1 2 1 2 2 2 2 3 4 4 1 2 2 2 3 2 2 2 1 1 1 2 2 2 2 2 1 3 2 2 1 2 2 3 3 4 4 5 5 3 2 2 1 1 2 1 2 2 3 1 1 1 2 2 2 1 2 1 6 5 5 5 4 4 4 3 2 2 1 2 2 1 1 2 3 4 5 5 6 6 6 7 8 1 2 3 4 1 2 2 2 3 3 2 1 1 1 1 2 2 2 2 3 1..."
},
{
"input": "338\n==R===L=RLRLR===RR=RRL==R=R=RLRLLRLRRRLR=LR=RR=RLLRR=RRRLLRLL=RRRRRLRLLLL=RLLRLLLRL===RRR=RRLLR=LLLL===RLL==LRLLLLRLLLLR=====RLRLRLRL=L==RRLL=RLL===LL=R=RRL=LL=L==RRLLR=LLRLL=LL=LL==RRLR=L=RLLL=LRLLLRRLR=RL=RR=R=L==RLRLL=LRRLLLLLL=RRL==RLL==R===LR===LRLRLR==LR=RR==RR=RRRRRLRRRLRLLRRRLL=LR=RRR=RL=R=LRRLR==RRR=LLL===RR=RL==RRLLL=RL=L=RLL",
"output": "1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 2 2 3 4 4 5 6 1 1 1 2 2 3 3 4 1 3 2 1 2 1 2 3 4 1 2 2 1 2 2 3 4 4 5 2 1 2 3 3 4 5 6 2 1 3 2 1 1 2 3 4 5 6 1 5 4 3 2 1 1 3 2 1 4 3 2 1 2 1 1 1 1 2 3 4 4 5 6 2 1 5 5 4 3 2 1 1 1 1 4 3 2 2 2 1 5 4 3 2 1 5 4 3 2 1 2 2 2 2 2 2 3 1 2 1 2 1 3 2 2 1 1 1 2 3 2 1 1 5 4 3 3 3 3 2 1 1 2 2 3 5 4 4 3 2 2 1 1 1 2 3 2 1 3 3 2 1 7 6 5 5 4 3 3 2 1 1 1 2 3 1 2 2 1 1 5 4 3 2 2 1 4 3 2 1 2 3 1 2 2 3 1 1 2 3 3 4 4 1 1 1 2 1 4 3 2 2 1 2 7 6 5 4 3 2 1 1 2 3 1 1 1 3 2 1 1 1 2 2 2 2 1 2 2 2 2 1 2 1 2 1..."
},
{
"input": "198\nLLRRR=RRRRLRRLRR=R===R=RL==R=RLLLR=R=L=LR=R====RRL=RRR=LL=R=RR=RRRLRRLRRR==L=LRLLL====LR=RL==L===LRR=L=L==R==R==L=LLL===R=LLL=R=L=LLLLRLL=RL=LRRLR=RL==RR=R==RLR==R=R==RLRL=LL=RRR=R===LLLRRRRL=RLRLL",
"output": "3 2 1 2 3 4 4 5 6 7 8 1 2 3 1 2 3 3 4 4 4 4 5 5 6 1 1 1 2 2 4 3 2 1 2 2 3 3 2 2 1 2 2 3 3 3 3 3 4 5 1 1 2 3 4 4 2 1 1 2 2 3 4 4 5 6 7 1 2 3 1 2 3 4 4 4 2 2 1 5 4 3 2 2 2 2 2 1 2 2 4 3 3 3 2 2 2 2 1 2 3 3 2 2 1 1 1 2 2 2 5 5 5 4 4 3 2 1 1 1 1 4 4 3 2 1 1 6 6 5 5 4 3 2 1 3 2 1 1 3 2 2 1 2 3 1 2 2 3 1 1 1 2 3 3 4 4 4 5 1 2 2 2 3 3 4 4 4 5 1 4 3 3 2 1 1 2 3 4 4 5 5 5 5 3 2 1 2 3 4 5 1 1 2 1 3 2 1"
},
{
"input": "426\nR==LRRRL=R==LLRRRLRLLLR=====R=RRRLLR==LL=L=RR=L=L==LRRR=LL=RR=LRRRLRLLR=R==RL=RRL===RRRL=RLRRRRRLRLLR=LR==LL=R=RRRLRLLLRL=L=RL=R==L==RRLLRRR=RRR==RL=====R=R==RLR=R==L==RL=RRR=RLL=L=LL=RLLR===R=RL==LR=LRLLLR==L==LR=RLLLRRRRL=RRRL=RL=LR=====R=RR=L=RL==L=LLRL=LL=L==LR=RLLRR=RLRLR=LRLLRR===L===RLL=RR==RR=R====RRLR=L=RLRLRLLRLLL=R=R=LLLRRRLR=L==L=R==LLR=L=L==RRLR=LR=R=LR=RR=R=LLRL=L=R=LLLLLR==L=LR=R=L=LL==LRR=L===RL==LL==R==RL",
"output": "1 2 2 2 1 2 3 4 1 1 3 3 3 2 1 2 3 4 1 4 3 2 1 2 2 2 2 2 2 3 3 4 5 6 2 1 4 4 4 3 2 2 1 1 2 4 4 3 3 2 2 2 1 2 3 4 4 2 1 1 2 3 3 1 2 3 4 1 3 2 1 2 2 3 3 3 4 1 1 2 3 1 1 1 1 2 3 4 1 1 2 1 2 3 4 5 6 1 3 2 1 2 2 1 3 3 3 2 1 1 2 2 3 4 5 1 4 3 2 1 3 2 2 1 1 2 1 1 2 2 2 1 1 1 2 3 2 1 2 3 4 4 5 6 7 7 7 8 1 1 1 1 1 1 2 2 3 3 3 4 1 2 2 3 3 3 1 1 1 2 1 1 2 3 4 4 6 5 4 4 3 3 2 1 1 3 2 1 2 2 2 2 3 3 4 2 2 2 1 2 2 1 4 3 2 1 3 3 3 2 2 2 1 2 2 4 3 2 1 2 3 4 5 1 1 2 3 4 1 1 3 2 2 1 2 2 2 2 2 2 3 3 4 5 5 1 1 5 4 4 4 3 3 2 1 6..."
},
{
"input": "10\nRL=R=RLR=",
"output": "1 2 1 1 2 2 3 1 2 2"
},
{
"input": "2\nL",
"output": "2 1"
},
{
"input": "100\nR=R=RRR=R=RR=RRLL=RLRLLLLLR==L=======L=LLR==RL=R=LRLLLR==LLLL=RRRL=LRL=LR=====L=LLLRRL=LLR===RLR=RR",
"output": "1 2 2 3 3 4 5 6 6 7 7 8 9 9 10 11 2 1 1 2 1 6 5 4 3 2 1 5 5 5 4 4 4 4 4 4 4 4 3 3 2 1 2 2 2 3 1 1 2 2 1 4 3 2 1 5 5 5 4 3 2 1 1 2 3 4 2 2 1 3 2 2 1 5 5 5 5 5 5 4 4 3 2 1 2 4 3 3 2 1 2 2 2 2 3 1 2 2 3 4"
},
{
"input": "23\nL=LLLLRL=RR=RLLLL=RR==",
"output": "6 5 5 4 3 2 1 2 1 1 2 3 3 5 4 3 2 1 1 2 3 3 3"
},
{
"input": "432\n=R=RRL=LLR=LLRLLRL=RL==R===L===LR=RR=LL==RLRLRRL=LRL=RLLRRLLL==RLLR=LLLRL=RLRRLLRRL=RLRRL=LL=RR=RL==LL===R==RR=LLL=RRR===R=RLLLR====R==RL=LRL=LLRLRLLRL=LLR==R==LLLL===R=R=LR=L=LRR=LR==LLL=L=LR=R=RLR=L=R==L=RLLLRR=R===R==L==R===L=RLLRLLLLLLL=LRRL=LLLL=RR==R===RR=LLLLRLRL==R====LR==LRL=L=R=R=L====LRLRL=RRR=RRRL====R=LRLRL===LRLLLR==R==LL=R==L==L=LRRRL==LL=R=L=LL=RRRLLRLRL==LLR===RRR=RRLRRR=R=RL===L=RRRR=R=RL===R==L===LLR=LLRLLLRL",
"output": "1 1 2 2 3 4 3 3 2 1 3 3 2 1 3 2 1 2 1 1 2 1 1 1 3 3 3 3 2 2 2 2 1 2 2 3 4 4 2 1 1 1 2 1 2 1 2 3 2 2 1 2 1 1 3 2 1 2 4 3 2 1 1 1 3 2 1 4 4 3 2 1 2 1 1 2 1 2 3 2 1 2 3 1 1 2 1 2 4 3 3 2 1 1 2 3 3 4 3 3 3 2 1 1 1 1 2 2 2 3 4 4 3 2 1 1 2 3 4 4 4 4 5 5 6 3 2 1 2 2 2 2 2 3 3 3 4 2 2 1 4 3 3 2 1 2 1 3 2 1 4 3 3 2 1 2 2 2 5 5 5 4 3 2 1 1 1 1 2 2 3 3 1 3 3 2 2 1 2 3 3 1 6 6 6 5 4 3 3 2 2 1 2 2 3 3 4 1 2 2 1 1 2 2 2 1 1 4 3 2 1 2 3 3 4 4 4 4 5 5 5 1 1 1 2 2 2 2 1 1 3 2 1 9 8 7 6 5 4 3 2 2 1 2 6 5 5 4 3 2 1 1 2 3 3 3..."
},
{
"input": "4\nRRL",
"output": "1 2 3 1"
},
{
"input": "17\n=RRR=L==LLLLRRRL",
"output": "1 1 2 3 6 6 5 5 5 4 3 2 1 2 3 4 1"
},
{
"input": "20\nRRLLLLLRRRRRRRRLRLR",
"output": "1 2 6 5 4 3 2 1 2 3 4 5 6 7 8 9 1 2 1 2"
},
{
"input": "9\nR===RRLL",
"output": "1 2 2 2 2 3 4 2 1"
},
{
"input": "15\n=RRR=LLLLLRRRL",
"output": "1 1 2 3 6 6 5 4 3 2 1 2 3 4 1"
}
] | 1,590,930,665 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 310 | 1,740,800 | n = int(input())
a = list(input())
b = [1]
for i in a:
if i == 'L':
b.append(b[-1]-1)
elif i == 'R':
b.append(b[-1]+1)
else:
b.append(b[-1])
delta = min(b) - 1
for i in range(n):
b[i] -= delta
print(*b)
'''
5
LRLR
''' | Title: Partial Teacher
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees.
He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one.
It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum.
Input Specification:
The first line of input contains the number of students *n* (2<=≤<=*n*<=≤<=1000). The second line gives (*n*<=-<=1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks.
Output Specification:
Output consists of *n* integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one.
Demo Input:
['5\nLRLR\n', '5\n=RRR\n']
Demo Output:
['2 1 2 1 2\n', '1 1 2 3 4\n']
Note:
none | ```python
n = int(input())
a = list(input())
b = [1]
for i in a:
if i == 'L':
b.append(b[-1]-1)
elif i == 'R':
b.append(b[-1]+1)
else:
b.append(b[-1])
delta = min(b) - 1
for i in range(n):
b[i] -= delta
print(*b)
'''
5
LRLR
'''
``` | 0 |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12",
"output": "712"
},
{
"input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6",
"output": "482"
},
{
"input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28",
"output": "6469"
},
{
"input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31",
"output": "1340"
},
{
"input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61",
"output": "329"
},
{
"input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16",
"output": "5753"
},
{
"input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29",
"output": "0"
},
{
"input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25",
"output": "851"
},
{
"input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4",
"output": "5884"
},
{
"input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1",
"output": "14170"
},
{
"input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30",
"output": "6650"
},
{
"input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20",
"output": "11786"
},
{
"input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28",
"output": "3182"
},
{
"input": "1 26\n26",
"output": "0"
},
{
"input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26",
"output": "1807"
},
{
"input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4",
"output": "946"
},
{
"input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2",
"output": "3164"
},
{
"input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16",
"output": "1262"
},
{
"input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18",
"output": "2024"
},
{
"input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15",
"output": "1984"
},
{
"input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55",
"output": "740"
},
{
"input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4",
"output": "14888"
},
{
"input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40",
"output": "13118"
},
{
"input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76",
"output": "3030"
},
{
"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": "19700"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "19696"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99",
"output": "0"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "0"
},
{
"input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100",
"output": "2"
},
{
"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": "0"
},
{
"input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1",
"output": "16"
},
{
"input": "3 5\n5 5 5",
"output": "0"
},
{
"input": "7 7\n1 1 1 1 1 1 1",
"output": "77"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"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": "19700"
},
{
"input": "4 10\n10 10 10 10",
"output": "0"
},
{
"input": "1 10\n10",
"output": "0"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "3 10\n10 10 10",
"output": "0"
},
{
"input": "2 4\n3 4",
"output": "0"
},
{
"input": "1 2\n2",
"output": "0"
},
{
"input": "3 4\n4 4 4",
"output": "0"
},
{
"input": "3 2\n2 2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 5",
"output": "0"
},
{
"input": "3 3\n3 3 3",
"output": "0"
},
{
"input": "2 9\n8 9",
"output": "0"
},
{
"input": "3 10\n9 10 10",
"output": "0"
},
{
"input": "1 3\n3",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "0"
},
{
"input": "2 10\n10 10",
"output": "0"
},
{
"input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14",
"output": "0"
},
{
"input": "2 10\n9 10",
"output": "0"
},
{
"input": "2 2\n2 2",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 4",
"output": "0"
},
{
"input": "3 5\n4 5 5",
"output": "0"
},
{
"input": "5 4\n4 4 4 4 4",
"output": "0"
},
{
"input": "2 10\n10 9",
"output": "0"
},
{
"input": "4 5\n3 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 5",
"output": "0"
},
{
"input": "3 10\n10 10 9",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "4 10\n9 10 10 10",
"output": "0"
},
{
"input": "5 2\n2 2 2 2 2",
"output": "0"
},
{
"input": "2 5\n4 5",
"output": "0"
},
{
"input": "5 10\n10 10 10 10 10",
"output": "0"
},
{
"input": "2 6\n6 6",
"output": "0"
},
{
"input": "2 9\n9 9",
"output": "0"
},
{
"input": "3 10\n10 9 10",
"output": "0"
},
{
"input": "4 40\n39 40 40 40",
"output": "0"
},
{
"input": "3 4\n3 4 4",
"output": "0"
},
{
"input": "9 9\n9 9 9 9 9 9 9 9 9",
"output": "0"
},
{
"input": "1 4\n4",
"output": "0"
},
{
"input": "4 7\n1 1 1 1",
"output": "44"
},
{
"input": "1 5\n5",
"output": "0"
},
{
"input": "3 1\n1 1 1",
"output": "0"
},
{
"input": "1 100\n100",
"output": "0"
},
{
"input": "2 7\n3 5",
"output": "10"
},
{
"input": "3 6\n6 6 6",
"output": "0"
},
{
"input": "4 2\n1 2 2 2",
"output": "0"
},
{
"input": "4 5\n4 5 5 5",
"output": "0"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "35"
},
{
"input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1",
"output": "0"
},
{
"input": "2 2\n2 1",
"output": "0"
},
{
"input": "5 5\n5 5 5 4 5",
"output": "0"
},
{
"input": "3 7\n1 1 1",
"output": "33"
},
{
"input": "2 5\n5 5",
"output": "0"
},
{
"input": "1 7\n1",
"output": "11"
},
{
"input": "6 7\n1 1 1 1 1 1",
"output": "66"
},
{
"input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64",
"output": "10077"
},
{
"input": "8 7\n1 1 1 1 1 1 1 1",
"output": "88"
},
{
"input": "3 2\n2 2 2",
"output": "0"
},
{
"input": "6 5\n5 5 5 5 5 5",
"output": "0"
},
{
"input": "10 5\n5 5 5 5 5 5 5 4 1 1",
"output": "8"
},
{
"input": "1 5\n1",
"output": "7"
},
{
"input": "10 10\n10 10 10 10 10 10 10 10 10 10",
"output": "0"
},
{
"input": "2 3\n2 3",
"output": "0"
},
{
"input": "1 9\n9",
"output": "0"
},
{
"input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2",
"output": "0"
},
{
"input": "5 5\n5 5 5 5 4",
"output": "0"
}
] | 1,505,452,315 | 2,147,483,647 | Python 3 | OK | TESTS | 106 | 62 | 0 | def average(ns):
return sum(ns)/len(ns)
def main():
t = [int(x) for x in input().split()]
n = t[0]
k = t[1]
ns = [int(y) for y in input().split()]
if round(average(ns)) == k:
print(0)
else:
print(int(-2 * (sum(ns) - k*n + 0.5*n)))
if __name__ == '__main__':
main()
| Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark *k*.
Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Output Specification:
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
Demo Input:
['2 10\n8 9\n', '3 5\n4 4 4\n']
Demo Output:
['4', '3']
Note:
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1b961585522f76271546da990a6228e7c666277f.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. | ```python
def average(ns):
return sum(ns)/len(ns)
def main():
t = [int(x) for x in input().split()]
n = t[0]
k = t[1]
ns = [int(y) for y in input().split()]
if round(average(ns)) == k:
print(0)
else:
print(int(-2 * (sum(ns) - k*n + 0.5*n)))
if __name__ == '__main__':
main()
``` | 3 |
|
793 | B | Igor and his way to work | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"implementation",
"shortest paths"
] | null | null | Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of *n* rows and *m* columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him. | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road works; - "S" — the cell where Igor's home is located; - "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each. | In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise. | [
"5 5\n..S..\n****.\nT....\n****.\n.....\n",
"5 5\nS....\n****.\n.....\n.****\n..T..\n"
] | [
"YES",
"NO"
] | The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | 1,000 | [
{
"input": "5 5\nS....\n****.\n.....\n.****\n..T..",
"output": "NO"
},
{
"input": "1 2\nST",
"output": "YES"
},
{
"input": "3 1\nS\n*\nT",
"output": "NO"
},
{
"input": "3 3\n*..\n...\nTS.",
"output": "YES"
},
{
"input": "3 3\nT.*\n*.*\n*S*",
"output": "YES"
},
{
"input": "7 7\n.S.****\n...*.*.\n.****..\n.*.**.*\n..T*...\n***..*.\n*******",
"output": "YES"
},
{
"input": "3 3\n**T\n*S*\n***",
"output": "NO"
},
{
"input": "2 2\nST\n*.",
"output": "YES"
},
{
"input": "2 2\nS.\n.T",
"output": "YES"
},
{
"input": "2 2\nTS\n.*",
"output": "YES"
},
{
"input": "2 2\n.T\nS*",
"output": "YES"
}
] | 1,492,968,311 | 2,411 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 62 | 4,915,200 | n, m = map(int, input().split())
data = [list(input().strip()) for i in range(n)]
for i, v in enumerate(data):
if "S" in v:
si = i
sk = v.index("S")
break
for i, v in enumerate(data):
if "T" in v:
ti = i
tk = v.index("T")
break
yes = False
for i in range(ti, -1 -1):
if data[i][tk] == 'S':
yes = True
break
elif data[i][tk] == '*':
break
else:
data[i][tk] == '0'
for i in range(ti, n):
if data[i][tk] == 'S':
yes = True
break
elif data[i][tk] == '*':
break
else:
data[i][tk] = '0'
for k in range(tk, -1 -1):
if data[ti][k] == 'S':
yes = True
break
elif data[ti][k] == '*':
break
else:
data[ti][k] == '0'
for k in range(tk, m):
if data[ti][k] == 'S':
yes = True
break
elif data[ti][k] == '*':
break
else:
data[ti][k] = '0'
if not yes:
for i in range(si, -1 -1):
if data[i][sk] == 'T':
yes = True
break
elif data[i][sk] == '0':
yes = True
break
elif data[i][sk] == '*':
break
else:
for k in range(sk, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for k in range(sk, m):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for i in range(si, n):
if data[i][sk] == 'T':
yes = True
break
elif data[i][sk] == '0':
yes = True
break
elif data[i][sk] == '*':
break
else:
for k in range(sk, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for k in range(sk, m):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for k in range(sk, -1 -1):
if data[si][k] == 'T':
yes = True
break
elif data[si][k] == '0':
yes = True
break
elif data[si][k] == '*':
break
else:
for i in range(si, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for i in range(si, n):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for k in range(sk, m):
if data[si][k] == 'T':
yes = True
break
elif data[si][k] == '0':
yes = True
break
elif data[si][k] == '*':
break
else:
for i in range(si, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for i in range(si, n):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if yes:
print("YES")
else:
print("NO")
| Title: Igor and his way to work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.
Bankopolis looks like a grid of *n* rows and *m* columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.
Input Specification:
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the grid.
Each of the next *n* lines contains *m* characters denoting the corresponding row of the grid. The following characters can occur:
- "." — an empty cell; - "*" — a cell with road works; - "S" — the cell where Igor's home is located; - "T" — the cell where Igor's office is located.
It is guaranteed that "S" and "T" appear exactly once each.
Output Specification:
In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.
Demo Input:
['5 5\n..S..\n****.\nT....\n****.\n.....\n', '5 5\nS....\n****.\n.....\n.****\n..T..\n']
Demo Output:
['YES', 'NO']
Note:
The first sample is shown on the following picture:
In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture: | ```python
n, m = map(int, input().split())
data = [list(input().strip()) for i in range(n)]
for i, v in enumerate(data):
if "S" in v:
si = i
sk = v.index("S")
break
for i, v in enumerate(data):
if "T" in v:
ti = i
tk = v.index("T")
break
yes = False
for i in range(ti, -1 -1):
if data[i][tk] == 'S':
yes = True
break
elif data[i][tk] == '*':
break
else:
data[i][tk] == '0'
for i in range(ti, n):
if data[i][tk] == 'S':
yes = True
break
elif data[i][tk] == '*':
break
else:
data[i][tk] = '0'
for k in range(tk, -1 -1):
if data[ti][k] == 'S':
yes = True
break
elif data[ti][k] == '*':
break
else:
data[ti][k] == '0'
for k in range(tk, m):
if data[ti][k] == 'S':
yes = True
break
elif data[ti][k] == '*':
break
else:
data[ti][k] = '0'
if not yes:
for i in range(si, -1 -1):
if data[i][sk] == 'T':
yes = True
break
elif data[i][sk] == '0':
yes = True
break
elif data[i][sk] == '*':
break
else:
for k in range(sk, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for k in range(sk, m):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for i in range(si, n):
if data[i][sk] == 'T':
yes = True
break
elif data[i][sk] == '0':
yes = True
break
elif data[i][sk] == '*':
break
else:
for k in range(sk, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for k in range(sk, m):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for k in range(sk, -1 -1):
if data[si][k] == 'T':
yes = True
break
elif data[si][k] == '0':
yes = True
break
elif data[si][k] == '*':
break
else:
for i in range(si, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for i in range(si, n):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if not yes:
for k in range(sk, m):
if data[si][k] == 'T':
yes = True
break
elif data[si][k] == '0':
yes = True
break
elif data[si][k] == '*':
break
else:
for i in range(si, -1 -1):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
for i in range(si, n):
if data[i][k] == 'T':
yes = True
break
elif data[i][k] == '0':
yes = True
break
elif data[i][k] == '*':
break
if yes:
print("YES")
else:
print("NO")
``` | 0 |
|
494 | A | Treasure | PROGRAMMING | 1,500 | [
"greedy"
] | null | null | Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. | The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. | If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them. | [
"(((#)((#)\n",
"()((#((#(#()\n",
"#\n",
"(#)\n"
] | [
"1\n2\n",
"2\n2\n1",
"-1\n",
"-1\n"
] | |*s*| denotes the length of the string *s*. | 500 | [
{
"input": "(((#)((#)",
"output": "1\n2"
},
{
"input": "()((#((#(#()",
"output": "1\n1\n3"
},
{
"input": "#",
"output": "-1"
},
{
"input": "(#)",
"output": "-1"
},
{
"input": "(((((#(#(#(#()",
"output": "1\n1\n1\n5"
},
{
"input": "#))))",
"output": "-1"
},
{
"input": "((#(()#(##",
"output": "1\n1\n1\n1"
},
{
"input": "##((((((()",
"output": "-1"
},
{
"input": "(((((((((((((((((((###################",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((#)((##",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": ")((##((###",
"output": "-1"
},
{
"input": "(#))(#(#)((((#(##((#(#((((#(##((((((#((()(()(())((()#((((#((()((((#(((((#(##)(##()((((()())(((((#(((",
"output": "-1"
},
{
"input": "#(#(#((##((()))(((#)(#()#(((()()(()#(##(((()(((()))#(((((()(((((((()#((#((()(#(((()(()##(()(((()((#(",
"output": "-1"
},
{
"input": "((#(",
"output": "-1"
},
{
"input": "()#(#())()()#)(#)()##)#((()#)((#)()#())((#((((((((#)()()(()()(((((#)#(#((((#((##()(##(((#(()(#((#))#",
"output": "-1"
},
{
"input": "(())((((#)",
"output": "3"
},
{
"input": "(#(",
"output": "-1"
},
{
"input": "((#)(",
"output": "-1"
},
{
"input": "(((()#(#)(",
"output": "-1"
},
{
"input": "#((#",
"output": "-1"
},
{
"input": "(#((((()",
"output": "-1"
},
{
"input": "(#((",
"output": "-1"
},
{
"input": ")(((())#",
"output": "-1"
}
] | 1,607,856,016 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 171 | 3,584,000 | s = input()
n = len(s)
p, curr = n - 1, 0
while s[p] != '#':
if s[p] == ')': curr += 1
else: curr -= 1
p -= 1
if curr < 0:
print(-1)
exit()
cnt_hash, curr = s.count('#'), 0
for i in range(p):
if s[i] == '(': curr += 1
else: curr -= 1
if curr < 0:
print(-1)
exit()
res = s.count('(') - s.count(')') - (cnt_hash - 1)
if res <= 0:
print(-1)
exit()
cnt_hash -= 1
print('\n'.join('1'*cnt_hash))
print(s.count('(') - s.count(')') - cnt_hash)
| Title: Treasure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful.
Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters.
Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with.
Input Specification:
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
Output Specification:
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with.
If there are several possible answers, you may output any of them.
Demo Input:
['(((#)((#)\n', '()((#((#(#()\n', '#\n', '(#)\n']
Demo Output:
['1\n2\n', '2\n2\n1', '-1\n', '-1\n']
Note:
|*s*| denotes the length of the string *s*. | ```python
s = input()
n = len(s)
p, curr = n - 1, 0
while s[p] != '#':
if s[p] == ')': curr += 1
else: curr -= 1
p -= 1
if curr < 0:
print(-1)
exit()
cnt_hash, curr = s.count('#'), 0
for i in range(p):
if s[i] == '(': curr += 1
else: curr -= 1
if curr < 0:
print(-1)
exit()
res = s.count('(') - s.count(')') - (cnt_hash - 1)
if res <= 0:
print(-1)
exit()
cnt_hash -= 1
print('\n'.join('1'*cnt_hash))
print(s.count('(') - s.count(')') - cnt_hash)
``` | 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,678,229,993 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 409,600 |
from fractions import Fraction
w, b = [int(i) for i in input().split(" ")]
d = 6 - max(w, b) + 1
if (Fraction(d, 6) == 1):
print("1/1")
if (Fraction(d, 6)) == 0:
print("0/1")
print(Fraction(d, 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
from fractions import Fraction
w, b = [int(i) for i in input().split(" ")]
d = 6 - max(w, b) + 1
if (Fraction(d, 6) == 1):
print("1/1")
if (Fraction(d, 6)) == 0:
print("0/1")
print(Fraction(d, 6))
``` | 0 |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28",
"output": "1"
},
{
"input": "30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77",
"output": "6"
},
{
"input": "30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35",
"output": "4"
},
{
"input": "2\n46 6\n6 46",
"output": "2"
},
{
"input": "29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11",
"output": "10"
},
{
"input": "23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33",
"output": "6"
},
{
"input": "13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73",
"output": "0"
},
{
"input": "18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2",
"output": "1"
},
{
"input": "18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100",
"output": "8"
},
{
"input": "30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "450"
},
{
"input": "30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3",
"output": "0"
},
{
"input": "15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5",
"output": "20"
},
{
"input": "15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2",
"output": "108"
},
{
"input": "25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2",
"output": "312"
},
{
"input": "25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6",
"output": "96"
},
{
"input": "28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97",
"output": "210"
},
{
"input": "29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78",
"output": "73"
},
{
"input": "29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80",
"output": "277"
},
{
"input": "30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21",
"output": "154"
},
{
"input": "30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17",
"output": "418"
},
{
"input": "22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80",
"output": "74"
},
{
"input": "24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9",
"output": "59"
},
{
"input": "30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67",
"output": "100"
},
{
"input": "4\n8 7\n8 7\n7 8\n7 8",
"output": "8"
},
{
"input": "6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1",
"output": "10"
},
{
"input": "12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1",
"output": "72"
},
{
"input": "4\n1 2\n1 2\n2 1\n2 1",
"output": "8"
}
] | 1,685,206,592 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | h=int(input())
v=0
list1=[]
list2=[]
for s in range(h):
f,g=map(lambda z:int(z),input().split())
list1.append(f)
list2.append(g)
for c in list1:
p=0
while p<len(list2):
if c == list2[p]:
v+=1
p+=1
print(v) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input Specification:
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
Output Specification:
In a single line print the number of games where the host team is going to play in the guest uniform.
Demo Input:
['3\n1 2\n2 4\n3 4\n', '4\n100 42\n42 100\n5 42\n100 5\n', '2\n1 2\n1 2\n']
Demo Output:
['1\n', '5\n', '0\n']
Note:
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | ```python
h=int(input())
v=0
list1=[]
list2=[]
for s in range(h):
f,g=map(lambda z:int(z),input().split())
list1.append(f)
list2.append(g)
for c in list1:
p=0
while p<len(list2):
if c == list2[p]:
v+=1
p+=1
print(v)
``` | 3 |
|
656 | B | Scrambled | PROGRAMMING | 1,700 | [
"*special",
"implementation"
] | null | null | Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht *D* *mod* *M*[*i*]<==<=*R*[*i*], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo. | The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*]. | Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4. | [
"1\n2\n0\n",
"2\n2 3\n1 0\n"
] | [
"0.500000\n",
"0.666667\n"
] | none | 0 | [
{
"input": "1\n2\n0",
"output": "0.500000"
},
{
"input": "2\n2 3\n1 0",
"output": "0.666667"
},
{
"input": "3\n2 4 4\n0 1 3",
"output": "1.000000"
},
{
"input": "1\n16\n15",
"output": "0.062500"
},
{
"input": "16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15",
"output": "1.000000"
},
{
"input": "16\n5 6 9 13 13 15 9 10 2 6 10 11 12 7 4 8\n4 3 3 5 8 3 6 5 1 4 2 6 7 4 0 1",
"output": "0.959707"
},
{
"input": "8\n15 3 7 11 14 10 16 2\n0 2 1 4 0 0 13 1",
"output": "0.826840"
},
{
"input": "1\n7\n5",
"output": "0.142857"
},
{
"input": "9\n6 12 3 10 15 14 6 9 3\n5 2 0 6 1 1 2 2 2",
"output": "0.752381"
},
{
"input": "3\n9 12 6\n0 5 0",
"output": "0.305556"
},
{
"input": "5\n3 3 13 5 10\n1 0 1 4 2",
"output": "0.784615"
},
{
"input": "7\n3 15 11 4 12 15 12\n2 9 3 0 9 13 6",
"output": "0.757576"
},
{
"input": "2\n13 3\n6 0",
"output": "0.384615"
},
{
"input": "9\n15 9 7 4 14 14 2 11 13\n2 6 2 3 11 12 0 3 3",
"output": "0.876790"
},
{
"input": "1\n15\n1",
"output": "0.066667"
},
{
"input": "1\n6\n3",
"output": "0.166667"
},
{
"input": "4\n3 8 9 4\n1 6 7 3",
"output": "0.583333"
},
{
"input": "7\n15 9 9 2 6 8 3\n10 2 7 1 3 2 0",
"output": "0.850000"
},
{
"input": "10\n9 8 7 7 16 3 10 13 5 6\n2 0 0 4 1 0 3 12 1 5",
"output": "0.832418"
},
{
"input": "4\n10 15 2 9\n8 14 0 0",
"output": "0.588889"
},
{
"input": "12\n5 16 12 3 10 15 11 14 2 3 4 11\n3 14 1 0 7 9 10 12 1 2 2 6",
"output": "0.953247"
},
{
"input": "5\n16 6 4 15 2\n13 3 0 13 0",
"output": "0.737500"
},
{
"input": "14\n12 11 7 12 2 4 14 10 7 4 15 3 5 16\n2 8 0 9 0 1 4 0 5 3 11 1 0 6",
"output": "1.000000"
},
{
"input": "12\n8 5 5 12 12 14 14 16 5 11 9 3\n1 4 0 11 10 0 2 3 1 8 8 2",
"output": "0.859307"
},
{
"input": "10\n3 16 16 9 5 16 9 7 8 2\n0 1 7 2 1 9 0 4 4 1",
"output": "0.857143"
},
{
"input": "9\n14 14 5 8 16 2 11 7 11\n9 7 0 2 7 1 10 2 4",
"output": "0.789610"
},
{
"input": "7\n13 12 4 2 7 13 8\n4 6 0 0 3 9 3",
"output": "0.728022"
},
{
"input": "5\n4 15 9 16 6\n3 9 8 14 1",
"output": "0.518056"
},
{
"input": "3\n16 13 3\n11 5 1",
"output": "0.423077"
},
{
"input": "7\n10 15 9 5 9 15 16\n2 7 2 4 0 12 13",
"output": "0.543056"
},
{
"input": "10\n16 10 16 15 12 5 4 9 3 10\n9 0 1 2 9 4 1 8 0 8",
"output": "0.811111"
},
{
"input": "14\n14 8 6 12 13 15 2 3 16 15 15 15 16 8\n10 0 5 6 1 7 0 2 1 4 2 11 14 2",
"output": "0.784615"
},
{
"input": "2\n10 14\n2 5",
"output": "0.171429"
},
{
"input": "10\n2 15 15 4 3 10 8 14 12 12\n1 8 13 0 0 6 4 2 4 5",
"output": "0.914286"
},
{
"input": "3\n6 14 7\n4 2 0",
"output": "0.333333"
},
{
"input": "13\n3 4 16 11 12 13 12 12 3 16 8 13 4\n0 1 14 5 8 5 11 7 1 6 4 1 0",
"output": "0.967949"
}
] | 1,459,551,741 | 2,147,483,647 | Python 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 233 | 67,072,000 | def main():
input()
w = 10000000
l = [0] * w
for m, r in zip(map(int, input().split()), map(int, input().split())):
l[r:w:m] = [1] * ((w - r + m - 1) // m)
print(sum(l) / w)
if __name__ == '__main__':
main()
| Title: Scrambled
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht *D* *mod* *M*[*i*]<==<=*R*[*i*], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.
Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.
Input Specification:
The first line of input contains a single integer N (1<=≤<=*N*<=≤<=16).
The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All *M*[*i*] are positive, for each *i* *R*[*i*]<=<<=*M*[*i*].
Output Specification:
Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=4.
Demo Input:
['1\n2\n0\n', '2\n2 3\n1 0\n']
Demo Output:
['0.500000\n', '0.666667\n']
Note:
none | ```python
def main():
input()
w = 10000000
l = [0] * w
for m, r in zip(map(int, input().split()), map(int, input().split())):
l[r:w:m] = [1] * ((w - r + m - 1) // m)
print(sum(l) / w)
if __name__ == '__main__':
main()
``` | 0 |
|
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive. | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
},
{
"input": "Danil_and_part_time_job",
"output": "YES"
},
{
"input": "Ann_and_books",
"output": "YES"
},
{
"input": "Olya",
"output": "YES"
},
{
"input": "Nikita",
"output": "YES"
},
{
"input": "Slava",
"output": "YES"
},
{
"input": "Vanya",
"output": "NO"
},
{
"input": "I_dont_know_what_to_write_here",
"output": "NO"
},
{
"input": "danil_and_work",
"output": "NO"
},
{
"input": "Ann",
"output": "YES"
},
{
"input": "Batman_Nananananananan_Batman",
"output": "NO"
},
{
"input": "Olya_Nikita_Ann_Slava_Danil",
"output": "NO"
},
{
"input": "its_me_Mario",
"output": "NO"
},
{
"input": "A",
"output": "NO"
},
{
"input": "Wake_up_Neo",
"output": "NO"
},
{
"input": "Hardest_problem_ever",
"output": "NO"
},
{
"input": "Nikita_Nikita",
"output": "NO"
},
{
"input": "____________________________________________________________________________________________________",
"output": "NO"
},
{
"input": "Nikitb",
"output": "NO"
},
{
"input": "Unn",
"output": "NO"
},
{
"input": "oLya_adn_smth",
"output": "NO"
},
{
"input": "FloorISLava",
"output": "NO"
},
{
"input": "ann",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "AAnnnnn",
"output": "YES"
},
{
"input": "AnnAnn",
"output": "NO"
},
{
"input": "Annn",
"output": "YES"
},
{
"input": "Dilzhan",
"output": "NO"
},
{
"input": "Danilaaa",
"output": "YES"
},
{
"input": "AndAnn",
"output": "YES"
},
{
"input": "OlyaAnnAnn",
"output": "NO"
},
{
"input": "DanilDanilOlya",
"output": "NO"
},
{
"input": "DDanil",
"output": "YES"
},
{
"input": "AnnAnnDanil",
"output": "NO"
},
{
"input": "And_Danil",
"output": "YES"
},
{
"input": "abcddddDanil",
"output": "YES"
},
{
"input": "DanilOlyaOlya",
"output": "NO"
},
{
"input": "Nikitaaa",
"output": "YES"
},
{
"input": "aaabbba",
"output": "NO"
},
{
"input": "Ann_Ann_Danil",
"output": "NO"
},
{
"input": "Danil_Danil_Nikita",
"output": "NO"
},
{
"input": "AlexaaaaaaBBBBBOlyaDDDDD",
"output": "YES"
},
{
"input": "IloveDaniland",
"output": "YES"
},
{
"input": "AnAnn",
"output": "YES"
},
{
"input": "Danil_Danil_Olya",
"output": "NO"
},
{
"input": "DanilDanilSlava",
"output": "NO"
},
{
"input": "DanilDanil",
"output": "NO"
},
{
"input": "OlyOlya",
"output": "YES"
},
{
"input": "NikitaNikitb",
"output": "YES"
},
{
"input": "ababaca",
"output": "NO"
},
{
"input": "AnnNikitaNikitaNikitaNikita__good_luck",
"output": "NO"
}
] | 1,645,785,530 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | s=input().rstrip()
l=["Danil", "Olya", "Slava", "Ann","Nikita"]
a=[]
f=0
for x in l:
if x in s:
a.append(x)
if len(a)==1:
if s.count(a[0])==1:print("YES")
else:print("NO")
else:print("NO") | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.
It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".
Names are case sensitive.
Input Specification:
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Output Specification:
Print "YES", if problem is from this contest, and "NO" otherwise.
Demo Input:
['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n']
Demo Output:
['NO', 'YES', 'NO']
Note:
none | ```python
s=input().rstrip()
l=["Danil", "Olya", "Slava", "Ann","Nikita"]
a=[]
f=0
for x in l:
if x in s:
a.append(x)
if len(a)==1:
if s.count(a[0])==1:print("YES")
else:print("NO")
else:print("NO")
``` | 3 |
|
906 | A | Shockers | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter. | Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined. | [
"5\n! abc\n. ad\n. b\n! cd\n? c\n",
"8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n",
"7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n"
] | [
"1\n",
"2\n",
"0\n"
] | In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. | 500 | [
{
"input": "5\n! abc\n. ad\n. b\n! cd\n? c",
"output": "1"
},
{
"input": "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e",
"output": "2"
},
{
"input": "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h",
"output": "0"
},
{
"input": "4\n! abcd\n! cdef\n? d\n? c",
"output": "0"
},
{
"input": "1\n? q",
"output": "0"
},
{
"input": "15\n. r\n? e\n. s\n. rw\n? y\n. fj\n. zftyd\n? r\n! wq\n? w\n? p\n. ours\n. dto\n. lbyfru\n? q",
"output": "2"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z",
"output": "1"
},
{
"input": "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z",
"output": "1"
}
] | 1,514,352,748 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 77 | 5,939,200 | n = int(input())
no = set()
yes = set()
ls = []
count = 0
for i in range(n):
x = input().split()
if x[0] != '.':
count += 1
ls.append(x)
count -= 1
act = 0
for i in range(n - 1):
x = ls[i]
if x[0] == '.':
no |= set(x[1])
elif x[0] == '!':
act += 1
if len(yes) == 0:
yes |= set(x[1])
yes &= set(x[1])
else:
act += 1
no |= set(x[1])
yes -= no
if len(yes) == 1:
break
print(count - act) | Title: Shockers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for each incorrect guess he receives an electric shock too. The show ends when Valentin guesses the selected letter correctly.
Valentin can't keep in mind everything, so he could guess the selected letter much later than it can be uniquely determined and get excessive electric shocks. Excessive electric shocks are those which Valentin got after the moment the selected letter can be uniquely determined. You should find out the number of excessive electric shocks.
Input Specification:
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of actions Valentin did.
The next *n* lines contain descriptions of his actions, each line contains description of one action. Each action can be of one of three types:
1. Valentin pronounced some word and didn't get an electric shock. This action is described by the string ". w" (without quotes), in which "." is a dot (ASCII-code 46), and *w* is the word that Valentin said. 1. Valentin pronounced some word and got an electric shock. This action is described by the string "! w" (without quotes), in which "!" is an exclamation mark (ASCII-code 33), and *w* is the word that Valentin said. 1. Valentin made a guess about the selected letter. This action is described by the string "? s" (without quotes), in which "?" is a question mark (ASCII-code 63), and *s* is the guess — a lowercase English letter.
All words consist only of lowercase English letters. The total length of all words does not exceed 105.
It is guaranteed that last action is a guess about the selected letter. Also, it is guaranteed that Valentin didn't make correct guesses about the selected letter before the last action. Moreover, it's guaranteed that if Valentin got an electric shock after pronouncing some word, then it contains the selected letter; and also if Valentin didn't get an electric shock after pronouncing some word, then it does not contain the selected letter.
Output Specification:
Output a single integer — the number of electric shocks that Valentin could have avoided if he had told the selected letter just after it became uniquely determined.
Demo Input:
['5\n! abc\n. ad\n. b\n! cd\n? c\n', '8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n', '7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n']
Demo Output:
['1\n', '2\n', '0\n']
Note:
In the first test case after the first action it becomes clear that the selected letter is one of the following: *a*, *b*, *c*. After the second action we can note that the selected letter is not *a*. Valentin tells word "b" and doesn't get a shock. After that it is clear that the selected letter is *c*, but Valentin pronounces the word *cd* and gets an excessive electric shock.
In the second test case after the first two electric shocks we understand that the selected letter is *e* or *o*. Valentin tries some words consisting of these letters and after the second word it's clear that the selected letter is *e*, but Valentin makes 3 more actions before he makes a correct hypothesis.
In the third example the selected letter can be uniquely determined only when Valentin guesses it, so he didn't get excessive electric shocks. | ```python
n = int(input())
no = set()
yes = set()
ls = []
count = 0
for i in range(n):
x = input().split()
if x[0] != '.':
count += 1
ls.append(x)
count -= 1
act = 0
for i in range(n - 1):
x = ls[i]
if x[0] == '.':
no |= set(x[1])
elif x[0] == '!':
act += 1
if len(yes) == 0:
yes |= set(x[1])
yes &= set(x[1])
else:
act += 1
no |= set(x[1])
yes -= no
if len(yes) == 1:
break
print(count - act)
``` | 0 |
|
304 | A | Pythagorean Theorem II | PROGRAMMING | 1,200 | [
"brute force",
"math"
] | null | null | In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*. | The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above. | Print a single integer — the answer to the problem. | [
"5\n",
"74\n"
] | [
"1\n",
"35\n"
] | none | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "74",
"output": "35"
},
{
"input": "1000",
"output": "881"
},
{
"input": "586",
"output": "472"
},
{
"input": "2",
"output": "0"
},
{
"input": "362",
"output": "258"
},
{
"input": "778",
"output": "653"
},
{
"input": "194",
"output": "120"
},
{
"input": "906",
"output": "786"
},
{
"input": "659",
"output": "535"
},
{
"input": "75",
"output": "37"
},
{
"input": "787",
"output": "664"
},
{
"input": "851",
"output": "730"
},
{
"input": "563",
"output": "446"
},
{
"input": "979",
"output": "862"
},
{
"input": "395",
"output": "291"
},
{
"input": "755",
"output": "634"
},
{
"input": "171",
"output": "103"
},
{
"input": "883",
"output": "759"
},
{
"input": "400",
"output": "294"
},
{
"input": "817",
"output": "693"
},
{
"input": "177",
"output": "107"
},
{
"input": "593",
"output": "476"
},
{
"input": "305",
"output": "214"
},
{
"input": "721",
"output": "595"
},
{
"input": "785",
"output": "664"
},
{
"input": "497",
"output": "383"
},
{
"input": "913",
"output": "791"
},
{
"input": "625",
"output": "507"
},
{
"input": "334",
"output": "236"
},
{
"input": "10000",
"output": "12471"
},
{
"input": "9999",
"output": "12467"
}
] | 1,685,650,157 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 3,000 | 2,150,400 | n = int(input())
count = 0
for a in range(1, n + 1):
for b in range(1, n + 1):
for c in range(1, n + 1):
if pow(a, 2) + pow(b, 2) == pow(c, 2):
count += 1
print(count // 2) | Title: Pythagorean Theorem II
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:
In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle).
The theorem can be written as an equation relating the lengths of the sides *a*, *b* and *c*, often called the Pythagorean equation:
where *c* represents the length of the hypotenuse, and *a* and *b* represent the lengths of the other two sides.
Given *n*, your task is to count how many right-angled triangles with side-lengths *a*, *b* and *c* that satisfied an inequality 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*.
Input Specification:
The only line contains one integer *n* (1<=≤<=*n*<=≤<=104) as we mentioned above.
Output Specification:
Print a single integer — the answer to the problem.
Demo Input:
['5\n', '74\n']
Demo Output:
['1\n', '35\n']
Note:
none | ```python
n = int(input())
count = 0
for a in range(1, n + 1):
for b in range(1, n + 1):
for c in range(1, n + 1):
if pow(a, 2) + pow(b, 2) == pow(c, 2):
count += 1
print(count // 2)
``` | 0 |
|
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
"output": "1"
},
{
"input": "1000 9",
"output": "1"
},
{
"input": "1 2",
"output": "2"
},
{
"input": "999 9",
"output": "1"
},
{
"input": "999 8",
"output": "2"
},
{
"input": "105 6",
"output": "2"
},
{
"input": "403 9",
"output": "3"
},
{
"input": "546 4",
"output": "4"
},
{
"input": "228 9",
"output": "5"
},
{
"input": "57 2",
"output": "6"
},
{
"input": "437 9",
"output": "7"
},
{
"input": "997 6",
"output": "8"
},
{
"input": "109 1",
"output": "9"
},
{
"input": "998 9",
"output": "5"
},
{
"input": "4 2",
"output": "3"
},
{
"input": "9 3",
"output": "7"
},
{
"input": "8 2",
"output": "4"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "1 4",
"output": "4"
},
{
"input": "1 5",
"output": "5"
},
{
"input": "1 6",
"output": "6"
},
{
"input": "1 7",
"output": "7"
},
{
"input": "1 8",
"output": "8"
},
{
"input": "100 3",
"output": "1"
},
{
"input": "1000 2",
"output": "1"
},
{
"input": "1000 4",
"output": "1"
},
{
"input": "1000 5",
"output": "1"
},
{
"input": "1000 6",
"output": "1"
},
{
"input": "1000 7",
"output": "1"
},
{
"input": "1000 8",
"output": "1"
},
{
"input": "23 4",
"output": "8"
},
{
"input": "33 1",
"output": "7"
},
{
"input": "33 2",
"output": "4"
},
{
"input": "666 5",
"output": "5"
},
{
"input": "2 3",
"output": "5"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "12 4",
"output": "2"
},
{
"input": "15 5",
"output": "1"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "25 5",
"output": "1"
},
{
"input": "2 9",
"output": "5"
},
{
"input": "6 7",
"output": "5"
},
{
"input": "8 9",
"output": "5"
},
{
"input": "2 7",
"output": "5"
},
{
"input": "4 7",
"output": "5"
},
{
"input": "2 1",
"output": "5"
},
{
"input": "261 1",
"output": "1"
}
] | 1,697,391,983 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k,m =map(int,input().split())
n=1
while (k*n-m)%10!=0:
if (k*n)%10==0:
break
n+=1
print(n) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9).
What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
Input Specification:
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Output Specification:
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
Demo Input:
['117 3\n', '237 7\n', '15 2\n']
Demo Output:
['9\n', '1\n', '2\n']
Note:
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change. | ```python
k,m =map(int,input().split())
n=1
while (k*n-m)%10!=0:
if (k*n)%10==0:
break
n+=1
print(n)
``` | 3 |
|
628 | A | Tennis Tournament | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes.
Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose). | The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* — the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | 0 | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
"output": "1497 500"
},
{
"input": "500 500 500",
"output": "499499 250000"
},
{
"input": "500 237 474",
"output": "237025 237000"
},
{
"input": "1 2 3",
"output": "0 3"
},
{
"input": "1 2 133",
"output": "0 133"
},
{
"input": "1 2 100",
"output": "0 100"
},
{
"input": "1 3 4",
"output": "0 4"
},
{
"input": "1 10 15",
"output": "0 15"
},
{
"input": "1 1 1",
"output": "0 1"
},
{
"input": "1 2 5",
"output": "0 5"
},
{
"input": "1 500 500",
"output": "0 500"
},
{
"input": "1 3 8",
"output": "0 8"
},
{
"input": "10 10 10",
"output": "189 100"
},
{
"input": "1 3 5",
"output": "0 5"
},
{
"input": "1 2 1",
"output": "0 1"
},
{
"input": "1 2 4",
"output": "0 4"
},
{
"input": "1 10 10",
"output": "0 10"
},
{
"input": "1 345 345",
"output": "0 345"
},
{
"input": "7 12 13",
"output": "150 91"
},
{
"input": "1 500 1",
"output": "0 1"
},
{
"input": "1 12 13",
"output": "0 13"
},
{
"input": "1 500 499",
"output": "0 499"
},
{
"input": "1 100 90",
"output": "0 90"
},
{
"input": "2 100 90",
"output": "201 180"
},
{
"input": "53 1 1",
"output": "156 53"
},
{
"input": "73 73 73",
"output": "10584 5329"
},
{
"input": "67 1 1",
"output": "198 67"
},
{
"input": "63 1 1",
"output": "186 63"
},
{
"input": "59 1 1",
"output": "174 59"
},
{
"input": "57 1 1",
"output": "168 57"
},
{
"input": "13 1 1",
"output": "36 13"
},
{
"input": "349 2 5",
"output": "1740 1745"
},
{
"input": "456 456 456",
"output": "415415 207936"
}
] | 1,484,849,539 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 124 | 5,324,800 | #Justin Hershberger
#Py3.5
import fileinput
def test():
pass
if __name__ == '__main__':
num_args = 1
for arg in range(num_args):
n,b,p = map(int, input().split())
#m is the number of participants of the current round
m = n
#initially we have n / 2 matches since there are n participants
num_matches = m // 2
#the remainder is the number of extras
extras = abs(-m // 2) - num_matches
#initially our running total will be num matches * 3
sum_b = (num_matches * 2 * b) + (num_matches)
#we have n participants so we initially need n * p towels
sum_p = n * p
# print("nm: ", num_matches, " ex: ", extras, " sum_b: ", sum_b, " sum_p: ", sum_p);
# print(m)
#each match needs b bottles * 3, each player needs p towels
while num_matches > 0:
#update the number of participants and num_bottles
m = num_matches + extras
# print("m: ", m)
#update the number of matches
num_matches = m // 2
# print("nm: ", num_matches)
extras = abs(-m // 2) - num_matches
# print("ex: ", extras)
#each match has two participants and one judge who gets one bottle
sum_b += (num_matches * 2 * b) + (num_matches)
print(sum_b, sum_p)
| Title: Tennis Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 such that *k*<=≤<=*m*, - *k* participants compete in the current round and a half of them passes to the next round, the other *m*<=-<=*k* participants pass to the next round directly, - when only one participant remains, the tournament finishes.
Each match requires *b* bottles of water for each participant and one bottle for the judge. Besides *p* towels are given to each participant for the whole tournament.
Find the number of bottles and towels needed for the tournament.
Note that it's a tennis tournament so in each match two participants compete (one of them will win and the other will lose).
Input Specification:
The only line contains three integers *n*,<=*b*,<=*p* (1<=≤<=*n*,<=*b*,<=*p*<=≤<=500) — the number of participants and the parameters described in the problem statement.
Output Specification:
Print two integers *x* and *y* — the number of bottles and towels need for the tournament.
Demo Input:
['5 2 3\n', '8 2 4\n']
Demo Output:
['20 15\n', '35 32\n']
Note:
In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be only one match, so we need another 5 bottles of water.
So in total we need 20 bottles of water.
In the second example no participant will move on to some round directly. | ```python
#Justin Hershberger
#Py3.5
import fileinput
def test():
pass
if __name__ == '__main__':
num_args = 1
for arg in range(num_args):
n,b,p = map(int, input().split())
#m is the number of participants of the current round
m = n
#initially we have n / 2 matches since there are n participants
num_matches = m // 2
#the remainder is the number of extras
extras = abs(-m // 2) - num_matches
#initially our running total will be num matches * 3
sum_b = (num_matches * 2 * b) + (num_matches)
#we have n participants so we initially need n * p towels
sum_p = n * p
# print("nm: ", num_matches, " ex: ", extras, " sum_b: ", sum_b, " sum_p: ", sum_p);
# print(m)
#each match needs b bottles * 3, each player needs p towels
while num_matches > 0:
#update the number of participants and num_bottles
m = num_matches + extras
# print("m: ", m)
#update the number of matches
num_matches = m // 2
# print("nm: ", num_matches)
extras = abs(-m // 2) - num_matches
# print("ex: ", extras)
#each match has two participants and one judge who gets one bottle
sum_b += (num_matches * 2 * b) + (num_matches)
print(sum_b, sum_p)
``` | 3 |
|
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhergiqrbvgrgf\n26",
"output": "14"
},
{
"input": "nfevghreuoghrueighoqghbnebvnejbvnbgneluqe\n26",
"output": "12"
},
{
"input": "a\n3",
"output": "impossible"
},
{
"input": "smaxpqplaqqbxuqxalqmbmmgubbpspxhawbxsuqhhegpmmpebqmqpbbeplwaepxmsahuepuhuhwxeqmmlgqubuaxehwuwasgxpqmugbmuawuhwqlswllssueglbxepbmwgs\n1",
"output": "0"
},
{
"input": "cuguccgcugcugucgggggcgcgucgucugcuuuccccuugccg\n4",
"output": "1"
},
{
"input": "fcfccfcfccfcfcffcffffffcfccfccfcffccccfcffffccfccfcffcfcccccffcfffcccffcfccfffffcccfccffffffccfccccf\n20",
"output": "18"
},
{
"input": "swmkwaruyv\n5",
"output": "0"
},
{
"input": "tnbqpsuhkczmejirvyfdolxwga\n22",
"output": "0"
},
{
"input": "abcde\n3",
"output": "0"
},
{
"input": "abb\n1",
"output": "0"
},
{
"input": "aaaa\n1",
"output": "0"
},
{
"input": "abcde\n2",
"output": "0"
},
{
"input": "yandex\n4",
"output": "0"
},
{
"input": "aaabbbccc\n1",
"output": "0"
},
{
"input": "abcd\n2",
"output": "0"
},
{
"input": "asdfgh\n2",
"output": "0"
},
{
"input": "aab\n1",
"output": "0"
},
{
"input": "mynameissako\n5",
"output": "0"
},
{
"input": "abcde\n1",
"output": "0"
},
{
"input": "abcd\n3",
"output": "0"
},
{
"input": "abcdef\n2",
"output": "0"
},
{
"input": "abcdefg\n4",
"output": "0"
},
{
"input": "abc\n1",
"output": "0"
},
{
"input": "asdafjsgljdllgjdgkl\n5",
"output": "0"
},
{
"input": "yaay\n3",
"output": "1"
},
{
"input": "yaay\n4",
"output": "2"
},
{
"input": "zzzzzz\n2",
"output": "1"
}
] | 1,604,651,453 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 93 | 0 | STR = list(input())
k = int(input())
SET = list(set(STR))
if len(STR)<k:
print('impossible')
else:
print(k-len(SET)) | Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.
Input Specification:
First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26).
Output Specification:
Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.
Demo Input:
['yandex\n6\n', 'yahoo\n5\n', 'google\n7\n']
Demo Output:
['0\n', '1\n', 'impossible\n']
Note:
In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for example, {'*b*'}.
In the third test case, it is impossible to make 7 different letters because the length of the string is 6. | ```python
STR = list(input())
k = int(input())
SET = list(set(STR))
if len(STR)<k:
print('impossible')
else:
print(k-len(SET))
``` | 0 |
|
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. | The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account. | In a single line print an integer — the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output": "423654797"
},
{
"input": "-623563697",
"output": "-62356367"
},
{
"input": "645894116",
"output": "645894116"
},
{
"input": "-384381709",
"output": "-38438170"
},
{
"input": "437587210",
"output": "437587210"
},
{
"input": "-297534606",
"output": "-29753460"
},
{
"input": "891773002",
"output": "891773002"
},
{
"input": "-56712976",
"output": "-5671296"
},
{
"input": "963662765",
"output": "963662765"
},
{
"input": "-272656295",
"output": "-27265625"
},
{
"input": "383441522",
"output": "383441522"
},
{
"input": "-477665112",
"output": "-47766511"
},
{
"input": "791725034",
"output": "791725034"
},
{
"input": "-812168727",
"output": "-81216872"
},
{
"input": "528894922",
"output": "528894922"
},
{
"input": "-479977172",
"output": "-47997712"
},
{
"input": "568044564",
"output": "568044564"
},
{
"input": "-392784794",
"output": "-39278474"
},
{
"input": "925596634",
"output": "925596634"
},
{
"input": "-836078769",
"output": "-83607876"
},
{
"input": "71036059",
"output": "71036059"
},
{
"input": "-337396162",
"output": "-33739612"
},
{
"input": "87129297",
"output": "87129297"
},
{
"input": "-648171877",
"output": "-64817187"
},
{
"input": "20218400",
"output": "20218400"
},
{
"input": "10",
"output": "10"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "-1000000000",
"output": "-100000000"
},
{
"input": "-102",
"output": "-10"
},
{
"input": "-120",
"output": "-10"
},
{
"input": "-20",
"output": "0"
},
{
"input": "-15",
"output": "-1"
},
{
"input": "-5575533",
"output": "-557553"
},
{
"input": "-50",
"output": "0"
},
{
"input": "-31",
"output": "-1"
},
{
"input": "-55",
"output": "-5"
},
{
"input": "-81",
"output": "-1"
},
{
"input": "-99",
"output": "-9"
},
{
"input": "-23",
"output": "-2"
},
{
"input": "-41",
"output": "-1"
},
{
"input": "-24",
"output": "-2"
},
{
"input": "46",
"output": "46"
}
] | 1,690,710,562 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 | n=int(input())
x=str(n)
if n<0:
if (len(x)-1)<2:
print(0)
else:
n1=(-1*n)%10
n2=((-1*n)%100)//10
if n1>n2:
y=(-1*n)//10
y=(-1*y)
print(y)
else:
y=(-1*n)//100
y=(y*10)+n1
y=(-1*y)
print(y)
else:
print(n) | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.
Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.
Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.
Input Specification:
The single line contains integer *n* (10<=≤<=|*n*|<=≤<=109) — the state of Ilya's bank account.
Output Specification:
In a single line print an integer — the maximum state of the bank account that Ilya can get.
Demo Input:
['2230\n', '-10\n', '-100003\n']
Demo Output:
['2230\n', '0\n', '-10000\n']
Note:
In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | ```python
n=int(input())
x=str(n)
if n<0:
if (len(x)-1)<2:
print(0)
else:
n1=(-1*n)%10
n2=((-1*n)%100)//10
if n1>n2:
y=(-1*n)//10
y=(-1*y)
print(y)
else:
y=(-1*n)//100
y=(y*10)+n1
y=(-1*y)
print(y)
else:
print(n)
``` | 3 |
|
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment. | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 100000",
"output": "Yes"
},
{
"input": "1 99989",
"output": "No"
},
{
"input": "512 2",
"output": "Yes"
},
{
"input": "100 24",
"output": "No"
},
{
"input": "1 100000",
"output": "No"
},
{
"input": "100000 1",
"output": "Yes"
},
{
"input": "3 99929",
"output": "No"
},
{
"input": "99961 99971",
"output": "No"
},
{
"input": "1 65536",
"output": "Yes"
},
{
"input": "4 65536",
"output": "Yes"
},
{
"input": "3 65536",
"output": "Yes"
},
{
"input": "32768 65536",
"output": "Yes"
},
{
"input": "65535 65536",
"output": "Yes"
},
{
"input": "1 65535",
"output": "No"
},
{
"input": "98812 100000",
"output": "No"
},
{
"input": "10 5",
"output": "Yes"
},
{
"input": "6 8",
"output": "Yes"
}
] | 1,629,292,299 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 62 | 6,758,400 | # _
#####################################################################################################################
from math import log2
def main():
nDetails, m = map(int, input().split())
return willProductionStop(nDetails, m)
def willProductionStop(nDetails, m):
power1, power2 = log2(m), log2(nDetails)
difference = power1 - power2
if round(power1) == power1 or round(difference) == difference or not nDetails%m:
return 'Yes'
return 'No'
if __name__ == '__main__':
print(main())
# main()
| Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.
The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*).
Given the number of details *a* on the first day and number *m* check if the production stops at some moment.
Input Specification:
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Output Specification:
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
Demo Input:
['1 5\n', '3 6\n']
Demo Output:
['No\n', 'Yes\n']
Note:
none | ```python
# _
#####################################################################################################################
from math import log2
def main():
nDetails, m = map(int, input().split())
return willProductionStop(nDetails, m)
def willProductionStop(nDetails, m):
power1, power2 = log2(m), log2(nDetails)
difference = power1 - power2
if round(power1) == power1 or round(difference) == difference or not nDetails%m:
return 'Yes'
return 'No'
if __name__ == '__main__':
print(main())
# main()
``` | 3 |
|
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B Y M\nG B Y M C\nB Y M C W\nY M C W G\nM C W G B",
"output": "#Color"
},
{
"input": "1 6\nC M Y W G B",
"output": "#Color"
},
{
"input": "1 3\nW G B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "5 5\nW G B W G\nG B W G B\nB W G B W\nW G B W G\nG B W G B",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G C",
"output": "#Color"
},
{
"input": "2 3\nW W W\nB G M",
"output": "#Color"
},
{
"input": "3 3\nC B W\nB Y M\nB B W",
"output": "#Color"
},
{
"input": "1 3\nW C W",
"output": "#Color"
},
{
"input": "3 3\nB W B\nB C W\nB W W",
"output": "#Color"
},
{
"input": "1 2\nW Y",
"output": "#Color"
},
{
"input": "1 1\nG",
"output": "#Black&White"
},
{
"input": "1 3\nB G W",
"output": "#Black&White"
},
{
"input": "2 2\nW W\nB C",
"output": "#Color"
},
{
"input": "1 1\nM",
"output": "#Color"
},
{
"input": "1 2\nW C",
"output": "#Color"
},
{
"input": "2 3\nW W M\nW W M",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB C",
"output": "#Color"
},
{
"input": "2 3\nW W C\nW W W",
"output": "#Color"
},
{
"input": "1 3\nG G G",
"output": "#Black&White"
},
{
"input": "1 1\nC",
"output": "#Color"
},
{
"input": "1 2\nC W",
"output": "#Color"
},
{
"input": "1 3\nW W C",
"output": "#Color"
},
{
"input": "2 2\nW B\nB G",
"output": "#Black&White"
},
{
"input": "2 2\nB B\nY Y",
"output": "#Color"
},
{
"input": "2 2\nG G\nC C",
"output": "#Color"
},
{
"input": "1 2\nB C",
"output": "#Color"
},
{
"input": "1 4\nG G G C",
"output": "#Color"
},
{
"input": "1 1\nB",
"output": "#Black&White"
},
{
"input": "2 1\nY\nB",
"output": "#Color"
}
] | 1,682,080,782 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 78 | 1,536,000 | a, b = map(int, input().split())
w = 0
c = 0
g = 0
for i in range(a):
l = list(map(str, input().split()))
w = l.count('W') + w
c = l.count('B') + c
g = l.count('G') + g
if (w+c+g) == a * b:
print("#Black&White")
else:
print("#Color")
| Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour!
As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white.
Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors:
- 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black)
The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored.
Input Specification:
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'.
Output Specification:
Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
Demo Input:
['2 2\nC M\nY Y\n', '3 2\nW W\nW W\nB B\n', '1 1\nW\n']
Demo Output:
['#Color', '#Black&White', '#Black&White']
Note:
none | ```python
a, b = map(int, input().split())
w = 0
c = 0
g = 0
for i in range(a):
l = list(map(str, input().split()))
w = l.count('W') + w
c = l.count('B') + c
g = l.count('G') + g
if (w+c+g) == a * b:
print("#Black&White")
else:
print("#Color")
``` | 3 |
|
411 | B | Multi-core Processor | PROGRAMMING | 1,600 | [
"implementation"
] | null | null | The research center Q has developed a new multi-core processor. The processor consists of *n* cores and has *k* cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within *m* cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the *m* cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100). Then follow *n* lines describing instructions. The *i*-th line contains *m* integers: *x**i*1,<=*x**i*2,<=...,<=*x**im* (0<=≤<=*x**ij*<=≤<=*k*), where *x**ij* is the instruction that must be executed by the *i*-th core at the *j*-th cycle. If *x**ij* equals 0, then the corresponding instruction is «do nothing». But if *x**ij* is a number from 1 to *k*, then the corresponding instruction is «write information to the memory cell number *x**ij*».
We assume that the cores are numbered from 1 to *n*, the work cycles are numbered from 1 to *m* and the memory cells are numbered from 1 to *k*. | Print *n* lines. In the *i*-th line print integer *t**i*. This number should be equal to 0 if the *i*-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked. | [
"4 3 5\n1 0 0\n1 0 2\n2 3 1\n3 2 0\n",
"3 2 2\n1 2\n1 2\n2 2\n",
"1 1 1\n0\n"
] | [
"1\n1\n3\n0\n",
"1\n1\n0\n",
"0\n"
] | none | 0 | [
{
"input": "4 3 5\n1 0 0\n1 0 2\n2 3 1\n3 2 0",
"output": "1\n1\n3\n0"
},
{
"input": "3 2 2\n1 2\n1 2\n2 2",
"output": "1\n1\n0"
},
{
"input": "1 1 1\n0",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 1\n1\n1",
"output": "1\n1"
},
{
"input": "2 1 1\n1\n0",
"output": "0\n0"
},
{
"input": "2 1 1\n0\n1",
"output": "0\n0"
},
{
"input": "2 1 1\n0\n0",
"output": "0\n0"
},
{
"input": "2 1 2\n1\n2",
"output": "0\n0"
},
{
"input": "2 1 1\n1\n1",
"output": "1\n1"
},
{
"input": "2 2 2\n2 1\n0 2",
"output": "0\n0"
},
{
"input": "1 100 100\n32 97 28 73 22 27 27 21 25 26 21 95 45 60 47 64 44 88 24 10 82 55 84 69 86 70 99 99 34 59 71 83 53 90 29 100 98 68 24 82 5 67 49 70 23 85 5 90 57 0 99 26 32 11 81 92 6 45 32 72 54 32 20 37 40 33 55 55 33 61 13 31 67 51 74 96 67 13 28 3 23 99 26 6 91 95 67 29 46 78 85 17 47 83 26 51 88 31 37 15",
"output": "0"
},
{
"input": "100 1 100\n59\n37\n53\n72\n37\n15\n8\n93\n92\n74\n11\n11\n68\n16\n92\n40\n76\n20\n10\n86\n76\n5\n9\n95\n5\n81\n44\n57\n10\n24\n22\n2\n57\n6\n26\n67\n48\n95\n34\n97\n55\n33\n70\n66\n51\n70\n74\n65\n35\n85\n37\n9\n27\n43\n65\n6\n5\n57\n54\n27\n22\n41\n8\n29\n10\n50\n9\n68\n78\n9\n92\n30\n88\n62\n30\n5\n80\n58\n19\n39\n22\n88\n81\n34\n36\n18\n28\n93\n64\n27\n47\n89\n30\n21\n24\n42\n34\n100\n27\n46",
"output": "0\n1\n0\n0\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n0\n0\n1\n1\n0\n0\n0\n1\n0\n0\n1\n1\n1\n0\n0\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n0\n0\n0\n0\n1\n1\n1\n1\n0\n0\n0\n1\n0\n1\n0\n0\n1\n0\n1\n0\n1\n0\n1\n0"
},
{
"input": "1 100 10\n7 2 8 3 0 10 0 3 0 5 3 6 4 1 2 2 5 1 7 10 7 9 10 6 2 8 6 10 0 10 4 4 4 9 7 0 0 8 6 2 2 4 10 10 5 9 4 6 1 1 9 7 2 7 4 7 2 2 3 3 10 3 8 1 0 4 3 10 9 8 6 2 10 7 5 10 0 3 6 2 3 6 6 2 5 9 10 0 10 4 10 3 4 2 2 10 4 5 7 8",
"output": "0"
},
{
"input": "100 1 10\n10\n6\n8\n2\n4\n3\n3\n2\n0\n2\n10\n5\n10\n4\n10\n2\n6\n9\n1\n1\n1\n3\n7\n3\n9\n10\n6\n1\n4\n1\n4\n1\n4\n4\n5\n1\n9\n4\n10\n3\n3\n2\n8\n10\n1\n2\n10\n4\n8\n8\n4\n8\n6\n3\n8\n6\n8\n1\n2\n3\n2\n2\n9\n4\n1\n10\n10\n7\n8\n10\n8\n8\n10\n9\n2\n0\n5\n0\n9\n0\n2\n6\n7\n4\n5\n4\n2\n3\n1\n9\n7\n0\n10\n7\n2\n1\n1\n9\n6\n7",
"output": "1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n0\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1"
},
{
"input": "7 2 98\n0 72\n71 26\n87 23\n26 37\n65 97\n81 30\n19 83",
"output": "0\n0\n0\n0\n0\n0\n0"
}
] | 1,397,564,308 | 58,708 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 0 | n,m,k=map(int,input('').split())
x={}
out=[]
memory=[]
for i in range(n):
x[i]=list(map(int, input('').split()))
out+=[(-1)]
for j in range(m):
for i in range(n):
k=x[i][j]
for q in range(n):
z=0
for p in memory:
if p==k: z=1
if ((k==x[q][j]) or z==1) and out[i]==-1 and out[q]==-1 and i!=q:
out[i]=j+1
if z!=1: out[q]=j+1
memory+=[(k)]
for i in range(n):
if out[i]==-1: out[i]=0
print (out[i])
| Title: Multi-core Processor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The research center Q has developed a new multi-core processor. The processor consists of *n* cores and has *k* cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or the number of the memory cell (the core will write an information to the cell). After receiving the command, the core executes it immediately. Sometimes it happens that at one cycle, multiple cores try to write the information into a single cell. Unfortunately, the developers did not foresee the possibility of resolving conflicts between cores, so in this case there is a deadlock: all these cores and the corresponding memory cell are locked forever. Each of the locked cores ignores all further commands, and no core in the future will be able to record an information into the locked cell. If any of the cores tries to write an information into some locked cell, it is immediately locked.
The development team wants to explore the deadlock situation. Therefore, they need a program that will simulate the processor for a given set of instructions for each core within *m* cycles . You're lucky, this interesting work is entrusted to you. According to the instructions, during the *m* cycles define for each core the number of the cycle, during which it will become locked. It is believed that initially all cores and all memory cells are not locked.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=100). Then follow *n* lines describing instructions. The *i*-th line contains *m* integers: *x**i*1,<=*x**i*2,<=...,<=*x**im* (0<=≤<=*x**ij*<=≤<=*k*), where *x**ij* is the instruction that must be executed by the *i*-th core at the *j*-th cycle. If *x**ij* equals 0, then the corresponding instruction is «do nothing». But if *x**ij* is a number from 1 to *k*, then the corresponding instruction is «write information to the memory cell number *x**ij*».
We assume that the cores are numbered from 1 to *n*, the work cycles are numbered from 1 to *m* and the memory cells are numbered from 1 to *k*.
Output Specification:
Print *n* lines. In the *i*-th line print integer *t**i*. This number should be equal to 0 if the *i*-th core won't be locked, or it should be equal to the number of the cycle when this core will be locked.
Demo Input:
['4 3 5\n1 0 0\n1 0 2\n2 3 1\n3 2 0\n', '3 2 2\n1 2\n1 2\n2 2\n', '1 1 1\n0\n']
Demo Output:
['1\n1\n3\n0\n', '1\n1\n0\n', '0\n']
Note:
none | ```python
n,m,k=map(int,input('').split())
x={}
out=[]
memory=[]
for i in range(n):
x[i]=list(map(int, input('').split()))
out+=[(-1)]
for j in range(m):
for i in range(n):
k=x[i][j]
for q in range(n):
z=0
for p in memory:
if p==k: z=1
if ((k==x[q][j]) or z==1) and out[i]==-1 and out[q]==-1 and i!=q:
out[i]=j+1
if z!=1: out[q]=j+1
memory+=[(k)]
for i in range(n):
if out[i]==-1: out[i]=0
print (out[i])
``` | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.