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
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,610,590,296 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 307,200 | n,m=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans=0
t=0
if b[0]>a[len(a)-1]:
ans=n
else:
i=0
for j in range (len(b)):
if b[j]>=a[i]:
t+=1
i+=1
if i==len(a):
break
ans=n-t
print(ans) | 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())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
ans=0
t=0
if b[0]>a[len(a)-1]:
ans=n
else:
i=0
for j in range (len(b)):
if b[j]>=a[i]:
t+=1
i+=1
if i==len(a):
break
ans=n-t
print(ans)
``` | 0 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023. | Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input. | [
"3\n| 3\n^ 2\n| 1\n",
"3\n& 1\n& 3\n& 5\n",
"3\n^ 1\n^ 2\n^ 3\n"
] | [
"2\n| 3\n^ 2\n",
"1\n& 1\n",
"0\n"
] | You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the same outputs. | 0 | [
{
"input": "3\n| 3\n^ 2\n| 1",
"output": "2\n| 3\n^ 2"
},
{
"input": "3\n& 1\n& 3\n& 5",
"output": "1\n& 1"
},
{
"input": "3\n^ 1\n^ 2\n^ 3",
"output": "0"
},
{
"input": "2\n| 999\n^ 689",
"output": "2\n| 999\n^ 689"
},
{
"input": "3\n& 242\n^ 506\n^ 522",
"output": "2\n| 781\n^ 253"
},
{
"input": "2\n| 56\n^ 875",
"output": "2\n| 56\n^ 875"
},
{
"input": "3\n^ 125\n^ 377\n& 1019",
"output": "2\n| 4\n^ 260"
},
{
"input": "1\n& 123",
"output": "1\n& 123"
},
{
"input": "1\n| 123",
"output": "1\n| 123"
},
{
"input": "1\n^ 123",
"output": "1\n^ 123"
},
{
"input": "10\n^ 218\n& 150\n| 935\n& 61\n| 588\n& 897\n| 411\n| 584\n^ 800\n| 704",
"output": "2\n| 1023\n^ 260"
},
{
"input": "10\n^ 160\n& 1021\n& 510\n^ 470\n& 1022\n& 251\n& 760\n& 1016\n| 772\n| 515",
"output": "2\n| 775\n^ 112"
},
{
"input": "1\n& 0",
"output": "1\n& 0"
},
{
"input": "1\n| 0",
"output": "0"
},
{
"input": "1\n^ 0",
"output": "0"
},
{
"input": "1\n& 1023",
"output": "0"
},
{
"input": "1\n| 1023",
"output": "1\n| 1023"
},
{
"input": "1\n^ 1023",
"output": "1\n^ 1023"
}
] | 1,686,019,537 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 2,000 | 8,704,000 | a, b = 0, 1023
# commands = []
for i in range(int(input())):
cmd = input()
# commands.append(cmd)
c, x = cmd.split()
x = int(x)
if c == "|":
a, b = a | x, b | x
elif c == "&":
a, b = a & x, b & x
else:
a, b = a ^ x, b ^ x
# a, b = eval("a " + cmd), eval("b " + cmd)
x = 0
y = 1023
z = 0
for i in range(10):
a_i = (a >> i) & 1
b_i = (b >> i) & 1
if a_i and b_i:
x |= 1 << i
if (not a_i) and (not b_i):
y ^= 1 << i
if a_i and (not b_i):
z ^= 1 << i
print("3\n| {}\n& {}\n^ {}".format(x, y, z))
# for i in range(1024):
# t1 = i
# for cmd in commands:
# t1 = eval("t1 " + cmd)
# t2 = eval("(((i | x) & y) ^ z)")
# if t1 != t2:
# print("Neq on ", i)
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.
In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.
Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=5·105) — the number of lines.
Next *n* lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant *x**i* 0<=≤<=*x**i*<=≤<=1023.
Output Specification:
Output an integer *k* (0<=≤<=*k*<=≤<=5) — the length of your program.
Next *k* lines must contain commands in the same format as in the input.
Demo Input:
['3\n| 3\n^ 2\n| 1\n', '3\n& 1\n& 3\n& 5\n', '3\n^ 1\n^ 2\n^ 3\n']
Demo Output:
['2\n| 3\n^ 2\n', '1\n& 1\n', '0\n']
Note:
You can read about bitwise operations in [https://en.wikipedia.org/wiki/Bitwise_operation](https://en.wikipedia.org/wiki/Bitwise_operation).
Second sample:
Let *x* be an input of the Petya's program. It's output is ((*x*&1)&3)&5 = *x*&(1&3&5) = *x*&1. So these two programs always give the same outputs. | ```python
a, b = 0, 1023
# commands = []
for i in range(int(input())):
cmd = input()
# commands.append(cmd)
c, x = cmd.split()
x = int(x)
if c == "|":
a, b = a | x, b | x
elif c == "&":
a, b = a & x, b & x
else:
a, b = a ^ x, b ^ x
# a, b = eval("a " + cmd), eval("b " + cmd)
x = 0
y = 1023
z = 0
for i in range(10):
a_i = (a >> i) & 1
b_i = (b >> i) & 1
if a_i and b_i:
x |= 1 << i
if (not a_i) and (not b_i):
y ^= 1 << i
if a_i and (not b_i):
z ^= 1 << i
print("3\n| {}\n& {}\n^ {}".format(x, y, z))
# for i in range(1024):
# t1 = i
# for cmd in commands:
# t1 = eval("t1 " + cmd)
# t2 = eval("(((i | x) & y) ^ z)")
# if t1 != t2:
# print("Neq on ", i)
``` | 0 |
|
36 | B | Fractal | PROGRAMMING | 1,600 | [
"implementation"
] | B. Fractal | 2 | 64 | Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm:
Step 1. The paper is divided into *n*2 identical squares and some of them are painted black according to the model.
Step 2. Every square that remains white is divided into *n*2 smaller squares and some of them are painted black according to the model.
Every following step repeats step 2.
Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals. | The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square. | Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm. | [
"2 3\n.*\n..\n",
"3 2\n.*.\n***\n.*.\n"
] | [
".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n",
".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n"
] | none | 1,000 | [
{
"input": "2 3\n.*\n..",
"output": ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........"
},
{
"input": "3 2\n.*.\n***\n.*.",
"output": ".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*."
},
{
"input": "2 1\n..\n..",
"output": "..\n.."
},
{
"input": "2 2\n*.\n*.",
"output": "***.\n***.\n***.\n***."
},
{
"input": "2 2\n**\n*.",
"output": "****\n****\n****\n***."
},
{
"input": "2 2\n*.\n..",
"output": "***.\n**..\n*.*.\n...."
},
{
"input": "2 3\n*.\n.*",
"output": "*******.\n******.*\n*****.**\n****.***\n***.****\n**.*****\n*.******\n.*******"
},
{
"input": "2 3\n..\n**",
"output": "........\n********\n********\n********\n********\n********\n********\n********"
},
{
"input": "2 3\n*.\n**",
"output": "*******.\n********\n********\n********\n********\n********\n********\n********"
},
{
"input": "2 4\n**\n..",
"output": "****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n****************\n................"
},
{
"input": "2 4\n*.\n.*",
"output": "***************.\n**************.*\n*************.**\n************.***\n***********.****\n**********.*****\n*********.******\n********.*******\n*******.********\n******.*********\n*****.**********\n****.***********\n***.************\n**.*************\n*.**************\n.***************"
},
{
"input": "2 4\n.*\n.*",
"output": ".***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************\n.***************"
},
{
"input": "2 5\n.*\n*.",
"output": ".*******************************\n*.******************************\n**.*****************************\n***.****************************\n****.***************************\n*****.**************************\n******.*************************\n*******.************************\n********.***********************\n*********.**********************\n**********.*********************\n***********.********************\n************.*******************\n*************.******************\n**************.*****************\n*..."
},
{
"input": "2 5\n*.\n..",
"output": "*******************************.\n******************************..\n*****************************.*.\n****************************....\n***************************.***.\n**************************..**..\n*************************.*.*.*.\n************************........\n***********************.*******.\n**********************..******..\n*********************.*.*****.*.\n********************....****....\n*******************.***.***.***.\n******************..**..**..**..\n*****************.*.*.*.*.*.*.*.\n*..."
},
{
"input": "2 5\n..\n*.",
"output": "................................\n*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.\n**..**..**..**..**..**..**..**..\n***.***.***.***.***.***.***.***.\n****....****....****....****....\n*****.*.*****.*.*****.*.*****.*.\n******..******..******..******..\n*******.*******.*******.*******.\n********........********........\n*********.*.*.*.*********.*.*.*.\n**********..**..**********..**..\n***********.***.***********.***.\n************....************....\n*************.*.*************.*.\n**************..**************..\n*..."
},
{
"input": "2 5\n**\n*.",
"output": "********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n********************************\n*..."
},
{
"input": "3 1\n*..\n...\n..*",
"output": "*..\n...\n..*"
},
{
"input": "3 2\n**.\n.**\n..*",
"output": "********.\n******.**\n******..*\n**.******\n.********\n..*******\n**.**.***\n.**.*****\n..*..****"
},
{
"input": "3 2\n..*\n***\n*..",
"output": "..*..****\n*********\n*..*..***\n*********\n*********\n*********\n***..*..*\n*********\n****..*.."
},
{
"input": "3 3\n**.\n..*\n*.*",
"output": "**************************.\n************************..*\n*************************.*\n********************.**.***\n******************..*..****\n*******************.**.****\n***********************.***\n*********************..****\n**********************.****\n********.********.*********\n******..*******..**********\n*******.********.**********\n**.**.*****.**.************\n..*..****..*..*************\n*.**.*****.**.*************\n*****.********.************\n***..*******..*************\n****.********.****..."
},
{
"input": "3 3\n*.*\n.*.\n..*",
"output": "*************.*************\n************.*.************\n************..*************\n**********.*****.**********\n*********.*.***.*.*********\n*********..****..**********\n**********.**.*************\n*********.*..*.************\n*********..*..*************\n****.*****************.****\n***.*.***************.*.***\n***..****************..****\n*.*****.***********.*****.*\n.*.***.*.*********.*.***.*.\n..****..**********..****..*\n*.**.**************.**.****\n.*..*.************.*..*.***\n..*..*************..."
},
{
"input": "3 3\n...\n*..\n..*",
"output": "...........................\n*..*..*..*..*..*..*..*..*..\n..*..*..*..*..*..*..*..*..*\n***......***......***......\n****..*..****..*..****..*..\n***..*..****..*..****..*..*\n......***......***......***\n*..*..****..*..****..*..***\n..*..****..*..****..*..****\n*********..................\n**********..*..*..*..*..*..\n*********..*..*..*..*..*..*\n************......***......\n*************..*..****..*..\n************..*..****..*..*\n*********......***......***\n**********..*..****..*..***\n*********..*..****..."
},
{
"input": "3 4\n***\n*.*\n***",
"output": "*********************************************************************************\n*********************************************************************************\n*********************************************************************************\n*********************************************************************************\n*********************************************************************************\n*********************************************************************************\n*************..."
},
{
"input": "3 4\n*..\n*..\n*..",
"output": "****************************************..*..****..*..*************..*..****..*..\n****************************************..*..****..*..*************..*..****..*..\n****************************************..*..****..*..*************..*..****..*..\n****************************************..*..****..*..*************..*..****..*..\n****************************************..*..****..*..*************..*..****..*..\n****************************************..*..****..*..*************..*..****..*..\n*************..."
},
{
"input": "3 4\n..*\n...\n.*.",
"output": "..*..****..*..*************..*..****..*..****************************************\n......***......************......***......***************************************\n.*..*.***.*..*.************.*..*.***.*..*.***************************************\n..*..*..*..*..*..**********..*..*..*..*..*..*************************************\n..................*********..................************************************\n.*..*..*..*..*..*.*********.*..*..*..*..*..*.************************************\n..****..*..**..."
},
{
"input": "3 5\n...\n*.*\n*..",
"output": "...................................................................................................................................................................................................................................................\n*.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.**.*\n*..*..*..*..*..*..*....."
},
{
"input": "3 5\n.*.\n*.*\n.*.",
"output": ".*.***.*.*********.*.***.*.***************************.*.***.*.*********.*.***.*.*********************************************************************************.*.***.*.*********.*.***.*.***************************.*.***.*.*********.*.***.*.\n*.*****.***********.*****.*****************************.*****.***********.*****.***********************************************************************************.*****.***********.*****.*****************************.*****.***********.*****.*\n.*.***.*.*********.*...."
},
{
"input": "3 5\n***\n**.\n***",
"output": "***************************************************************************************************************************************************************************************************************************************************\n***************************************************************************************************************************************************************************************************************************************************\n*********************..."
},
{
"input": "3 5\n.*.\n***\n**.",
"output": ".*.***.*.*********.*.***.*.***************************.*.***.*.*********.*.***.*.*********************************************************************************.*.***.*.*********.*.***.*.***************************.*.***.*.*********.*.***.*.\n***************************************************************************************************************************************************************************************************************************************************\n**.*****.***********...."
}
] | 1,602,681,987 | 1,287 | Python 3 | OK | TESTS | 30 | 218 | 921,600 | import sys
from array import array # noqa: F401
def input1():
with open('input.txt') as fp:
return fp.readlines()
def output1(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
def input2():
return [line.decode('utf-8') for line in sys.stdin.buffer.readlines()]
def output2(ans):
print(ans)
submit = 1
if submit:
input = input1
output = output1
else:
input = input2
output = output2
s = input()
n, k = map(int, s[0].split())
model = [list(line.rstrip()) for line in s[1:]]
a = [['.']]
m = 1
for e in range(1, k + 1):
size = n**e
b = [['*'] * size for _ in range(size)]
for i in range(len(a)):
for j in range(len(a)):
if a[i][j] == '.':
for di in range(n):
b[i * n + di][j * n:(j + 1) * n] = model[di]
a = b
output('\n'.join(''.join(row) for row in a))
| Title: Fractal
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm:
Step 1. The paper is divided into *n*2 identical squares and some of them are painted black according to the model.
Step 2. Every square that remains white is divided into *n*2 smaller squares and some of them are painted black according to the model.
Every following step repeats step 2.
Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals.
Input Specification:
The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square.
Output Specification:
Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm.
Demo Input:
['2 3\n.*\n..\n', '3 2\n.*.\n***\n.*.\n']
Demo Output:
['.*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n', '.*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n']
Note:
none | ```python
import sys
from array import array # noqa: F401
def input1():
with open('input.txt') as fp:
return fp.readlines()
def output1(ans: str):
with open('output.txt', mode='w') as fp:
fp.write(ans)
def input2():
return [line.decode('utf-8') for line in sys.stdin.buffer.readlines()]
def output2(ans):
print(ans)
submit = 1
if submit:
input = input1
output = output1
else:
input = input2
output = output2
s = input()
n, k = map(int, s[0].split())
model = [list(line.rstrip()) for line in s[1:]]
a = [['.']]
m = 1
for e in range(1, k + 1):
size = n**e
b = [['*'] * size for _ in range(size)]
for i in range(len(a)):
for j in range(len(a)):
if a[i][j] == '.':
for di in range(n):
b[i * n + di][j * n:(j + 1) * n] = model[di]
a = b
output('\n'.join(''.join(row) for row in a))
``` | 3.938634 |
402 | B | Trees in a Row | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes? | The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row. | In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them. | [
"4 1\n1 2 1 5\n",
"4 1\n1 2 3 4\n"
] | [
"2\n+ 3 2\n- 4 1\n",
"0\n"
] | none | 1,000 | [
{
"input": "4 1\n1 2 1 5",
"output": "2\n+ 3 2\n- 4 1"
},
{
"input": "4 1\n1 2 3 4",
"output": "0"
},
{
"input": "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "0"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "0"
},
{
"input": "50 5\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 131 136 141 146 151 156 161 166 755 176 181 186 191 196 201 206 211 216 221 226 231 236 241 246",
"output": "5\n- 1 231\n- 11 614\n- 17 521\n- 20 616\n- 35 584"
},
{
"input": "10 99\n1 100 199 298 397 496 364 694 793 676",
"output": "2\n+ 7 231\n+ 10 216"
},
{
"input": "1 99\n1",
"output": "0"
},
{
"input": "2 99\n1 100",
"output": "0"
},
{
"input": "3 99\n1 100 199",
"output": "0"
},
{
"input": "4 99\n1 100 199 298",
"output": "0"
},
{
"input": "3 99\n295 566 992",
"output": "2\n- 2 172\n- 3 499"
},
{
"input": "2 99\n307 854",
"output": "1\n- 2 448"
},
{
"input": "7 1\n1 1 2 3 4 5 6",
"output": "6\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1\n+ 6 1\n+ 7 1"
},
{
"input": "5 1\n1 1 2 3 4",
"output": "4\n+ 2 1\n+ 3 1\n+ 4 1\n+ 5 1"
},
{
"input": "4 2\n1 1 3 5",
"output": "3\n+ 2 2\n+ 3 2\n+ 4 2"
},
{
"input": "4 1\n1 1 2 3",
"output": "3\n+ 2 1\n+ 3 1\n+ 4 1"
},
{
"input": "5 1\n1 1 1 2 3",
"output": "4\n+ 2 1\n+ 3 2\n+ 4 2\n+ 5 2"
},
{
"input": "3 1\n1 1 2",
"output": "2\n+ 2 1\n+ 3 1"
}
] | 1,402,172,495 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | def main():
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = {}
for i, v in enumerate(a):
good_first = v - k * i
if good_first >= 1:
if good_first not in d:
d[good_first] = 0
d[good_first] += 1
best_first = d.keys()[d.values().index(max(d.values()))]
print(n - d[best_first])
for i, v in enumerate(a):
diff = v - k * i
if diff > 0:
print('+', i + 1, diff)
else:
print('-', i + 1, -diff)
main() | Title: Trees in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a**i*<==<=*k*, where *k* is the number the Queen chose.
Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes?
Input Specification:
The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row.
Output Specification:
In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, print on the corresponding line "- j x".
If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them.
Demo Input:
['4 1\n1 2 1 5\n', '4 1\n1 2 3 4\n']
Demo Output:
['2\n+ 3 2\n- 4 1\n', '0\n']
Note:
none | ```python
def main():
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = {}
for i, v in enumerate(a):
good_first = v - k * i
if good_first >= 1:
if good_first not in d:
d[good_first] = 0
d[good_first] += 1
best_first = d.keys()[d.values().index(max(d.values()))]
print(n - d[best_first])
for i, v in enumerate(a):
diff = v - k * i
if diff > 0:
print('+', i + 1, diff)
else:
print('-', i + 1, -diff)
main()
``` | -1 |
|
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,687,495,357 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n=int(input())
mishka_wins=0
chris_wins=0
for i in range(n):
m,c=map(int,input().split())
if m>c:
mishka_wins += 1
if c>m:
chris_wins +=1
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
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
n=int(input())
mishka_wins=0
chris_wins=0
for i in range(n):
m,c=map(int,input().split())
if m>c:
mishka_wins += 1
if c>m:
chris_wins +=1
if mishka_wins > chris_wins:
print("Mishka")
elif chris_wins > mishka_wins:
print("Chris")
else:
print("Friendship is magic")
``` | 0 |
|
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair. | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe. | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32",
"output": "25"
},
{
"input": "50\n1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50",
"output": "1"
},
{
"input": "50\n50 50 49 49 48 48 47 47 46 46 45 45 44 44 43 43 42 42 41 41 40 40 39 39 38 38 37 37 36 36 35 35 34 34 33 33 32 32 31 31 30 30 29 29 28 28 27 27 26 26 25 25 24 24 23 23 22 22 21 21 20 20 19 19 18 18 17 17 16 16 15 15 14 14 13 13 12 12 11 11 10 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1",
"output": "1"
},
{
"input": "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 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",
"output": "50"
},
{
"input": "50\n50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "50"
},
{
"input": "10\n2 9 4 1 6 7 10 3 1 5 8 6 2 3 10 7 4 8 5 9",
"output": "9"
}
] | 1,536,098,890 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 10,854,400 | n = int(input())
h = input().split(' ')
s = list()
m = 0
for i in h :
if s.count(i)>0 :
s.remove(i)
else :
s.append(i)
if len(s)>m :
m = len(s)
print(m)
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe.
Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time?
Input Specification:
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*.
It is guaranteed that Andryusha took exactly two socks of each pair.
Output Specification:
Print single integer — the maximum number of socks that were on the table at the same time.
Demo Input:
['1\n1 1\n', '3\n2 1 1 3 2 3\n']
Demo Output:
['1\n', '2\n']
Note:
In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- Initially the table was empty, he took out a sock from pair 2 and put it on the table. - Sock (2) was on the table. Andryusha took out a sock from pair 1 and put it on the table. - Socks (1, 2) were on the table. Andryusha took out a sock from pair 1, and put this pair into the wardrobe. - Sock (2) was on the table. Andryusha took out a sock from pair 3 and put it on the table. - Socks (2, 3) were on the table. Andryusha took out a sock from pair 2, and put this pair into the wardrobe. - Sock (3) was on the table. Andryusha took out a sock from pair 3 and put this pair into the wardrobe. | ```python
n = int(input())
h = input().split(' ')
s = list()
m = 0
for i in h :
if s.count(i)>0 :
s.remove(i)
else :
s.append(i)
if len(s)>m :
m = len(s)
print(m)
``` | 0 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,634,645,672 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 0 | n=int(input())
d={}
l=[]
for test in range(n):
a,b=input().split()
l.append((a,b))
d[a]=int(b)+d.get(a,0)
m=0
for item in d.items():
m=max(m,item[1])
d={}
x=[]
for a,b in l:
c=int(b)+d.get(a,0)
d[a]=c
if(c>=m):
x.append(a)
r=""
for c in x:
if d[c]==m:
r=c
break
print(r)
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
n=int(input())
d={}
l=[]
for test in range(n):
a,b=input().split()
l.append((a,b))
d[a]=int(b)+d.get(a,0)
m=0
for item in d.items():
m=max(m,item[1])
d={}
x=[]
for a,b in l:
c=int(b)+d.get(a,0)
d[a]=c
if(c>=m):
x.append(a)
r=""
for c in x:
if d[c]==m:
r=c
break
print(r)
``` | 3.938 |
803 | B | Distances to Zero | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | null | null | You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array. | The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109). | Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*. | [
"9\n2 1 0 3 0 0 3 2 4\n",
"5\n0 1 2 3 4\n",
"7\n5 6 0 1 -2 3 4\n"
] | [
"2 1 0 1 0 0 1 2 3 ",
"0 1 2 3 4 ",
"2 1 0 1 2 3 4 "
] | none | 0 | [
{
"input": "9\n2 1 0 3 0 0 3 2 4",
"output": "2 1 0 1 0 0 1 2 3 "
},
{
"input": "5\n0 1 2 3 4",
"output": "0 1 2 3 4 "
},
{
"input": "7\n5 6 0 1 -2 3 4",
"output": "2 1 0 1 2 3 4 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 1",
"output": "0 1 "
},
{
"input": "2\n1 0",
"output": "1 0 "
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 "
},
{
"input": "5\n-1000000000 -1000000000 0 1000000000 1000000000",
"output": "2 1 0 1 2 "
},
{
"input": "5\n-1000000000 1000000000 1000000000 1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "15\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 0",
"output": "14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 "
},
{
"input": "15\n0 0 0 0 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000",
"output": "0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 "
},
{
"input": "15\n-1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 0 -1000000000 -1000000000 0 0 1000000000 -1000000000 0 -1000000000",
"output": "6 5 4 3 2 1 0 1 1 0 0 1 1 0 1 "
},
{
"input": "15\n-1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 1000000000 0 0 0 0",
"output": "11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 "
},
{
"input": "4\n0 0 2 0",
"output": "0 0 1 0 "
},
{
"input": "15\n1 2 3 4 0 1 2 3 -5 -4 -3 -1 0 5 4",
"output": "4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 "
},
{
"input": "2\n0 -1",
"output": "0 1 "
},
{
"input": "5\n0 -1 -1 -1 0",
"output": "0 1 2 1 0 "
},
{
"input": "5\n0 0 0 -1 0",
"output": "0 0 0 1 0 "
},
{
"input": "3\n0 0 -1",
"output": "0 0 1 "
},
{
"input": "3\n0 -1 -1",
"output": "0 1 2 "
},
{
"input": "12\n0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0",
"output": "0 1 2 3 4 5 5 4 3 2 1 0 "
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 "
},
{
"input": "30\n0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "1\n0",
"output": "0 "
},
{
"input": "2\n0 -1000000000",
"output": "0 1 "
},
{
"input": "2\n0 1000000000",
"output": "0 1 "
},
{
"input": "2\n-1000000000 0",
"output": "1 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "2\n0 0",
"output": "0 0 "
},
{
"input": "3\n0 -1000000000 -1000000000",
"output": "0 1 2 "
},
{
"input": "3\n0 1000000000 1000000000",
"output": "0 1 2 "
},
{
"input": "3\n1000000000 1000000000 0",
"output": "2 1 0 "
},
{
"input": "3\n0 0 -1000000000",
"output": "0 0 1 "
},
{
"input": "3\n0 1000000000 0",
"output": "0 1 0 "
},
{
"input": "3\n-1000000000 0 0",
"output": "1 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "3\n0 0 0",
"output": "0 0 0 "
},
{
"input": "4\n0 -1000000000 -1000000000 -1000000000",
"output": "0 1 2 3 "
},
{
"input": "4\n1000000000 -1000000000 0 -1000000000",
"output": "2 1 0 1 "
},
{
"input": "4\n1000000000 -1000000000 1000000000 0",
"output": "3 2 1 0 "
},
{
"input": "4\n0 0 -1000000000 1000000000",
"output": "0 0 1 2 "
},
{
"input": "4\n0 0 1000000000 -1000000000",
"output": "0 0 1 2 "
},
{
"input": "4\n-1000000000 1000000000 0 0",
"output": "2 1 0 0 "
},
{
"input": "4\n0 0 0 -1000000000",
"output": "0 0 0 1 "
},
{
"input": "4\n1000000000 0 0 0",
"output": "1 0 0 0 "
},
{
"input": "4\n1000000000 0 0 0",
"output": "1 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "4\n0 0 0 0",
"output": "0 0 0 0 "
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 "
},
{
"input": "5\n1000000000 -1000000000 -1000000000 1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "5\n1000000000 -1000000000 1000000000 -1000000000 0",
"output": "4 3 2 1 0 "
},
{
"input": "5\n0 0 -1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 "
},
{
"input": "5\n1000000000 0 -1000000000 0 -1000000000",
"output": "1 0 1 0 1 "
},
{
"input": "5\n1000000000 1000000000 1000000000 0 0",
"output": "3 2 1 0 0 "
},
{
"input": "5\n0 0 0 -1000000000 -1000000000",
"output": "0 0 0 1 2 "
},
{
"input": "5\n-1000000000 1000000000 0 0 0",
"output": "2 1 0 0 0 "
},
{
"input": "5\n1000000000 1000000000 0 0 0",
"output": "2 1 0 0 0 "
},
{
"input": "5\n0 0 0 0 -1000000000",
"output": "0 0 0 0 1 "
},
{
"input": "5\n0 0 1000000000 0 0",
"output": "0 0 1 0 0 "
},
{
"input": "5\n1000000000 0 0 0 0",
"output": "1 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "5\n0 0 0 0 0",
"output": "0 0 0 0 0 "
},
{
"input": "6\n0 1000000000 -1000000000 1000000000 -1000000000 1000000000",
"output": "0 1 2 3 4 5 "
},
{
"input": "6\n-1000000000 -1000000000 1000000000 1000000000 1000000000 0",
"output": "5 4 3 2 1 0 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0",
"output": "5 4 3 2 1 0 "
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 4 "
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000",
"output": "0 0 1 2 3 4 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 -1000000000 0 0",
"output": "4 3 2 1 0 0 "
},
{
"input": "6\n0 0 0 -1000000000 1000000000 1000000000",
"output": "0 0 0 1 2 3 "
},
{
"input": "6\n-1000000000 1000000000 -1000000000 0 0 0",
"output": "3 2 1 0 0 0 "
},
{
"input": "6\n-1000000000 -1000000000 1000000000 0 0 0",
"output": "3 2 1 0 0 0 "
},
{
"input": "6\n0 0 0 0 -1000000000 1000000000",
"output": "0 0 0 0 1 2 "
},
{
"input": "6\n0 0 0 -1000000000 1000000000 0",
"output": "0 0 0 1 1 0 "
},
{
"input": "6\n1000000000 1000000000 0 0 0 0",
"output": "2 1 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 1 "
},
{
"input": "6\n0 0 0 1000000000 0 0",
"output": "0 0 0 1 0 0 "
},
{
"input": "6\n1000000000 0 0 0 0 0",
"output": "1 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "6\n0 0 0 0 0 0",
"output": "0 0 0 0 0 0 "
},
{
"input": "7\n0 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000",
"output": "0 1 2 3 4 5 6 "
},
{
"input": "7\n1000000000 1000000000 -1000000000 0 -1000000000 1000000000 -1000000000",
"output": "3 2 1 0 1 2 3 "
},
{
"input": "7\n1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 0",
"output": "6 5 4 3 2 1 0 "
},
{
"input": "7\n0 0 1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 1 2 3 4 5 "
},
{
"input": "7\n0 1000000000 1000000000 -1000000000 1000000000 1000000000 0",
"output": "0 1 2 3 2 1 0 "
},
{
"input": "7\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 0 0",
"output": "5 4 3 2 1 0 0 "
},
{
"input": "7\n0 0 0 1000000000 -1000000000 -1000000000 1000000000",
"output": "0 0 0 1 2 3 4 "
},
{
"input": "7\n-1000000000 0 0 -1000000000 0 -1000000000 1000000000",
"output": "1 0 0 1 0 1 2 "
},
{
"input": "7\n1000000000 1000000000 1000000000 -1000000000 0 0 0",
"output": "4 3 2 1 0 0 0 "
},
{
"input": "7\n0 0 0 0 -1000000000 -1000000000 1000000000",
"output": "0 0 0 0 1 2 3 "
},
{
"input": "7\n0 -1000000000 0 0 0 -1000000000 1000000000",
"output": "0 1 0 0 0 1 2 "
},
{
"input": "7\n1000000000 1000000000 1000000000 0 0 0 0",
"output": "3 2 1 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 -1000000000 1000000000",
"output": "0 0 0 0 0 1 2 "
},
{
"input": "7\n0 -1000000000 0 0 0 0 -1000000000",
"output": "0 1 0 0 0 0 1 "
},
{
"input": "7\n-1000000000 1000000000 0 0 0 0 0",
"output": "2 1 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 0 1 "
},
{
"input": "7\n0 0 0 0 0 1000000000 0",
"output": "0 0 0 0 0 1 0 "
},
{
"input": "7\n1000000000 0 0 0 0 0 0",
"output": "1 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "7\n0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 "
},
{
"input": "8\n0 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 1 2 3 4 5 6 7 "
},
{
"input": "8\n0 -1000000000 1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000",
"output": "0 1 2 3 4 5 6 7 "
},
{
"input": "8\n1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 0",
"output": "7 6 5 4 3 2 1 0 "
},
{
"input": "8\n0 0 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 1 2 3 4 5 6 "
},
{
"input": "8\n1000000000 0 0 -1000000000 -1000000000 1000000000 -1000000000 -1000000000",
"output": "1 0 0 1 2 3 4 5 "
},
{
"input": "8\n1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 0 0",
"output": "6 5 4 3 2 1 0 0 "
},
{
"input": "8\n0 0 0 1000000000 1000000000 -1000000000 -1000000000 -1000000000",
"output": "0 0 0 1 2 3 4 5 "
},
{
"input": "8\n-1000000000 0 0 1000000000 1000000000 0 -1000000000 1000000000",
"output": "1 0 0 1 1 0 1 2 "
},
{
"input": "8\n1000000000 1000000000 1000000000 -1000000000 -1000000000 0 0 0",
"output": "5 4 3 2 1 0 0 0 "
},
{
"input": "8\n0 0 0 0 1000000000 1000000000 1000000000 -1000000000",
"output": "0 0 0 0 1 2 3 4 "
},
{
"input": "8\n1000000000 0 1000000000 -1000000000 0 -1000000000 0 0",
"output": "1 0 1 1 0 1 0 0 "
},
{
"input": "8\n-1000000000 -1000000000 -1000000000 -1000000000 0 0 0 0",
"output": "4 3 2 1 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 1000000000 1000000000 -1000000000",
"output": "0 0 0 0 0 1 2 3 "
},
{
"input": "8\n-1000000000 0 -1000000000 0 0 1000000000 0 0",
"output": "1 0 1 0 0 1 0 0 "
},
{
"input": "8\n1000000000 1000000000 1000000000 0 0 0 0 0",
"output": "3 2 1 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 -1000000000 -1000000000",
"output": "0 0 0 0 0 0 1 2 "
},
{
"input": "8\n0 0 0 1000000000 -1000000000 0 0 0",
"output": "0 0 0 1 1 0 0 0 "
},
{
"input": "8\n1000000000 1000000000 0 0 0 0 0 0",
"output": "2 1 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 -1000000000",
"output": "0 0 0 0 0 0 0 1 "
},
{
"input": "8\n0 1000000000 0 0 0 0 0 0",
"output": "0 1 0 0 0 0 0 0 "
},
{
"input": "8\n1000000000 0 0 0 0 0 0 0",
"output": "1 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
},
{
"input": "8\n0 0 0 0 0 0 0 0",
"output": "0 0 0 0 0 0 0 0 "
}
] | 1,577,973,306 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | a=list(map(int, input().split()))
for i in range(len(a)):
if a[i]!=0:
b=[a[:i + 1], a[i:]]
b[0]=list(reversed(b[0]))
left=len(a)+1
right=len(a)+1
for j in range(len(b[0])):
if b[0][j]==0:
left=j
break
for k in range(len(b[1])):
if b[1][k]==0:
right=k
break
a[i]=min(left,right)
print(a)
| Title: Distances to Zero
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the array of integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=2·105) — length of the array *a*. The second line contains integer elements of the array separated by single spaces (<=-<=109<=≤<=*a**i*<=≤<=109).
Output Specification:
Print the sequence *d*0,<=*d*1,<=...,<=*d**n*<=-<=1, where *d**i* is the difference of indices between *i* and nearest *j* such that *a**j*<==<=0. It is possible that *i*<==<=*j*.
Demo Input:
['9\n2 1 0 3 0 0 3 2 4\n', '5\n0 1 2 3 4\n', '7\n5 6 0 1 -2 3 4\n']
Demo Output:
['2 1 0 1 0 0 1 2 3 ', '0 1 2 3 4 ', '2 1 0 1 2 3 4 ']
Note:
none | ```python
a=list(map(int, input().split()))
for i in range(len(a)):
if a[i]!=0:
b=[a[:i + 1], a[i:]]
b[0]=list(reversed(b[0]))
left=len(a)+1
right=len(a)+1
for j in range(len(b[0])):
if b[0][j]==0:
left=j
break
for k in range(len(b[1])):
if b[1][k]==0:
right=k
break
a[i]=min(left,right)
print(a)
``` | 0 |
|
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"output": "99"
},
{
"input": "gngvi",
"output": "44"
},
{
"input": "aaaaa",
"output": "0"
},
{
"input": "a",
"output": "0"
},
{
"input": "z",
"output": "1"
},
{
"input": "vyadeehhikklnoqrs",
"output": "28"
},
{
"input": "jjiihhhhgggfedcccbazyxx",
"output": "21"
},
{
"input": "fyyptqqxuciqvwdewyppjdzur",
"output": "117"
},
{
"input": "fqcnzmzmbobmancqcoalzmanaobpdse",
"output": "368"
},
{
"input": "zzzzzaaaaaaazzzzzzaaaaaaazzzzzzaaaazzzza",
"output": "8"
},
{
"input": "aucnwhfixuruefkypvrvnvznwtjgwlghoqtisbkhuwxmgzuljvqhmnwzisnsgjhivnjmbknptxatdkelhzkhsuxzrmlcpeoyukiy",
"output": "644"
},
{
"input": "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss",
"output": "8"
},
{
"input": "nypjygrdtpzpigzyrisqeqfriwgwlengnezppgttgtndbrryjdl",
"output": "421"
},
{
"input": "pnllnnmmmmoqqqqqrrtssssuuvtsrpopqoonllmonnnpppopnonoopooqpnopppqppqstuuuwwwwvxzxzzaa",
"output": "84"
},
{
"input": "btaoahqgxnfsdmzsjxgvdwjukcvereqeskrdufqfqgzqfsftdqcthtkcnaipftcnco",
"output": "666"
},
{
"input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrwwwwwwwwww",
"output": "22"
},
{
"input": "uyknzcrwjyzmscqucclvacmorepdgmnyhmakmmnygqwglrxkxhkpansbmruwxdeoprxzmpsvwackopujxbbkpwyeggsvjykpxh",
"output": "643"
},
{
"input": "gzwpooohffcxwtpjgfzwtooiccxsrrokezutoojdzwsrmmhecaxwrojcbyrqlfdwwrliiib",
"output": "245"
},
{
"input": "dbvnkktasjdwqsrzfwwtmjgbcxggdxsoeilecihduypktkkbwfbruxzzhlttrssicgdwqruddwrlbtxgmhdbatzvdxbbro",
"output": "468"
},
{
"input": "mdtvowlktxzzbuaeiuebfeorgbdczauxsovbucactkvyvemsknsjfhifqgycqredzchipmkvzbxdjkcbyukomjlzvxzoswumned",
"output": "523"
},
{
"input": "kkkkkkkaaaaxxaaaaaaaxxxxxxxxaaaaaaxaaaaaaaaaakkkkkkkkkaaaaaaannnnnxxxxkkkkkkkkaannnnnnna",
"output": "130"
},
{
"input": "dffiknqqrsvwzcdgjkmpqtuwxadfhkkkmpqrtwxyadfggjmpppsuuwyyzcdgghhknnpsvvvwwwyabccffiloqruwwyyzabeeehh",
"output": "163"
},
{
"input": "qpppmmkjihgecbyvvsppnnnkjiffeebaaywutrrqpmkjhgddbzzzywtssssqnmmljheddbbaxvusrqonmlifedbbzyywwtqnkheb",
"output": "155"
},
{
"input": "wvvwwwvvwxxxyyyxxwwvwwvuttttttuvvwxxwxxyxxwwwwwvvuttssrssstsssssrqpqqppqrssrsrrssrssssrrsrqqrrqpppqp",
"output": "57"
},
{
"input": "dqcpcobpcobnznamznamzlykxkxlxlylzmaobnaobpbnanbpcoaobnboaoboanzlymzmykylymylzlylymanboanaocqdqesfrfs",
"output": "1236"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnaaaaaaaaaaaaaaaaaaaakkkkkkkkkkkkkkkkkkkkkkaaaaaaaaaaaaaaaaaaaaxxxxxxxxxxxxxxxxxx",
"output": "49"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "cgilqsuwzaffilptwwbgmnttyyejkorxzflqvzbddhmnrvxchijpuwaeiimosxyycejlpquuwbfkpvbgijkqvxybdjjjptxcfkqt",
"output": "331"
},
{
"input": "ufsepwgtzgtgjssxaitgpailuvgqweoppszjwhoxdhhhpwwdorwfrdjwcdekxiktwziqwbkvbknrtvajpyeqbjvhiikxxaejjpte",
"output": "692"
},
{
"input": "uhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuhuh",
"output": "1293"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvgggggggggggggggggggggggggggggggggggggggggggggggggg",
"output": "16"
},
{
"input": "lyidmjyzbszgiwkxhhpnnthfwcvvstueionspfrvqgkvngmwyhezlosrpdnbvtcjjxxsykixwnepbumaacdzadlqhnjlcejovple",
"output": "616"
},
{
"input": "etzqqbaveffalkdguunfmyyrzkccnxmlluxeasqmopxzfvlkbhipqdwjgrttoemruohgwukfisdhznqyvhswbbypoxgtxyappcrl",
"output": "605"
},
{
"input": "lizussgedcbdjhrbeskhgatyozvwwekanlggcstijrniivupmcoofbaxfqrxddyzzptwxcftlhajsmmkkriarrqtkoauhcqefyud",
"output": "549"
},
{
"input": "dvjuvgfdogpknmbowlsfjzcimnygbtjiucyeeroqwhmzwpjqxlbjkqawrdtmvxbiqufllfuqibxvmtdrwaqkjblxqjpwzmhwqore",
"output": "688"
},
{
"input": "eeycuijtbgynmiczjfslwobmnkpgodfgvujvduyfeqchuaoktqrrairkkmmsjahltfcxwtpzzyddxrqfxabfoocmpuviinrjitsc",
"output": "604"
},
{
"input": "cgglnakewwvzoytaghksebrhjdbcdegssuzilrcppayxtgxopybbwshvyqnzhdsifkuwghourmeottrgjwdqpihbklvfzxpomqsa",
"output": "572"
},
{
"input": "aexullmxncckzryymfnuugdklaffevabqqztelpvojecljnhqldazdcaamubpenwxikysxxjjctvbndprsolzehywmgnvkgqvrfp",
"output": "609"
},
{
"input": "psnoieutsvvcwfhtnnphhxkwigzsbzyjmdiyl",
"output": "223"
},
{
"input": "aa",
"output": "0"
}
] | 1,688,808,564 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 44 | 62 | 0 | s = list(input())
r = 0
current = "a"
for l in s:
d = min((ord(l) - ord(current)) % 26, (ord(current) - ord(l)) % 26)
r += d
current = l
print(r)
# This porblem was solved with a lot of help from ChatGPT,
# I could not figure out who to rotate around and it gave me two big hints:
# I can rotate around using module arithmetic, and
# I can use `ord()` function to get a number of a ASCII character instead of defining
# my own list of letters in the alphabet. | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture:
After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.
Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.
Input Specification:
The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Output Specification:
Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.
Demo Input:
['zeus\n', 'map\n', 'ares\n']
Demo Output:
['18\n', '35\n', '34\n']
Note:
To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | ```python
s = list(input())
r = 0
current = "a"
for l in s:
d = min((ord(l) - ord(current)) % 26, (ord(current) - ord(l)) % 26)
r += d
current = l
print(r)
# This porblem was solved with a lot of help from ChatGPT,
# I could not figure out who to rotate around and it gave me two big hints:
# I can rotate around using module arithmetic, and
# I can use `ord()` function to get a number of a ASCII character instead of defining
# my own list of letters in the alphabet.
``` | 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,684,322,879 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 40 | 62 | 0 | a = input()
if len(a)<7:
print("NO")
else:
cur='2'
count=0
for i in range(len(a)):
if i == len(a)-1 and count<7:
print("NO")
break
if count==7:
print('YES')
break
if a[i] == cur:
count+=1
else:
count=1
cur=a[i]
| 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
a = input()
if len(a)<7:
print("NO")
else:
cur='2'
count=0
for i in range(len(a)):
if i == len(a)-1 and count<7:
print("NO")
break
if count==7:
print('YES')
break
if a[i] == cur:
count+=1
else:
count=1
cur=a[i]
``` | 0 |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
},
{
"input": "997",
"output": "328"
},
{
"input": "2",
"output": "1"
},
{
"input": "1987",
"output": "660"
},
{
"input": "1993",
"output": "656"
},
{
"input": "1997",
"output": "996"
},
{
"input": "1999",
"output": "648"
},
{
"input": "1297",
"output": "432"
},
{
"input": "163",
"output": "54"
},
{
"input": "1259",
"output": "576"
},
{
"input": "821",
"output": "320"
},
{
"input": "29",
"output": "12"
},
{
"input": "43",
"output": "12"
},
{
"input": "1949",
"output": "972"
},
{
"input": "1879",
"output": "624"
},
{
"input": "1759",
"output": "584"
},
{
"input": "1597",
"output": "432"
},
{
"input": "1619",
"output": "808"
},
{
"input": "1277",
"output": "560"
},
{
"input": "1097",
"output": "544"
},
{
"input": "953",
"output": "384"
},
{
"input": "751",
"output": "200"
},
{
"input": "607",
"output": "200"
},
{
"input": "509",
"output": "252"
},
{
"input": "431",
"output": "168"
},
{
"input": "317",
"output": "156"
},
{
"input": "211",
"output": "48"
},
{
"input": "127",
"output": "36"
},
{
"input": "101",
"output": "40"
},
{
"input": "31",
"output": "8"
}
] | 1,687,540,441 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 154 | 1,536,000 | p=int(input())
g=0
for x in range(1,p):
i=x
u=1
o=0
while u<p-1:
x%=p
if (x-1)%p==0:
break
x*=i
u+=1
else:
if (x-1)%p==0:
g+=1
print(g) | Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots .
Input Specification:
The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime.
Output Specification:
Output on a single line the number of primitive roots .
Demo Input:
['3\n', '5\n']
Demo Output:
['1\n', '2\n']
Note:
The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf94d00bc49a7ac458fd58.png" style="max-width: 100.0%;max-height: 100.0%;"/> are 2 and 3. | ```python
p=int(input())
g=0
for x in range(1,p):
i=x
u=1
o=0
while u<p-1:
x%=p
if (x-1)%p==0:
break
x*=i
u+=1
else:
if (x-1)%p==0:
g+=1
print(g)
``` | 3 |
|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate. | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "10\n01",
"output": "11"
},
{
"input": "00111111\n11011101",
"output": "11100010"
},
{
"input": "011001100\n101001010",
"output": "110000110"
},
{
"input": "1100100001\n0110101100",
"output": "1010001101"
},
{
"input": "00011101010\n10010100101",
"output": "10001001111"
},
{
"input": "100000101101\n111010100011",
"output": "011010001110"
},
{
"input": "1000001111010\n1101100110001",
"output": "0101101001011"
},
{
"input": "01011111010111\n10001110111010",
"output": "11010001101101"
},
{
"input": "110010000111100\n001100101011010",
"output": "111110101100110"
},
{
"input": "0010010111110000\n0000000011010110",
"output": "0010010100100110"
},
{
"input": "00111110111110000\n01111100001100000",
"output": "01000010110010000"
},
{
"input": "101010101111010001\n001001111101111101",
"output": "100011010010101100"
},
{
"input": "0110010101111100000\n0011000101000000110",
"output": "0101010000111100110"
},
{
"input": "11110100011101010111\n00001000011011000000",
"output": "11111100000110010111"
},
{
"input": "101010101111101101001\n111010010010000011111",
"output": "010000111101101110110"
},
{
"input": "0000111111100011000010\n1110110110110000001010",
"output": "1110001001010011001000"
},
{
"input": "10010010101000110111000\n00101110100110111000111",
"output": "10111100001110001111111"
},
{
"input": "010010010010111100000111\n100100111111100011001110",
"output": "110110101101011111001001"
},
{
"input": "0101110100100111011010010\n0101100011010111001010001",
"output": "0000010111110000010000011"
},
{
"input": "10010010100011110111111011\n10000110101100000001000100",
"output": "00010100001111110110111111"
},
{
"input": "000001111000000100001000000\n011100111101111001110110001",
"output": "011101000101111101111110001"
},
{
"input": "0011110010001001011001011100\n0000101101000011101011001010",
"output": "0011011111001010110010010110"
},
{
"input": "11111000000000010011001101111\n11101110011001010100010000000",
"output": "00010110011001000111011101111"
},
{
"input": "011001110000110100001100101100\n001010000011110000001000101001",
"output": "010011110011000100000100000101"
},
{
"input": "1011111010001100011010110101111\n1011001110010000000101100010101",
"output": "0000110100011100011111010111010"
},
{
"input": "10111000100001000001010110000001\n10111000001100101011011001011000",
"output": "00000000101101101010001111011001"
},
{
"input": "000001010000100001000000011011100\n111111111001010100100001100000111",
"output": "111110101001110101100001111011011"
},
{
"input": "1101000000000010011011101100000110\n1110000001100010011010000011011110",
"output": "0011000001100000000001101111011000"
},
{
"input": "01011011000010100001100100011110001\n01011010111000001010010100001110000",
"output": "00000001111010101011110000010000001"
},
{
"input": "000011111000011001000110111100000100\n011011000110000111101011100111000111",
"output": "011000111110011110101101011011000011"
},
{
"input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000",
"output": "1011001001111001001011101010101000010"
},
{
"input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011",
"output": "10001110000010101110000111000011111110"
},
{
"input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100",
"output": "000100001011110000011101110111010001110"
},
{
"input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001",
"output": "1101110101010110000011000000101011110011"
},
{
"input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100",
"output": "11001011110010010000010111001100001001110"
},
{
"input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110",
"output": "001100101000011111111101111011101010111001"
},
{
"input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001",
"output": "0111010010100110110101100010000100010100000"
},
{
"input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100",
"output": "11111110000000100101000100110111001100011001"
},
{
"input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011",
"output": "101011011100100010100011011001101010100100010"
},
{
"input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001",
"output": "1101001100111011010111110110101111001011110111"
},
{
"input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001",
"output": "10010101000101000000011010011110011110011110001"
},
{
"input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100",
"output": "011011011100000000010101110010000000101000111101"
},
{
"input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100",
"output": "0101010111101001011011110110011101010101010100011"
},
{
"input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011",
"output": "11001011010010111000010110011101100100001110111111"
},
{
"input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011",
"output": "111011101010011100001111101001101011110010010110001"
},
{
"input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001",
"output": "0100111110110011111110010010010000110111100101101101"
},
{
"input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100",
"output": "01011001110111010111001100010011010100010000111011000"
},
{
"input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111",
"output": "100011101001001000011011011001111000100000010100100100"
},
{
"input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110",
"output": "1100110010000101101010111111101001001001110101110010110"
},
{
"input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110",
"output": "01000111100111001011110010100011111111110010101100001101"
},
{
"input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010",
"output": "110001010001000011000101110101000100001011111001011001001"
},
{
"input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111",
"output": "1110100010111000101001001011101110011111100111000011011011"
},
{
"input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110",
"output": "01110110101110100100110011010000001000101100101111000111011"
},
{
"input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011",
"output": "111100101000000011101011011001110010101111000110010010000000"
},
{
"input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111",
"output": "0100100010111110010011101010000011111110001110010110010111001"
},
{
"input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111",
"output": "00110100000011001101101100100010110010001100000001100110011101"
},
{
"input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011",
"output": "000000011000111011110011101000010000010100101000000011010110010"
},
{
"input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010",
"output": "0010100110110100111100100100101101010100100111011010001001010101"
},
{
"input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111",
"output": "11010110111100101111101001100001110100010110010110110111100110100"
},
{
"input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111",
"output": "111111010011011100101110100110111111111001111110011010111111110000"
},
{
"input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110",
"output": "1010101010100010001001001001100000111000010010010100010011000100000"
},
{
"input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000",
"output": "00011111011111001000011100010011100011010100101011011000001001111110"
},
{
"input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111",
"output": "001111000011001110100111010101111111011100110011001010010010000111011"
},
{
"input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101",
"output": "0110001100110100010000110111000010011010011000011001010011010100010100"
},
{
"input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010",
"output": "00010000000110110101000011001000000100100110111010011111101010001010000"
},
{
"input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001",
"output": "000100100000000110011100100001010110101001100101110010010011111001110111"
},
{
"input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000",
"output": "1000111100010011010110011101000000101010101100011111100001101111001010010"
},
{
"input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011",
"output": "01000010011110111001011011110000001011000111101101101010010110001010100100"
},
{
"input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101",
"output": "101101110110110010011100001011111100100001110000101100110000100011011100110"
},
{
"input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001",
"output": "1110111111110010111000001100101010101011010100101010100101100011001001111111"
},
{
"input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111",
"output": "10111011000111000101110100101000100111011011100011110110000101010001111010111"
},
{
"input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110",
"output": "110100100110000101010010011010011001100110000111010000010100001011110111111101"
},
{
"input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111",
"output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111"
},
{
"input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001",
"output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001"
},
{
"input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110",
"output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011"
},
{
"input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111",
"output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101"
},
{
"input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010",
"output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101"
},
{
"input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000",
"output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001"
},
{
"input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011",
"output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110"
},
{
"input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011",
"output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011"
},
{
"input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011",
"output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011"
},
{
"input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010",
"output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011"
},
{
"input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001",
"output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110"
},
{
"input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111",
"output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010"
},
{
"input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011",
"output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011"
},
{
"input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100",
"output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000"
},
{
"input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001",
"output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101"
},
{
"input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110",
"output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101"
},
{
"input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011",
"output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110"
},
{
"input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111",
"output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110"
},
{
"input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000",
"output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001"
},
{
"input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010",
"output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101"
},
{
"input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101",
"output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011"
},
{
"input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011",
"output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010",
"output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\n1",
"output": "1"
}
] | 1,619,061,876 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 0 | a, b = input(), input()
print(''.join([str(int(a[i] != b[i])) for i in range(len(a))])) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.
In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0.
Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.
Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
Input Specification:
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Output Specification:
Write one line — the corresponding answer. Do not omit the leading 0s.
Demo Input:
['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n']
Demo Output:
['1110001\n', '111\n', '0100\n', '00010\n']
Note:
none | ```python
a, b = input(), input()
print(''.join([str(int(a[i] != b[i])) for i in range(len(a))]))
``` | 3.98075 |
987 | A | Infinity Gauntlet | PROGRAMMING | 800 | [
"implementation"
] | null | null | You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. | In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. | In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. | [
"4\nred\npurple\nyellow\norange\n",
"0\n"
] | [
"2\nSpace\nTime\n",
"6\nTime\nMind\nSoul\nPower\nReality\nSpace\n"
] | In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | 500 | [
{
"input": "4\nred\npurple\nyellow\norange",
"output": "2\nSpace\nTime"
},
{
"input": "0",
"output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul"
},
{
"input": "6\npurple\nblue\nyellow\nred\ngreen\norange",
"output": "0"
},
{
"input": "1\npurple",
"output": "5\nTime\nReality\nSoul\nSpace\nMind"
},
{
"input": "3\nblue\norange\npurple",
"output": "3\nTime\nReality\nMind"
},
{
"input": "2\nyellow\nred",
"output": "4\nPower\nSoul\nSpace\nTime"
},
{
"input": "1\ngreen",
"output": "5\nReality\nSpace\nPower\nSoul\nMind"
},
{
"input": "2\npurple\ngreen",
"output": "4\nReality\nMind\nSpace\nSoul"
},
{
"input": "1\nblue",
"output": "5\nPower\nReality\nSoul\nTime\nMind"
},
{
"input": "2\npurple\nblue",
"output": "4\nMind\nSoul\nTime\nReality"
},
{
"input": "2\ngreen\nblue",
"output": "4\nReality\nMind\nPower\nSoul"
},
{
"input": "3\npurple\ngreen\nblue",
"output": "3\nMind\nReality\nSoul"
},
{
"input": "1\norange",
"output": "5\nReality\nTime\nPower\nSpace\nMind"
},
{
"input": "2\npurple\norange",
"output": "4\nReality\nMind\nTime\nSpace"
},
{
"input": "2\norange\ngreen",
"output": "4\nSpace\nMind\nReality\nPower"
},
{
"input": "3\norange\npurple\ngreen",
"output": "3\nReality\nSpace\nMind"
},
{
"input": "2\norange\nblue",
"output": "4\nTime\nMind\nReality\nPower"
},
{
"input": "3\nblue\ngreen\norange",
"output": "3\nPower\nMind\nReality"
},
{
"input": "4\nblue\norange\ngreen\npurple",
"output": "2\nMind\nReality"
},
{
"input": "1\nred",
"output": "5\nTime\nSoul\nMind\nPower\nSpace"
},
{
"input": "2\nred\npurple",
"output": "4\nMind\nSpace\nTime\nSoul"
},
{
"input": "2\nred\ngreen",
"output": "4\nMind\nSpace\nPower\nSoul"
},
{
"input": "3\nred\npurple\ngreen",
"output": "3\nSoul\nSpace\nMind"
},
{
"input": "2\nblue\nred",
"output": "4\nMind\nTime\nPower\nSoul"
},
{
"input": "3\nred\nblue\npurple",
"output": "3\nTime\nMind\nSoul"
},
{
"input": "3\nred\nblue\ngreen",
"output": "3\nSoul\nPower\nMind"
},
{
"input": "4\npurple\nblue\ngreen\nred",
"output": "2\nMind\nSoul"
},
{
"input": "2\norange\nred",
"output": "4\nPower\nMind\nTime\nSpace"
},
{
"input": "3\nred\norange\npurple",
"output": "3\nMind\nSpace\nTime"
},
{
"input": "3\nred\norange\ngreen",
"output": "3\nMind\nSpace\nPower"
},
{
"input": "4\nred\norange\ngreen\npurple",
"output": "2\nSpace\nMind"
},
{
"input": "3\nblue\norange\nred",
"output": "3\nPower\nMind\nTime"
},
{
"input": "4\norange\nblue\npurple\nred",
"output": "2\nTime\nMind"
},
{
"input": "4\ngreen\norange\nred\nblue",
"output": "2\nMind\nPower"
},
{
"input": "5\npurple\norange\nblue\nred\ngreen",
"output": "1\nMind"
},
{
"input": "1\nyellow",
"output": "5\nPower\nSoul\nReality\nSpace\nTime"
},
{
"input": "2\npurple\nyellow",
"output": "4\nTime\nReality\nSpace\nSoul"
},
{
"input": "2\ngreen\nyellow",
"output": "4\nSpace\nReality\nPower\nSoul"
},
{
"input": "3\npurple\nyellow\ngreen",
"output": "3\nSoul\nReality\nSpace"
},
{
"input": "2\nblue\nyellow",
"output": "4\nTime\nReality\nPower\nSoul"
},
{
"input": "3\nyellow\nblue\npurple",
"output": "3\nSoul\nReality\nTime"
},
{
"input": "3\ngreen\nyellow\nblue",
"output": "3\nSoul\nReality\nPower"
},
{
"input": "4\nyellow\nblue\ngreen\npurple",
"output": "2\nReality\nSoul"
},
{
"input": "2\nyellow\norange",
"output": "4\nTime\nSpace\nReality\nPower"
},
{
"input": "3\nyellow\npurple\norange",
"output": "3\nSpace\nReality\nTime"
},
{
"input": "3\norange\nyellow\ngreen",
"output": "3\nSpace\nReality\nPower"
},
{
"input": "4\ngreen\nyellow\norange\npurple",
"output": "2\nSpace\nReality"
},
{
"input": "3\nyellow\nblue\norange",
"output": "3\nTime\nReality\nPower"
},
{
"input": "4\norange\npurple\nblue\nyellow",
"output": "2\nReality\nTime"
},
{
"input": "4\nblue\norange\nyellow\ngreen",
"output": "2\nReality\nPower"
},
{
"input": "5\ngreen\nyellow\norange\nblue\npurple",
"output": "1\nReality"
},
{
"input": "3\nyellow\npurple\nred",
"output": "3\nTime\nSoul\nSpace"
},
{
"input": "3\nred\ngreen\nyellow",
"output": "3\nPower\nSoul\nSpace"
},
{
"input": "4\nred\npurple\ngreen\nyellow",
"output": "2\nSpace\nSoul"
},
{
"input": "3\nred\nyellow\nblue",
"output": "3\nPower\nSoul\nTime"
},
{
"input": "4\nblue\nyellow\nred\npurple",
"output": "2\nTime\nSoul"
},
{
"input": "4\nblue\nyellow\nred\ngreen",
"output": "2\nSoul\nPower"
},
{
"input": "5\nred\nyellow\ngreen\nblue\npurple",
"output": "1\nSoul"
},
{
"input": "3\nred\nyellow\norange",
"output": "3\nPower\nSpace\nTime"
},
{
"input": "4\norange\ngreen\nyellow\nred",
"output": "2\nPower\nSpace"
},
{
"input": "5\norange\nred\ngreen\nyellow\npurple",
"output": "1\nSpace"
},
{
"input": "4\nyellow\nred\norange\nblue",
"output": "2\nTime\nPower"
},
{
"input": "5\npurple\nblue\norange\nyellow\nred",
"output": "1\nTime"
},
{
"input": "5\norange\nblue\nyellow\nred\ngreen",
"output": "1\nPower"
}
] | 1,655,146,091 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 46 | 0 | dict={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
user=int(input())
string=[]
for i in range(user):
user1=str(input())
string.append(user1)
print(6-user)
for i in dict:
if i not in string:
print(dict[i])
| Title: Infinity Gauntlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:
- the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color.
Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
Input Specification:
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet.
In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
Output Specification:
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems.
Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
Demo Input:
['4\nred\npurple\nyellow\norange\n', '0\n']
Demo Output:
['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n']
Note:
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.
In the second sample Thanos doesn't have any Gems, so he needs all six. | ```python
dict={"purple":"Power","green":"Time","blue":"Space","orange":"Soul","red":"Reality","yellow":"Mind"}
user=int(input())
string=[]
for i in range(user):
user1=str(input())
string.append(user1)
print(6-user)
for i in dict:
if i not in string:
print(dict[i])
``` | 3 |
|
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
"output": "52"
},
{
"input": "2\nAA",
"output": "1"
},
{
"input": "4\nqqqE",
"output": "2"
},
{
"input": "10\nrrrrroooro",
"output": "2"
},
{
"input": "15\nOCOCCCCiCOCCCOi",
"output": "3"
},
{
"input": "20\nVEVnVVnWnVEVVnEVBEWn",
"output": "5"
},
{
"input": "25\ncpcyPPjPPcPPPPcppPcPpppcP",
"output": "6"
},
{
"input": "30\nsssssAsesssssssssssssessssssss",
"output": "3"
},
{
"input": "35\ngdXdddgddddddddggggXdbgdggdgddddddb",
"output": "4"
},
{
"input": "40\nIgsggIiIggzgigIIiiIIIiIgIggIzgIiiiggggIi",
"output": "9"
},
{
"input": "45\neteeeeeteaattaeetaetteeettoetettteyeteeeotaae",
"output": "9"
},
{
"input": "50\nlUlUllUlUllllUllllUllllUlUlllUlllUlllllUUlllUUlkUl",
"output": "3"
},
{
"input": "55\nAAAAASAAAASAASAAAAAAAAAAAAASAAAAAAAAAAAAAAAASAAAAAAAAAA",
"output": "2"
},
{
"input": "60\nRRRrSRRRRRRRRRSSRRRSRRRRRRRRrRSRRRRRRRRRRRRRRSRRRRRSSRSRrRRR",
"output": "3"
},
{
"input": "65\nhhMhMhhhhhhhhhhhMhhMMMhhhhBhhhhMhhhhMhhhhhMhhhBhhhhhhhhhhBhhhhhhh",
"output": "5"
},
{
"input": "70\nwAwwwAwwwwwwwwwwwwwwAwAAwwAwwwwwwwwAwAAAwAAwwwwwwwwwAwwwwwwwwwwwwAAwww",
"output": "2"
},
{
"input": "75\niiiXXiiyiiiXyXiiyXiiXiiiiiiXXyiiiiXXiiXiiXifiXiXXiifiiiiiiXfXiyiXXiXiiiiXiX",
"output": "4"
},
{
"input": "80\nSrSrrrrrrrrrrrrrrSSSrrrrrrSrrrrSrrrrrrrrrrSSrrrrrrrrrrrSrrrSrrrrSrrrrSrrrrSSrSSr",
"output": "2"
},
{
"input": "85\nwkMMMwMMkMMMMMMMkkkkMMMMzkkMMwMMkkwMkMwkMMkMMwwMzMMMkkMwwMMMMMMkMMkMzMMMkMMkwMkMMMkMM",
"output": "6"
},
{
"input": "90\nZllZZZyZlZlllZlylllZlllZZllllllllZZllllllllllyylZZyvZvZlllZZlZllZlZlllZyllZyZlllZlllllllZl",
"output": "5"
},
{
"input": "95\nEmuBuEBmmEBBElBlElmmBEmmmEmmEuBEEmummmEmBBBBEWBBBmEEBmmummBBmmlluBBmElmEBEmBmBBmBmuLmEBBmlEBmBu",
"output": "39"
},
{
"input": "100\nfAfhfNNNhfffAfNffNANhffNffffffNfffffhNfffNfffNfffNfNNNffNfffNfhNNNffffNfNfffAffNffNffNNfhfffNhNffNNN",
"output": "4"
},
{
"input": "7\nabcbbab",
"output": "3"
},
{
"input": "65\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkjjjjkkkkkkkkkkkkkkkkkkkllllllljk",
"output": "3"
},
{
"input": "9\nbcdddbddc",
"output": "3"
},
{
"input": "71\nlqcrdopdpfagcilpcmheqhjbmnciqmeoabflrenbkrsaabaanpehdmpqcdqnljcrsplnlco",
"output": "36"
},
{
"input": "8\nabbbbbbc",
"output": "8"
}
] | 1,626,507,355 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 24,985,600 | # link: https://codeforces.com/problemset/problem/701/C
for _ in range(1):
n = int(input())
p = list(input())
pokemons = len(set(p))
ans = float('inf')
for i in range(n):
temp = set()
count = 0
for j in range(i, n):
if p[j] not in temp:
temp.add(p[j])
count += 1
if count == pokemons:
ans = min(ans, j - i + 1)
break
print(ans) | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number *n* is only connected with the flat number *n*<=-<=1.
There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once.
Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit.
Input Specification:
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*.
Output Specification:
Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house.
Demo Input:
['3\nAaA\n', '7\nbcAAcbc\n', '6\naaBCCe\n']
Demo Output:
['2\n', '3\n', '5\n']
Note:
In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | ```python
# link: https://codeforces.com/problemset/problem/701/C
for _ in range(1):
n = int(input())
p = list(input())
pokemons = len(set(p))
ans = float('inf')
for i in range(n):
temp = set()
count = 0
for j in range(i, n):
if p[j] not in temp:
temp.add(p[j])
count += 1
if count == pokemons:
ans = min(ans, j - i + 1)
break
print(ans)
``` | 0 |
|
34 | A | Reconnaissance 2 | PROGRAMMING | 800 | [
"implementation"
] | A. Reconnaissance 2 | 2 | 256 | *n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit. | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction. | Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle. | [
"5\n10 12 13 15 10\n",
"4\n10 20 30 40\n"
] | [
"5 1\n",
"1 2\n"
] | none | 500 | [
{
"input": "5\n10 12 13 15 10",
"output": "5 1"
},
{
"input": "4\n10 20 30 40",
"output": "1 2"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "2 3"
},
{
"input": "5\n826 747 849 687 437",
"output": "1 2"
},
{
"input": "5\n999 999 993 969 999",
"output": "1 2"
},
{
"input": "5\n4 24 6 1 15",
"output": "3 4"
},
{
"input": "2\n511 32",
"output": "1 2"
},
{
"input": "3\n907 452 355",
"output": "2 3"
},
{
"input": "4\n303 872 764 401",
"output": "4 1"
},
{
"input": "10\n684 698 429 694 956 812 594 170 937 764",
"output": "1 2"
},
{
"input": "20\n646 840 437 946 640 564 936 917 487 752 844 734 468 969 674 646 728 642 514 695",
"output": "7 8"
},
{
"input": "30\n996 999 998 984 989 1000 996 993 1000 983 992 999 999 1000 979 992 987 1000 996 1000 1000 989 981 996 995 999 999 989 999 1000",
"output": "12 13"
},
{
"input": "50\n93 27 28 4 5 78 59 24 19 134 31 128 118 36 90 32 32 1 44 32 33 13 31 10 12 25 38 50 25 12 4 22 28 53 48 83 4 25 57 31 71 24 8 7 28 86 23 80 101 58",
"output": "16 17"
},
{
"input": "88\n1000 1000 1000 1000 1000 998 998 1000 1000 1000 1000 999 999 1000 1000 1000 999 1000 997 999 997 1000 999 998 1000 999 1000 1000 1000 999 1000 999 999 1000 1000 999 1000 999 1000 1000 998 1000 1000 1000 998 998 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 999 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 998 1000 1000 1000 998 1000 1000 998 1000 999 1000 1000 1000 1000",
"output": "1 2"
},
{
"input": "99\n4 4 21 6 5 3 13 2 6 1 3 4 1 3 1 9 11 1 6 17 4 5 20 4 1 9 5 11 3 4 14 1 3 3 1 4 3 5 27 1 1 2 10 7 11 4 19 7 11 6 11 13 3 1 10 7 2 1 16 1 9 4 29 13 2 12 14 2 21 1 9 8 26 12 12 5 2 14 7 8 8 8 9 4 12 2 6 6 7 16 8 14 2 10 20 15 3 7 4",
"output": "1 2"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "86 87"
},
{
"input": "100\n31 75 86 68 111 27 22 22 26 30 54 163 107 75 160 122 14 23 17 26 27 20 43 58 59 71 21 148 9 32 43 91 133 286 132 70 90 156 84 14 77 93 23 18 13 72 18 131 33 28 72 175 30 86 249 20 14 208 28 57 63 199 6 10 24 30 62 267 43 479 60 28 138 1 45 3 19 47 7 166 116 117 50 140 28 14 95 85 93 43 61 15 2 70 10 51 7 95 9 25",
"output": "7 8"
},
{
"input": "100\n896 898 967 979 973 709 961 968 806 967 896 967 826 975 936 903 986 856 851 931 852 971 786 837 949 978 686 936 952 909 965 749 908 916 943 973 983 975 939 886 964 928 960 976 907 788 994 773 949 871 947 980 945 985 726 981 887 943 907 990 931 874 840 867 948 951 961 904 888 901 976 967 994 921 828 970 972 722 755 970 860 855 914 869 714 899 969 978 898 862 642 939 904 936 819 934 884 983 955 964",
"output": "1 2"
},
{
"input": "100\n994 927 872 970 815 986 952 996 965 1000 877 986 978 999 950 990 936 997 993 960 921 860 895 869 943 998 983 968 973 953 999 990 995 871 853 979 973 963 953 938 997 989 993 964 960 973 946 975 1000 962 920 746 989 957 904 965 920 979 966 961 1000 993 975 952 846 971 991 979 985 969 984 973 956 1000 952 778 983 974 956 927 995 997 980 997 1000 970 960 970 988 983 947 904 935 972 1000 863 992 996 932 967",
"output": "81 82"
},
{
"input": "100\n48 108 63 21 27 8 49 21 75 8 24 42 149 18 8 28 21 18 25 35 59 70 59 33 40 1 67 34 120 82 4 115 72 87 3 15 15 63 37 12 40 27 83 14 38 20 14 58 93 10 31 3 39 6 197 77 54 16 31 146 9 49 14 8 77 82 5 11 80 116 8 61 50 24 7 103 29 11 3 3 1 12 46 24 21 131 39 29 36 2 107 40 16 99 31 41 29 48 17 17",
"output": "36 37"
}
] | 1,613,559,291 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 307,200 | n=int(input())
lst=list(map(int,input().split(" ")))
m=abs(lst[0]-lst[n-1])
p=0
k,h=0,n-1
for i in range(len(lst)-1):
p=abs(lst[i]-lst[i+1])
if p<m:
m=abs(lst[i]-lst[i+1])
k,h=i,i+1
print(k+1,h+1)
# 6
# 744 359 230 586 944 442 | Title: Reconnaissance 2
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
*n* soldiers stand in a circle. For each soldier his height *a**i* is known. A reconnaissance unit can be made of such two neighbouring soldiers, whose heights difference is minimal, i.e. |*a**i*<=-<=*a**j*| is minimal. So each of them will be less noticeable with the other. Output any pair of soldiers that can form a reconnaissance unit.
Input Specification:
The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of soldiers. Then follow the heights of the soldiers in their order in the circle — *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). The soldier heights are given in clockwise or counterclockwise direction.
Output Specification:
Output two integers — indexes of neighbouring soldiers, who should form a reconnaissance unit. If there are many optimum solutions, output any of them. Remember, that the soldiers stand in a circle.
Demo Input:
['5\n10 12 13 15 10\n', '4\n10 20 30 40\n']
Demo Output:
['5 1\n', '1 2\n']
Note:
none | ```python
n=int(input())
lst=list(map(int,input().split(" ")))
m=abs(lst[0]-lst[n-1])
p=0
k,h=0,n-1
for i in range(len(lst)-1):
p=abs(lst[i]-lst[i+1])
if p<m:
m=abs(lst[i]-lst[i+1])
k,h=i,i+1
print(k+1,h+1)
# 6
# 744 359 230 586 944 442
``` | 3.968428 |
723 | A | The New Year: Meeting Friends | PROGRAMMING | 800 | [
"implementation",
"math",
"sortings"
] | null | null | There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer. | The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively. | Print one integer — the minimum total distance the friends need to travel in order to meet together. | [
"7 1 4\n",
"30 20 10\n"
] | [
"6\n",
"20\n"
] | In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | 500 | [
{
"input": "7 1 4",
"output": "6"
},
{
"input": "30 20 10",
"output": "20"
},
{
"input": "1 4 100",
"output": "99"
},
{
"input": "100 1 91",
"output": "99"
},
{
"input": "1 45 100",
"output": "99"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "71 85 88",
"output": "17"
},
{
"input": "30 38 99",
"output": "69"
},
{
"input": "23 82 95",
"output": "72"
},
{
"input": "22 41 47",
"output": "25"
},
{
"input": "9 94 77",
"output": "85"
},
{
"input": "1 53 51",
"output": "52"
},
{
"input": "25 97 93",
"output": "72"
},
{
"input": "42 53 51",
"output": "11"
},
{
"input": "81 96 94",
"output": "15"
},
{
"input": "21 5 93",
"output": "88"
},
{
"input": "50 13 75",
"output": "62"
},
{
"input": "41 28 98",
"output": "70"
},
{
"input": "69 46 82",
"output": "36"
},
{
"input": "87 28 89",
"output": "61"
},
{
"input": "44 45 40",
"output": "5"
},
{
"input": "86 97 68",
"output": "29"
},
{
"input": "43 92 30",
"output": "62"
},
{
"input": "16 70 1",
"output": "69"
},
{
"input": "40 46 19",
"output": "27"
},
{
"input": "71 38 56",
"output": "33"
},
{
"input": "82 21 80",
"output": "61"
},
{
"input": "75 8 35",
"output": "67"
},
{
"input": "75 24 28",
"output": "51"
},
{
"input": "78 23 56",
"output": "55"
},
{
"input": "85 31 10",
"output": "75"
},
{
"input": "76 50 9",
"output": "67"
},
{
"input": "95 37 34",
"output": "61"
},
{
"input": "84 61 35",
"output": "49"
},
{
"input": "87 85 37",
"output": "50"
},
{
"input": "1 3 2",
"output": "2"
},
{
"input": "4 2 6",
"output": "4"
},
{
"input": "6 9 3",
"output": "6"
},
{
"input": "12 4 8",
"output": "8"
},
{
"input": "15 10 5",
"output": "10"
},
{
"input": "1 50 17",
"output": "49"
},
{
"input": "10 5 15",
"output": "10"
},
{
"input": "8 1 9",
"output": "8"
},
{
"input": "3 5 4",
"output": "2"
},
{
"input": "2 1 3",
"output": "2"
},
{
"input": "1 8 2",
"output": "7"
},
{
"input": "1 100 2",
"output": "99"
},
{
"input": "1 4 6",
"output": "5"
}
] | 1,684,666,861 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | l=list(map(int, input().split()))
l.sort()
m=(l[0]+l[2])//2
print(abs(m-l[0])+abs(m-l[1])+abs(m-l[2])) | Title: The New Year: Meeting Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?
It's guaranteed that the optimal answer is always integer.
Input Specification:
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Output Specification:
Print one integer — the minimum total distance the friends need to travel in order to meet together.
Demo Input:
['7 1 4\n', '30 20 10\n']
Demo Output:
['6\n', '20\n']
Note:
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4. | ```python
l=list(map(int, input().split()))
l.sort()
m=(l[0]+l[2])//2
print(abs(m-l[0])+abs(m-l[1])+abs(m-l[2]))
``` | 0 |
|
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers. | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
{
"input": "192",
"output": "4 188"
},
{
"input": "86",
"output": "4 82"
},
{
"input": "46220",
"output": "4 46216"
},
{
"input": "57114",
"output": "4 57110"
},
{
"input": "869",
"output": "4 865"
},
{
"input": "738457",
"output": "4 738453"
},
{
"input": "58113",
"output": "6 58107"
},
{
"input": "4864",
"output": "4 4860"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "74752",
"output": "4 74748"
},
{
"input": "6073",
"output": "4 6069"
},
{
"input": "1289",
"output": "4 1285"
},
{
"input": "20",
"output": "4 16"
},
{
"input": "58134",
"output": "4 58130"
},
{
"input": "57756",
"output": "4 57752"
},
{
"input": "765",
"output": "6 759"
},
{
"input": "59",
"output": "4 55"
},
{
"input": "991666",
"output": "4 991662"
},
{
"input": "70761",
"output": "4 70757"
},
{
"input": "13",
"output": "4 9"
},
{
"input": "999999",
"output": "4 999995"
},
{
"input": "17",
"output": "8 9"
},
{
"input": "21",
"output": "6 15"
},
{
"input": "19",
"output": "4 15"
},
{
"input": "100007",
"output": "6 100001"
},
{
"input": "999987",
"output": "6 999981"
},
{
"input": "22",
"output": "4 18"
}
] | 1,665,584,367 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 | n = int(input())
if n % 2 == 0:
num1 = n//2 - 1
num2 = n//2 + 1
else:
num1 = n//2
num2 = n//2 + 1
prime = []
for x in range(2, n+1):
count = 0
for y in range(1, x+1):
if x % y == 0:
count += 1
if count <= 2:
prime.append(x)
while True:
if num1 in prime or num2 in prime:
num1 -= 1
num2 += 1
else:
print(num1, num2)
break | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.
You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
Input Specification:
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output Specification:
Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
Demo Input:
['12\n', '15\n', '23\n', '1000000\n']
Demo Output:
['4 8\n', '6 9\n', '8 15\n', '500000 500000\n']
Note:
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | ```python
n = int(input())
if n % 2 == 0:
num1 = n//2 - 1
num2 = n//2 + 1
else:
num1 = n//2
num2 = n//2 + 1
prime = []
for x in range(2, n+1):
count = 0
for y in range(1, x+1):
if x % y == 0:
count += 1
if count <= 2:
prime.append(x)
while True:
if num1 in prime or num2 in prime:
num1 -= 1
num2 += 1
else:
print(num1, num2)
break
``` | 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,676,091,320 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | def has_AB_BA(s):
# Check if the string s contains "AB" and "BA"
return "AB" in s and "BA" in s
def main():
s = input().strip()
if has_AB_BA(s):
# Check if "AB" and "BA" are non-overlapping
for i in range(len(s) - 1):
if s[i:i+2] == "AB" and s[i+2:i+4] == "BA":
print("YES")
return
if s[i:i+2] == "BA" and s[i+2:i+4] == "AB":
print("YES")
return
print("NO")
else:
print("NO")
if __name__ == "__main__":
main()
| 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
def has_AB_BA(s):
# Check if the string s contains "AB" and "BA"
return "AB" in s and "BA" in s
def main():
s = input().strip()
if has_AB_BA(s):
# Check if "AB" and "BA" are non-overlapping
for i in range(len(s) - 1):
if s[i:i+2] == "AB" and s[i+2:i+4] == "BA":
print("YES")
return
if s[i:i+2] == "BA" and s[i+2:i+4] == "AB":
print("YES")
return
print("NO")
else:
print("NO")
if __name__ == "__main__":
main()
``` | 0 |
|
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,675,898,015 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | asList=[int(i) for i in input().split()]
x=(asList[0]+asList[2]-1)/asList[2]
oven1=0
oven2=asList[3]
for i in range(len(asList)):
if oven1<oven2:
oven1+=1
else:
oven2+=1
if max(oven1,oven2)<x*asList[1]:
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
asList=[int(i) for i in input().split()]
x=(asList[0]+asList[2]-1)/asList[2]
oven1=0
oven2=asList[3]
for i in range(len(asList)):
if oven1<oven2:
oven1+=1
else:
oven2+=1
if max(oven1,oven2)<x*asList[1]:
print("YES")
else:
print("NO")
``` | 0 |
|
17 | A | Noldbach problem | PROGRAMMING | 1,000 | [
"brute force",
"math",
"number theory"
] | A. Noldbach problem | 2 | 64 | Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong. | The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). | Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. | [
"27 2\n",
"45 7\n"
] | [
"YES",
"NO"
] | In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | 0 | [
{
"input": "27 2",
"output": "YES"
},
{
"input": "45 7",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
},
{
"input": "15 1",
"output": "YES"
},
{
"input": "17 1",
"output": "YES"
},
{
"input": "34 5",
"output": "NO"
},
{
"input": "37 4",
"output": "YES"
},
{
"input": "43 5",
"output": "YES"
},
{
"input": "47 7",
"output": "NO"
},
{
"input": "50 5",
"output": "YES"
},
{
"input": "57 6",
"output": "YES"
},
{
"input": "60 8",
"output": "NO"
},
{
"input": "62 7",
"output": "YES"
},
{
"input": "76 9",
"output": "NO"
},
{
"input": "69 7",
"output": "YES"
},
{
"input": "113 10",
"output": "YES"
},
{
"input": "141 11",
"output": "YES"
},
{
"input": "207 16",
"output": "NO"
},
{
"input": "231 18",
"output": "NO"
},
{
"input": "296 19",
"output": "YES"
},
{
"input": "332 20",
"output": "YES"
},
{
"input": "378 24",
"output": "NO"
},
{
"input": "428 23",
"output": "YES"
},
{
"input": "497 27",
"output": "NO"
},
{
"input": "640 32",
"output": "YES"
},
{
"input": "798 35",
"output": "YES"
},
{
"input": "802 35",
"output": "YES"
},
{
"input": "864 40",
"output": "NO"
},
{
"input": "953 44",
"output": "NO"
},
{
"input": "995 44",
"output": "YES"
},
{
"input": "1000 44",
"output": "YES"
},
{
"input": "1000 0",
"output": "YES"
},
{
"input": "1000 1000",
"output": "NO"
},
{
"input": "2 1000",
"output": "NO"
},
{
"input": "2 0",
"output": "YES"
}
] | 1,674,170,748 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 |
n = int(input())
k = int(input())
primos = [3, 5]
contagem = 2
for numero in range(7, n+1, 2):
i = 0
while (i < contagem) and (numero % primos[i] != 0):
i += 1
if i == contagem:
for j in range(1, contagem):
if primos[j] + primos[j-1] + 1 == numero:
k -= 1
break
primos.append(numero)
contagem += 1
print("YES" if k == 0 else "NO")
| Title: Noldbach problem
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.
Two prime numbers are called neighboring if there are no other prime numbers between them.
You are to help Nick, and find out if he is right or wrong.
Input Specification:
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output Specification:
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
Demo Input:
['27 2\n', '45 7\n']
Demo Output:
['YES', 'NO']
Note:
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form. | ```python
n = int(input())
k = int(input())
primos = [3, 5]
contagem = 2
for numero in range(7, n+1, 2):
i = 0
while (i < contagem) and (numero % primos[i] != 0):
i += 1
if i == contagem:
for j in range(1, contagem):
if primos[j] + primos[j-1] + 1 == numero:
k -= 1
break
primos.append(numero)
contagem += 1
print("YES" if k == 0 else "NO")
``` | -1 |
217 | A | Ice Skating | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"dsu",
"graphs"
] | null | null | Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates. | The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. | Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. | [
"2\n2 1\n1 2\n",
"2\n2 1\n4 1\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "2\n2 1\n1 2",
"output": "1"
},
{
"input": "2\n2 1\n4 1",
"output": "0"
},
{
"input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459",
"output": "21"
},
{
"input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815",
"output": "16"
},
{
"input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663",
"output": "10"
},
{
"input": "1\n321 88",
"output": "0"
},
{
"input": "9\n811 859\n656 676\n76 141\n945 951\n497 455\n18 55\n335 294\n267 275\n656 689",
"output": "7"
},
{
"input": "7\n948 946\n130 130\n761 758\n941 938\n971 971\n387 385\n509 510",
"output": "6"
},
{
"input": "6\n535 699\n217 337\n508 780\n180 292\n393 112\n732 888",
"output": "5"
},
{
"input": "14\n25 23\n499 406\n193 266\n823 751\n219 227\n101 138\n978 992\n43 74\n997 932\n237 189\n634 538\n774 740\n842 767\n742 802",
"output": "13"
},
{
"input": "12\n548 506\n151 198\n370 380\n655 694\n654 690\n407 370\n518 497\n819 827\n765 751\n802 771\n741 752\n653 662",
"output": "11"
},
{
"input": "40\n685 711\n433 403\n703 710\n491 485\n616 619\n288 282\n884 871\n367 352\n500 511\n977 982\n51 31\n576 564\n508 519\n755 762\n22 20\n368 353\n232 225\n953 955\n452 436\n311 330\n967 988\n369 364\n791 803\n150 149\n651 661\n118 93\n398 387\n748 766\n852 852\n230 228\n555 545\n515 519\n667 678\n867 862\n134 146\n859 863\n96 99\n486 469\n303 296\n780 786",
"output": "38"
},
{
"input": "3\n175 201\n907 909\n388 360",
"output": "2"
},
{
"input": "7\n312 298\n86 78\n73 97\n619 594\n403 451\n538 528\n71 86",
"output": "6"
},
{
"input": "19\n802 820\n368 248\n758 794\n455 378\n876 888\n771 814\n245 177\n586 555\n844 842\n364 360\n820 856\n731 624\n982 975\n825 856\n122 121\n862 896\n42 4\n792 841\n828 820",
"output": "16"
},
{
"input": "32\n643 877\n842 614\n387 176\n99 338\n894 798\n652 728\n611 648\n622 694\n579 781\n243 46\n322 305\n198 438\n708 579\n246 325\n536 459\n874 593\n120 277\n989 907\n223 110\n35 130\n761 692\n690 661\n518 766\n226 93\n678 597\n725 617\n661 574\n775 496\n56 416\n14 189\n358 359\n898 901",
"output": "31"
},
{
"input": "32\n325 327\n20 22\n72 74\n935 933\n664 663\n726 729\n785 784\n170 171\n315 314\n577 580\n984 987\n313 317\n434 435\n962 961\n55 54\n46 44\n743 742\n434 433\n617 612\n332 332\n883 886\n940 936\n793 792\n645 644\n611 607\n418 418\n465 465\n219 218\n167 164\n56 54\n403 405\n210 210",
"output": "29"
},
{
"input": "32\n652 712\n260 241\n27 154\n188 16\n521 351\n518 356\n452 540\n790 827\n339 396\n336 551\n897 930\n828 627\n27 168\n180 113\n134 67\n794 671\n812 711\n100 241\n686 813\n138 289\n384 506\n884 932\n913 959\n470 508\n730 734\n373 478\n788 862\n392 426\n148 68\n113 49\n713 852\n924 894",
"output": "29"
},
{
"input": "14\n685 808\n542 677\n712 747\n832 852\n187 410\n399 338\n626 556\n530 635\n267 145\n215 209\n559 684\n944 949\n753 596\n601 823",
"output": "13"
},
{
"input": "5\n175 158\n16 2\n397 381\n668 686\n957 945",
"output": "4"
},
{
"input": "5\n312 284\n490 509\n730 747\n504 497\n782 793",
"output": "4"
},
{
"input": "2\n802 903\n476 348",
"output": "1"
},
{
"input": "4\n325 343\n425 442\n785 798\n275 270",
"output": "3"
},
{
"input": "28\n462 483\n411 401\n118 94\n111 127\n5 6\n70 52\n893 910\n73 63\n818 818\n182 201\n642 633\n900 886\n893 886\n684 700\n157 173\n953 953\n671 660\n224 225\n832 801\n152 157\n601 585\n115 101\n739 722\n611 606\n659 642\n461 469\n702 689\n649 653",
"output": "25"
},
{
"input": "36\n952 981\n885 900\n803 790\n107 129\n670 654\n143 132\n66 58\n813 819\n849 837\n165 198\n247 228\n15 39\n619 618\n105 138\n868 855\n965 957\n293 298\n613 599\n227 212\n745 754\n723 704\n877 858\n503 487\n678 697\n592 595\n155 135\n962 982\n93 89\n660 673\n225 212\n967 987\n690 680\n804 813\n489 518\n240 221\n111 124",
"output": "34"
},
{
"input": "30\n89 3\n167 156\n784 849\n943 937\n144 95\n24 159\n80 120\n657 683\n585 596\n43 147\n909 964\n131 84\n345 389\n333 321\n91 126\n274 325\n859 723\n866 922\n622 595\n690 752\n902 944\n127 170\n426 383\n905 925\n172 284\n793 810\n414 510\n890 884\n123 24\n267 255",
"output": "29"
},
{
"input": "5\n664 666\n951 941\n739 742\n844 842\n2 2",
"output": "4"
},
{
"input": "3\n939 867\n411 427\n757 708",
"output": "2"
},
{
"input": "36\n429 424\n885 972\n442 386\n512 511\n751 759\n4 115\n461 497\n496 408\n8 23\n542 562\n296 331\n448 492\n412 395\n109 166\n622 640\n379 355\n251 262\n564 586\n66 115\n275 291\n666 611\n629 534\n510 567\n635 666\n738 803\n420 369\n92 17\n101 144\n141 92\n258 258\n184 235\n492 456\n311 210\n394 357\n531 512\n634 636",
"output": "34"
},
{
"input": "29\n462 519\n871 825\n127 335\n156 93\n576 612\n885 830\n634 779\n340 105\n744 795\n716 474\n93 139\n563 805\n137 276\n177 101\n333 14\n391 437\n873 588\n817 518\n460 597\n572 670\n140 303\n392 441\n273 120\n862 578\n670 639\n410 161\n544 577\n193 116\n252 195",
"output": "28"
},
{
"input": "23\n952 907\n345 356\n812 807\n344 328\n242 268\n254 280\n1000 990\n80 78\n424 396\n595 608\n755 813\n383 380\n55 56\n598 633\n203 211\n508 476\n600 593\n206 192\n855 882\n517 462\n967 994\n642 657\n493 488",
"output": "22"
},
{
"input": "10\n579 816\n806 590\n830 787\n120 278\n677 800\n16 67\n188 251\n559 560\n87 67\n104 235",
"output": "8"
},
{
"input": "23\n420 424\n280 303\n515 511\n956 948\n799 803\n441 455\n362 369\n299 289\n823 813\n982 967\n876 878\n185 157\n529 551\n964 989\n655 656\n1 21\n114 112\n45 56\n935 937\n1000 997\n934 942\n360 366\n648 621",
"output": "22"
},
{
"input": "23\n102 84\n562 608\n200 127\n952 999\n465 496\n322 367\n728 690\n143 147\n855 867\n861 866\n26 59\n300 273\n255 351\n192 246\n70 111\n365 277\n32 104\n298 319\n330 354\n241 141\n56 125\n315 298\n412 461",
"output": "22"
},
{
"input": "7\n429 506\n346 307\n99 171\n853 916\n322 263\n115 157\n906 924",
"output": "6"
},
{
"input": "3\n1 1\n2 1\n2 2",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "5\n1 1\n1 2\n2 2\n3 1\n3 3",
"output": "0"
},
{
"input": "6\n1 1\n1 2\n2 2\n3 1\n3 2\n3 3",
"output": "0"
},
{
"input": "20\n1 1\n2 2\n3 3\n3 9\n4 4\n5 2\n5 5\n5 7\n5 8\n6 2\n6 6\n6 9\n7 7\n8 8\n9 4\n9 7\n9 9\n10 2\n10 9\n10 10",
"output": "1"
},
{
"input": "21\n1 1\n1 9\n2 1\n2 2\n2 5\n2 6\n2 9\n3 3\n3 8\n4 1\n4 4\n5 5\n5 8\n6 6\n7 7\n8 8\n9 9\n10 4\n10 10\n11 5\n11 11",
"output": "1"
},
{
"input": "22\n1 1\n1 3\n1 4\n1 8\n1 9\n1 11\n2 2\n3 3\n4 4\n4 5\n5 5\n6 6\n6 8\n7 7\n8 3\n8 4\n8 8\n9 9\n10 10\n11 4\n11 9\n11 11",
"output": "3"
},
{
"input": "50\n1 1\n2 2\n2 9\n3 3\n4 4\n4 9\n4 16\n4 24\n5 5\n6 6\n7 7\n8 8\n8 9\n8 20\n9 9\n10 10\n11 11\n12 12\n13 13\n14 7\n14 14\n14 16\n14 25\n15 4\n15 6\n15 15\n15 22\n16 6\n16 16\n17 17\n18 18\n19 6\n19 19\n20 20\n21 21\n22 6\n22 22\n23 23\n24 6\n24 7\n24 8\n24 9\n24 24\n25 1\n25 3\n25 5\n25 7\n25 23\n25 24\n25 25",
"output": "7"
},
{
"input": "55\n1 1\n1 14\n2 2\n2 19\n3 1\n3 3\n3 8\n3 14\n3 23\n4 1\n4 4\n5 5\n5 8\n5 15\n6 2\n6 3\n6 4\n6 6\n7 7\n8 8\n8 21\n9 9\n10 1\n10 10\n11 9\n11 11\n12 12\n13 13\n14 14\n15 15\n15 24\n16 5\n16 16\n17 5\n17 10\n17 17\n17 18\n17 22\n17 27\n18 18\n19 19\n20 20\n21 20\n21 21\n22 22\n23 23\n24 14\n24 24\n25 25\n26 8\n26 11\n26 26\n27 3\n27 27\n28 28",
"output": "5"
},
{
"input": "3\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "6\n4 4\n3 4\n5 4\n4 5\n4 3\n3 1",
"output": "0"
},
{
"input": "4\n1 1\n1 2\n2 1\n2 2",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n1 2",
"output": "0"
},
{
"input": "8\n1 3\n1 1\n4 1\n2 2\n2 5\n5 9\n5 1\n5 4",
"output": "1"
},
{
"input": "10\n1 1\n1 2\n1 3\n1 4\n5 5\n6 6\n7 7\n8 8\n9 9\n100 100",
"output": "6"
},
{
"input": "7\n1 1\n2 2\n3 3\n4 4\n1 2\n2 3\n3 4",
"output": "0"
},
{
"input": "6\n1 1\n2 1\n2 2\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "4\n3 1\n2 1\n2 2\n1 2",
"output": "0"
},
{
"input": "6\n1 1\n2 2\n2 1\n2 4\n4 3\n2 3",
"output": "0"
},
{
"input": "3\n1 2\n1 3\n1 4",
"output": "0"
},
{
"input": "4\n1 1\n2 2\n1 2\n2 1",
"output": "0"
},
{
"input": "4\n1 3\n2 1\n3 2\n3 1",
"output": "1"
},
{
"input": "7\n1 1\n1 2\n2 2\n3 3\n3 4\n4 4\n1 4",
"output": "0"
},
{
"input": "21\n12 12\n13 12\n12 11\n13 13\n10 10\n11 10\n11 11\n501 500\n501 501\n503 502\n500 500\n503 503\n502 501\n502 502\n700 700\n702 702\n703 702\n701 701\n702 701\n703 703\n701 700",
"output": "2"
},
{
"input": "6\n1 11\n6 8\n11 10\n1 10\n11 11\n6 9",
"output": "1"
},
{
"input": "4\n1 1\n2 2\n3 2\n3 1",
"output": "0"
},
{
"input": "3\n1 2\n3 4\n3 2",
"output": "0"
},
{
"input": "3\n1 1\n1 2\n2 2",
"output": "0"
},
{
"input": "4\n5 5\n5 4\n6 3\n6 4",
"output": "0"
},
{
"input": "3\n1 1\n2 2\n2 1",
"output": "0"
}
] | 1,677,339,810 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n=int(input())
x=[]
y=[]
for i in range(n) :
k=input().split()
x.append(int(k[0]))
y.append(int(k[1]))
print(x)
print(y)
def test(xi,yi,x,y,another):
if x.count(xi)>1 or y.count(yi)>1 or another==1 :
another=0
return(0)
else :
another=1
return 1
def retouch(r,n,x):
test=0
for i in range (r+1,n) :
if x[i]==x[r]:
test= 1
if y.count(y[i])>1 :
return (0)
return (test)
s=0
another=0
for i in range (n) :
another=test(x[i],y[i],x,y,another)
s+=another
if x[i] not in x[:i] :
s+=retouch(i,n,x)
print(s)
| Title: Ice Skating
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.
We assume that Bajtek can only heap up snow drifts at integer coordinates.
Input Specification:
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift.
Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
Output Specification:
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
Demo Input:
['2\n2 1\n1 2\n', '2\n2 1\n4 1\n']
Demo Output:
['1\n', '0\n']
Note:
none | ```python
n=int(input())
x=[]
y=[]
for i in range(n) :
k=input().split()
x.append(int(k[0]))
y.append(int(k[1]))
print(x)
print(y)
def test(xi,yi,x,y,another):
if x.count(xi)>1 or y.count(yi)>1 or another==1 :
another=0
return(0)
else :
another=1
return 1
def retouch(r,n,x):
test=0
for i in range (r+1,n) :
if x[i]==x[r]:
test= 1
if y.count(y[i])>1 :
return (0)
return (test)
s=0
another=0
for i in range (n) :
another=test(x[i],y[i],x,y,another)
s+=another
if x[i] not in x[:i] :
s+=retouch(i,n,x)
print(s)
``` | 0 |
|
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geometric progression with common ratio *k*.
A subsequence of length three is a combination of three such indexes *i*1,<=*i*2,<=*i*3, that 1<=≤<=*i*1<=<<=*i*2<=<<=*i*3<=≤<=*n*. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.
A geometric progression with common ratio *k* is a sequence of numbers of the form *b*·*k*0,<=*b*·*k*1,<=...,<=*b*·*k**r*<=-<=1.
Polycarp is only three years old, so he can not calculate this number himself. Help him to do it. | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45",
"output": "3"
},
{
"input": "7 1\n1 2 1 2 1 2 1",
"output": "5"
},
{
"input": "10 10\n1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000",
"output": "8"
},
{
"input": "30 4096\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912",
"output": "6"
},
{
"input": "3 17\n2 34 578",
"output": "1"
},
{
"input": "12 2\n1 2 1 2 1 2 1 2 1 2 1 2",
"output": "0"
},
{
"input": "10 5\n-100 -100 -500 -100 -500 -2500 -500 -100 -500 -2500",
"output": "17"
},
{
"input": "3 10000\n10 100000 1000000000",
"output": "1"
},
{
"input": "3 200000\n999999998 999999999 1000000000",
"output": "0"
},
{
"input": "15 2\n1 1 1 1 1 2 2 2 2 2 4 4 4 4 4",
"output": "125"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10 1\n8 6 1 7 9 3 5 2 10 4",
"output": "0"
},
{
"input": "3 110000\n1 110000 -784901888",
"output": "0"
},
{
"input": "9 187000\n1 187000 609261632 1 187000 609261632 1 187000 609261632",
"output": "0"
},
{
"input": "3 2\n1 3 6",
"output": "0"
},
{
"input": "3 2\n2 3 6",
"output": "0"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 200000\n1",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n1 2",
"output": "0"
},
{
"input": "3 1\n-1000000000 -1000000000 -1000000000",
"output": "1"
},
{
"input": "18 10\n10000000 100000000 1000000000 -10000000 -100000000 -1000000000 -10000000 -100000000 -1000000000 -10000000 -100000000 -1000000000 10000000 100000000 1000000000 10000000 100000000 1000000000",
"output": "20"
},
{
"input": "2 2\n0 0",
"output": "0"
},
{
"input": "3 2\n0 0 0",
"output": "1"
},
{
"input": "1 2\n0",
"output": "0"
},
{
"input": "5 5\n0 0 0 0 0",
"output": "10"
},
{
"input": "3 4\n0 0 1",
"output": "0"
},
{
"input": "3 4\n1 0 0",
"output": "0"
},
{
"input": "5 1\n0 0 0 0 0",
"output": "10"
},
{
"input": "5 3\n0 0 0 0 0",
"output": "10"
},
{
"input": "3 3\n1 0 0",
"output": "0"
},
{
"input": "5 2\n0 0 0 0 0",
"output": "10"
},
{
"input": "4 5\n0 0 0 0",
"output": "4"
},
{
"input": "3 70000\n1 70000 605032704",
"output": "0"
},
{
"input": "3 1\n0 0 0",
"output": "1"
},
{
"input": "4 200000\n0 0 0 0",
"output": "4"
},
{
"input": "3 2048\n-1024 -2097152 0",
"output": "0"
},
{
"input": "3 2\n0 -1 -2",
"output": "0"
},
{
"input": "5 200000\n0 0 0 0 0",
"output": "10"
},
{
"input": "3 10\n0 0 0",
"output": "1"
},
{
"input": "4 1\n0 0 0 0",
"output": "4"
},
{
"input": "3 100000\n-10000 -1000000000 -276447232",
"output": "0"
}
] | 1,689,026,138 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 233 | 38,195,200 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
N,K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp1,dp2 = defaultdict(int),defaultdict(int)
for a in A:
if a%K==0:
ans += dp2[a//K]
dp2[a]+=dp1[a//K]
dp1[a]+=1
print(ans)
| Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geometric progression with common ratio *k*.
A subsequence of length three is a combination of three such indexes *i*1,<=*i*2,<=*i*3, that 1<=≤<=*i*1<=<<=*i*2<=<<=*i*3<=≤<=*n*. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.
A geometric progression with common ratio *k* is a sequence of numbers of the form *b*·*k*0,<=*b*·*k*1,<=...,<=*b*·*k**r*<=-<=1.
Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.
Input Specification:
The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence.
Output Specification:
Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*.
Demo Input:
['5 2\n1 1 2 2 4\n', '3 1\n1 1 1\n', '10 3\n1 2 6 2 3 6 9 18 3 9\n']
Demo Output:
['4', '1', '6']
Note:
In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import Counter,defaultdict
N,K = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
dp1,dp2 = defaultdict(int),defaultdict(int)
for a in A:
if a%K==0:
ans += dp2[a//K]
dp2[a]+=dp1[a//K]
dp1[a]+=1
print(ans)
``` | 3 |
|
165 | B | Burning Midnight Oil | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ...
The expression is regarded as the integral part from dividing number *a* by number *b*.
The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.
Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep. | The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. | Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. | [
"7 2\n",
"59 9\n"
] | [
"4\n",
"54\n"
] | In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59. | 1,000 | [
{
"input": "7 2",
"output": "4"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "11 2",
"output": "7"
},
{
"input": "747 2",
"output": "376"
},
{
"input": "6578 2",
"output": "3293"
},
{
"input": "37212 2",
"output": "18609"
},
{
"input": "12357 2",
"output": "6181"
},
{
"input": "7998332 2",
"output": "3999172"
},
{
"input": "86275251 2",
"output": "43137632"
},
{
"input": "75584551 2",
"output": "37792280"
},
{
"input": "6 3",
"output": "5"
},
{
"input": "43 4",
"output": "33"
},
{
"input": "811 3",
"output": "543"
},
{
"input": "3410 4",
"output": "2560"
},
{
"input": "21341 4",
"output": "16009"
},
{
"input": "696485 4",
"output": "522368"
},
{
"input": "8856748 3",
"output": "5904504"
},
{
"input": "2959379 4",
"output": "2219538"
},
{
"input": "831410263 3",
"output": "554273516"
},
{
"input": "2 5",
"output": "2"
},
{
"input": "19 6",
"output": "17"
},
{
"input": "715 7",
"output": "615"
},
{
"input": "9122 5",
"output": "7300"
},
{
"input": "89117 6",
"output": "74268"
},
{
"input": "689973 7",
"output": "591408"
},
{
"input": "3024524 5",
"output": "2419624"
},
{
"input": "67127156 6",
"output": "55939302"
},
{
"input": "412262167 7",
"output": "353367574"
},
{
"input": "6 8",
"output": "6"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "246 10",
"output": "222"
},
{
"input": "5314 8",
"output": "4651"
},
{
"input": "15309 9",
"output": "13609"
},
{
"input": "35648 10",
"output": "32085"
},
{
"input": "3018012 8",
"output": "2640764"
},
{
"input": "92153348 9",
"output": "81914089"
},
{
"input": "177583558 10",
"output": "159825206"
},
{
"input": "1000000000 2",
"output": "500000008"
},
{
"input": "1000000000 3",
"output": "666666672"
},
{
"input": "1000000000 4",
"output": "750000005"
},
{
"input": "1000000000 5",
"output": "800000003"
},
{
"input": "1000000000 6",
"output": "833333338"
},
{
"input": "1000000000 7",
"output": "857142861"
},
{
"input": "1000000000 8",
"output": "875000004"
},
{
"input": "1000000000 9",
"output": "888888894"
},
{
"input": "1000000000 10",
"output": "900000001"
},
{
"input": "1 4",
"output": "1"
},
{
"input": "2 10",
"output": "2"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "6 8",
"output": "6"
},
{
"input": "987862820 9",
"output": "878100288"
},
{
"input": "979591791 9",
"output": "870748262"
},
{
"input": "948889213 9",
"output": "843457081"
},
{
"input": "8 9",
"output": "8"
},
{
"input": "999999999 10",
"output": "900000000"
}
] | 1,655,834,597 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 92 | 0 | def test(n,k):
sumi = n
i = 1
while n >= k **i :
sumi += n // k**i
i+=1
return sumi
n,k = map(int,input().split())
start = 1
end = n
ans = -1
while start <= end :
mid = (start +end) //2
res = test(mid,k)
if res < n :
start = mid +1
elif res >= n :
ans = mid
end = mid -1
print(ans)
| Title: Burning Midnight Oil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lines and so on: , , , ...
The expression is regarded as the integral part from dividing number *a* by number *b*.
The moment the current value equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.
Vasya is wondering, what minimum allowable value *v* can take to let him write not less than *n* lines of code before he falls asleep.
Input Specification:
The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10.
Output Specification:
Print the only integer — the minimum value of *v* that lets Vasya write the program in one night.
Demo Input:
['7 2\n', '59 9\n']
Demo Output:
['4\n', '54\n']
Note:
In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following portions: 54, 6. The total sum is 54 + 6 = 60, that's even more than *n* = 59. | ```python
def test(n,k):
sumi = n
i = 1
while n >= k **i :
sumi += n // k**i
i+=1
return sumi
n,k = map(int,input().split())
start = 1
end = n
ans = -1
while start <= end :
mid = (start +end) //2
res = test(mid,k)
if res < n :
start = mid +1
elif res >= n :
ans = mid
end = mid -1
print(ans)
``` | 3 |
|
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries. | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "0\n0\n0\n0"
},
{
"input": "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4",
"output": "0\n0\n0\n0\n0"
},
{
"input": "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4",
"output": "0\n1\n0\n0\n0\n1"
},
{
"input": "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4 7\n1 7\n6 7",
"output": "0\n0\n0\n0\n0\n0\n1"
},
{
"input": "8 8\n1 1 1 1 1 1 1 1\n5 8\n2 6\n2 3\n1 7\n7 7\n1 6\n1 8\n1 3",
"output": "0\n0\n0\n0\n0\n0\n0\n0"
},
{
"input": "9 9\n-1 1 1 1 1 1 1 1 1\n1 7\n5 6\n1 4\n1 1\n1 1\n6 8\n1 1\n6 7\n3 5",
"output": "0\n1\n0\n0\n0\n0\n0\n1\n0"
},
{
"input": "10 10\n-1 1 -1 1 -1 -1 -1 -1 -1 -1\n6 7\n2 5\n3 6\n1 3\n3 5\n4 5\n3 4\n1 6\n1 1\n1 1",
"output": "1\n1\n1\n0\n0\n1\n1\n0\n0\n0"
},
{
"input": "1 1\n-1\n1 1",
"output": "0"
},
{
"input": "1 1\n1\n1 1",
"output": "0"
}
] | 1,603,994,831 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 12,595,200 | n,m=map(int,input().split())
l=input().split()
c=l.count("-1")
c=min(c,n-c)
res=""
for i in range(m):
l,r=map(int,input().split())
if (r-l)%2==1 and c>=(r-l+1)/2:
res+="1\n"
else:
res+="0\n"
print(res) | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of array *a* can be rearranged so as the sum *a**l**i*<=+<=*a**l**i*<=+<=1<=+<=...<=+<=*a**r**i*<==<=0, otherwise the response to the query will be integer 0.
Help Eugeny, answer all his queries.
Input Specification:
The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*).
Output Specification:
Print *m* integers — the responses to Eugene's queries in the order they occur in the input.
Demo Input:
['2 3\n1 -1\n1 1\n1 2\n2 2\n', '5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n']
Demo Output:
['0\n1\n0\n', '0\n1\n0\n1\n0\n']
Note:
none | ```python
n,m=map(int,input().split())
l=input().split()
c=l.count("-1")
c=min(c,n-c)
res=""
for i in range(m):
l,r=map(int,input().split())
if (r-l)%2==1 and c>=(r-l+1)/2:
res+="1\n"
else:
res+="0\n"
print(res)
``` | 0 |
|
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won. | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order. | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-12\n-13\n-14",
"output": "second"
},
{
"input": "4\n16\n12\n19\n-98",
"output": "second"
},
{
"input": "5\n-6\n-1\n-1\n5\n3",
"output": "second"
},
{
"input": "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1",
"output": "first"
},
{
"input": "1\n-534365",
"output": "second"
},
{
"input": "1\n10253033",
"output": "first"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "8\n1\n-2\n-3\n4\n5\n-6\n-7\n8",
"output": "second"
},
{
"input": "2\n1\n-1",
"output": "second"
},
{
"input": "5\n1\n2\n3\n4\n5",
"output": "first"
},
{
"input": "5\n-1\n-2\n-3\n-4\n-5",
"output": "second"
},
{
"input": "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1",
"output": "first"
},
{
"input": "131\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n-1\n-1\n2",
"output": "first"
},
{
"input": "6\n-1\n-2\n-3\n1\n2\n3",
"output": "first"
},
{
"input": "3\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "12\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-1000000000",
"output": "first"
},
{
"input": "20\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "5\n1000000000\n1000000000\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "4\n1\n-1000000000\n-1000000000\n-1000000000",
"output": "second"
},
{
"input": "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000",
"output": "first"
},
{
"input": "4\n-1\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "11\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000",
"output": "first"
},
{
"input": "2\n-4\n4",
"output": "first"
},
{
"input": "3\n-12\n3\n9",
"output": "second"
},
{
"input": "3\n9\n1\n-10",
"output": "second"
},
{
"input": "3\n1\n2\n-3",
"output": "second"
},
{
"input": "4\n55\n5\n-5\n-55",
"output": "first"
},
{
"input": "4\n5\n-1\n1\n-5",
"output": "first"
},
{
"input": "2\n-5\n6",
"output": "first"
},
{
"input": "4\n5\n-4\n3\n-40",
"output": "second"
},
{
"input": "4\n1000000000\n1000000000\n1000000000\n-5",
"output": "first"
},
{
"input": "6\n3\n2\n1\n-3\n-1\n-2",
"output": "first"
},
{
"input": "5\n4\n1\n1\n-3\n-3",
"output": "first"
},
{
"input": "5\n208\n-52\n-52\n-52\n-52",
"output": "first"
},
{
"input": "3\n-100\n-200\n300",
"output": "first"
},
{
"input": "3\n400\n-200\n-200",
"output": "first"
},
{
"input": "3\n208\n-207\n-1",
"output": "first"
},
{
"input": "3\n98888887\n98888888\n-197777775",
"output": "second"
}
] | 1,591,442,789 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 405 | 6,348,800 | def is_same(l1,l2):
if(len(l1)==len(l2)):
for i in range(0,len(l1)):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
return True
else:
for i in range(0,min(len(l1),len(l2))):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
t=int(input())
l1=[]#first
sum1=0
l2=[]#second
sum2=0
inp=0
for i in range(0,t):
inp=int(input())
if(inp<0):
sum2+=abs(inp)
l2.append(abs(inp))
else:
sum1+=inp
l1.append(inp)
if(sum2>sum1):
print('second')
elif(sum1>sum2):
print("first")
else:
check=is_same(l1,l2)
if(check==True):
if(inp>0):
print('first')
else:
print('second')
else:
print(check)
| Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of the awarded points coincide, the wrestler who performed the last technique wins. Your task is to determine which wrestler won.
Input Specification:
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* points. And if *a**i* is negative, that means that the second wrestler performed the technique that was awarded with (<=-<=*a**i*) points.
The techniques are given in chronological order.
Output Specification:
If the first wrestler wins, print string "first", otherwise print "second"
Demo Input:
['5\n1\n2\n-3\n-4\n3\n', '3\n-1\n-2\n3\n', '2\n4\n-4\n']
Demo Output:
['second\n', 'first\n', 'second\n']
Note:
Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |*y*| and *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">|*y*|</sub> = *y*<sub class="lower-index">|*y*|</sub>, or there is such number *r* (*r* < |*x*|, *r* < |*y*|), that *x*<sub class="lower-index">1</sub> = *y*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub> = *y*<sub class="lower-index">2</sub>, ... , *x*<sub class="lower-index">*r*</sub> = *y*<sub class="lower-index">*r*</sub> and *x*<sub class="lower-index">*r* + 1</sub> > *y*<sub class="lower-index">*r* + 1</sub>.
We use notation |*a*| to denote length of sequence *a*. | ```python
def is_same(l1,l2):
if(len(l1)==len(l2)):
for i in range(0,len(l1)):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
return True
else:
for i in range(0,min(len(l1),len(l2))):
if(l1[i]!=l2[i]):
if(l1[i]>l2[i]):
return 'first'
else:
return 'second'
t=int(input())
l1=[]#first
sum1=0
l2=[]#second
sum2=0
inp=0
for i in range(0,t):
inp=int(input())
if(inp<0):
sum2+=abs(inp)
l2.append(abs(inp))
else:
sum1+=inp
l1.append(inp)
if(sum2>sum1):
print('second')
elif(sum1>sum2):
print("first")
else:
check=is_same(l1,l2)
if(check==True):
if(inp>0):
print('first')
else:
print('second')
else:
print(check)
``` | 3 |
|
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
"output": "21223442"
},
{
"input": "91730629",
"output": "91230320"
},
{
"input": "420062703497",
"output": "420032203402"
},
{
"input": "332711047202",
"output": "332211042202"
},
{
"input": "3395184971407775",
"output": "3304114021402224"
},
{
"input": "8464062628894325",
"output": "1434032321104324"
},
{
"input": "164324828731963982",
"output": "134324121231033012"
},
{
"input": "384979173822804784",
"output": "314020123122104214"
},
{
"input": "41312150450968417",
"output": "41312140440031412"
},
{
"input": "2156",
"output": "2143"
},
{
"input": "1932",
"output": "1032"
},
{
"input": "5902",
"output": "4002"
},
{
"input": "5728",
"output": "4221"
},
{
"input": "8537",
"output": "1432"
},
{
"input": "55403857",
"output": "44403142"
},
{
"input": "270739",
"output": "220230"
},
{
"input": "28746918",
"output": "21243011"
},
{
"input": "10279211",
"output": "10220211"
},
{
"input": "40289679",
"output": "40210320"
},
{
"input": "545203238506",
"output": "444203231403"
},
{
"input": "461117063340",
"output": "431112033340"
},
{
"input": "658492686568",
"output": "341402313431"
},
{
"input": "857373361868",
"output": "142323331131"
},
{
"input": "429325660016",
"output": "420324330013"
},
{
"input": "9894448650287940",
"output": "9104441340212040"
},
{
"input": "6354510839296263",
"output": "3344410130203233"
},
{
"input": "6873575462224593",
"output": "3123424432224403"
},
{
"input": "4237951492601449",
"output": "4232041402301440"
},
{
"input": "2680352384836991",
"output": "2310342314133001"
},
{
"input": "606187734191890310",
"output": "303112234101100310"
},
{
"input": "351499943576823355",
"output": "341400043423123344"
},
{
"input": "180593481782177068",
"output": "110403411212122031"
},
{
"input": "999999999999999999",
"output": "900000000000000000"
},
{
"input": "1000000000000000000",
"output": "1000000000000000000"
},
{
"input": "9999",
"output": "9000"
},
{
"input": "99",
"output": "90"
},
{
"input": "9991",
"output": "9001"
}
] | 1,699,845,370 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 62 | 0 | string = input()
newString = ''.split()
#checks if each inversed digit would reduce the number
for digit in string:
newString += str(min((9 - int(digit), int(digit))))
if int(newString[0]) < 1: #prevents trailing zeros
newString[0] = '9'
#prints the new number as a full string
for digit in newString:
print(digit, end = '') | Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero.
Input Specification:
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Output Specification:
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
Demo Input:
['27\n', '4545\n']
Demo Output:
['22\n', '4444\n']
Note:
none | ```python
string = input()
newString = ''.split()
#checks if each inversed digit would reduce the number
for digit in string:
newString += str(min((9 - int(digit), int(digit))))
if int(newString[0]) < 1: #prevents trailing zeros
newString[0] = '9'
#prints the new number as a full string
for digit in newString:
print(digit, end = '')
``` | 3 |
|
18 | B | Platforms | PROGRAMMING | 1,700 | [
"brute force",
"math"
] | B. Platforms | 2 | 64 | In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*], and *l*<=<<=*m*. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly *d* units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down. | The first input line contains 4 integer numbers *n*, *d*, *m*, *l* (1<=≤<=*n*,<=*d*,<=*m*,<=*l*<=≤<=106,<=*l*<=<<=*m*) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers *m* and *l* needed to find coordinates of the *k*-th platform: [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*]. | Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down. | [
"2 2 5 3\n",
"5 4 11 8\n"
] | [
"4\n",
"20\n"
] | none | 0 | [
{
"input": "2 2 5 3",
"output": "4"
},
{
"input": "5 4 11 8",
"output": "20"
},
{
"input": "228385 744978 699604 157872",
"output": "2979912"
},
{
"input": "773663 427904 329049 243542",
"output": "1283712"
},
{
"input": "835293 627183 442142 361649",
"output": "1254366"
},
{
"input": "896922 310109 71587 16487",
"output": "310109"
},
{
"input": "958552 993036 701031 109903",
"output": "993036"
},
{
"input": "20182 192314 814124 268107",
"output": "384628"
},
{
"input": "81812 875240 443569 287155",
"output": "875240"
},
{
"input": "3 6 6 3",
"output": "18"
},
{
"input": "3 16 6 3",
"output": "16"
},
{
"input": "3 4 6 3",
"output": "4"
},
{
"input": "680892 333996 619800 374820",
"output": "1001988"
},
{
"input": "658990 366800 43771 676",
"output": "366800"
},
{
"input": "637089 915955 984094 706836",
"output": "915955"
},
{
"input": "615188 948759 924417 924407",
"output": "183286007415"
},
{
"input": "593287 497915 864740 864733",
"output": "82319789035"
},
{
"input": "87738 530718 805063 805047",
"output": "11387616126"
},
{
"input": "65837 79874 229034 229024",
"output": "1636218890"
},
{
"input": "755991 187301 743241 743232",
"output": "2217831141"
},
{
"input": "402841 635488 123613 122628",
"output": "49568064"
},
{
"input": "999463 261665 255021 255007",
"output": "1596941495"
},
{
"input": "43496 179847 327622 327621",
"output": "14250356892"
},
{
"input": "105126 379125 440715 440713",
"output": "46330970625"
},
{
"input": "1000000 1 1000000 999999",
"output": "1000000000000"
},
{
"input": "1000000 16 999952 999951",
"output": "999952000000"
},
{
"input": "1000000 49 999983 999982",
"output": "999983000023"
},
{
"input": "1000000 3 999997 999996",
"output": "999997000002"
},
{
"input": "1000000 11 999989 999988",
"output": "999989000010"
},
{
"input": "1000000 64 999956 999955",
"output": "999956000000"
},
{
"input": "1000000 531 999106 999105",
"output": "999106000236"
},
{
"input": "1000000 337 999956 999955",
"output": "999956000119"
},
{
"input": "1 1 2 1",
"output": "2"
},
{
"input": "1 1000000 5 3",
"output": "1000000"
},
{
"input": "1000000 1000000 1000000 999999",
"output": "1000000000000"
}
] | 1,570,117,784 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 966 | 50,892,800 | class Node:
def __init__(self, low, high):
self.low = low
self.high = high
self.max = high
self.left = None
self.right = None
def insert(root, low, high):
if not root:
return Node(low, high)
l = root.low
if low < l:
root.left = insert(root.left, low, high)
else:
root.right = insert(root.right, low, high)
if root.max < high:
root.max = high
return root
def overlaps(l1, h1, l2, h2):
return l1 <= h2 and l2 <= h1
def overlap_search(root, low, high):
if not root:
return None
if overlaps(root.low, root.high, low, high):
return root.low, root.high
if root.left:
if root.left.max >= low:
return overlap_search(root.left, low, high)
return overlap_search(root.right, low, high)
class CodeforcesTask18BSolution:
def __init__(self):
self.result = ''
self.n_d_m_l = []
def read_input(self):
self.n_d_m_l = [int(x) for x in input().split(" ")]
def process_task(self):
intervals = []
for k in range(1, 1 + self.n_d_m_l[0]):
intervals.append(((k - 1) * self.n_d_m_l[2], (k - 1) * self.n_d_m_l[2] + self.n_d_m_l[3]))
root = None
for inter in intervals:
root = insert(root, *inter)
x = self.n_d_m_l[1]
while overlap_search(root, x, x):
x += self.n_d_m_l[1]
self.result = str(x)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask18BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| Title: Platforms
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
In one one-dimensional world there are *n* platforms. Platform with index *k* (platforms are numbered from 1) is a segment with coordinates [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*], and *l*<=<<=*m*. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly *d* units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.
Input Specification:
The first input line contains 4 integer numbers *n*, *d*, *m*, *l* (1<=≤<=*n*,<=*d*,<=*m*,<=*l*<=≤<=106,<=*l*<=<<=*m*) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers *m* and *l* needed to find coordinates of the *k*-th platform: [(*k*<=-<=1)*m*,<=(*k*<=-<=1)*m*<=+<=*l*].
Output Specification:
Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.
Demo Input:
['2 2 5 3\n', '5 4 11 8\n']
Demo Output:
['4\n', '20\n']
Note:
none | ```python
class Node:
def __init__(self, low, high):
self.low = low
self.high = high
self.max = high
self.left = None
self.right = None
def insert(root, low, high):
if not root:
return Node(low, high)
l = root.low
if low < l:
root.left = insert(root.left, low, high)
else:
root.right = insert(root.right, low, high)
if root.max < high:
root.max = high
return root
def overlaps(l1, h1, l2, h2):
return l1 <= h2 and l2 <= h1
def overlap_search(root, low, high):
if not root:
return None
if overlaps(root.low, root.high, low, high):
return root.low, root.high
if root.left:
if root.left.max >= low:
return overlap_search(root.left, low, high)
return overlap_search(root.right, low, high)
class CodeforcesTask18BSolution:
def __init__(self):
self.result = ''
self.n_d_m_l = []
def read_input(self):
self.n_d_m_l = [int(x) for x in input().split(" ")]
def process_task(self):
intervals = []
for k in range(1, 1 + self.n_d_m_l[0]):
intervals.append(((k - 1) * self.n_d_m_l[2], (k - 1) * self.n_d_m_l[2] + self.n_d_m_l[3]))
root = None
for inter in intervals:
root = insert(root, *inter)
x = self.n_d_m_l[1]
while overlap_search(root, x, x):
x += self.n_d_m_l[1]
self.result = str(x)
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask18BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
``` | -1 |
955 | A | Feed the cat | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero. | The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). | Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . | [
"19 00\n255 1 100 1\n",
"17 41\n1000 6 15 11\n"
] | [
"25200.0000\n",
"1365.0000\n"
] | In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | 500 | [
{
"input": "19 00\n255 1 100 1",
"output": "25200.0000"
},
{
"input": "17 41\n1000 6 15 11",
"output": "1365.0000"
},
{
"input": "16 34\n61066 14 50 59",
"output": "43360.0000"
},
{
"input": "18 18\n23331 86 87 41",
"output": "49590.0000"
},
{
"input": "10 48\n68438 8 18 29",
"output": "36187.2000"
},
{
"input": "08 05\n63677 9 83 25",
"output": "186252.0000"
},
{
"input": "00 00\n100000 100 100 100",
"output": "100000.0000"
},
{
"input": "20 55\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "23 59\n100000 100 100 100",
"output": "80000.0000"
},
{
"input": "00 00\n1 100 100 100",
"output": "100.0000"
},
{
"input": "21 26\n33193 54 97 66",
"output": "39032.8000"
},
{
"input": "20 45\n33756 24 21 1",
"output": "567100.8000"
},
{
"input": "14 33\n92062 59 89 72",
"output": "110146.4000"
},
{
"input": "01 24\n92730 5 35 29",
"output": "94920.0000"
},
{
"input": "20 58\n93398 43 86 99",
"output": "64947.2000"
},
{
"input": "23 04\n37170 81 32 64",
"output": "14873.6000"
},
{
"input": "01 38\n70542 27 74 26",
"output": "200836.0000"
},
{
"input": "04 28\n38505 65 25 95",
"output": "10150.0000"
},
{
"input": "00 10\n33077 21 40 22",
"output": "60160.0000"
},
{
"input": "10 44\n66449 67 90 83",
"output": "72090.0000"
},
{
"input": "05 51\n10220 5 33 48",
"output": "7029.0000"
},
{
"input": "20 19\n68886 28 48 94",
"output": "28147.2000"
},
{
"input": "01 49\n11621 55 78 46",
"output": "19734.0000"
},
{
"input": "21 28\n78549 91 4 98",
"output": "2566.4000"
},
{
"input": "18 06\n88580 22 35 59",
"output": "43232.0000"
},
{
"input": "22 28\n55507 53 61 11",
"output": "246293.6000"
},
{
"input": "18 58\n22434 84 91 59",
"output": "34143.2000"
},
{
"input": "15 36\n32466 27 22 15",
"output": "46464.0000"
},
{
"input": "17 31\n9603 53 73 74",
"output": "9490.0000"
},
{
"input": "14 53\n76530 92 4 22",
"output": "13916.0000"
},
{
"input": "18 31\n10753 23 30 74",
"output": "4152.0000"
},
{
"input": "17 43\n16290 46 90 94",
"output": "15660.0000"
},
{
"input": "18 38\n3652 11 53 94",
"output": "2067.0000"
},
{
"input": "19 57\n3 4 7 6",
"output": "7.0000"
}
] | 1,521,829,680 | 6,780 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 77 | 7,065,600 | h, m = [int(x) for x in input().split()]
H, D, C, N = [int(x) for x in input().split()]
current_time = h * 60 + m
current_buns = H//N
if H%N != 0:
current_buns += 1
if current_time > 1200:
print(current_buns * C)
else:
later_hunger = H + D * (1200-current_time)
later_buns = later_hunger//N
if later_hunger%N != 0:
later_buns += 1
current_money = current_buns * C
later_money = later_buns * C * 0.8
if later_money > current_money:
print(current_money)
else:
print(later_money)
| Title: Feed the cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points.
At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts.
Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
Input Specification:
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening.
The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output Specification:
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4.
Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
Demo Input:
['19 00\n255 1 100 1\n', '17 41\n1000 6 15 11\n']
Demo Output:
['25200.0000\n', '1365.0000\n']
Note:
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles.
In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. | ```python
h, m = [int(x) for x in input().split()]
H, D, C, N = [int(x) for x in input().split()]
current_time = h * 60 + m
current_buns = H//N
if H%N != 0:
current_buns += 1
if current_time > 1200:
print(current_buns * C)
else:
later_hunger = H + D * (1200-current_time)
later_buns = later_hunger//N
if later_hunger%N != 0:
later_buns += 1
current_money = current_buns * C
later_money = later_buns * C * 0.8
if later_money > current_money:
print(current_money)
else:
print(later_money)
``` | 0 |
|
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots. | The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment. | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 81 2 67 52\n2\n2 40\n6 51",
"output": "87\n0\n23\n28\n141\n0\n86\n2\n67\n52"
},
{
"input": "2\n72 45\n6\n1 69\n2 41\n1 19\n2 7\n1 5\n2 1",
"output": "0\n0"
},
{
"input": "10\n95 54 36 39 98 30 19 24 14 12\n3\n9 5\n8 15\n7 5",
"output": "95\n54\n36\n39\n98\n34\n0\n28\n13\n21"
},
{
"input": "100\n95 15 25 18 64 62 23 59 70 84 50 26 87 35 75 86 0 22 77 60 66 41 21 9 75 50 25 3 69 14 39 68 64 46 59 99 2 0 21 76 90 12 61 42 6 91 36 39 47 41 93 81 66 57 70 36 68 89 52 1 19 93 67 22 76 20 8 81 98 18 100 73 61 93 75 80 53 72 40 20 2 86 33 59 27 16 11 26 55 44 47 55 94 58 2 55 82 22 9 95\n0",
"output": "95\n15\n25\n18\n64\n62\n23\n59\n70\n84\n50\n26\n87\n35\n75\n86\n0\n22\n77\n60\n66\n41\n21\n9\n75\n50\n25\n3\n69\n14\n39\n68\n64\n46\n59\n99\n2\n0\n21\n76\n90\n12\n61\n42\n6\n91\n36\n39\n47\n41\n93\n81\n66\n57\n70\n36\n68\n89\n52\n1\n19\n93\n67\n22\n76\n20\n8\n81\n98\n18\n100\n73\n61\n93\n75\n80\n53\n72\n40\n20\n2\n86\n33\n59\n27\n16\n11\n26\n55\n44\n47\n55\n94\n58\n2\n55\n82\n22\n9\n95"
},
{
"input": "1\n100\n1\n1 100",
"output": "0"
},
{
"input": "1\n100\n1\n1 1",
"output": "0"
},
{
"input": "1\n50\n1\n1 25",
"output": "0"
},
{
"input": "2\n50 0\n1\n1 1",
"output": "0\n49"
},
{
"input": "1\n10\n0",
"output": "10"
}
] | 1,589,002,350 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 186 | 7,065,600 | # bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
import random
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
shot = []
line = []
for i in range(m):
x, y = map(int, input().split())
line.append(x)
shot.append(y)
for i in range(0, len(line)):
# line vale position ko zeo kr diya
temp = arr[line[i] - 1]
arr[line[i] - 1] = 0
# phir uske age vali position me add kr diya
if line[i] == len(arr):
continue
else:
arr[line[i]] += temp - shot[i]
if line[i] - 1 == 0:
continue
else:
arr[line[i] - 2] += shot[i] - 1
for i in arr:
print(i)
| Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i* oskols sitting on the *i*-th wire.
Sometimes Shaass shots one of the birds and the bird dies (suppose that this bird sat at the *i*-th wire). Consequently all the birds on the *i*-th wire to the left of the dead bird get scared and jump up on the wire number *i*<=-<=1, if there exists no upper wire they fly away. Also all the birds to the right of the dead bird jump down on wire number *i*<=+<=1, if there exists no such wire they fly away.
Shaass has shot *m* birds. You're given the initial number of birds on each wire, tell him how many birds are sitting on each wire after the shots.
Input Specification:
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100).
The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The integers mean that for the *i*-th time Shaass shoot the *y**i*-th (from left) bird on the *x**i*-th wire, (1<=≤<=*x**i*<=≤<=*n*,<=1<=≤<=*y**i*). It's guaranteed there will be at least *y**i* birds on the *x**i*-th wire at that moment.
Output Specification:
On the *i*-th line of the output print the number of birds on the *i*-th wire.
Demo Input:
['5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n', '3\n2 4 1\n1\n2 2\n']
Demo Output:
['0\n12\n5\n0\n16\n', '3\n0\n3\n']
Note:
none | ```python
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
import random
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
shot = []
line = []
for i in range(m):
x, y = map(int, input().split())
line.append(x)
shot.append(y)
for i in range(0, len(line)):
# line vale position ko zeo kr diya
temp = arr[line[i] - 1]
arr[line[i] - 1] = 0
# phir uske age vali position me add kr diya
if line[i] == len(arr):
continue
else:
arr[line[i]] += temp - shot[i]
if line[i] - 1 == 0:
continue
else:
arr[line[i] - 2] += shot[i] - 1
for i in arr:
print(i)
``` | 0 |
|
169 | A | Chores | PROGRAMMING | 800 | [
"sortings"
] | null | null | Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? | The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces. | Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. | [
"5 2 3\n6 2 3 100 1\n",
"7 3 4\n1 1 9 1 1 1 1\n"
] | [
"3\n",
"0\n"
] | In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | 500 | [
{
"input": "5 2 3\n6 2 3 100 1",
"output": "3"
},
{
"input": "7 3 4\n1 1 9 1 1 1 1",
"output": "0"
},
{
"input": "2 1 1\n10 2",
"output": "8"
},
{
"input": "2 1 1\n7 7",
"output": "0"
},
{
"input": "2 1 1\n1 1000000000",
"output": "999999999"
},
{
"input": "3 1 2\n6 5 5",
"output": "1"
},
{
"input": "3 2 1\n10 10 8",
"output": "2"
},
{
"input": "8 3 5\n42 55 61 72 83 10 22 33",
"output": "6"
},
{
"input": "10 5 5\n1 2 3 4 5 999999999 999999998 999999997 999999996 999999995",
"output": "999999990"
},
{
"input": "4 1 3\n10 8 7 3",
"output": "2"
},
{
"input": "4 2 2\n402 10 10 402",
"output": "392"
},
{
"input": "4 1 3\n10 402 402 10",
"output": "0"
},
{
"input": "4 3 1\n100 100 200 200",
"output": "0"
},
{
"input": "150 10 140\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "102 101 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 1 1",
"output": "0"
}
] | 1,529,066,633 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = input().split()
a = int(n[1])
b = int(n[2])
n = int(n[0])
x = list(map(int,input().split()))
x.sort()
res = x[a] - x[a-1]
print(res) | Title: Chores
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*.
As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=><=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≤<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*).
In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores?
Input Specification:
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores.
The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different.
All numbers on the lines are separated by single spaces.
Output Specification:
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
Demo Input:
['5 2 3\n6 2 3 100 1\n', '7 3 4\n1 1 9 1 1 1 1\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the possible values of *x* are 3, 4 or 5.
In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4. | ```python
n = input().split()
a = int(n[1])
b = int(n[2])
n = int(n[0])
x = list(map(int,input().split()))
x.sort()
res = x[a] - x[a-1]
print(res)
``` | 0 |
|
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "111010010111",
"output": "11110010111"
},
{
"input": "11110111011100000000",
"output": "1111111011100000000"
},
{
"input": "11110010010100001110110101110011110110100111101",
"output": "1111010010100001110110101110011110110100111101"
},
{
"input": "1001011111010010100111111",
"output": "101011111010010100111111"
},
{
"input": "1111111111",
"output": "111111111"
},
{
"input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101",
"output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101"
},
{
"input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100",
"output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100"
},
{
"input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011",
"output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011"
},
{
"input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011",
"output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011"
},
{
"input": "11",
"output": "1"
},
{
"input": "111",
"output": "11"
},
{
"input": "111111",
"output": "11111"
},
{
"input": "11111",
"output": "1111"
},
{
"input": "1111",
"output": "111"
}
] | 1,628,668,135 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 154 | 7,168,000 | a=input()
i=a.find('0')
if i!=-1:
a=a[:i]+a[i+1:]
else:
a=a[:-1]
print(a) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes).
The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
Input Specification:
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
Output Specification:
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
Demo Input:
['101\n', '110010\n']
Demo Output:
['11\n', '11010\n']
Note:
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>. | ```python
a=input()
i=a.find('0')
if i!=-1:
a=a[:i]+a[i+1:]
else:
a=a[:-1]
print(a)
``` | 3 |
|
656 | G | You're a Professional | PROGRAMMING | 1,900 | [
"*special"
] | null | null | A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends. | The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. | Output an integer — the number of items liked by at least *T* of user's friends. | [
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] | [
"2\n",
"4\n"
] | none | 0 | [
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN",
"output": "0"
},
{
"input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN",
"output": "0"
},
{
"input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY",
"output": "10"
},
{
"input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY",
"output": "9"
},
{
"input": "5 2 3\nNN\nNY\nYY\nNN\nNY",
"output": "1"
},
{
"input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY",
"output": "0"
},
{
"input": "6 1 3\nY\nY\nY\nY\nY\nN",
"output": "1"
},
{
"input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN",
"output": "1"
},
{
"input": "2 4 2\nNYNY\nNYNY",
"output": "2"
},
{
"input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY",
"output": "6"
},
{
"input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN",
"output": "0"
},
{
"input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN",
"output": "0"
},
{
"input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY",
"output": "1"
},
{
"input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY",
"output": "6"
},
{
"input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN",
"output": "4"
},
{
"input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY",
"output": "2"
},
{
"input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN",
"output": "2"
},
{
"input": "3 1 1\nN\nY\nN",
"output": "1"
},
{
"input": "7 1 3\nY\nY\nY\nN\nY\nY\nY",
"output": "1"
},
{
"input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY",
"output": "1"
},
{
"input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN",
"output": "0"
},
{
"input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN",
"output": "4"
},
{
"input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN",
"output": "3"
},
{
"input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY",
"output": "5"
},
{
"input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY",
"output": "2"
},
{
"input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN",
"output": "1"
},
{
"input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN",
"output": "3"
},
{
"input": "1 3 1\nYYN",
"output": "2"
},
{
"input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY",
"output": "4"
}
] | 1,480,509,547 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | f,n,t=map(int,input().split())
s=0
y=[0]*n
for i in range(f):
a=input()
for j in range(n):
if a[j]=='Y':
y[j]+=1;
for i in range(n):
if y[i] >= t:
s += 1
print(s) | Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends.
Input Specification:
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output Specification:
Output an integer — the number of items liked by at least *T* of user's friends.
Demo Input:
['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n']
Demo Output:
['2\n', '4\n']
Note:
none | ```python
f,n,t=map(int,input().split())
s=0
y=[0]*n
for i in range(f):
a=input()
for j in range(n):
if a[j]=='Y':
y[j]+=1;
for i in range(n):
if y[i] >= t:
s += 1
print(s)
``` | 0 |
|
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,582,148,671 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | n = int(input())+1
l = sum(list(map(int,input().split())))
ways = 0
for i in range(1,6):
#print(i)
if (l + i ) % n == 0 :
ways +=1
#print(ways)
if l % 2 == 0 :
print(ways + 1)
else:
print(ways)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input())+1
l = sum(list(map(int,input().split())))
ways = 0
for i in range(1,6):
#print(i)
if (l + i ) % n == 0 :
ways +=1
#print(ways)
if l % 2 == 0 :
print(ways + 1)
else:
print(ways)
``` | 0 |
|
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them. | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
{
"input": "100000 180",
"output": "2 1 100000"
},
{
"input": "100000 42",
"output": "2 1 23335"
},
{
"input": "100000 123",
"output": "2 1 68335"
},
{
"input": "5 1",
"output": "2 1 3"
},
{
"input": "5 36",
"output": "2 1 3"
},
{
"input": "5 54",
"output": "2 1 3"
},
{
"input": "5 55",
"output": "2 1 4"
},
{
"input": "5 70",
"output": "2 1 4"
},
{
"input": "5 89",
"output": "2 1 4"
},
{
"input": "5 90",
"output": "2 1 4"
},
{
"input": "5 91",
"output": "2 1 5"
},
{
"input": "5 111",
"output": "2 1 5"
},
{
"input": "5 126",
"output": "2 1 5"
},
{
"input": "5 127",
"output": "2 1 5"
},
{
"input": "5 141",
"output": "2 1 5"
},
{
"input": "5 162",
"output": "2 1 5"
},
{
"input": "5 180",
"output": "2 1 5"
},
{
"input": "6 46",
"output": "2 1 4"
},
{
"input": "6 33",
"output": "2 1 3"
},
{
"input": "13 4",
"output": "2 1 3"
},
{
"input": "23 11",
"output": "2 1 3"
},
{
"input": "11 119",
"output": "2 1 9"
},
{
"input": "13 117",
"output": "2 1 10"
},
{
"input": "18 174",
"output": "2 1 18"
},
{
"input": "8509 139",
"output": "2 1 6573"
},
{
"input": "29770 76",
"output": "2 1 12572"
},
{
"input": "59115 40",
"output": "2 1 13139"
},
{
"input": "68459 88",
"output": "2 1 33471"
},
{
"input": "85100 129",
"output": "2 1 60990"
},
{
"input": "100000 13",
"output": "2 1 7224"
},
{
"input": "100000 35",
"output": "2 1 19446"
},
{
"input": "100000 49",
"output": "2 1 27224"
},
{
"input": "100000 71",
"output": "2 1 39446"
},
{
"input": "100000 79",
"output": "2 1 43891"
},
{
"input": "100000 101",
"output": "2 1 56113"
},
{
"input": "100000 109",
"output": "2 1 60558"
},
{
"input": "100000 143",
"output": "2 1 79446"
},
{
"input": "100000 148",
"output": "2 1 82224"
},
{
"input": "100000 176",
"output": "2 1 97780"
},
{
"input": "4 16",
"output": "2 1 3"
}
] | 1,498,578,871 | 4,771 | Python 3 | OK | TESTS | 46 | 62 | 5,529,600 | n, alp = map(int, input().split())
a = 180 / n
if alp >= (n-2)*180/n:
print("1 2 3")
else:
k1 = int(alp / a)
if (k1 + 1) * a - alp < alp - k1 * a:
k1 += 1
if k1 == 0:
print("2 1 3")
else:
print(1, 2, n + 1 - k1)
| Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible.
If there are many optimal solutions, Mister B should be satisfied with any of them.
Input Specification:
First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees.
Output Specification:
Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order.
Demo Input:
['3 15\n', '4 67\n', '4 68\n']
Demo Output:
['1 2 3\n', '2 1 3\n', '4 1 2\n']
Note:
In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: "3 1 2", "3 2 4", "4 2 3", "4 3 1", "1 3 4", "1 4 2", "2 4 1", "4 1 3", "3 1 4", "3 4 2", "2 4 3", "2 3 1", "1 3 2", "1 2 4", "4 2 1".
In third sample test, on the contrary, the angle of 90 degrees was chosen, since |90 - 68| < |45 - 68|. Other correct answers are: "2 1 4", "3 2 1", "1 2 3", "4 3 2", "2 3 4", "1 4 3", "3 4 1". | ```python
n, alp = map(int, input().split())
a = 180 / n
if alp >= (n-2)*180/n:
print("1 2 3")
else:
k1 = int(alp / a)
if (k1 + 1) * a - alp < alp - k1 * a:
k1 += 1
if k1 == 0:
print("2 1 3")
else:
print(1, 2, n + 1 - k1)
``` | 3 |
|
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input": "5\n5 4 3 2 1",
"output": "5 4 3 2 1"
},
{
"input": "20\n2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19",
"output": "2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19"
},
{
"input": "21\n3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19",
"output": "3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19"
},
{
"input": "10\n3 4 5 6 7 8 9 10 1 2",
"output": "9 10 1 2 3 4 5 6 7 8"
},
{
"input": "8\n1 5 3 7 2 6 4 8",
"output": "1 5 3 7 2 6 4 8"
},
{
"input": "50\n49 22 4 2 20 46 7 32 5 19 48 24 26 15 45 21 44 11 50 43 39 17 31 1 42 34 3 27 36 25 12 30 13 33 28 35 18 6 8 37 38 14 10 9 29 16 40 23 41 47",
"output": "24 4 27 3 9 38 7 39 44 43 18 31 33 42 14 46 22 37 10 5 16 2 48 12 30 13 28 35 45 32 23 8 34 26 36 29 40 41 21 47 49 25 20 17 15 6 50 11 1 19"
},
{
"input": "34\n13 20 33 30 15 11 27 4 8 2 29 25 24 7 3 22 18 10 26 16 5 1 32 9 34 6 12 14 28 19 31 21 23 17",
"output": "22 10 15 8 21 26 14 9 24 18 6 27 1 28 5 20 34 17 30 2 32 16 33 13 12 19 7 29 11 4 31 23 3 25"
},
{
"input": "92\n23 1 6 4 84 54 44 76 63 34 61 20 48 13 28 78 26 46 90 72 24 55 91 89 53 38 82 5 79 92 29 32 15 64 11 88 60 70 7 66 18 59 8 57 19 16 42 21 80 71 62 27 75 86 36 9 83 73 74 50 43 31 56 30 17 33 40 81 49 12 10 41 22 77 25 68 51 2 47 3 58 69 87 67 39 37 35 65 14 45 52 85",
"output": "2 78 80 4 28 3 39 43 56 71 35 70 14 89 33 46 65 41 45 12 48 73 1 21 75 17 52 15 31 64 62 32 66 10 87 55 86 26 85 67 72 47 61 7 90 18 79 13 69 60 77 91 25 6 22 63 44 81 42 37 11 51 9 34 88 40 84 76 82 38 50 20 58 59 53 8 74 16 29 49 68 27 57 5 92 54 83 36 24 19 23 30"
},
{
"input": "49\n30 24 33 48 7 3 17 2 8 35 10 39 23 40 46 32 18 21 26 22 1 16 47 45 41 28 31 6 12 43 27 11 13 37 19 15 44 5 29 42 4 38 20 34 14 9 25 36 49",
"output": "21 8 6 41 38 28 5 9 46 11 32 29 33 45 36 22 7 17 35 43 18 20 13 2 47 19 31 26 39 1 27 16 3 44 10 48 34 42 12 14 25 40 30 37 24 15 23 4 49"
},
{
"input": "12\n3 8 7 4 6 5 2 1 11 9 10 12",
"output": "8 7 1 4 6 5 3 2 10 11 9 12"
},
{
"input": "78\n16 56 36 78 21 14 9 77 26 57 70 61 41 47 18 44 5 31 50 74 65 52 6 39 22 62 67 69 43 7 64 29 24 40 48 51 73 54 72 12 19 34 4 25 55 33 17 35 23 53 10 8 27 32 42 68 20 63 3 2 1 71 58 46 13 30 49 11 37 66 38 60 28 75 15 59 45 76",
"output": "61 60 59 43 17 23 30 52 7 51 68 40 65 6 75 1 47 15 41 57 5 25 49 33 44 9 53 73 32 66 18 54 46 42 48 3 69 71 24 34 13 55 29 16 77 64 14 35 67 19 36 22 50 38 45 2 10 63 76 72 12 26 58 31 21 70 27 56 28 11 62 39 37 20 74 78 8 4"
},
{
"input": "64\n64 57 40 3 15 8 62 18 33 59 51 19 22 13 4 37 47 45 50 35 63 11 58 42 46 21 7 2 41 48 32 23 28 38 17 12 24 27 49 31 60 6 30 25 61 52 26 54 9 14 29 20 44 39 55 10 34 16 5 56 1 36 53 43",
"output": "61 28 4 15 59 42 27 6 49 56 22 36 14 50 5 58 35 8 12 52 26 13 32 37 44 47 38 33 51 43 40 31 9 57 20 62 16 34 54 3 29 24 64 53 18 25 17 30 39 19 11 46 63 48 55 60 2 23 10 41 45 7 21 1"
},
{
"input": "49\n38 20 49 32 14 41 39 45 25 48 40 19 26 43 34 12 10 3 35 42 5 7 46 47 4 2 13 22 16 24 33 15 11 18 29 31 23 9 44 36 6 17 37 1 30 28 8 21 27",
"output": "44 26 18 25 21 41 22 47 38 17 33 16 27 5 32 29 42 34 12 2 48 28 37 30 9 13 49 46 35 45 36 4 31 15 19 40 43 1 7 11 6 20 14 39 8 23 24 10 3"
},
{
"input": "78\n17 50 30 48 33 12 42 4 18 53 76 67 38 3 20 72 51 55 60 63 46 10 57 45 54 32 24 62 8 11 35 44 65 74 58 28 2 6 56 52 39 23 47 49 61 1 66 41 15 77 7 27 78 13 14 34 5 31 37 21 40 16 29 69 59 43 64 36 70 19 25 73 71 75 9 68 26 22",
"output": "46 37 14 8 57 38 51 29 75 22 30 6 54 55 49 62 1 9 70 15 60 78 42 27 71 77 52 36 63 3 58 26 5 56 31 68 59 13 41 61 48 7 66 32 24 21 43 4 44 2 17 40 10 25 18 39 23 35 65 19 45 28 20 67 33 47 12 76 64 69 73 16 72 34 74 11 50 53"
},
{
"input": "29\n14 21 27 1 4 18 10 17 20 23 2 24 7 9 28 22 8 25 12 15 11 6 16 29 3 26 19 5 13",
"output": "4 11 25 5 28 22 13 17 14 7 21 19 29 1 20 23 8 6 27 9 2 16 10 12 18 26 3 15 24"
},
{
"input": "82\n6 1 10 75 28 66 61 81 78 63 17 19 58 34 49 12 67 50 41 44 3 15 59 38 51 72 36 11 46 29 18 64 27 23 13 53 56 68 2 25 47 40 69 54 42 5 60 55 4 16 24 79 57 20 7 73 32 80 76 52 82 37 26 31 65 8 39 62 33 71 30 9 77 43 48 74 70 22 14 45 35 21",
"output": "2 39 21 49 46 1 55 66 72 3 28 16 35 79 22 50 11 31 12 54 82 78 34 51 40 63 33 5 30 71 64 57 69 14 81 27 62 24 67 42 19 45 74 20 80 29 41 75 15 18 25 60 36 44 48 37 53 13 23 47 7 68 10 32 65 6 17 38 43 77 70 26 56 76 4 59 73 9 52 58 8 61"
},
{
"input": "82\n74 18 15 69 71 77 19 26 80 20 66 7 30 82 22 48 21 44 52 65 64 61 35 49 12 8 53 81 54 16 11 9 40 46 13 1 29 58 5 41 55 4 78 60 6 51 56 2 38 36 34 62 63 25 17 67 45 14 32 37 75 79 10 47 27 39 31 68 59 24 50 43 72 70 42 28 76 23 57 3 73 33",
"output": "36 48 80 42 39 45 12 26 32 63 31 25 35 58 3 30 55 2 7 10 17 15 78 70 54 8 65 76 37 13 67 59 82 51 23 50 60 49 66 33 40 75 72 18 57 34 64 16 24 71 46 19 27 29 41 47 79 38 69 44 22 52 53 21 20 11 56 68 4 74 5 73 81 1 61 77 6 43 62 9 28 14"
},
{
"input": "45\n2 32 34 13 3 15 16 33 22 12 31 38 42 14 27 7 36 8 4 19 45 41 5 35 10 11 39 20 29 44 17 9 6 40 37 28 25 21 1 30 24 18 43 26 23",
"output": "39 1 5 19 23 33 16 18 32 25 26 10 4 14 6 7 31 42 20 28 38 9 45 41 37 44 15 36 29 40 11 2 8 3 24 17 35 12 27 34 22 13 43 30 21"
},
{
"input": "45\n4 32 33 39 43 21 22 35 45 7 14 5 16 9 42 31 24 36 17 29 41 25 37 34 27 20 11 44 3 13 19 2 1 10 26 30 38 18 6 8 15 23 40 28 12",
"output": "33 32 29 1 12 39 10 40 14 34 27 45 30 11 41 13 19 38 31 26 6 7 42 17 22 35 25 44 20 36 16 2 3 24 8 18 23 37 4 43 21 15 5 28 9"
},
{
"input": "74\n48 72 40 67 17 4 27 53 11 32 25 9 74 2 41 24 56 22 14 21 33 5 18 55 20 7 29 36 69 13 52 19 38 30 68 59 66 34 63 6 47 45 54 44 62 12 50 71 16 10 8 64 57 73 46 26 49 42 3 23 35 1 61 39 70 60 65 43 15 28 37 51 58 31",
"output": "62 14 59 6 22 40 26 51 12 50 9 46 30 19 69 49 5 23 32 25 20 18 60 16 11 56 7 70 27 34 74 10 21 38 61 28 71 33 64 3 15 58 68 44 42 55 41 1 57 47 72 31 8 43 24 17 53 73 36 66 63 45 39 52 67 37 4 35 29 65 48 2 54 13"
},
{
"input": "47\n9 26 27 10 6 34 28 42 39 22 45 21 11 43 14 47 38 15 40 32 46 1 36 29 17 25 2 23 31 5 24 4 7 8 12 19 16 44 37 20 18 33 30 13 35 41 3",
"output": "22 27 47 32 30 5 33 34 1 4 13 35 44 15 18 37 25 41 36 40 12 10 28 31 26 2 3 7 24 43 29 20 42 6 45 23 39 17 9 19 46 8 14 38 11 21 16"
},
{
"input": "49\n14 38 6 29 9 49 36 43 47 3 44 20 34 15 7 11 1 28 12 40 16 37 31 10 42 41 33 21 18 30 5 27 17 35 25 26 45 19 2 13 23 32 4 22 46 48 24 39 8",
"output": "17 39 10 43 31 3 15 49 5 24 16 19 40 1 14 21 33 29 38 12 28 44 41 47 35 36 32 18 4 30 23 42 27 13 34 7 22 2 48 20 26 25 8 11 37 45 9 46 6"
},
{
"input": "100\n78 56 31 91 90 95 16 65 58 77 37 89 33 61 10 76 62 47 35 67 69 7 63 83 22 25 49 8 12 30 39 44 57 64 48 42 32 11 70 43 55 50 99 24 85 73 45 14 54 21 98 84 74 2 26 18 9 36 80 53 75 46 66 86 59 93 87 68 94 13 72 28 79 88 92 29 52 82 34 97 19 38 1 41 27 4 40 5 96 100 51 6 20 23 81 15 17 3 60 71",
"output": "83 54 98 86 88 92 22 28 57 15 38 29 70 48 96 7 97 56 81 93 50 25 94 44 26 55 85 72 76 30 3 37 13 79 19 58 11 82 31 87 84 36 40 32 47 62 18 35 27 42 91 77 60 49 41 2 33 9 65 99 14 17 23 34 8 63 20 68 21 39 100 71 46 53 61 16 10 1 73 59 95 78 24 52 45 64 67 74 12 5 4 75 66 69 6 89 80 51 43 90"
},
{
"input": "22\n12 8 11 2 16 7 13 6 22 21 20 10 4 14 18 1 5 15 3 19 17 9",
"output": "16 4 19 13 17 8 6 2 22 12 3 1 7 14 18 5 21 15 20 11 10 9"
},
{
"input": "72\n16 11 49 51 3 27 60 55 23 40 66 7 53 70 13 5 15 32 18 72 33 30 8 31 46 12 28 67 25 38 50 22 69 34 71 52 58 39 24 35 42 9 41 26 62 1 63 65 36 64 68 61 37 14 45 47 6 57 54 20 17 2 56 59 29 10 4 48 21 43 19 44",
"output": "46 62 5 67 16 57 12 23 42 66 2 26 15 54 17 1 61 19 71 60 69 32 9 39 29 44 6 27 65 22 24 18 21 34 40 49 53 30 38 10 43 41 70 72 55 25 56 68 3 31 4 36 13 59 8 63 58 37 64 7 52 45 47 50 48 11 28 51 33 14 35 20"
},
{
"input": "63\n21 56 11 10 62 24 20 42 28 52 38 2 37 43 48 22 7 8 40 14 13 46 53 1 23 4 60 63 51 36 25 12 39 32 49 16 58 44 31 61 33 50 55 54 45 6 47 41 9 57 30 29 26 18 19 27 15 34 3 35 59 5 17",
"output": "24 12 59 26 62 46 17 18 49 4 3 32 21 20 57 36 63 54 55 7 1 16 25 6 31 53 56 9 52 51 39 34 41 58 60 30 13 11 33 19 48 8 14 38 45 22 47 15 35 42 29 10 23 44 43 2 50 37 61 27 40 5 28"
},
{
"input": "18\n2 16 8 4 18 12 3 6 5 9 10 15 11 17 14 13 1 7",
"output": "17 1 7 4 9 8 18 3 10 11 13 6 16 15 12 2 14 5"
},
{
"input": "47\n6 9 10 41 25 3 4 37 20 1 36 22 29 27 11 24 43 31 12 17 34 42 38 39 13 2 7 21 18 5 15 35 44 26 33 46 19 40 30 14 28 23 47 32 45 8 16",
"output": "10 26 6 7 30 1 27 46 2 3 15 19 25 40 31 47 20 29 37 9 28 12 42 16 5 34 14 41 13 39 18 44 35 21 32 11 8 23 24 38 4 22 17 33 45 36 43"
},
{
"input": "96\n41 91 48 88 29 57 1 19 44 43 37 5 10 75 25 63 30 78 76 53 8 92 18 70 39 17 49 60 9 16 3 34 86 59 23 79 55 45 72 51 28 33 96 40 26 54 6 32 89 61 85 74 7 82 52 31 64 66 94 95 11 22 2 73 35 13 42 71 14 47 84 69 50 67 58 12 77 46 38 68 15 36 20 93 27 90 83 56 87 4 21 24 81 62 80 65",
"output": "7 63 31 90 12 47 53 21 29 13 61 76 66 69 81 30 26 23 8 83 91 62 35 92 15 45 85 41 5 17 56 48 42 32 65 82 11 79 25 44 1 67 10 9 38 78 70 3 27 73 40 55 20 46 37 88 6 75 34 28 50 94 16 57 96 58 74 80 72 24 68 39 64 52 14 19 77 18 36 95 93 54 87 71 51 33 89 4 49 86 2 22 84 59 60 43"
},
{
"input": "73\n67 24 39 22 23 20 48 34 42 40 19 70 65 69 64 21 53 11 59 15 26 10 30 33 72 29 55 25 56 71 8 9 57 49 41 61 13 12 6 27 66 36 47 50 73 60 2 37 7 4 51 17 1 46 14 62 35 3 45 63 43 58 54 32 31 5 28 44 18 52 68 38 16",
"output": "53 47 58 50 66 39 49 31 32 22 18 38 37 55 20 73 52 69 11 6 16 4 5 2 28 21 40 67 26 23 65 64 24 8 57 42 48 72 3 10 35 9 61 68 59 54 43 7 34 44 51 70 17 63 27 29 33 62 19 46 36 56 60 15 13 41 1 71 14 12 30 25 45"
},
{
"input": "81\n25 2 78 40 12 80 69 13 49 43 17 33 23 54 32 61 77 66 27 71 24 26 42 55 60 9 5 30 7 37 45 63 53 11 38 44 68 34 28 52 67 22 57 46 47 50 8 16 79 62 4 36 20 14 73 64 6 76 35 74 58 10 29 81 59 31 19 1 75 39 70 18 41 21 72 65 3 48 15 56 51",
"output": "68 2 77 51 27 57 29 47 26 62 34 5 8 54 79 48 11 72 67 53 74 42 13 21 1 22 19 39 63 28 66 15 12 38 59 52 30 35 70 4 73 23 10 36 31 44 45 78 9 46 81 40 33 14 24 80 43 61 65 25 16 50 32 56 76 18 41 37 7 71 20 75 55 60 69 58 17 3 49 6 64"
},
{
"input": "12\n12 3 1 5 11 6 7 10 2 8 9 4",
"output": "3 9 2 12 4 6 7 10 11 8 5 1"
},
{
"input": "47\n7 21 41 18 40 31 12 28 24 14 43 23 33 10 19 38 26 8 34 15 29 44 5 13 39 25 3 27 20 42 35 9 2 1 30 46 36 32 4 22 37 45 6 47 11 16 17",
"output": "34 33 27 39 23 43 1 18 32 14 45 7 24 10 20 46 47 4 15 29 2 40 12 9 26 17 28 8 21 35 6 38 13 19 31 37 41 16 25 5 3 30 11 22 42 36 44"
},
{
"input": "8\n1 3 5 2 4 8 6 7",
"output": "1 4 2 5 3 7 8 6"
},
{
"input": "38\n28 8 2 33 20 32 26 29 23 31 15 38 11 37 18 21 22 19 4 34 1 35 16 7 17 6 27 30 36 12 9 24 25 13 5 3 10 14",
"output": "21 3 36 19 35 26 24 2 31 37 13 30 34 38 11 23 25 15 18 5 16 17 9 32 33 7 27 1 8 28 10 6 4 20 22 29 14 12"
},
{
"input": "10\n2 9 4 6 10 1 7 5 3 8",
"output": "6 1 9 3 8 4 7 10 2 5"
},
{
"input": "23\n20 11 15 1 5 12 23 9 2 22 13 19 16 14 7 4 8 21 6 17 18 10 3",
"output": "4 9 23 16 5 19 15 17 8 22 2 6 11 14 3 13 20 21 12 1 18 10 7"
},
{
"input": "10\n2 4 9 3 6 8 10 5 1 7",
"output": "9 1 4 2 8 5 10 6 3 7"
},
{
"input": "55\n9 48 23 49 11 24 4 22 34 32 17 45 39 13 14 21 19 25 2 31 37 7 55 36 20 51 5 12 54 10 35 40 43 1 46 18 53 41 38 26 29 50 3 42 52 27 8 28 47 33 6 16 30 44 15",
"output": "34 19 43 7 27 51 22 47 1 30 5 28 14 15 55 52 11 36 17 25 16 8 3 6 18 40 46 48 41 53 20 10 50 9 31 24 21 39 13 32 38 44 33 54 12 35 49 2 4 42 26 45 37 29 23"
},
{
"input": "58\n49 13 12 54 2 38 56 11 33 25 26 19 28 8 23 41 20 36 46 55 15 35 9 7 32 37 58 6 3 14 47 31 40 30 53 44 4 50 29 34 10 43 39 57 5 22 27 45 51 42 24 16 18 21 52 17 48 1",
"output": "58 5 29 37 45 28 24 14 23 41 8 3 2 30 21 52 56 53 12 17 54 46 15 51 10 11 47 13 39 34 32 25 9 40 22 18 26 6 43 33 16 50 42 36 48 19 31 57 1 38 49 55 35 4 20 7 44 27"
},
{
"input": "34\n20 25 2 3 33 29 1 16 14 7 21 9 32 31 6 26 22 4 27 23 24 10 34 12 19 15 5 18 28 17 13 8 11 30",
"output": "7 3 4 18 27 15 10 32 12 22 33 24 31 9 26 8 30 28 25 1 11 17 20 21 2 16 19 29 6 34 14 13 5 23"
},
{
"input": "53\n47 29 46 25 23 13 7 31 33 4 38 11 35 16 42 14 15 43 34 39 28 18 6 45 30 1 40 20 2 37 5 32 24 12 44 26 27 3 19 51 36 21 22 9 10 50 41 48 49 53 8 17 52",
"output": "26 29 38 10 31 23 7 51 44 45 12 34 6 16 17 14 52 22 39 28 42 43 5 33 4 36 37 21 2 25 8 32 9 19 13 41 30 11 20 27 47 15 18 35 24 3 1 48 49 46 40 53 50"
},
{
"input": "99\n77 87 90 48 53 38 68 6 28 57 35 82 63 71 60 41 3 12 86 65 10 59 22 67 33 74 93 27 24 1 61 43 25 4 51 52 15 88 9 31 30 42 89 49 23 21 29 32 46 73 37 16 5 69 56 26 92 64 20 54 75 14 98 13 94 2 95 7 36 66 58 8 50 78 84 45 11 96 76 62 97 80 40 39 47 85 34 79 83 17 91 72 19 44 70 81 55 99 18",
"output": "30 66 17 34 53 8 68 72 39 21 77 18 64 62 37 52 90 99 93 59 46 23 45 29 33 56 28 9 47 41 40 48 25 87 11 69 51 6 84 83 16 42 32 94 76 49 85 4 44 73 35 36 5 60 97 55 10 71 22 15 31 80 13 58 20 70 24 7 54 95 14 92 50 26 61 79 1 74 88 82 96 12 89 75 86 19 2 38 43 3 91 57 27 65 67 78 81 63 98"
},
{
"input": "32\n17 29 2 6 30 8 26 7 1 27 10 9 13 24 31 21 15 19 22 18 4 11 25 28 32 3 23 12 5 14 20 16",
"output": "9 3 26 21 29 4 8 6 12 11 22 28 13 30 17 32 1 20 18 31 16 19 27 14 23 7 10 24 2 5 15 25"
},
{
"input": "65\n18 40 1 60 17 19 4 6 12 49 28 58 2 25 13 14 64 56 61 34 62 30 59 51 26 8 33 63 36 48 46 7 43 21 31 27 11 44 29 5 32 23 35 9 53 57 52 50 15 38 42 3 54 65 55 41 20 24 22 47 45 10 39 16 37",
"output": "3 13 52 7 40 8 32 26 44 62 37 9 15 16 49 64 5 1 6 57 34 59 42 58 14 25 36 11 39 22 35 41 27 20 43 29 65 50 63 2 56 51 33 38 61 31 60 30 10 48 24 47 45 53 55 18 46 12 23 4 19 21 28 17 54"
},
{
"input": "71\n35 50 55 58 25 32 26 40 63 34 44 53 24 18 37 7 64 27 56 65 1 19 2 43 42 14 57 47 22 13 59 61 39 67 30 45 54 38 33 48 6 5 3 69 36 21 41 4 16 46 20 17 15 12 10 70 68 23 60 31 52 29 66 28 51 49 62 11 8 9 71",
"output": "21 23 43 48 42 41 16 69 70 55 68 54 30 26 53 49 52 14 22 51 46 29 58 13 5 7 18 64 62 35 60 6 39 10 1 45 15 38 33 8 47 25 24 11 36 50 28 40 66 2 65 61 12 37 3 19 27 4 31 59 32 67 9 17 20 63 34 57 44 56 71"
},
{
"input": "74\n33 8 42 63 64 61 31 74 11 50 68 14 36 25 57 30 7 44 21 15 6 9 23 59 46 3 73 16 62 51 40 60 41 54 5 39 35 28 48 4 58 12 66 69 13 26 71 1 24 19 29 52 37 2 20 43 18 72 17 56 34 38 65 67 27 10 47 70 53 32 45 55 49 22",
"output": "48 54 26 40 35 21 17 2 22 66 9 42 45 12 20 28 59 57 50 55 19 74 23 49 14 46 65 38 51 16 7 70 1 61 37 13 53 62 36 31 33 3 56 18 71 25 67 39 73 10 30 52 69 34 72 60 15 41 24 32 6 29 4 5 63 43 64 11 44 68 47 58 27 8"
},
{
"input": "96\n78 10 82 46 38 91 77 69 2 27 58 80 79 44 59 41 6 31 76 11 42 48 51 37 19 87 43 25 52 32 1 39 63 29 21 65 53 74 92 16 15 95 90 83 30 73 71 5 50 17 96 33 86 60 67 64 20 26 61 40 55 88 94 93 9 72 47 57 14 45 22 3 54 68 13 24 4 7 56 81 89 70 49 8 84 28 18 62 35 36 75 23 66 85 34 12",
"output": "31 9 72 77 48 17 78 84 65 2 20 96 75 69 41 40 50 87 25 57 35 71 92 76 28 58 10 86 34 45 18 30 52 95 89 90 24 5 32 60 16 21 27 14 70 4 67 22 83 49 23 29 37 73 61 79 68 11 15 54 59 88 33 56 36 93 55 74 8 82 47 66 46 38 91 19 7 1 13 12 80 3 44 85 94 53 26 62 81 43 6 39 64 63 42 51"
},
{
"input": "7\n2 1 5 7 3 4 6",
"output": "2 1 5 6 3 7 4"
},
{
"input": "51\n8 33 37 2 16 22 24 30 4 9 5 15 27 3 18 39 31 26 10 17 46 41 25 14 6 1 29 48 36 20 51 49 21 43 19 13 38 50 47 34 11 23 28 12 42 7 32 40 44 45 35",
"output": "26 4 14 9 11 25 46 1 10 19 41 44 36 24 12 5 20 15 35 30 33 6 42 7 23 18 13 43 27 8 17 47 2 40 51 29 3 37 16 48 22 45 34 49 50 21 39 28 32 38 31"
},
{
"input": "27\n12 14 7 3 20 21 25 13 22 15 23 4 2 24 10 17 19 8 26 11 27 18 9 5 6 1 16",
"output": "26 13 4 12 24 25 3 18 23 15 20 1 8 2 10 27 16 22 17 5 6 9 11 14 7 19 21"
},
{
"input": "71\n51 13 20 48 54 23 24 64 14 62 71 67 57 53 3 30 55 43 33 25 39 40 66 6 46 18 5 19 61 16 32 68 70 41 60 44 29 49 27 69 50 38 10 17 45 56 9 21 26 63 28 35 7 59 1 65 2 15 8 11 12 34 37 47 58 22 31 4 36 42 52",
"output": "55 57 15 68 27 24 53 59 47 43 60 61 2 9 58 30 44 26 28 3 48 66 6 7 20 49 39 51 37 16 67 31 19 62 52 69 63 42 21 22 34 70 18 36 45 25 64 4 38 41 1 71 14 5 17 46 13 65 54 35 29 10 50 8 56 23 12 32 40 33 11"
},
{
"input": "9\n8 5 2 6 1 9 4 7 3",
"output": "5 3 9 7 2 4 8 1 6"
},
{
"input": "29\n10 24 11 5 26 25 2 9 22 15 8 14 29 21 4 1 23 17 3 12 13 16 18 28 19 20 7 6 27",
"output": "16 7 19 15 4 28 27 11 8 1 3 20 21 12 10 22 18 23 25 26 14 9 17 2 6 5 29 24 13"
},
{
"input": "60\n39 25 42 4 55 60 16 18 47 1 11 40 7 50 19 35 49 54 12 3 30 38 2 58 17 26 45 6 33 43 37 32 52 36 15 23 27 59 24 20 28 14 8 9 13 29 44 46 41 21 5 48 51 22 31 56 57 53 10 34",
"output": "10 23 20 4 51 28 13 43 44 59 11 19 45 42 35 7 25 8 15 40 50 54 36 39 2 26 37 41 46 21 55 32 29 60 16 34 31 22 1 12 49 3 30 47 27 48 9 52 17 14 53 33 58 18 5 56 57 24 38 6"
},
{
"input": "50\n37 45 22 5 12 21 28 24 18 47 20 25 8 50 14 2 34 43 11 16 49 41 48 1 19 31 39 46 32 23 15 42 3 35 38 30 44 26 10 9 40 36 7 17 33 4 27 6 13 29",
"output": "24 16 33 46 4 48 43 13 40 39 19 5 49 15 31 20 44 9 25 11 6 3 30 8 12 38 47 7 50 36 26 29 45 17 34 42 1 35 27 41 22 32 18 37 2 28 10 23 21 14"
},
{
"input": "30\n8 29 28 16 17 25 27 15 21 11 6 20 2 13 1 30 5 4 24 10 14 3 23 18 26 9 12 22 19 7",
"output": "15 13 22 18 17 11 30 1 26 20 10 27 14 21 8 4 5 24 29 12 9 28 23 19 6 25 7 3 2 16"
},
{
"input": "46\n15 2 44 43 38 19 31 42 4 37 29 30 24 45 27 41 8 20 33 7 35 3 18 46 36 26 1 28 21 40 16 22 32 11 14 13 12 9 25 39 10 6 23 17 5 34",
"output": "27 2 22 9 45 42 20 17 38 41 34 37 36 35 1 31 44 23 6 18 29 32 43 13 39 26 15 28 11 12 7 33 19 46 21 25 10 5 40 30 16 8 4 3 14 24"
},
{
"input": "9\n4 8 6 5 3 9 2 7 1",
"output": "9 7 5 1 4 3 8 2 6"
},
{
"input": "46\n31 30 33 23 45 7 36 8 11 3 32 39 41 20 1 28 6 27 18 24 17 5 16 37 26 13 22 14 2 38 15 46 9 4 19 21 12 44 10 35 25 34 42 43 40 29",
"output": "15 29 10 34 22 17 6 8 33 39 9 37 26 28 31 23 21 19 35 14 36 27 4 20 41 25 18 16 46 2 1 11 3 42 40 7 24 30 12 45 13 43 44 38 5 32"
},
{
"input": "66\n27 12 37 48 46 21 34 58 38 28 66 2 64 32 44 31 13 36 40 15 19 11 22 5 30 29 6 7 61 39 20 42 23 54 51 33 50 9 60 8 57 45 49 10 62 41 59 3 55 63 52 24 25 26 43 56 65 4 16 14 1 35 18 17 53 47",
"output": "61 12 48 58 24 27 28 40 38 44 22 2 17 60 20 59 64 63 21 31 6 23 33 52 53 54 1 10 26 25 16 14 36 7 62 18 3 9 30 19 46 32 55 15 42 5 66 4 43 37 35 51 65 34 49 56 41 8 47 39 29 45 50 13 57 11"
},
{
"input": "13\n3 12 9 2 8 5 13 4 11 1 10 7 6",
"output": "10 4 1 8 6 13 12 5 3 11 9 2 7"
},
{
"input": "80\n21 25 56 50 20 61 7 74 51 69 8 2 46 57 45 71 14 52 17 43 9 30 70 78 31 10 38 13 23 15 37 79 6 16 77 73 80 4 49 48 18 28 26 58 33 41 64 22 54 72 59 60 40 63 53 27 1 5 75 67 62 34 19 39 68 65 44 55 3 32 11 42 76 12 35 47 66 36 24 29",
"output": "57 12 69 38 58 33 7 11 21 26 71 74 28 17 30 34 19 41 63 5 1 48 29 79 2 43 56 42 80 22 25 70 45 62 75 78 31 27 64 53 46 72 20 67 15 13 76 40 39 4 9 18 55 49 68 3 14 44 51 52 6 61 54 47 66 77 60 65 10 23 16 50 36 8 59 73 35 24 32 37"
},
{
"input": "63\n9 49 53 25 40 46 43 51 54 22 58 16 23 26 10 47 5 27 2 8 61 59 19 35 63 56 28 20 34 4 62 38 6 55 36 31 57 15 29 33 1 48 50 37 7 30 18 42 32 52 12 41 14 21 45 11 24 17 39 13 44 60 3",
"output": "41 19 63 30 17 33 45 20 1 15 56 51 60 53 38 12 58 47 23 28 54 10 13 57 4 14 18 27 39 46 36 49 40 29 24 35 44 32 59 5 52 48 7 61 55 6 16 42 2 43 8 50 3 9 34 26 37 11 22 62 21 31 25"
},
{
"input": "26\n11 4 19 13 17 9 2 24 6 5 22 23 14 15 3 25 16 8 18 10 21 1 12 26 7 20",
"output": "22 7 15 2 10 9 25 18 6 20 1 23 4 13 14 17 5 19 3 26 21 11 12 8 16 24"
},
{
"input": "69\n40 22 11 66 4 27 31 29 64 53 37 55 51 2 7 36 18 52 6 1 30 21 17 20 14 9 59 62 49 68 3 50 65 57 44 5 67 46 33 13 34 15 24 48 63 58 38 25 41 35 16 54 32 10 60 61 39 12 69 8 23 45 26 47 56 43 28 19 42",
"output": "20 14 31 5 36 19 15 60 26 54 3 58 40 25 42 51 23 17 68 24 22 2 61 43 48 63 6 67 8 21 7 53 39 41 50 16 11 47 57 1 49 69 66 35 62 38 64 44 29 32 13 18 10 52 12 65 34 46 27 55 56 28 45 9 33 4 37 30 59"
},
{
"input": "6\n4 3 6 5 1 2",
"output": "5 6 2 1 4 3"
},
{
"input": "9\n7 8 5 3 1 4 2 9 6",
"output": "5 7 4 6 3 9 1 2 8"
},
{
"input": "41\n27 24 16 30 25 8 32 2 26 20 39 33 41 22 40 14 36 9 28 4 34 11 31 23 19 18 17 35 3 10 6 13 5 15 29 38 7 21 1 12 37",
"output": "39 8 29 20 33 31 37 6 18 30 22 40 32 16 34 3 27 26 25 10 38 14 24 2 5 9 1 19 35 4 23 7 12 21 28 17 41 36 11 15 13"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "20\n2 6 4 18 7 10 17 13 16 8 14 9 20 5 19 12 1 3 15 11",
"output": "17 1 18 3 14 2 5 10 12 6 20 16 8 11 19 9 7 4 15 13"
},
{
"input": "2\n2 1",
"output": "2 1"
},
{
"input": "60\n2 4 31 51 11 7 34 20 3 14 18 23 48 54 15 36 38 60 49 40 5 33 41 26 55 58 10 8 13 9 27 30 37 1 21 59 44 57 35 19 46 43 42 45 12 22 39 32 24 16 6 56 53 52 25 17 47 29 50 28",
"output": "34 1 9 2 21 51 6 28 30 27 5 45 29 10 15 50 56 11 40 8 35 46 12 49 55 24 31 60 58 32 3 48 22 7 39 16 33 17 47 20 23 43 42 37 44 41 57 13 19 59 4 54 53 14 25 52 38 26 36 18"
},
{
"input": "14\n14 6 3 12 11 2 7 1 10 9 8 5 4 13",
"output": "8 6 3 13 12 2 7 11 10 9 5 4 14 1"
},
{
"input": "81\n13 43 79 8 7 21 73 46 63 4 62 78 56 11 70 68 61 53 60 49 16 27 59 47 69 5 22 44 77 57 52 48 1 9 72 81 28 55 58 33 51 18 31 17 41 20 42 3 32 54 19 2 75 34 64 10 65 50 30 29 67 12 71 66 74 15 26 23 6 38 25 35 37 24 80 76 40 45 39 36 14",
"output": "33 52 48 10 26 69 5 4 34 56 14 62 1 81 66 21 44 42 51 46 6 27 68 74 71 67 22 37 60 59 43 49 40 54 72 80 73 70 79 77 45 47 2 28 78 8 24 32 20 58 41 31 18 50 38 13 30 39 23 19 17 11 9 55 57 64 61 16 25 15 63 35 7 65 53 76 29 12 3 75 36"
},
{
"input": "42\n41 11 10 8 21 37 32 19 31 25 1 15 36 5 6 27 4 3 13 7 16 17 2 23 34 24 38 28 12 20 30 42 18 26 39 35 33 40 9 14 22 29",
"output": "11 23 18 17 14 15 20 4 39 3 2 29 19 40 12 21 22 33 8 30 5 41 24 26 10 34 16 28 42 31 9 7 37 25 36 13 6 27 35 38 1 32"
},
{
"input": "97\n20 6 76 42 4 18 35 59 39 63 27 7 66 47 61 52 15 36 88 93 19 33 10 92 1 34 46 86 78 57 51 94 77 29 26 73 41 2 58 97 43 65 17 74 21 49 25 3 91 82 95 12 96 13 84 90 69 24 72 37 16 55 54 71 64 62 48 89 11 70 80 67 30 40 44 85 53 83 79 9 56 45 75 87 22 14 81 68 8 38 60 50 28 23 31 32 5",
"output": "25 38 48 5 97 2 12 89 80 23 69 52 54 86 17 61 43 6 21 1 45 85 94 58 47 35 11 93 34 73 95 96 22 26 7 18 60 90 9 74 37 4 41 75 82 27 14 67 46 92 31 16 77 63 62 81 30 39 8 91 15 66 10 65 42 13 72 88 57 70 64 59 36 44 83 3 33 29 79 71 87 50 78 55 76 28 84 19 68 56 49 24 20 32 51 53 40"
},
{
"input": "62\n15 27 46 6 8 51 14 56 23 48 42 49 52 22 20 31 29 12 47 3 62 34 37 35 32 57 19 25 5 60 61 38 18 10 11 55 45 53 17 30 9 36 4 50 41 16 44 28 40 59 24 1 13 39 26 7 33 58 2 43 21 54",
"output": "52 59 20 43 29 4 56 5 41 34 35 18 53 7 1 46 39 33 27 15 61 14 9 51 28 55 2 48 17 40 16 25 57 22 24 42 23 32 54 49 45 11 60 47 37 3 19 10 12 44 6 13 38 62 36 8 26 58 50 30 31 21"
},
{
"input": "61\n35 27 4 61 52 32 41 46 14 37 17 54 55 31 11 26 44 49 15 30 9 50 45 39 7 38 53 3 58 40 13 56 18 19 28 6 43 5 21 42 20 34 2 25 36 12 33 57 16 60 1 8 59 10 22 23 24 48 51 47 29",
"output": "51 43 28 3 38 36 25 52 21 54 15 46 31 9 19 49 11 33 34 41 39 55 56 57 44 16 2 35 61 20 14 6 47 42 1 45 10 26 24 30 7 40 37 17 23 8 60 58 18 22 59 5 27 12 13 32 48 29 53 50 4"
},
{
"input": "59\n31 26 36 15 17 19 10 53 11 34 13 46 55 9 44 7 8 37 32 52 47 25 51 22 35 39 41 4 43 24 5 27 20 57 6 38 3 28 21 40 50 18 14 56 33 45 12 2 49 59 54 29 16 48 42 58 1 30 23",
"output": "57 48 37 28 31 35 16 17 14 7 9 47 11 43 4 53 5 42 6 33 39 24 59 30 22 2 32 38 52 58 1 19 45 10 25 3 18 36 26 40 27 55 29 15 46 12 21 54 49 41 23 20 8 51 13 44 34 56 50"
},
{
"input": "10\n2 10 7 4 1 5 8 6 3 9",
"output": "5 1 9 4 6 8 3 7 10 2"
},
{
"input": "14\n14 2 1 8 6 12 11 10 9 7 3 4 5 13",
"output": "3 2 11 12 13 5 10 4 9 8 7 6 14 1"
},
{
"input": "43\n28 38 15 14 31 42 27 30 19 33 43 26 22 29 18 32 3 13 1 8 35 34 4 12 11 17 41 21 5 25 39 37 20 23 7 24 16 10 40 9 6 36 2",
"output": "19 43 17 23 29 41 35 20 40 38 25 24 18 4 3 37 26 15 9 33 28 13 34 36 30 12 7 1 14 8 5 16 10 22 21 42 32 2 31 39 27 6 11"
},
{
"input": "86\n39 11 20 31 28 76 29 64 35 21 41 71 12 82 5 37 80 73 38 26 79 75 23 15 59 45 47 6 3 62 50 49 51 22 2 65 86 60 70 42 74 17 1 30 55 44 8 66 81 27 57 77 43 13 54 32 72 46 48 56 14 34 78 52 36 85 24 19 69 83 25 61 7 4 84 33 63 58 18 40 68 10 67 9 16 53",
"output": "43 35 29 74 15 28 73 47 84 82 2 13 54 61 24 85 42 79 68 3 10 34 23 67 71 20 50 5 7 44 4 56 76 62 9 65 16 19 1 80 11 40 53 46 26 58 27 59 32 31 33 64 86 55 45 60 51 78 25 38 72 30 77 8 36 48 83 81 69 39 12 57 18 41 22 6 52 63 21 17 49 14 70 75 66 37"
},
{
"input": "99\n65 78 56 98 33 24 61 40 29 93 1 64 57 22 25 52 67 95 50 3 31 15 90 68 71 83 38 36 6 46 89 26 4 87 14 88 72 37 23 43 63 12 80 96 5 34 73 86 9 48 92 62 99 10 16 20 66 27 28 2 82 70 30 94 49 8 84 69 18 60 58 59 44 39 21 7 91 76 54 19 75 85 74 47 55 32 97 77 51 13 35 79 45 42 11 41 17 81 53",
"output": "11 60 20 33 45 29 76 66 49 54 95 42 90 35 22 55 97 69 80 56 75 14 39 6 15 32 58 59 9 63 21 86 5 46 91 28 38 27 74 8 96 94 40 73 93 30 84 50 65 19 89 16 99 79 85 3 13 71 72 70 7 52 41 12 1 57 17 24 68 62 25 37 47 83 81 78 88 2 92 43 98 61 26 67 82 48 34 36 31 23 77 51 10 64 18 44 87 4 53"
},
{
"input": "100\n42 23 48 88 36 6 18 70 96 1 34 40 46 22 39 55 85 93 45 67 71 75 59 9 21 3 86 63 65 68 20 38 73 31 84 90 50 51 56 95 72 33 49 19 83 76 54 74 100 30 17 98 15 94 4 97 5 99 81 27 92 32 89 12 13 91 87 29 60 11 52 43 35 58 10 25 16 80 28 2 44 61 8 82 66 69 41 24 57 62 78 37 79 77 53 7 14 47 26 64",
"output": "10 80 26 55 57 6 96 83 24 75 70 64 65 97 53 77 51 7 44 31 25 14 2 88 76 99 60 79 68 50 34 62 42 11 73 5 92 32 15 12 87 1 72 81 19 13 98 3 43 37 38 71 95 47 16 39 89 74 23 69 82 90 28 100 29 85 20 30 86 8 21 41 33 48 22 46 94 91 93 78 59 84 45 35 17 27 67 4 63 36 66 61 18 54 40 9 56 52 58 49"
},
{
"input": "99\n8 68 94 75 71 60 57 58 6 11 5 48 65 41 49 12 46 72 95 59 13 70 74 7 84 62 17 36 55 76 38 79 2 85 23 10 32 99 87 50 83 28 54 91 53 51 1 3 97 81 21 89 93 78 61 26 82 96 4 98 25 40 31 44 24 47 30 52 14 16 39 27 9 29 45 18 67 63 37 43 90 66 19 69 88 22 92 77 34 42 73 80 56 64 20 35 15 33 86",
"output": "47 33 48 59 11 9 24 1 73 36 10 16 21 69 97 70 27 76 83 95 51 86 35 65 61 56 72 42 74 67 63 37 98 89 96 28 79 31 71 62 14 90 80 64 75 17 66 12 15 40 46 68 45 43 29 93 7 8 20 6 55 26 78 94 13 82 77 2 84 22 5 18 91 23 4 30 88 54 32 92 50 57 41 25 34 99 39 85 52 81 44 87 53 3 19 58 49 60 38"
},
{
"input": "99\n12 99 88 13 7 19 74 47 23 90 16 29 26 11 58 60 64 98 37 18 82 67 72 46 51 85 17 92 87 20 77 36 78 71 57 35 80 54 73 15 14 62 97 45 31 79 94 56 76 96 28 63 8 44 38 86 49 2 52 66 61 59 10 43 55 50 22 34 83 53 95 40 81 21 30 42 27 3 5 41 1 70 69 25 93 48 65 6 24 89 91 33 39 68 9 4 32 84 75",
"output": "81 58 78 96 79 88 5 53 95 63 14 1 4 41 40 11 27 20 6 30 74 67 9 89 84 13 77 51 12 75 45 97 92 68 36 32 19 55 93 72 80 76 64 54 44 24 8 86 57 66 25 59 70 38 65 48 35 15 62 16 61 42 52 17 87 60 22 94 83 82 34 23 39 7 99 49 31 33 46 37 73 21 69 98 26 56 29 3 90 10 91 28 85 47 71 50 43 18 2"
},
{
"input": "99\n20 79 26 75 99 69 98 47 93 62 18 42 43 38 90 66 67 8 13 84 76 58 81 60 64 46 56 23 78 17 86 36 19 52 85 39 48 27 96 49 37 95 5 31 10 24 12 1 80 35 92 33 16 68 57 54 32 29 45 88 72 77 4 87 97 89 59 3 21 22 61 94 83 15 44 34 70 91 55 9 51 50 73 11 14 6 40 7 63 25 2 82 41 65 28 74 71 30 53",
"output": "48 91 68 63 43 86 88 18 80 45 84 47 19 85 74 53 30 11 33 1 69 70 28 46 90 3 38 95 58 98 44 57 52 76 50 32 41 14 36 87 93 12 13 75 59 26 8 37 40 82 81 34 99 56 79 27 55 22 67 24 71 10 89 25 94 16 17 54 6 77 97 61 83 96 4 21 62 29 2 49 23 92 73 20 35 31 64 60 66 15 78 51 9 72 42 39 65 7 5"
},
{
"input": "99\n74 20 9 1 60 85 65 13 4 25 40 99 5 53 64 3 36 31 73 44 55 50 45 63 98 51 68 6 47 37 71 82 88 34 84 18 19 12 93 58 86 7 11 46 90 17 33 27 81 69 42 59 56 32 95 52 76 61 96 62 78 43 66 21 49 97 75 14 41 72 89 16 30 79 22 23 15 83 91 38 48 2 87 26 28 80 94 70 54 92 57 10 8 35 67 77 29 24 39",
"output": "4 82 16 9 13 28 42 93 3 92 43 38 8 68 77 72 46 36 37 2 64 75 76 98 10 84 48 85 97 73 18 54 47 34 94 17 30 80 99 11 69 51 62 20 23 44 29 81 65 22 26 56 14 89 21 53 91 40 52 5 58 60 24 15 7 63 95 27 50 88 31 70 19 1 67 57 96 61 74 86 49 32 78 35 6 41 83 33 71 45 79 90 39 87 55 59 66 25 12"
},
{
"input": "99\n50 94 2 18 69 90 59 83 75 68 77 97 39 78 25 7 16 9 49 4 42 89 44 48 17 96 61 70 3 10 5 81 56 57 88 6 98 1 46 67 92 37 11 30 85 41 8 36 51 29 20 71 19 79 74 93 43 34 55 40 38 21 64 63 32 24 72 14 12 86 82 15 65 23 66 22 28 53 13 26 95 99 91 52 76 27 60 45 47 33 73 84 31 35 54 80 58 62 87",
"output": "38 3 29 20 31 36 16 47 18 30 43 69 79 68 72 17 25 4 53 51 62 76 74 66 15 80 86 77 50 44 93 65 90 58 94 48 42 61 13 60 46 21 57 23 88 39 89 24 19 1 49 84 78 95 59 33 34 97 7 87 27 98 64 63 73 75 40 10 5 28 52 67 91 55 9 85 11 14 54 96 32 71 8 92 45 70 99 35 22 6 83 41 56 2 81 26 12 37 82"
},
{
"input": "99\n19 93 14 34 39 37 33 15 52 88 7 43 69 27 9 77 94 31 48 22 63 70 79 17 50 6 81 8 76 58 23 74 86 11 57 62 41 87 75 51 12 18 68 56 95 3 80 83 84 29 24 61 71 78 59 96 20 85 90 28 45 36 38 97 1 49 40 98 44 67 13 73 72 91 47 10 30 54 35 42 4 2 92 26 64 60 53 21 5 82 46 32 55 66 16 89 99 65 25",
"output": "65 82 46 81 89 26 11 28 15 76 34 41 71 3 8 95 24 42 1 57 88 20 31 51 99 84 14 60 50 77 18 92 7 4 79 62 6 63 5 67 37 80 12 69 61 91 75 19 66 25 40 9 87 78 93 44 35 30 55 86 52 36 21 85 98 94 70 43 13 22 53 73 72 32 39 29 16 54 23 47 27 90 48 49 58 33 38 10 96 59 74 83 2 17 45 56 64 68 97"
},
{
"input": "99\n86 25 50 51 62 39 41 67 44 20 45 14 80 88 66 7 36 59 13 84 78 58 96 75 2 43 48 47 69 12 19 98 22 38 28 55 11 76 68 46 53 70 85 34 16 33 91 30 8 40 74 60 94 82 87 32 37 4 5 10 89 73 90 29 35 26 23 57 27 65 24 3 9 83 77 72 6 31 15 92 93 79 64 18 63 42 56 1 52 97 17 81 71 21 49 99 54 95 61",
"output": "88 25 72 58 59 77 16 49 73 60 37 30 19 12 79 45 91 84 31 10 94 33 67 71 2 66 69 35 64 48 78 56 46 44 65 17 57 34 6 50 7 86 26 9 11 40 28 27 95 3 4 89 41 97 36 87 68 22 18 52 99 5 85 83 70 15 8 39 29 42 93 76 62 51 24 38 75 21 82 13 92 54 74 20 43 1 55 14 61 63 47 80 81 53 98 23 90 32 96"
},
{
"input": "100\n66 44 99 15 43 79 28 33 88 90 49 68 82 38 9 74 4 58 29 81 31 94 10 42 89 21 63 40 62 61 18 6 84 72 48 25 67 69 71 85 98 34 83 70 65 78 91 77 93 41 23 24 87 11 55 12 59 73 36 97 7 14 26 39 30 27 45 20 50 17 53 2 57 47 95 56 75 19 37 96 16 35 8 3 76 60 13 86 5 32 64 80 46 51 54 100 1 22 52 92",
"output": "97 72 84 17 89 32 61 83 15 23 54 56 87 62 4 81 70 31 78 68 26 98 51 52 36 63 66 7 19 65 21 90 8 42 82 59 79 14 64 28 50 24 5 2 67 93 74 35 11 69 94 99 71 95 55 76 73 18 57 86 30 29 27 91 45 1 37 12 38 44 39 34 58 16 77 85 48 46 6 92 20 13 43 33 40 88 53 9 25 10 47 100 49 22 75 80 60 41 3 96"
},
{
"input": "99\n3 73 32 37 25 15 93 63 85 8 91 78 80 5 39 48 46 7 83 70 23 96 9 29 77 53 30 20 56 50 13 45 21 76 87 99 65 31 16 18 14 72 51 28 43 2 81 34 38 40 66 54 74 26 71 4 61 17 58 24 22 33 49 36 42 11 12 55 60 27 62 90 79 92 94 68 1 52 84 41 86 35 69 75 47 10 64 88 97 98 67 19 89 95 59 82 57 44 6",
"output": "77 46 1 56 14 99 18 10 23 86 66 67 31 41 6 39 58 40 92 28 33 61 21 60 5 54 70 44 24 27 38 3 62 48 82 64 4 49 15 50 80 65 45 98 32 17 85 16 63 30 43 78 26 52 68 29 97 59 95 69 57 71 8 87 37 51 91 76 83 20 55 42 2 53 84 34 25 12 73 13 47 96 19 79 9 81 35 88 93 72 11 74 7 75 94 22 89 90 36"
},
{
"input": "100\n100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1",
"output": "100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1"
}
] | 1,682,539,922 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 154 | 0 | n = int(input())
s = list(map(int, input().split()))
fi = [0]*n
for i in range(n):
fi[s[i] - 1] = str(i + 1)
print(str(' '.join(fi))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift.
Now Petya wants to know for each friend *i* the number of a friend who has given him a gift.
Input Specification:
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves.
Output Specification:
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
Demo Input:
['4\n2 3 4 1\n', '3\n1 3 2\n', '2\n1 2\n']
Demo Output:
['4 1 2 3\n', '1 3 2\n', '1 2\n']
Note:
none | ```python
n = int(input())
s = list(map(int, input().split()))
fi = [0]*n
for i in range(n):
fi[s[i] - 1] = str(i + 1)
print(str(' '.join(fi)))
``` | 3 |
|
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions. | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"output": "5"
},
{
"input": "2 6",
"output": "6"
},
{
"input": "2 7",
"output": "7"
},
{
"input": "2 14",
"output": "14"
},
{
"input": "2 15",
"output": "15"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "2 16",
"output": "16"
},
{
"input": "3 5",
"output": "7"
},
{
"input": "3 6",
"output": "9"
},
{
"input": "3 10",
"output": "15"
},
{
"input": "3 14",
"output": "21"
},
{
"input": "3 15",
"output": "22"
},
{
"input": "3 16",
"output": "24"
},
{
"input": "5 7",
"output": "17"
},
{
"input": "16 16",
"output": "128"
},
{
"input": "15 16",
"output": "120"
},
{
"input": "2 3",
"output": "3"
},
{
"input": "15 15",
"output": "112"
},
{
"input": "14 16",
"output": "112"
},
{
"input": "11 13",
"output": "71"
},
{
"input": "5 16",
"output": "40"
},
{
"input": "8 15",
"output": "60"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "3 4",
"output": "6"
},
{
"input": "4 4",
"output": "8"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "1 3",
"output": "1"
},
{
"input": "14 15",
"output": "105"
}
] | 1,676,731,503 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | from math import floor
m,n=map(int,input().split())
k=(m*n)/2
print(floor(k)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers two squares.
2. No two dominoes overlap.
3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board.
Find the maximum number of dominoes, which can be placed under these restrictions.
Input Specification:
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output Specification:
Output one number — the maximal number of dominoes, which can be placed.
Demo Input:
['2 4\n', '3 3\n']
Demo Output:
['4\n', '4\n']
Note:
none | ```python
from math import floor
m,n=map(int,input().split())
k=(m*n)/2
print(floor(k))
``` | 3.977 |
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,550,410,205 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 202 | 6,656,000 | cnt=lambda s,i:s.count(i)
ii=lambda:int(input())
si=lambda:input()
f=lambda:map(int,input().split())
il=lambda:list(map(int,input().split()))
n,a,b=f()
l=il()
sm=sum(l)
k=l.pop(0)
c=0
l.sort(reverse=True)
for i in range(0,n-1):
if (k*a)/sm<b:
c+=1
sm-=l[i]
l[i] = 0
else:
break
print(c) | 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
cnt=lambda s,i:s.count(i)
ii=lambda:int(input())
si=lambda:input()
f=lambda:map(int,input().split())
il=lambda:list(map(int,input().split()))
n,a,b=f()
l=il()
sm=sum(l)
k=l.pop(0)
c=0
l.sort(reverse=True)
for i in range(0,n-1):
if (k*a)/sm<b:
c+=1
sm-=l[i]
l[i] = 0
else:
break
print(c)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1<=×<=1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an *n*<=×<=*m* piece of paper, somebody has already made *k* cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move. | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game. | If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them). | [
"2 1 0\n",
"2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n"
] | [
"FIRST\n1 0 1 1\n",
"SECOND\n"
] | none | 0 | [] | 1,693,505,806 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1693505806.7356255")# 1693505806.7356417 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.
Obviously, the game ends when the entire sheet is cut into 1<=×<=1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.
You are given an *n*<=×<=*m* piece of paper, somebody has already made *k* cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.
Input Specification:
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=109,<=0<=≤<=*k*<=≤<=105) — the sizes of the piece of paper and the number of cuts. Then follow *k* lines, each containing 4 integers *xb**i*,<=*yb**i*,<=*xe**i*,<=*ye**i* (0<=≤<=*xb**i*,<=*xe**i*<=≤<=*n*,<=0<=≤<=*yb**i*,<=*ye**i*<=≤<=*m*) — the coordinates of the ends of the existing cuts.
It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border.
The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.
Output Specification:
If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).
Demo Input:
['2 1 0\n', '2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n']
Demo Output:
['FIRST\n1 0 1 1\n', 'SECOND\n']
Note:
none | ```python
print("_RANDOM_GUESS_1693505806.7356255")# 1693505806.7356417
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,622,092,957 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | a = list(map(int, input().split()))
o = []
e = []
for i in a:
if(i%2 == 0):
e.append(i)
else:
o.append(i)
if(len(e) > len(o) and len(o) == 1):
f = 0
break
elif(len(o) > len(e) and len(e) == 1):
f = 1
break
if(f == 0):
print(a.index(o[0])+1)
elif(f == 1):
print(a.index(e[0])+1) | Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
a = list(map(int, input().split()))
o = []
e = []
for i in a:
if(i%2 == 0):
e.append(i)
else:
o.append(i)
if(len(e) > len(o) and len(o) == 1):
f = 0
break
elif(len(o) > len(e) and len(e) == 1):
f = 1
break
if(f == 0):
print(a.index(o[0])+1)
elif(f == 1):
print(a.index(e[0])+1)
``` | -1 |
821 | B | Okabe and Banana Trees | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.
Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.
Okabe is sure that the answer does not exceed 1018. You can trust him. | The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). | Print the maximum number of bananas Okabe can get from the trees he cuts. | [
"1 5\n",
"2 3\n"
] | [
"30\n",
"25\n"
] | The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | 1,000 | [
{
"input": "1 5",
"output": "30"
},
{
"input": "2 3",
"output": "25"
},
{
"input": "4 6",
"output": "459"
},
{
"input": "6 3",
"output": "171"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 1",
"output": "55"
},
{
"input": "20 10",
"output": "40326"
},
{
"input": "1000 10000",
"output": "74133360011484445"
},
{
"input": "139 9252",
"output": "1137907933561080"
},
{
"input": "859 8096",
"output": "29032056230649780"
},
{
"input": "987 4237",
"output": "5495451829240878"
},
{
"input": "411 3081",
"output": "366755153481948"
},
{
"input": "539 9221",
"output": "16893595018603386"
},
{
"input": "259 770",
"output": "2281741798549"
},
{
"input": "387 5422",
"output": "1771610559998400"
},
{
"input": "515 1563",
"output": "75233740231341"
},
{
"input": "939 407",
"output": "4438222781916"
},
{
"input": "518 6518",
"output": "5511730799718825"
},
{
"input": "646 1171",
"output": "49802404050106"
},
{
"input": "70 7311",
"output": "142915220249910"
},
{
"input": "494 6155",
"output": "4221391613846823"
},
{
"input": "918 7704",
"output": "28569727339126165"
},
{
"input": "46 3844",
"output": "9007500020760"
},
{
"input": "174 2688",
"output": "43730657099581"
},
{
"input": "894 4637",
"output": "5909849585253250"
},
{
"input": "22 3481",
"output": "1548544125646"
},
{
"input": "446 5030",
"output": "1878390629993745"
},
{
"input": "440 8704",
"output": "9470470760118060"
},
{
"input": "569 7548",
"output": "10326205017481606"
},
{
"input": "289 6393",
"output": "1620061541812350"
},
{
"input": "417 1045",
"output": "14758909519725"
},
{
"input": "841 7185",
"output": "19452619774222875"
},
{
"input": "969 6030",
"output": "15265318959845745"
},
{
"input": "393 4874",
"output": "1327174123029975"
},
{
"input": "817 3719",
"output": "2546859449982016"
},
{
"input": "945 2563",
"output": "1115613396515835"
},
{
"input": "369 4511",
"output": "927715710215505"
},
{
"input": "555 3594",
"output": "1061060598862891"
}
] | 1,498,405,947 | 4,647 | Python 3 | OK | TESTS | 38 | 78 | 5,529,600 | def get2(n):
res = n*(n+1)*(2*n+1)//6 + n*(n+1)//2
res //= 2;
return res
def get(x,y):
return get2(x+y) - get2(x-1) - get2(y-1)
m,b = input().split()
m = int(m)
b = int(b)
mv = 0
for i in range(b+1):
j = m*b-m*i
cur = get(j,i)
if cur > mv:
mv = cur
print(mv) | Title: Okabe and Banana Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.
Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.
Okabe is sure that the answer does not exceed 1018. You can trust him.
Input Specification:
The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000).
Output Specification:
Print the maximum number of bananas Okabe can get from the trees he cuts.
Demo Input:
['1 5\n', '2 3\n']
Demo Output:
['30\n', '25\n']
Note:
The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | ```python
def get2(n):
res = n*(n+1)*(2*n+1)//6 + n*(n+1)//2
res //= 2;
return res
def get(x,y):
return get2(x+y) - get2(x-1) - get2(y-1)
m,b = input().split()
m = int(m)
b = int(b)
mv = 0
for i in range(b+1):
j = m*b-m*i
cur = get(j,i)
if cur > mv:
mv = cur
print(mv)
``` | 3 |
|
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. | The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input": "gqrk",
"output": "NO"
},
{
"input": "glxlg",
"output": "YES"
},
{
"input": "czhfc",
"output": "YES"
},
{
"input": "broon",
"output": "NO"
},
{
"input": "rmggmr",
"output": "NO"
},
{
"input": "wvxxzw",
"output": "YES"
},
{
"input": "ukvciu",
"output": "NO"
},
{
"input": "vrnwnrv",
"output": "YES"
},
{
"input": "vlkjkav",
"output": "YES"
},
{
"input": "guayhmg",
"output": "NO"
},
{
"input": "lkvhhvkl",
"output": "NO"
},
{
"input": "ffdsslff",
"output": "YES"
},
{
"input": "galjjtyw",
"output": "NO"
},
{
"input": "uosgwgsou",
"output": "YES"
},
{
"input": "qjwmjmljq",
"output": "YES"
},
{
"input": "ustrvrodf",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"input": "qjfyjjyfjq",
"output": "NO"
},
{
"input": "ysxibbixsq",
"output": "YES"
},
{
"input": "howfslfwmh",
"output": "NO"
},
{
"input": "ekhajrjahke",
"output": "YES"
},
{
"input": "ucnolsloncw",
"output": "YES"
},
{
"input": "jrzsfrrkrtj",
"output": "NO"
},
{
"input": "typayzzyapyt",
"output": "NO"
},
{
"input": "uwdhkzokhdwu",
"output": "YES"
},
{
"input": "xokxpyyuafij",
"output": "NO"
},
{
"input": "eusneioiensue",
"output": "YES"
},
{
"input": "fuxpuajabpxuf",
"output": "YES"
},
{
"input": "guvggtfhlgruy",
"output": "NO"
},
{
"input": "cojhkhxxhkhjoc",
"output": "NO"
},
{
"input": "mhifbmmmmbmihm",
"output": "YES"
},
{
"input": "kxfqqncnebpami",
"output": "NO"
},
{
"input": "scfwrjevejrwfcs",
"output": "YES"
},
{
"input": "thdaonpepdoadht",
"output": "YES"
},
{
"input": "jsfzcbnhsccuqsj",
"output": "NO"
},
{
"input": "nn",
"output": "NO"
},
{
"input": "nm",
"output": "YES"
},
{
"input": "jdj",
"output": "YES"
},
{
"input": "bbcaa",
"output": "NO"
},
{
"input": "abcde",
"output": "NO"
},
{
"input": "abcdf",
"output": "NO"
},
{
"input": "aa",
"output": "NO"
},
{
"input": "abecd",
"output": "NO"
},
{
"input": "abccacb",
"output": "NO"
},
{
"input": "aabc",
"output": "NO"
},
{
"input": "anpqb",
"output": "NO"
},
{
"input": "c",
"output": "YES"
},
{
"input": "abcdefg",
"output": "NO"
},
{
"input": "aanbb",
"output": "NO"
},
{
"input": "aabbb",
"output": "NO"
},
{
"input": "aaabbab",
"output": "NO"
},
{
"input": "ab",
"output": "YES"
},
{
"input": "aabbc",
"output": "NO"
},
{
"input": "ecabd",
"output": "NO"
},
{
"input": "abcdrty",
"output": "NO"
},
{
"input": "abcdmnp",
"output": "NO"
},
{
"input": "bbbbbb",
"output": "NO"
},
{
"input": "abcxuio",
"output": "NO"
},
{
"input": "abcdabcde",
"output": "NO"
},
{
"input": "abcxpoi",
"output": "NO"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "aacbb",
"output": "NO"
},
{
"input": "abcedca",
"output": "NO"
},
{
"input": "abcdd",
"output": "NO"
},
{
"input": "abbcs",
"output": "NO"
},
{
"input": "aaabccc",
"output": "NO"
},
{
"input": "paxkxbq",
"output": "NO"
},
{
"input": "z",
"output": "YES"
},
{
"input": "b",
"output": "YES"
},
{
"input": "abcdefghi",
"output": "NO"
},
{
"input": "abcqr",
"output": "NO"
},
{
"input": "abcdc",
"output": "NO"
},
{
"input": "abcb",
"output": "NO"
},
{
"input": "aabcd",
"output": "NO"
},
{
"input": "abbba",
"output": "YES"
},
{
"input": "aaabbb",
"output": "NO"
},
{
"input": "bb",
"output": "NO"
},
{
"input": "aaacbbb",
"output": "NO"
},
{
"input": "abbzcca",
"output": "NO"
},
{
"input": "abxab",
"output": "NO"
},
{
"input": "bbb",
"output": "YES"
},
{
"input": "abcrtyu",
"output": "NO"
},
{
"input": "cbacb",
"output": "NO"
},
{
"input": "acbb",
"output": "NO"
},
{
"input": "ww",
"output": "NO"
},
{
"input": "aaaaaa",
"output": "NO"
},
{
"input": "jizzz",
"output": "NO"
},
{
"input": "aaakcba",
"output": "NO"
},
{
"input": "acbak",
"output": "NO"
},
{
"input": "bddeffd",
"output": "NO"
},
{
"input": "aaa",
"output": "YES"
},
{
"input": "afghqwe",
"output": "NO"
},
{
"input": "abcdfga",
"output": "NO"
}
] | 1,656,625,910 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | s = input()
x = len(s)
c = 0
for i in range(int(x / 2)):
c += int(s[i] != s[x - i - 1])
if c == 1:
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input Specification:
The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15).
Output Specification:
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Demo Input:
['abccaa\n', 'abbcca\n', 'abcda\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
s = input()
x = len(s)
c = 0
for i in range(int(x / 2)):
c += int(s[i] != s[x - i - 1])
if c == 1:
print("YES")
else:
print("NO")
``` | 0 |
|
807 | A | Is it rated? | PROGRAMMING | 900 | [
"implementation",
"sortings"
] | null | null | Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. | If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". | [
"6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n"
] | [
"rated\n",
"unrated\n",
"maybe\n"
] | In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | 500 | [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884",
"output": "rated"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n1 1\n1 1",
"output": "maybe"
},
{
"input": "2\n4126 4126\n4126 4126",
"output": "maybe"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423",
"output": "rated"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110",
"output": "unrated"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143",
"output": "maybe"
},
{
"input": "2\n3936 3936\n2967 2967",
"output": "maybe"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 1\n1 2",
"output": "rated"
},
{
"input": "2\n2967 2967\n3936 3936",
"output": "unrated"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300",
"output": "unrated"
},
{
"input": "3\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "3\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "2\n3 2\n3 2",
"output": "rated"
},
{
"input": "3\n5 5\n4 4\n3 4",
"output": "rated"
},
{
"input": "3\n200 200\n200 200\n300 300",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n3 3",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699",
"output": "maybe"
},
{
"input": "2\n10 10\n8 8",
"output": "maybe"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80",
"output": "unrated"
},
{
"input": "2\n1 2\n2 1",
"output": "rated"
},
{
"input": "3\n5 5\n4 3\n3 3",
"output": "rated"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450",
"output": "rated"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700",
"output": "unrated"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700",
"output": "unrated"
},
{
"input": "2\n1600 1600\n1400 1400",
"output": "maybe"
},
{
"input": "2\n3 1\n9 8",
"output": "rated"
},
{
"input": "2\n2 1\n1 1",
"output": "rated"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670",
"output": "unrated"
},
{
"input": "2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n10 11\n5 4",
"output": "rated"
},
{
"input": "2\n15 14\n13 12",
"output": "rated"
},
{
"input": "2\n2 1\n2 2",
"output": "rated"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106",
"output": "unrated"
},
{
"input": "3\n4 5\n3 3\n2 2",
"output": "rated"
},
{
"input": "2\n10 9\n10 10",
"output": "rated"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100",
"output": "rated"
},
{
"input": "2\n3 3\n5 5",
"output": "unrated"
},
{
"input": "2\n1500 1500\n3000 2000",
"output": "rated"
},
{
"input": "2\n5 6\n5 5",
"output": "rated"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500",
"output": "rated"
},
{
"input": "2\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n1 2\n1 1",
"output": "rated"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699",
"output": "maybe"
},
{
"input": "2\n15 14\n14 13",
"output": "rated"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900",
"output": "unrated"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884",
"output": "rated"
},
{
"input": "2\n100 99\n100 100",
"output": "rated"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n100 101\n100 100\n100 100",
"output": "rated"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890",
"output": "rated"
},
{
"input": "2\n2 3\n1 1",
"output": "rated"
},
{
"input": "2\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n3 2\n2 2",
"output": "rated"
},
{
"input": "2\n3 2\n3 3",
"output": "rated"
},
{
"input": "2\n1 1\n2 2",
"output": "unrated"
},
{
"input": "3\n3 2\n3 3\n3 3",
"output": "rated"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "3\n1000 1000\n500 500\n400 300",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000",
"output": "unrated"
},
{
"input": "2\n1 1\n2 3",
"output": "rated"
},
{
"input": "2\n6 2\n6 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246",
"output": "unrated"
},
{
"input": "2\n1500 1500\n1600 1600",
"output": "unrated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699",
"output": "maybe"
},
{
"input": "2\n20 30\n10 5",
"output": "rated"
},
{
"input": "3\n1 1\n2 2\n1 1",
"output": "unrated"
},
{
"input": "2\n1 2\n3 3",
"output": "rated"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n2 2\n2 1",
"output": "rated"
},
{
"input": "2\n100 100\n90 89",
"output": "rated"
},
{
"input": "2\n1000 900\n2000 2000",
"output": "rated"
},
{
"input": "2\n50 10\n10 50",
"output": "rated"
},
{
"input": "2\n200 200\n100 100",
"output": "maybe"
},
{
"input": "3\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "3\n1000 1000\n300 300\n100 100",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4",
"output": "unrated"
},
{
"input": "2\n5 3\n6 3",
"output": "rated"
},
{
"input": "2\n1200 1100\n1200 1000",
"output": "rated"
},
{
"input": "2\n5 5\n4 4",
"output": "maybe"
},
{
"input": "2\n5 5\n3 3",
"output": "maybe"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100",
"output": "unrated"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6",
"output": "maybe"
},
{
"input": "3\n1000 1000\n300 300\n10 10",
"output": "maybe"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "2\n3 3\n1 1",
"output": "maybe"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3",
"output": "unrated"
},
{
"input": "2\n1000 1000\n700 700",
"output": "maybe"
},
{
"input": "2\n4 3\n5 3",
"output": "rated"
},
{
"input": "2\n1000 1000\n1100 1100",
"output": "unrated"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2",
"output": "maybe"
},
{
"input": "3\n1 1\n2 3\n2 2",
"output": "rated"
},
{
"input": "2\n1 2\n1 3",
"output": "rated"
},
{
"input": "2\n3 3\n1 2",
"output": "rated"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400",
"output": "rated"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "2\n10 10\n1 2",
"output": "rated"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900",
"output": "unrated"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699",
"output": "unrated"
},
{
"input": "2\n100 100\n110 110",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n3 3\n3 2\n4 4",
"output": "rated"
},
{
"input": "3\n5 2\n4 4\n3 3",
"output": "rated"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1",
"output": "maybe"
},
{
"input": "2\n1 1\n3 2",
"output": "rated"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699",
"output": "unrated"
},
{
"input": "3\n3 3\n3 3\n3 4",
"output": "rated"
},
{
"input": "3\n1 2\n2 2\n3 3",
"output": "rated"
},
{
"input": "3\n1 2\n1 2\n1 2",
"output": "rated"
},
{
"input": "2\n2 1\n2 1",
"output": "rated"
},
{
"input": "2\n1 2\n3 4",
"output": "rated"
},
{
"input": "2\n3 2\n2 3",
"output": "rated"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600",
"output": "unrated"
},
{
"input": "3\n1 1\n3 3\n4 4",
"output": "unrated"
},
{
"input": "3\n1 1\n2 2\n2 2",
"output": "unrated"
},
{
"input": "2\n10 12\n8 8",
"output": "rated"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500",
"output": "unrated"
},
{
"input": "2\n1 2\n2 2",
"output": "rated"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100",
"output": "rated"
},
{
"input": "2\n10 12\n10 10",
"output": "rated"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300",
"output": "maybe"
},
{
"input": "3\n3 3\n4 4\n5 5",
"output": "unrated"
},
{
"input": "3\n2 6\n3 5\n4 4",
"output": "rated"
},
{
"input": "2\n5 6\n4 6",
"output": "rated"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8",
"output": "unrated"
},
{
"input": "2\n4 4\n3 3",
"output": "maybe"
}
] | 1,617,392,937 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 92 | 204,800 | num = int(input())
participants = []
for i in range(num):
participant = input().split()
participants.append(participant)
i =0
for j in range(num):
if int(participants[j][0])!= int(participants[j][1]) :
print('rated')
break
elif j == num -1:
while i < num -1:
if int(participants[i][1]) < int(participants[i +1][1]):
print('unrated')
break
i +=1
else:
print('maybe') | Title: Is it rated?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of round participants.
Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=4126) — the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
Output Specification:
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
Demo Input:
['6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n', '4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n', '5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n']
Demo Output:
['rated\n', 'unrated\n', 'maybe\n']
Note:
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not. | ```python
num = int(input())
participants = []
for i in range(num):
participant = input().split()
participants.append(participant)
i =0
for j in range(num):
if int(participants[j][0])!= int(participants[j][1]) :
print('rated')
break
elif j == num -1:
while i < num -1:
if int(participants[i][1]) < int(participants[i +1][1]):
print('unrated')
break
i +=1
else:
print('maybe')
``` | 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,679,101,362 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | entrada = int(input())
cartas = input()
lista_cartas = cartas.split(" ")
operacoes = 0
if '1' not in lista_cartas:
print(0)
else:
index = -1
for i in range(len(lista_cartas)):
if lista_cartas[i] == '1':
if(index < 0 or index + 1 == i):
operacoes +=1
else:
operacoes +=2
index = i
print(operacoes)
| 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
entrada = int(input())
cartas = input()
lista_cartas = cartas.split(" ")
operacoes = 0
if '1' not in lista_cartas:
print(0)
else:
index = -1
for i in range(len(lista_cartas)):
if lista_cartas[i] == '1':
if(index < 0 or index + 1 == i):
operacoes +=1
else:
operacoes +=2
index = i
print(operacoes)
``` | 3 |
|
656 | G | You're a Professional | PROGRAMMING | 1,900 | [
"*special"
] | null | null | A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends. | The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise. | Output an integer — the number of items liked by at least *T* of user's friends. | [
"3 3 2\nYYY\nNNN\nYNY\n",
"4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n"
] | [
"2\n",
"4\n"
] | none | 0 | [
{
"input": "3 3 2\nYYY\nNNN\nYNY",
"output": "2"
},
{
"input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN",
"output": "4"
},
{
"input": "3 5 2\nNYNNY\nYNNNN\nNNYYN",
"output": "0"
},
{
"input": "1 10 1\nYYYNYNNYNN",
"output": "5"
},
{
"input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN",
"output": "0"
},
{
"input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN",
"output": "0"
},
{
"input": "10 10 10\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY\nYYYYYYYYYY",
"output": "10"
},
{
"input": "8 9 1\nNYNNYYYYN\nNNNYNYNNY\nYYNYNYNNN\nNYYYNYNNN\nYNYNYNYYN\nYYNNYYYYY\nYYYYNYNYY\nNYYNNYYYY",
"output": "9"
},
{
"input": "5 2 3\nNN\nNY\nYY\nNN\nNY",
"output": "1"
},
{
"input": "6 4 5\nYNNY\nNYYY\nNNNY\nYNYN\nYYYN\nYNNY",
"output": "0"
},
{
"input": "6 1 3\nY\nY\nY\nY\nY\nN",
"output": "1"
},
{
"input": "6 2 2\nYN\nNN\nYN\nNN\nYN\nNN",
"output": "1"
},
{
"input": "2 4 2\nNYNY\nNYNY",
"output": "2"
},
{
"input": "9 6 3\nNYYYYN\nNNNYYN\nYYYYYY\nNYNNNN\nYNNYNY\nNNNNNY\nYNNYNN\nYYYYNY\nNNYYYY",
"output": "6"
},
{
"input": "6 9 6\nYYYYNYNNN\nYNNYNNNYN\nNYYYNNNYY\nNYYYNNNNY\nYYNYNNNYY\nYYYNYYNNN",
"output": "0"
},
{
"input": "9 7 8\nYNNNNYN\nNNNYYNN\nNNYYYNY\nNYYNYYY\nNNYYNYN\nNYYYNNY\nYYNYNYY\nNYYYYYY\nNNYYNYN",
"output": "0"
},
{
"input": "9 1 6\nN\nN\nY\nN\nY\nY\nY\nY\nY",
"output": "1"
},
{
"input": "7 7 2\nNNYNNYN\nNNNYYNY\nNNNYYNY\nYNNNNNY\nNNYNYYY\nYYNNYYN\nNNYYYNY",
"output": "6"
},
{
"input": "8 4 2\nYNYY\nYNYY\nYNNN\nNNNN\nNYNN\nYNNN\nNNYN\nNYNN",
"output": "4"
},
{
"input": "9 10 7\nNNYNNYYYYY\nYNYYNYYNYN\nNYNYYNNNNY\nYYYYYYYYYN\nYYNYNYYNNN\nYYYNNYYYYY\nNYYYYYNNNN\nNYNNYYYYNN\nYYYYYNNYYY",
"output": "2"
},
{
"input": "6 4 2\nNNNN\nNYYY\nNYNN\nNYNN\nYNNY\nNNNN",
"output": "2"
},
{
"input": "3 1 1\nN\nY\nN",
"output": "1"
},
{
"input": "7 1 3\nY\nY\nY\nN\nY\nY\nY",
"output": "1"
},
{
"input": "9 8 7\nNYYNNNYY\nYYYNYNNN\nYNYNYNNY\nNYYYNNNY\nNYYYYNYN\nNNNNYYNN\nYNYYYYYY\nNNYNYNYY\nNYYNNYYY",
"output": "1"
},
{
"input": "9 5 9\nYYYYN\nYYYNN\nNNYNN\nNNYYY\nYNNNN\nNYNNN\nYYYYN\nYNYYN\nNNNYN",
"output": "0"
},
{
"input": "8 4 1\nYYYN\nNNNN\nNYNY\nYNNY\nYNYY\nYNYN\nYNNY\nNNYN",
"output": "4"
},
{
"input": "7 9 5\nYNNYYYYNN\nYNYYYNNYY\nYNYYYYYNN\nYYNYYNYYN\nNNYYNNNYY\nYYNYNYYNN\nYYNNYYNYN",
"output": "3"
},
{
"input": "5 8 3\nNYYYNNNN\nYNNNNNYY\nYNYYYNYY\nNNNNNYNN\nYYYYYYYY",
"output": "5"
},
{
"input": "5 10 4\nYYYYNNNNYN\nYYYNYYYNNY\nNNNYNYNYNY\nYNYNNNNNNY\nNNYNYNYNYY",
"output": "2"
},
{
"input": "6 9 6\nNYYNNYNYN\nYNYNYNNNN\nNNYNNYYYY\nNNYNNNYNY\nNYYYNNYNY\nNNYYNNNYN",
"output": "1"
},
{
"input": "4 4 1\nYNYY\nNNNY\nYNNN\nNNYN",
"output": "3"
},
{
"input": "1 3 1\nYYN",
"output": "2"
},
{
"input": "10 4 5\nNNYN\nYYNY\nYYNY\nNYYN\nYNYY\nYNYY\nYYNN\nYNYN\nYYYY\nYYNY",
"output": "4"
}
] | 1,610,366,081 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 0 | 0 | f,kitten,n=map(int,input().split())
a=zip(*[input() for _ in range(f)])
print(sum(sum(f=='Y' for f in e)>=n for e in a))
| Title: You're a Professional
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system.
You are given user's friends' opinions about a list of items. You are also given a threshold *T* — the minimal number of "likes" necessary for an item to be recommended to the user.
Output the number of items in the list liked by at least *T* of user's friends.
Input Specification:
The first line of the input will contain three space-separated integers: the number of friends *F* (1<=≤<=*F*<=≤<=10), the number of items *I* (1<=≤<=*I*<=≤<=10) and the threshold *T* (1<=≤<=*T*<=≤<=*F*).
The following *F* lines of input contain user's friends' opinions. *j*-th character of *i*-th line is 'Y' if *i*-th friend likes *j*-th item, and 'N' otherwise.
Output Specification:
Output an integer — the number of items liked by at least *T* of user's friends.
Demo Input:
['3 3 2\nYYY\nNNN\nYNY\n', '4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n']
Demo Output:
['2\n', '4\n']
Note:
none | ```python
f,kitten,n=map(int,input().split())
a=zip(*[input() for _ in range(f)])
print(sum(sum(f=='Y' for f in e)>=n for e in a))
``` | 0 |
|
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match. | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
},
{
"input": "4 5 4 5",
"output": "0.833333333333"
},
{
"input": "466 701 95 721",
"output": "0.937693791148"
},
{
"input": "268 470 444 885",
"output": "0.725614009325"
},
{
"input": "632 916 713 821",
"output": "0.719292895126"
},
{
"input": "269 656 918 992",
"output": "0.428937461623"
},
{
"input": "71 657 187 695",
"output": "0.310488463257"
},
{
"input": "435 852 973 978",
"output": "0.511844133157"
},
{
"input": "518 816 243 359",
"output": "0.719734031025"
},
{
"input": "882 962 311 811",
"output": "0.966386645447"
},
{
"input": "684 774 580 736",
"output": "0.906051574446"
},
{
"input": "486 868 929 999",
"output": "0.577723252958"
},
{
"input": "132 359 996 998",
"output": "0.368154532345"
},
{
"input": "933 977 266 450",
"output": "0.972879407907"
},
{
"input": "298 833 615 872",
"output": "0.441270817024"
},
{
"input": "34 554 14 958",
"output": "0.817324099167"
},
{
"input": "836 934 800 905",
"output": "0.906105535462"
},
{
"input": "482 815 69 509",
"output": "0.914365577772"
},
{
"input": "284 423 137 521",
"output": "0.885974839378"
},
{
"input": "648 881 486 703",
"output": "0.800911421248"
},
{
"input": "450 885 755 836",
"output": "0.533901011176"
},
{
"input": "533 773 823 998",
"output": "0.729222130525"
},
{
"input": "897 957 92 898",
"output": "0.993193806364"
},
{
"input": "699 925 441 928",
"output": "0.866816866175"
},
{
"input": "64 704 148 603",
"output": "0.289486317811"
},
{
"input": "719 735 626 990",
"output": "0.986124079764"
},
{
"input": "1 1000 1 1000",
"output": "0.500250125063"
}
] | 1,601,713,436 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 140 | 0 | a,b,c,d=map(int,input().split())
r=a/b
R=c/d
r1=1-r
r2=1-R
print(r*(1/(1-r1*r2)))
| Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will win the match.
Input Specification:
A single line contains four integers .
Output Specification:
Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
Demo Input:
['1 2 1 2\n']
Demo Output:
['0.666666666667']
Note:
none | ```python
a,b,c,d=map(int,input().split())
r=a/b
R=c/d
r1=1-r
r2=1-R
print(r*(1/(1-r1*r2)))
``` | 3 |
|
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,622,522,770 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 140 | 0 | if __name__=="__main__":
s=[int(x) for x in input().split()]
n,k=s[0],s[1]
if (n==k) or (n-k<k):
print("YES")
if(n-k==k) or (n-k>k):
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
if __name__=="__main__":
s=[int(x) for x in input().split()]
n,k=s[0],s[1]
if (n==k) or (n-k<k):
print("YES")
if(n-k==k) or (n-k>k):
print("NO")
``` | 0 |
|
624 | A | Save Luke | PROGRAMMING | 800 | [
"math"
] | null | null | Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive. | The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively. | Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . | [
"2 6 2 2\n",
"1 9 1 2\n"
] | [
"1.00000000000000000000\n",
"2.66666666666666650000\n"
] | In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | 500 | [
{
"input": "2 6 2 2",
"output": "1.00000000000000000000"
},
{
"input": "1 9 1 2",
"output": "2.66666666666666650000"
},
{
"input": "1 10000 1 1",
"output": "4999.50000000000000000000"
},
{
"input": "9999 10000 10000 10000",
"output": "0.00005000000000000000"
},
{
"input": "1023 2340 1029 3021",
"output": "0.32518518518518519000"
},
{
"input": "2173 2176 10000 9989",
"output": "0.00015008254539996998"
},
{
"input": "1 2 123 1",
"output": "0.00806451612903225780"
},
{
"input": "123 1242 12 312",
"output": "3.45370370370370370000"
},
{
"input": "2 9997 3 12",
"output": "666.33333333333337000000"
},
{
"input": "1 10000 10000 10000",
"output": "0.49995000000000001000"
},
{
"input": "3274 4728 888 4578",
"output": "0.26600804976216613000"
},
{
"input": "4600 9696 5634 8248",
"output": "0.36709407866301685000"
},
{
"input": "2255 7902 8891 429",
"output": "0.60590128755364803000"
},
{
"input": "6745 9881 2149 9907",
"output": "0.26011944260119441000"
},
{
"input": "4400 8021 6895 2089",
"output": "0.40304986642920748000"
},
{
"input": "5726 9082 7448 3054",
"output": "0.31955817939440107000"
},
{
"input": "3381 9769 4898 2532",
"output": "0.85975773889636609000"
},
{
"input": "1036 6259 5451 4713",
"output": "0.51387249114521838000"
},
{
"input": "5526 6455 197 4191",
"output": "0.21171376481312670000"
},
{
"input": "1196 4082 4071 9971",
"output": "0.20552627830793335000"
},
{
"input": "8850 9921 8816 9449",
"output": "0.05863673692855187600"
},
{
"input": "3341 7299 2074 8927",
"output": "0.35978547404781386000"
},
{
"input": "7831 8609 6820 2596",
"output": "0.08262531860662701600"
},
{
"input": "2322 7212 77 4778",
"output": "1.00720906282183310000"
},
{
"input": "9976 9996 4823 4255",
"output": "0.00220312844238819110"
},
{
"input": "7631 9769 5377 6437",
"output": "0.18097172845776197000"
},
{
"input": "8957 9525 8634 107",
"output": "0.06498112344125385500"
},
{
"input": "6612 9565 3380 2288",
"output": "0.52099505998588569000"
},
{
"input": "1103 6256 3934 9062",
"output": "0.39650661742074483000"
},
{
"input": "1854 3280 1481 2140",
"output": "0.39381386357359843000"
}
] | 1,666,605,303 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | d, L, v1, v2 = map(int, input().split())
t = 1
e = 10e-14
a = 0
b = L
result = 0.0
while True:
if b-a > d:
if (b-v2) - (a+v1) < d:
v1 /= 2
v2 /= 2
t /= 2
continue
else:
a += v1
b -= v2
result += t
if (b-a)-d < e:
print(f"%.12f" % (result))
break | Title: Save Luke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and *L*, and they move towards each other with speed *v*1 and *v*2, respectively. Luke has width *d* and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.
Input Specification:
The first line of the input contains four integers *d*, *L*, *v*1, *v*2 (1<=≤<=*d*,<=*L*,<=*v*1,<=*v*2<=≤<=10<=000,<=*d*<=<<=*L*) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.
Output Specification:
Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
Demo Input:
['2 6 2 2\n', '1 9 1 2\n']
Demo Output:
['1.00000000000000000000\n', '2.66666666666666650000\n']
Note:
In the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.
In the second sample he needs to occupy the position <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/71395c777960eaded59a9fdc428a9625f152605b.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In this case both presses move to his edges at the same time. | ```python
d, L, v1, v2 = map(int, input().split())
t = 1
e = 10e-14
a = 0
b = L
result = 0.0
while True:
if b-a > d:
if (b-v2) - (a+v1) < d:
v1 /= 2
v2 /= 2
t /= 2
continue
else:
a += v1
b -= v2
result += t
if (b-a)-d < e:
print(f"%.12f" % (result))
break
``` | 3 |
|
413 | B | Spyke Chatting | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | The R2 company has *n* employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.
R2 has *m* Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the *k*-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification.
The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee. | The first line contains three space-separated integers *n*, *m* and *k* (2<=≤<=*n*<=≤<=2·104; 1<=≤<=*m*<=≤<=10; 1<=≤<=*k*<=≤<=2·105) — the number of the employees, the number of chats and the number of events in the log, correspondingly.
Next *n* lines contain matrix *a* of size *n*<=×<=*m*, consisting of numbers zero and one. The element of this matrix, recorded in the *j*-th column of the *i*-th line, (let's denote it as *a**ij*) equals 1, if the *i*-th employee is the participant of the *j*-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to *n* and the chats are numbered from 1 to *m*.
Next *k* lines contain the description of the log events. The *i*-th line contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*; 1<=≤<=*y**i*<=≤<=*m*) which mean that the employee number *x**i* sent one message to chat number *y**i*. It is guaranteed that employee number *x**i* is a participant of chat *y**i*. It is guaranteed that each chat contains at least two employees. | Print in the single line *n* space-separated integers, where the *i*-th integer shows the number of message notifications the *i*-th employee receives. | [
"3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2\n",
"4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3\n"
] | [
"3 3 1 ",
"0 2 3 0 "
] | none | 1,000 | [
{
"input": "3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2",
"output": "3 3 1 "
},
{
"input": "4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3",
"output": "0 2 3 0 "
},
{
"input": "2 1 1\n1\n1\n1 1",
"output": "0 1 "
},
{
"input": "3 3 1\n1 1 1\n1 1 1\n1 1 1\n3 1",
"output": "1 1 0 "
},
{
"input": "3 2 1\n0 1\n1 0\n1 1\n1 2",
"output": "0 0 1 "
},
{
"input": "5 5 5\n0 1 1 1 0\n1 1 0 1 1\n1 1 1 1 1\n0 1 1 1 1\n1 0 0 1 1\n4 5\n4 5\n1 3\n5 4\n1 2",
"output": "1 4 5 3 2 "
},
{
"input": "4 5 6\n1 1 1 1 1\n1 1 1 0 1\n1 0 1 1 1\n1 0 1 1 1\n2 3\n2 5\n1 2\n4 5\n4 5\n4 1",
"output": "5 4 5 2 "
},
{
"input": "7 6 5\n0 1 0 1 1 1\n0 1 1 0 1 1\n1 0 1 1 1 0\n1 0 1 1 1 1\n1 1 1 1 1 0\n1 1 1 0 1 0\n1 0 1 0 0 0\n4 1\n2 6\n7 3\n7 1\n5 3",
"output": "1 2 4 4 3 4 2 "
},
{
"input": "3 3 4\n1 1 1\n0 0 0\n1 1 1\n1 1\n3 1\n3 2\n3 3",
"output": "3 0 1 "
},
{
"input": "10 1 10\n0\n0\n0\n0\n0\n0\n1\n0\n1\n0\n7 1\n9 1\n9 1\n7 1\n9 1\n9 1\n9 1\n7 1\n9 1\n9 1",
"output": "0 0 0 0 0 0 7 0 3 0 "
},
{
"input": "2 1 1\n1\n1\n1 1",
"output": "0 1 "
},
{
"input": "2 1 1\n1\n1\n2 1",
"output": "1 0 "
},
{
"input": "3 1 2\n1\n1\n0\n1 1\n2 1",
"output": "1 1 0 "
},
{
"input": "3 1 2\n1\n0\n1\n1 1\n3 1",
"output": "1 0 1 "
},
{
"input": "3 1 2\n0\n1\n1\n2 1\n3 1",
"output": "0 1 1 "
}
] | 1,397,982,509 | 5,309 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 9 | 1,000 | 10,956,800 | n, m, k = map(int, input().split())
list_of_a = [list(map(int, input().split())) for i in range(n)]
list_of_xy = [list(map(int, input().split())) for i in range(k)]
list_of_n = [0] * n
for sotrud in range(n):
for matriza in list_of_xy:
if list_of_a[sotrud][matriza[1] - 1] == 1:
if matriza[0] != sotrud + 1:
list_of_n[sotrud] += 1
for i in list_of_n:
print(i, end=" ")
| Title: Spyke Chatting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The R2 company has *n* employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke.
R2 has *m* Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges messages daily. An employee can simultaneously talk in multiple chats. If some employee is in the *k*-th chat, he can write messages to this chat and receive notifications about messages from this chat. If an employee writes a message in the chat, all other participants of the chat receive a message notification.
The R2 company is conducting an audit. Now the specialists study effective communication between the employees. For this purpose, they have a chat log and the description of chat structure. You, as one of audit specialists, are commissioned to write a program that will use this data to determine the total number of message notifications received by each employee.
Input Specification:
The first line contains three space-separated integers *n*, *m* and *k* (2<=≤<=*n*<=≤<=2·104; 1<=≤<=*m*<=≤<=10; 1<=≤<=*k*<=≤<=2·105) — the number of the employees, the number of chats and the number of events in the log, correspondingly.
Next *n* lines contain matrix *a* of size *n*<=×<=*m*, consisting of numbers zero and one. The element of this matrix, recorded in the *j*-th column of the *i*-th line, (let's denote it as *a**ij*) equals 1, if the *i*-th employee is the participant of the *j*-th chat, otherwise the element equals 0. Assume that the employees are numbered from 1 to *n* and the chats are numbered from 1 to *m*.
Next *k* lines contain the description of the log events. The *i*-th line contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=*n*; 1<=≤<=*y**i*<=≤<=*m*) which mean that the employee number *x**i* sent one message to chat number *y**i*. It is guaranteed that employee number *x**i* is a participant of chat *y**i*. It is guaranteed that each chat contains at least two employees.
Output Specification:
Print in the single line *n* space-separated integers, where the *i*-th integer shows the number of message notifications the *i*-th employee receives.
Demo Input:
['3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2\n', '4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3\n']
Demo Output:
['3 3 1 ', '0 2 3 0 ']
Note:
none | ```python
n, m, k = map(int, input().split())
list_of_a = [list(map(int, input().split())) for i in range(n)]
list_of_xy = [list(map(int, input().split())) for i in range(k)]
list_of_n = [0] * n
for sotrud in range(n):
for matriza in list_of_xy:
if list_of_a[sotrud][matriza[1] - 1] == 1:
if matriza[0] != sotrud + 1:
list_of_n[sotrud] += 1
for i in list_of_n:
print(i, end=" ")
``` | 0 |
|
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output": "5 2 1"
},
{
"input": "10\n858 972 670 15 662 114 33 273 53 310",
"output": "2 6 1"
},
{
"input": "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 362 585 952 365 92 749 904 525 307 626 883 367 450 755 564 950 728 724 69 106 119 157 96 290",
"output": "1 38 25"
},
{
"input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438",
"output": "1 63 61"
},
{
"input": "100\n156 822 179 298 981 82 610 345 373 378 895 734 768 15 78 335 764 608 932 297 717 553 916 367 425 447 361 195 66 70 901 236 905 744 919 564 296 610 963 628 840 52 100 750 345 308 37 687 192 704 101 815 10 990 216 358 823 546 578 821 706 148 182 582 421 482 829 425 121 337 500 301 402 868 66 935 625 527 746 585 308 523 488 914 608 709 875 252 151 781 447 2 756 176 976 302 450 35 680 791",
"output": "1 98 69"
},
{
"input": "100\n54 947 785 838 359 647 92 445 48 465 323 486 101 86 607 31 860 420 709 432 435 372 272 37 903 814 309 197 638 58 259 822 793 564 309 22 522 907 101 853 486 824 614 734 630 452 166 532 256 499 470 9 933 452 256 450 7 26 916 406 257 285 895 117 59 369 424 133 16 417 352 440 806 236 478 34 889 469 540 806 172 296 73 655 261 792 868 380 204 454 330 53 136 629 236 850 134 560 264 291",
"output": "2 29 27"
},
{
"input": "99\n175 269 828 129 499 890 127 263 995 807 508 289 996 226 437 320 365 642 757 22 190 8 345 499 834 713 962 889 336 171 608 492 320 257 472 801 176 325 301 306 198 729 933 4 640 322 226 317 567 586 249 237 202 633 287 128 911 654 719 988 420 855 361 574 716 899 317 356 581 440 284 982 541 111 439 29 37 560 961 224 478 906 319 416 736 603 808 87 762 697 392 713 19 459 262 238 239 599 997",
"output": "1 44 30"
},
{
"input": "98\n443 719 559 672 16 69 529 632 953 999 725 431 54 22 346 968 558 696 48 669 963 129 257 712 39 870 498 595 45 821 344 925 179 388 792 346 755 213 423 365 344 659 824 356 773 637 628 897 841 155 243 536 951 361 192 105 418 431 635 596 150 162 145 548 473 531 750 306 377 354 450 975 79 743 656 733 440 940 19 139 237 346 276 227 64 799 479 633 199 17 796 362 517 234 729 62 995 535",
"output": "2 70 40"
},
{
"input": "97\n359 522 938 862 181 600 283 1000 910 191 590 220 761 818 903 264 751 751 987 316 737 898 168 925 244 674 34 950 754 472 81 6 37 520 112 891 981 454 897 424 489 238 363 709 906 951 677 828 114 373 589 835 52 89 97 435 277 560 551 204 879 469 928 523 231 163 183 609 821 915 615 969 616 23 874 437 844 321 78 53 643 786 585 38 744 347 150 179 988 985 200 11 15 9 547 886 752",
"output": "1 23 10"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "100\n328 397 235 453 188 254 879 225 423 36 384 296 486 592 231 849 856 255 213 898 234 800 701 529 951 693 507 326 15 905 618 348 967 927 28 979 752 850 343 35 84 302 36 390 482 826 249 918 91 289 973 457 557 348 365 239 709 565 320 560 153 130 647 708 483 469 788 473 322 844 830 562 611 961 397 673 69 960 74 703 369 968 382 451 328 160 211 230 566 208 7 545 293 73 806 375 157 410 303 58",
"output": "1 79 6"
},
{
"input": "33\n52 145 137 734 180 847 178 286 716 134 181 630 358 764 593 762 785 28 1 468 189 540 764 485 165 656 114 58 628 108 605 584 257",
"output": "8 30 7"
},
{
"input": "57\n75 291 309 68 444 654 985 158 514 204 116 918 374 806 176 31 49 455 269 66 722 713 164 818 317 295 546 564 134 641 28 13 987 478 146 219 213 940 289 173 157 666 168 391 392 71 870 477 446 988 414 568 964 684 409 671 454",
"output": "2 41 29"
},
{
"input": "88\n327 644 942 738 84 118 981 686 530 404 137 197 434 16 693 183 423 325 410 345 941 329 7 106 79 867 584 358 533 675 192 718 641 329 900 768 404 301 101 538 954 590 401 954 447 14 559 337 756 586 934 367 538 928 945 936 770 641 488 579 206 869 902 139 216 446 723 150 829 205 373 578 357 368 960 40 121 206 503 385 521 161 501 694 138 370 709 308",
"output": "1 77 61"
},
{
"input": "100\n804 510 266 304 788 625 862 888 408 82 414 470 777 991 729 229 933 406 601 1 596 720 608 706 432 361 527 548 59 548 474 515 4 991 263 568 681 24 117 563 576 587 281 643 904 521 891 106 842 884 943 54 605 815 504 757 311 374 335 192 447 652 633 410 455 402 382 150 432 836 413 819 669 875 638 925 217 805 632 520 605 266 728 795 162 222 603 159 284 790 914 443 775 97 789 606 859 13 851 47",
"output": "1 77 42"
},
{
"input": "100\n449 649 615 713 64 385 927 466 138 126 143 886 80 199 208 43 196 694 92 89 264 180 617 970 191 196 910 150 275 89 693 190 191 99 542 342 45 592 114 56 451 170 64 589 176 102 308 92 402 153 414 675 352 157 69 150 91 288 163 121 816 184 20 234 836 12 593 150 793 439 540 93 99 663 186 125 349 247 476 106 77 523 215 7 363 278 441 745 337 25 148 384 15 915 108 211 240 58 23 408",
"output": "1 6 5"
},
{
"input": "90\n881 436 52 308 97 261 153 931 670 538 702 156 114 445 154 685 452 76 966 790 93 42 547 65 736 364 136 489 719 322 239 628 696 735 55 703 622 375 100 188 804 341 546 474 484 446 729 290 974 301 602 225 996 244 488 983 882 460 962 754 395 617 61 640 534 292 158 375 632 902 420 979 379 38 100 67 963 928 190 456 545 571 45 716 153 68 844 2 102 116",
"output": "1 14 2"
},
{
"input": "80\n313 674 262 240 697 146 391 221 793 504 896 818 92 899 86 370 341 339 306 887 937 570 830 683 729 519 240 833 656 847 427 958 435 704 853 230 758 347 660 575 843 293 649 396 437 787 654 599 35 103 779 783 447 379 444 585 902 713 791 150 851 228 306 721 996 471 617 403 102 168 197 741 877 481 968 545 331 715 236 654",
"output": "1 13 8"
},
{
"input": "70\n745 264 471 171 946 32 277 511 269 469 89 831 69 2 369 407 583 602 646 633 429 747 113 302 722 321 344 824 241 372 263 287 822 24 652 758 246 967 219 313 882 597 752 965 389 775 227 556 95 904 308 340 899 514 400 187 275 318 621 546 659 488 199 154 811 1 725 79 925 82",
"output": "1 63 60"
},
{
"input": "60\n176 502 680 102 546 917 516 801 392 435 635 492 398 456 653 444 472 513 634 378 273 276 44 920 68 124 800 167 825 250 452 264 561 344 98 933 381 939 426 51 568 548 206 887 342 763 151 514 156 354 486 546 998 649 356 438 295 570 450 589",
"output": "2 26 20"
},
{
"input": "50\n608 92 889 33 146 803 402 91 868 400 828 505 375 558 584 129 361 776 974 123 765 804 326 186 61 927 904 511 762 775 640 593 300 664 897 461 869 911 986 789 607 500 309 457 294 104 724 471 216 155",
"output": "3 25 11"
},
{
"input": "40\n40 330 98 612 747 336 640 381 991 366 22 167 352 12 868 166 603 40 313 869 609 981 609 804 54 729 8 854 347 300 828 922 39 633 695 988 4 530 545 176",
"output": "5 10 8"
},
{
"input": "30\n471 920 308 544 347 222 878 671 467 332 215 180 681 114 151 203 492 951 653 614 453 510 540 422 399 532 113 198 932 825",
"output": "2 21 9"
},
{
"input": "20\n551 158 517 475 595 108 764 961 590 297 761 841 659 568 82 888 733 214 993 359",
"output": "3 20 2"
},
{
"input": "10\n983 748 726 406 196 993 2 251 66 263",
"output": "-1"
},
{
"input": "9\n933 266 457 863 768 257 594 136 145",
"output": "-1"
},
{
"input": "8\n537 198 48 771 944 868 700 163",
"output": "7 8 1"
},
{
"input": "7\n140 779 639 679 768 479 158",
"output": "2 3 1"
},
{
"input": "6\n744 359 230 586 944 442",
"output": "-1"
},
{
"input": "5\n700 939 173 494 120",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "3\n907 452 355",
"output": "-1"
},
{
"input": "3\n963 630 333",
"output": "1 3 2"
},
{
"input": "3\n2 2 4",
"output": "3 2 1"
},
{
"input": "3\n2 4 100",
"output": "-1"
}
] | 1,641,554,472 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 218 | 1,228,800 | # complexity O(n^3) ?!, I believe that there is a better way to solve it in O(n^2).
n = int(input())
list1 = list(map(int,input().strip().split()))[:n]
def foo(list1):
list2 = []
for i in range(0,len(list1) - 2):
for j in range(1,len(list1) - 1):
for k in range(2, len(list1)):
if list1[i] == list1[k] + list1[j]:
list2.append(i+1)
list2.append(k+1)
list2.append(j+1)
return list2
elif list1[j] == list1[k] + list1[i]:
list2.append(j + 1)
list2.append(k + 1)
list2.append(i + 1)
return list2
elif list1[k] == list1[j] + list1[i]:
list2.append(k + 1)
list2.append(j + 1)
list2.append(i + 1)
return list2
list3 = foo(list1)
if list3:
list3 = list(dict.fromkeys(list3))
for i in list3:
print(i,end=" ")
elif not list3:
print(-1)
| Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output Specification:
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
Demo Input:
['5\n1 2 3 5 7\n', '5\n1 8 1 5 1\n']
Demo Output:
['3 2 1\n', '-1\n']
Note:
none | ```python
# complexity O(n^3) ?!, I believe that there is a better way to solve it in O(n^2).
n = int(input())
list1 = list(map(int,input().strip().split()))[:n]
def foo(list1):
list2 = []
for i in range(0,len(list1) - 2):
for j in range(1,len(list1) - 1):
for k in range(2, len(list1)):
if list1[i] == list1[k] + list1[j]:
list2.append(i+1)
list2.append(k+1)
list2.append(j+1)
return list2
elif list1[j] == list1[k] + list1[i]:
list2.append(j + 1)
list2.append(k + 1)
list2.append(i + 1)
return list2
elif list1[k] == list1[j] + list1[i]:
list2.append(k + 1)
list2.append(j + 1)
list2.append(i + 1)
return list2
list3 = foo(list1)
if list3:
list3 = list(dict.fromkeys(list3))
for i in list3:
print(i,end=" ")
elif not list3:
print(-1)
``` | 3.943211 |
609 | C | Load Balancing | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression *m**a*<=-<=*m**b*, where *a* is the most loaded server and *b* is the least loaded one.
In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another.
Write a program to find the minimum number of seconds needed to balance the load of servers. | The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server. | Print the minimum number of seconds required to balance the load. | [
"2\n1 6\n",
"7\n10 11 10 11 10 11 11\n",
"5\n1 2 3 4 5\n"
] | [
"2\n",
"0\n",
"3\n"
] | In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
1. move a task from server #4 to server #1 (the sequence *m* becomes: 2 2 3 3 5); 1. then move task from server #5 to server #1 (the sequence *m* becomes: 3 2 3 3 4); 1. then move task from server #5 to server #2 (the sequence *m* becomes: 3 3 3 3 3).
The above sequence is one of several possible ways to balance the load of servers in three seconds. | 0 | [
{
"input": "2\n1 6",
"output": "2"
},
{
"input": "7\n10 11 10 11 10 11 11",
"output": "0"
},
{
"input": "5\n1 2 3 4 5",
"output": "3"
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n20000",
"output": "0"
},
{
"input": "3\n1 10000 20000",
"output": "9999"
},
{
"input": "10\n19999 19999 20000 20000 19999 20000 20000 20000 19999 19999",
"output": "0"
},
{
"input": "10\n8 5 5 5 6 6 6 6 5 5",
"output": "2"
},
{
"input": "2\n10 3",
"output": "3"
},
{
"input": "5\n6 5 9 7 6",
"output": "2"
},
{
"input": "5\n2 10 20 30 50",
"output": "34"
},
{
"input": "7\n2 2 2 2 2 3 4",
"output": "1"
}
] | 1,683,320,774 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import math
def main():
n = int(input())
m = list(map(int, input().split()))
min_load = m[0]
max_load = m[0]
for i in range(1, n):
if m[i] < min_load:
min_load = m[i]
elif m[i] > max_load:
max_load = m[i]
print(max_load - min_load)
if __name__ == "__main__":
main()
| Title: Load Balancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the school computer room there are *n* servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are *m**i* tasks assigned to the *i*-th server.
In order to balance the load for each server, you want to reassign some tasks to make the difference between the most loaded server and the least loaded server as small as possible. In other words you want to minimize expression *m**a*<=-<=*m**b*, where *a* is the most loaded server and *b* is the least loaded one.
In one second you can reassign a single task. Thus in one second you can choose any pair of servers and move a single task from one server to another.
Write a program to find the minimum number of seconds needed to balance the load of servers.
Input Specification:
The first line contains positive number *n* (1<=≤<=*n*<=≤<=105) — the number of the servers.
The second line contains the sequence of non-negative integers *m*1,<=*m*2,<=...,<=*m**n* (0<=≤<=*m**i*<=≤<=2·104), where *m**i* is the number of tasks assigned to the *i*-th server.
Output Specification:
Print the minimum number of seconds required to balance the load.
Demo Input:
['2\n1 6\n', '7\n10 11 10 11 10 11 11\n', '5\n1 2 3 4 5\n']
Demo Output:
['2\n', '0\n', '3\n']
Note:
In the first example two seconds are needed. In each second, a single task from server #2 should be moved to server #1. After two seconds there should be 3 tasks on server #1 and 4 tasks on server #2.
In the second example the load is already balanced.
A possible sequence of task movements for the third example is:
1. move a task from server #4 to server #1 (the sequence *m* becomes: 2 2 3 3 5); 1. then move task from server #5 to server #1 (the sequence *m* becomes: 3 2 3 3 4); 1. then move task from server #5 to server #2 (the sequence *m* becomes: 3 3 3 3 3).
The above sequence is one of several possible ways to balance the load of servers in three seconds. | ```python
import math
def main():
n = int(input())
m = list(map(int, input().split()))
min_load = m[0]
max_load = m[0]
for i in range(1, n):
if m[i] < min_load:
min_load = m[i]
elif m[i] > max_load:
max_load = m[i]
print(max_load - min_load)
if __name__ == "__main__":
main()
``` | 0 |
|
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output": "1"
},
{
"input": "86",
"output": "2"
},
{
"input": "2",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "34",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "28",
"output": "2"
},
{
"input": "23",
"output": "1"
},
{
"input": "57",
"output": "2"
},
{
"input": "29",
"output": "2"
},
{
"input": "353869285",
"output": "3"
},
{
"input": "549548646",
"output": "2"
},
{
"input": "858893424",
"output": "2"
},
{
"input": "644818852",
"output": "3"
},
{
"input": "360322525",
"output": "3"
},
{
"input": "122937520",
"output": "2"
},
{
"input": "288403032",
"output": "2"
},
{
"input": "677257481",
"output": "3"
},
{
"input": "58059561",
"output": "3"
},
{
"input": "211288847",
"output": "2"
},
{
"input": "339900034079539584",
"output": "2"
},
{
"input": "784084029310269952",
"output": "3"
},
{
"input": "774730557264864000",
"output": "3"
},
{
"input": "478233807148352256",
"output": "3"
},
{
"input": "165646874056812544",
"output": "3"
},
{
"input": "477533739511673792",
"output": "3"
},
{
"input": "660119944377002240",
"output": "3"
},
{
"input": "448375218506078080",
"output": "3"
},
{
"input": "77213334785795616",
"output": "3"
},
{
"input": "165767221702271872",
"output": "3"
},
{
"input": "1",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "8",
"output": "0"
},
{
"input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561",
"output": "3"
},
{
"input": "9",
"output": "0"
}
] | 1,652,416,474 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 2,000 | 0 | n = int(input())
if n<10: print(0)
else:
k,sum=0,0
while True:
sum+=n%10
n//=10
k+=1
if n==0: n=sum
print(k) | Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
Input Specification:
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Output Specification:
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
Demo Input:
['0\n', '10\n', '991\n']
Demo Output:
['0\n', '1\n', '3\n']
Note:
In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit. | ```python
n = int(input())
if n<10: print(0)
else:
k,sum=0,0
while True:
sum+=n%10
n//=10
k+=1
if n==0: n=sum
print(k)
``` | 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,579,363,486 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 108 | 0 | string=input()
if string.count('h')>=1 and string.count('e')>=1 and string.count('ll')>=1 and string.count('o')>=1:
print('YES')
else:
print("NO") | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
Input Specification:
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
Output Specification:
If Vasya managed to say hello, print "YES", otherwise print "NO".
Demo Input:
['ahhellllloou\n', 'hlelo\n']
Demo Output:
['YES\n', 'NO\n']
Note:
none | ```python
string=input()
if string.count('h')>=1 and string.count('e')>=1 and string.count('ll')>=1 and string.count('o')>=1:
print('YES')
else:
print("NO")
``` | 0 |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "3\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "3\n0 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "5\n0 73\n73 189\n189 766\n766 0\n0 0",
"output": "766"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 1\n1 0",
"output": "1"
},
{
"input": "5\n0 917\n917 923\n904 992\n1000 0\n11 0",
"output": "1011"
},
{
"input": "5\n0 1\n1 2\n2 1\n1 2\n2 0",
"output": "2"
},
{
"input": "5\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "20\n0 7\n2 1\n2 2\n5 7\n2 6\n6 10\n2 4\n0 4\n7 4\n8 0\n10 6\n2 1\n6 1\n1 7\n0 3\n8 7\n6 3\n6 3\n1 1\n3 0",
"output": "22"
},
{
"input": "5\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "10\n0 592\n258 598\n389 203\n249 836\n196 635\n478 482\n994 987\n1000 0\n769 0\n0 0",
"output": "1776"
},
{
"input": "10\n0 1\n1 0\n0 0\n0 0\n0 0\n0 1\n1 1\n0 1\n1 0\n1 0",
"output": "2"
},
{
"input": "10\n0 926\n926 938\n938 931\n931 964\n937 989\n983 936\n908 949\n997 932\n945 988\n988 0",
"output": "1016"
},
{
"input": "10\n0 1\n1 2\n1 2\n2 2\n2 2\n2 2\n1 1\n1 1\n2 1\n2 0",
"output": "3"
},
{
"input": "10\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "10\n0 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 0",
"output": "1000"
},
{
"input": "50\n0 332\n332 268\n268 56\n56 711\n420 180\n160 834\n149 341\n373 777\n763 93\n994 407\n86 803\n700 132\n471 608\n429 467\n75 5\n638 305\n405 853\n316 478\n643 163\n18 131\n648 241\n241 766\n316 847\n640 380\n923 759\n789 41\n125 421\n421 9\n9 388\n388 829\n408 108\n462 856\n816 411\n518 688\n290 7\n405 912\n397 772\n396 652\n394 146\n27 648\n462 617\n514 433\n780 35\n710 705\n460 390\n194 508\n643 56\n172 469\n1000 0\n194 0",
"output": "2071"
},
{
"input": "50\n0 0\n0 1\n1 1\n0 1\n0 0\n1 0\n0 0\n1 0\n0 0\n0 0\n0 0\n0 0\n0 1\n0 0\n0 0\n0 1\n1 0\n0 1\n0 0\n1 1\n1 0\n0 1\n0 0\n1 1\n0 1\n1 0\n1 1\n1 0\n0 0\n1 1\n1 0\n0 1\n0 0\n0 1\n1 1\n1 1\n1 1\n1 0\n1 1\n1 0\n0 1\n1 0\n0 0\n0 1\n1 1\n1 1\n0 1\n0 0\n1 0\n1 0",
"output": "3"
},
{
"input": "50\n0 926\n926 971\n915 980\n920 965\n954 944\n928 952\n955 980\n916 980\n906 935\n944 913\n905 923\n912 922\n965 934\n912 900\n946 930\n931 983\n979 905\n925 969\n924 926\n910 914\n921 977\n934 979\n962 986\n942 909\n976 903\n982 982\n991 941\n954 929\n902 980\n947 983\n919 924\n917 943\n916 905\n907 913\n964 977\n984 904\n905 999\n950 970\n986 906\n993 970\n960 994\n963 983\n918 986\n980 900\n931 986\n993 997\n941 909\n907 909\n1000 0\n278 0",
"output": "1329"
},
{
"input": "2\n0 863\n863 0",
"output": "863"
},
{
"input": "50\n0 1\n1 2\n2 2\n1 1\n1 1\n1 2\n1 2\n1 1\n1 2\n1 1\n1 1\n1 2\n1 2\n1 1\n2 1\n2 2\n1 2\n2 2\n1 2\n2 1\n2 1\n2 2\n2 1\n1 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 1\n1 2\n2 2\n1 2\n1 1\n1 1\n2 1\n2 1\n2 2\n2 1\n2 1\n1 2\n1 2\n1 2\n1 2\n2 0\n2 0\n2 0\n0 0",
"output": "8"
},
{
"input": "50\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "100\n0 1\n0 0\n0 0\n1 0\n0 0\n0 1\n0 1\n1 1\n0 0\n0 0\n1 1\n0 0\n1 1\n0 1\n1 1\n0 1\n1 1\n1 0\n1 0\n0 0\n1 0\n0 1\n1 0\n0 0\n0 0\n1 1\n1 1\n0 1\n0 0\n1 0\n1 1\n0 1\n1 0\n1 1\n0 1\n1 1\n1 0\n0 0\n0 0\n0 1\n0 0\n0 1\n1 1\n0 0\n1 1\n1 1\n0 0\n0 1\n1 0\n0 1\n0 0\n0 1\n0 1\n1 1\n1 1\n1 1\n0 0\n0 0\n1 1\n0 1\n0 1\n1 0\n0 0\n0 0\n1 1\n0 1\n0 1\n1 1\n1 1\n0 1\n1 1\n1 1\n0 0\n1 0\n0 1\n0 0\n0 0\n1 1\n1 1\n1 1\n1 1\n0 1\n1 0\n1 0\n1 0\n1 0\n1 0\n0 0\n1 0\n1 0\n0 0\n1 0\n0 0\n0 1\n1 0\n0 1\n1 0\n1 0\n1 0\n1 0",
"output": "11"
},
{
"input": "100\n0 2\n1 2\n2 1\n1 2\n1 2\n2 1\n2 2\n1 1\n1 1\n2 1\n1 2\n2 1\n1 2\n2 2\n2 2\n2 2\n1 2\n2 2\n2 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 2\n1 1\n1 1\n1 1\n1 1\n2 2\n1 2\n2 1\n1 1\n2 2\n1 1\n2 1\n1 1\n2 2\n2 1\n1 2\n1 1\n1 2\n2 1\n2 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 2\n2 2\n2 2\n1 1\n2 2\n1 2\n2 1\n2 1\n1 1\n1 1\n1 2\n1 2\n1 1\n1 1\n2 1\n1 2\n1 2\n2 1\n2 2\n2 2\n2 2\n2 1\n2 2\n1 1\n1 2\n1 2\n1 1\n2 2\n2 2\n1 1\n2 1\n1 1\n1 2\n1 2\n1 2\n1 1\n1 1\n2 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 1\n2 2\n1 2\n2 0\n2 0\n2 0\n1 0",
"output": "7"
},
{
"input": "100\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 900\n900 0",
"output": "900"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "2\n0 0\n0 0",
"output": "0"
},
{
"input": "2\n0 1000\n1000 0",
"output": "1000"
},
{
"input": "3\n0 802\n175 188\n815 0",
"output": "815"
},
{
"input": "3\n0 910\n910 976\n976 0",
"output": "976"
},
{
"input": "3\n0 2\n2 1\n1 0",
"output": "2"
}
] | 1,687,445,423 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 |
n = int(input())
res = 0
x = 0
for i in range(n):
a, b = [int(i) for i in input().split()]
x -= a
x += b
if res < x:
res = x
print(res) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.
Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
Input Specification:
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement.
- The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0.
Output Specification:
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
Demo Input:
['4\n0 3\n2 5\n4 2\n4 0\n']
Demo Output:
['6\n']
Note:
For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now. - At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now. - Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer. | ```python
n = int(input())
res = 0
x = 0
for i in range(n):
a, b = [int(i) for i in input().split()]
x -= a
x += b
if res < x:
res = x
print(res)
``` | 3 |
|
612 | D | The Union of k-Segments | PROGRAMMING | 1,800 | [
"greedy",
"sortings"
] | null | null | You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order. | First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right. | [
"3 2\n0 5\n-3 2\n3 8\n",
"3 2\n0 5\n-3 3\n3 8\n"
] | [
"2\n0 2\n3 5\n",
"1\n0 5\n"
] | none | 0 | [
{
"input": "3 2\n0 5\n-3 2\n3 8",
"output": "2\n0 2\n3 5"
},
{
"input": "3 2\n0 5\n-3 3\n3 8",
"output": "1\n0 5"
},
{
"input": "1 1\n-1 1",
"output": "1\n-1 1"
},
{
"input": "10 2\n27 96\n-22 45\n-68 26\n46 69\n-91 86\n12 73\n-89 76\n-11 33\n17 47\n-57 78",
"output": "1\n-89 86"
},
{
"input": "10 1\n3 60\n-73 -37\n59 69\n-56 1\n-84 -24\n-14 46\n-65 -23\n-66 -57\n-87 -80\n-21 20",
"output": "1\n-87 69"
},
{
"input": "10 10\n-92 87\n-100 -67\n-88 80\n-82 -59\n-72 81\n-50 30\n30 77\n65 92\n-76 -60\n-29 -15",
"output": "0"
},
{
"input": "1 1\n-941727901 756748222",
"output": "1\n-941727901 756748222"
},
{
"input": "1 1\n-990637865 387517231",
"output": "1\n-990637865 387517231"
},
{
"input": "1 1\n-870080964 571991746",
"output": "1\n-870080964 571991746"
},
{
"input": "10 8\n-749560329 759073394\n-186423470 816422576\n-674251064 742056817\n-342947007 954589677\n-306243234 999298121\n-448636479 409818446\n-885248428 624359061\n-936960294 754851875\n-781500924 984124751\n-342740564 618223559",
"output": "1\n-342740564 624359061"
},
{
"input": "10 1\n-260424665 -168566709\n299109864 663179811\n769984405 942516913\n-998905510 -707148023\n-167958021 60599275\n658861231 718845364\n79407402 279078536\n13652788 79756488\n-676213666 -339118351\n-349156760 -258185154",
"output": "5\n-998905510 -707148023\n-676213666 -168566709\n-167958021 279078536\n299109864 718845364\n769984405 942516913"
},
{
"input": "10 8\n-278661264 757623461\n-751226975 996393413\n-721476675 863607399\n-228431002 643113689\n-209293138 701503607\n-433870703 932866969\n-385182911 667745533\n-661057075 783312740\n-617789923 657076219\n-890369225 990071765",
"output": "1\n-278661264 667745533"
},
{
"input": "4 2\n2 2\n2 2\n2 3\n3 3",
"output": "2\n2 2\n3 3"
},
{
"input": "2 2\n-3 1\n-4 -1",
"output": "1\n-3 -1"
},
{
"input": "1 1\n2 2",
"output": "1\n2 2"
},
{
"input": "2 1\n0 2\n-1 0",
"output": "1\n-1 2"
},
{
"input": "2 2\n-1000000000 1000000000\n-1000000000 100",
"output": "1\n-1000000000 100"
}
] | 1,451,094,534 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 18 | 4,000 | 158,924,800 | import sys
n,k=map(int,input().split())
ss=[0]*n
ee=[0]*(n+1); ee[n]=2e9
for i,inp in enumerate(sys.stdin.readlines()):
s, e = map(int,inp.split())
ss[i] = s
ee[i] = e
ss.sort()
ee.sort()
m,i,j,p=0,0,0,0
s = ""
while j<n:
if i<n and ss[i] < ee[j]:
x = ss[i]
else:
x = ee[j]
while i<n and ss[i] == x:
i += 1
m += 1
if m == k:
s += str(x) + ' '
while ee[j] == x:
if m == k:
s += str(x) + '\n'
p += 1
j += 1
m -= 1
print(p)
print(s)
| Title: The Union of k-Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* segments on the coordinate axis Ox and the number *k*. The point is satisfied if it belongs to at least *k* segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others.
Input Specification:
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=106) — the number of segments and the value of *k*.
The next *n* lines contain two integers *l**i*,<=*r**i* (<=-<=109<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) each — the endpoints of the *i*-th segment. The segments can degenerate and intersect each other. The segments are given in arbitrary order.
Output Specification:
First line contains integer *m* — the smallest number of segments.
Next *m* lines contain two integers *a**j*,<=*b**j* (*a**j*<=≤<=*b**j*) — the ends of *j*-th segment in the answer. The segments should be listed in the order from left to right.
Demo Input:
['3 2\n0 5\n-3 2\n3 8\n', '3 2\n0 5\n-3 3\n3 8\n']
Demo Output:
['2\n0 2\n3 5\n', '1\n0 5\n']
Note:
none | ```python
import sys
n,k=map(int,input().split())
ss=[0]*n
ee=[0]*(n+1); ee[n]=2e9
for i,inp in enumerate(sys.stdin.readlines()):
s, e = map(int,inp.split())
ss[i] = s
ee[i] = e
ss.sort()
ee.sort()
m,i,j,p=0,0,0,0
s = ""
while j<n:
if i<n and ss[i] < ee[j]:
x = ss[i]
else:
x = ee[j]
while i<n and ss[i] == x:
i += 1
m += 1
if m == k:
s += str(x) + ' '
while ee[j] == x:
if m == k:
s += str(x) + '\n'
p += 1
j += 1
m -= 1
print(p)
print(s)
``` | 0 |
|
673 | B | Problems for Round | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset of each division should be non-empty. - Each problem should be used in exactly one division (yes, it is unusual requirement). - Each problem used in division 1 should be harder than any problem used in division 2. - If two problems are similar, they should be used in different divisions.
Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.
Note, that the relation of similarity is not transitive. That is, if problem *i* is similar to problem *j* and problem *j* is similar to problem *k*, it doesn't follow that *i* is similar to *k*. | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). It's guaranteed, that no pair of problems meets twice in the input. | Print one integer — the number of ways to split problems in two divisions. | [
"5 2\n1 4\n5 2\n",
"3 3\n1 2\n2 3\n1 3\n",
"3 2\n3 1\n3 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together. | 750 | [
{
"input": "5 2\n1 4\n5 2",
"output": "2"
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "0"
},
{
"input": "3 2\n3 1\n3 2",
"output": "1"
},
{
"input": "2 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 0",
"output": "2"
},
{
"input": "3 1\n1 2",
"output": "1"
},
{
"input": "3 1\n1 3",
"output": "2"
},
{
"input": "100000 0",
"output": "99999"
},
{
"input": "4 2\n1 2\n3 4",
"output": "0"
},
{
"input": "3 1\n2 3",
"output": "1"
},
{
"input": "3 2\n1 2\n1 3",
"output": "1"
},
{
"input": "3 2\n1 2\n2 3",
"output": "0"
},
{
"input": "4 0",
"output": "3"
},
{
"input": "100000 1\n100000 1",
"output": "99999"
},
{
"input": "100000 1\n26711 97965",
"output": "71254"
},
{
"input": "100000 10\n99562 479\n643 99684\n593 99867\n99529 175\n99738 616\n99523 766\n99503 121\n99784 158\n199 99199\n15 99849",
"output": "98433"
},
{
"input": "10 10\n8 3\n2 8\n3 7\n3 9\n9 4\n7 2\n1 8\n1 9\n10 2\n10 1",
"output": "3"
},
{
"input": "55 1\n55 1",
"output": "54"
},
{
"input": "4 2\n1 4\n3 2",
"output": "1"
},
{
"input": "5 1\n1 5",
"output": "4"
},
{
"input": "7 1\n3 5",
"output": "2"
},
{
"input": "7 2\n1 6\n2 7",
"output": "4"
},
{
"input": "5 1\n2 3",
"output": "1"
},
{
"input": "5 2\n3 5\n1 2",
"output": "0"
},
{
"input": "4 2\n3 4\n1 2",
"output": "0"
},
{
"input": "7 2\n1 5\n5 2",
"output": "3"
},
{
"input": "7 2\n1 3\n3 6",
"output": "0"
},
{
"input": "10 11\n1 10\n1 9\n1 8\n1 7\n2 10\n2 9\n2 8\n2 7\n3 10\n3 9\n3 8",
"output": "4"
},
{
"input": "4 2\n1 2\n1 3",
"output": "1"
}
] | 1,621,286,334 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 10 | 779 | 12,288,000 | n,m=map(int,input().split())
l1=set()
l2=set()
for i in range(m):
k,t=sorted(map(int,input().split()))
l1.add(k)
l2.add(t)
if m == 0:
print(n-1)
else:
l3=set()
for i in l1:
l3.add(i)
for i in l2:
l3.add(i)
if len(l3) != len(l1)+len(l2):
print(0)
else:
if len(l3) == n:
if len(l1) != 0 and len(l2) != 0:
print(1)
else:
print(0)
else:
maxl=min(l1)
minh=min(l2)
t=0
for i in range(1,n+1):
if i not in l3:
if i < maxl:
pass
if i > minh:
pass
else:
t+=1
print(t+1)
| Title: Problems for Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules:
- Problemset of each division should be non-empty. - Each problem should be used in exactly one division (yes, it is unusual requirement). - Each problem used in division 1 should be harder than any problem used in division 2. - If two problems are similar, they should be used in different divisions.
Your goal is count the number of ways to split problem between two divisions and satisfy all the rules. Two ways to split problems are considered to be different if there is at least one problem that belongs to division 1 in one of them and to division 2 in the other.
Note, that the relation of similarity is not transitive. That is, if problem *i* is similar to problem *j* and problem *j* is similar to problem *k*, it doesn't follow that *i* is similar to *k*.
Input Specification:
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively.
Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*). It's guaranteed, that no pair of problems meets twice in the input.
Output Specification:
Print one integer — the number of ways to split problems in two divisions.
Demo Input:
['5 2\n1 4\n5 2\n', '3 3\n1 2\n2 3\n1 3\n', '3 2\n3 1\n3 2\n']
Demo Output:
['2\n', '0\n', '1\n']
Note:
In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2.
In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules.
Third sample reminds you that the similarity relation is not transitive. Problem 3 is similar to both 1 and 2, but 1 is not similar to 2, so they may be used together. | ```python
n,m=map(int,input().split())
l1=set()
l2=set()
for i in range(m):
k,t=sorted(map(int,input().split()))
l1.add(k)
l2.add(t)
if m == 0:
print(n-1)
else:
l3=set()
for i in l1:
l3.add(i)
for i in l2:
l3.add(i)
if len(l3) != len(l1)+len(l2):
print(0)
else:
if len(l3) == n:
if len(l1) != 0 and len(l2) != 0:
print(1)
else:
print(0)
else:
maxl=min(l1)
minh=min(l2)
t=0
for i in range(1,n+1):
if i not in l3:
if i < maxl:
pass
if i > minh:
pass
else:
t+=1
print(t+1)
``` | 0 |
|
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness. | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output": "2"
},
{
"input": "4\n75 13 94 77",
"output": "3"
},
{
"input": "4\n97 8 27 3",
"output": "2"
},
{
"input": "10\n95 51 12 91 85 3 1 31 25 7",
"output": "3"
},
{
"input": "20\n88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46",
"output": "4"
},
{
"input": "30\n20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36",
"output": "26"
},
{
"input": "50\n79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 97 85 9 23 1 9 3 99 77 77 21 79 69 15 37 15 7 93 81 13 89 91 31 45 93 15 97 55 80 85 83",
"output": "48"
},
{
"input": "60\n46 11 73 65 3 69 3 53 43 53 97 47 55 93 31 75 35 3 9 73 23 31 3 81 91 79 61 21 15 11 11 11 81 7 83 75 39 87 83 59 89 55 93 27 49 67 67 29 1 93 11 17 9 19 35 21 63 31 31 25",
"output": "1"
},
{
"input": "70\n28 42 42 92 64 54 22 38 38 78 62 38 4 38 14 66 4 92 66 58 94 26 4 44 41 88 48 82 44 26 74 44 48 4 16 92 34 38 26 64 94 4 30 78 50 54 12 90 8 16 80 98 28 100 74 50 36 42 92 18 76 98 8 22 2 50 58 50 64 46",
"output": "25"
},
{
"input": "100\n43 35 79 53 13 91 91 45 65 83 57 9 42 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75 73",
"output": "13"
},
{
"input": "100\n50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24 31 76",
"output": "99"
},
{
"input": "100\n47 48 94 48 14 18 94 36 96 22 12 30 94 20 48 98 40 58 2 94 8 36 98 18 98 68 2 60 76 38 18 100 8 72 100 68 2 86 92 72 58 16 48 14 6 58 72 76 6 88 80 66 20 28 74 62 86 68 90 86 2 56 34 38 56 90 4 8 76 44 32 86 12 98 38 34 54 92 70 94 10 24 82 66 90 58 62 2 32 58 100 22 58 72 2 22 68 72 42 14",
"output": "1"
},
{
"input": "99\n38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 50 74 70 94 2 94 24 66 68 46 22 30 6 10 64 32 88 14 98 100 64 58 50 18 50 50 8 38 8 16 54 2 60 54 62 84 92 98 4 72 66 26 14 88 99 16 10 6 88 56 22",
"output": "93"
},
{
"input": "99\n50 83 43 89 53 47 69 1 5 37 63 87 95 15 55 95 75 89 33 53 89 75 93 75 11 85 49 29 11 97 49 67 87 11 25 37 97 73 67 49 87 43 53 97 43 29 53 33 45 91 37 73 39 49 59 5 21 43 87 35 5 63 89 57 63 47 29 99 19 85 13 13 3 13 43 19 5 9 61 51 51 57 15 89 13 97 41 13 99 79 13 27 97 95 73 33 99 27 23",
"output": "1"
},
{
"input": "98\n61 56 44 30 58 14 20 24 88 28 46 56 96 52 58 42 94 50 46 30 46 80 72 88 68 16 6 60 26 90 10 98 76 20 56 40 30 16 96 20 88 32 62 30 74 58 36 76 60 4 24 36 42 54 24 92 28 14 2 74 86 90 14 52 34 82 40 76 8 64 2 56 10 8 78 16 70 86 70 42 70 74 22 18 76 98 88 28 62 70 36 72 20 68 34 48 80 98",
"output": "1"
},
{
"input": "98\n66 26 46 42 78 32 76 42 26 82 8 12 4 10 24 26 64 44 100 46 94 64 30 18 88 28 8 66 30 82 82 28 74 52 62 80 80 60 94 86 64 32 44 88 92 20 12 74 94 28 34 58 4 22 16 10 94 76 82 58 40 66 22 6 30 32 92 54 16 76 74 98 18 48 48 30 92 2 16 42 84 74 30 60 64 52 50 26 16 86 58 96 79 60 20 62 82 94",
"output": "93"
},
{
"input": "95\n9 31 27 93 17 77 75 9 9 53 89 39 51 99 5 1 11 39 27 49 91 17 27 79 81 71 37 75 35 13 93 4 99 55 85 11 23 57 5 43 5 61 15 35 23 91 3 81 99 85 43 37 39 27 5 67 7 33 75 59 13 71 51 27 15 93 51 63 91 53 43 99 25 47 17 71 81 15 53 31 59 83 41 23 73 25 91 91 13 17 25 13 55 57 29",
"output": "32"
},
{
"input": "100\n91 89 81 45 53 1 41 3 77 93 55 97 55 97 87 27 69 95 73 41 93 21 75 35 53 56 5 51 87 59 91 67 33 3 99 45 83 17 97 47 75 97 7 89 17 99 23 23 81 25 55 97 27 35 69 5 77 35 93 19 55 59 37 21 31 37 49 41 91 53 73 69 7 37 37 39 17 71 7 97 55 17 47 23 15 73 31 39 57 37 9 5 61 41 65 57 77 79 35 47",
"output": "26"
},
{
"input": "99\n38 56 58 98 80 54 26 90 14 16 78 92 52 74 40 30 84 14 44 80 16 90 98 68 26 24 78 72 42 16 84 40 14 44 2 52 50 2 12 96 58 66 8 80 44 52 34 34 72 98 74 4 66 74 56 21 8 38 76 40 10 22 48 32 98 34 12 62 80 68 64 82 22 78 58 74 20 22 48 56 12 38 32 72 6 16 74 24 94 84 26 38 18 24 76 78 98 94 72",
"output": "56"
},
{
"input": "100\n44 40 6 40 56 90 98 8 36 64 76 86 98 76 36 92 6 30 98 70 24 98 96 60 24 82 88 68 86 96 34 42 58 10 40 26 56 10 88 58 70 32 24 28 14 82 52 12 62 36 70 60 52 34 74 30 78 76 10 16 42 94 66 90 70 38 52 12 58 22 98 96 14 68 24 70 4 30 84 98 8 50 14 52 66 34 100 10 28 100 56 48 38 12 38 14 91 80 70 86",
"output": "97"
},
{
"input": "100\n96 62 64 20 90 46 56 90 68 36 30 56 70 28 16 64 94 34 6 32 34 50 94 22 90 32 40 2 72 10 88 38 28 92 20 26 56 80 4 100 100 90 16 74 74 84 8 2 30 20 80 32 16 46 92 56 42 12 96 64 64 42 64 58 50 42 74 28 2 4 36 32 70 50 54 92 70 16 45 76 28 16 18 50 48 2 62 94 4 12 52 52 4 100 70 60 82 62 98 42",
"output": "79"
},
{
"input": "99\n14 26 34 68 90 58 50 36 8 16 18 6 2 74 54 20 36 84 32 50 52 2 26 24 3 64 20 10 54 26 66 44 28 72 4 96 78 90 96 86 68 28 94 4 12 46 100 32 22 36 84 32 44 94 76 94 4 52 12 30 74 4 34 64 58 72 44 16 70 56 54 8 14 74 8 6 58 62 98 54 14 40 80 20 36 72 28 98 20 58 40 52 90 64 22 48 54 70 52",
"output": "25"
},
{
"input": "95\n82 86 30 78 6 46 80 66 74 72 16 24 18 52 52 38 60 36 86 26 62 28 22 46 96 26 94 84 20 46 66 88 76 32 12 86 74 18 34 88 4 48 94 6 58 6 100 82 4 24 88 32 54 98 34 48 6 76 42 88 42 28 100 4 22 2 10 66 82 54 98 20 60 66 38 98 32 47 86 58 6 100 12 46 2 42 8 84 78 28 24 70 34 28 86",
"output": "78"
},
{
"input": "90\n40 50 8 42 76 24 58 42 26 68 20 48 54 12 34 84 14 36 32 88 6 50 96 56 20 92 48 16 40 34 96 46 20 84 30 50 20 98 8 44 96 42 8 76 70 38 84 30 40 88 84 72 2 22 52 58 16 62 100 66 80 40 50 32 14 62 88 72 22 99 76 50 84 82 8 82 98 46 26 40 2 98 18 78 30 72 70 18 34 68",
"output": "70"
},
{
"input": "80\n81 43 87 1 55 43 53 61 27 19 43 13 89 9 33 83 75 55 97 71 91 37 95 5 21 69 81 93 95 69 31 83 55 7 97 7 79 57 8 61 27 85 49 1 15 97 63 79 29 73 41 85 5 41 31 93 67 11 63 59 15 99 91 77 43 69 23 23 81 73 19 1 67 51 1 75 99 67 3 81",
"output": "39"
},
{
"input": "98\n13 83 61 27 35 1 85 95 97 73 95 65 73 45 5 43 27 83 91 19 11 3 85 59 9 39 69 23 45 7 51 85 5 71 5 95 1 51 75 3 43 57 3 11 33 71 21 99 47 41 87 39 71 87 31 85 91 49 83 5 49 85 47 91 55 99 33 23 31 23 23 73 29 77 55 31 25 5 81 49 91 15 15 39 87 5 9 40 69 47 29 33 11 21 49 79 51 83",
"output": "88"
},
{
"input": "3\n100 100 1",
"output": "3"
}
] | 1,636,211,742 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 154 | 17,715,200 | n = int(input())
arr = list(map(int, input().split()))
even = 0
odd = 0
is_even = False
for i in arr:
if i % 2 == 1:
odd += 1
else:
even += 1
if even > odd:
is_even = True
for i in range(len(arr)):
if is_even:
if arr[i] % 2 == 1:
print(i + 1)
else:
if arr[i] % 2 == 0:
print(i + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that is different in evenness.
Input Specification:
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output Specification:
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
Demo Input:
['5\n2 4 7 8 10\n', '4\n1 2 1 1\n']
Demo Output:
['3\n', '2\n']
Note:
none | ```python
n = int(input())
arr = list(map(int, input().split()))
even = 0
odd = 0
is_even = False
for i in arr:
if i % 2 == 1:
odd += 1
else:
even += 1
if even > odd:
is_even = True
for i in range(len(arr)):
if is_even:
if arr[i] % 2 == 1:
print(i + 1)
else:
if arr[i] % 2 == 0:
print(i + 1)
``` | 3.928503 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chnenu"
},
{
"input": "ERPZGrodyu",
"output": "erpzgrodyu"
},
{
"input": "KSXBXWpebh",
"output": "KSXBXWPEBH"
},
{
"input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv",
"output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv"
},
{
"input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd",
"output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd"
},
{
"input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv",
"output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv"
},
{
"input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg",
"output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg"
},
{
"input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak",
"output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK"
},
{
"input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw",
"output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW"
},
{
"input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB",
"output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB"
},
{
"input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge",
"output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge"
},
{
"input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw",
"output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw"
},
{
"input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks",
"output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks"
},
{
"input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz",
"output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ"
},
{
"input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg",
"output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG"
},
{
"input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO",
"output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO"
},
{
"input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd",
"output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD"
},
{
"input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas",
"output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas"
},
{
"input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm",
"output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM"
},
{
"input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn",
"output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn"
},
{
"input": "t",
"output": "t"
},
{
"input": "N",
"output": "N"
},
{
"input": "kv",
"output": "kv"
},
{
"input": "Ur",
"output": "ur"
},
{
"input": "CN",
"output": "CN"
}
] | 1,635,566,977 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 4,300,800 | name=input()
n=len(name)
count=0
for x in name:
if x.isupper():
count+=1
if count<=(n/2):
print(name.lower())
elif count>(n/2):
print(name.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
Input Specification:
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Output Specification:
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
Demo Input:
['HoUse\n', 'ViP\n', 'maTRIx\n']
Demo Output:
['house\n', 'VIP\n', 'matrix\n']
Note:
none | ```python
name=input()
n=len(name)
count=0
for x in name:
if x.isupper():
count+=1
if count<=(n/2):
print(name.lower())
elif count>(n/2):
print(name.upper())
``` | 3.961489 |
112 | A | Petya and Strings | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Petya and Strings | 2 | 256 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. | Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. | If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. | [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n"
] | [
"0\n",
"-1\n",
"1\n"
] | If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | 500 | [
{
"input": "aaaa\naaaA",
"output": "0"
},
{
"input": "abs\nAbz",
"output": "-1"
},
{
"input": "abcdefg\nAbCdEfF",
"output": "1"
},
{
"input": "asadasdasd\nasdwasdawd",
"output": "-1"
},
{
"input": "aslkjlkasdd\nasdlkjdajwi",
"output": "1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "aAaaaAAaAaaAzZsssSsdDfeEaeqZlpP\nAaaaAaaAaaAaZzSSSSsDdFeeAeQZLpp",
"output": "0"
},
{
"input": "bwuEhEveouaTECagLZiqmUdxEmhRSOzMauJRWLQMppZOumxhAmwuGeDIkvkBLvMXwUoFmpAfDprBcFtEwOULcZWRQhcTbTbX\nHhoDWbcxwiMnCNexOsKsujLiSGcLllXOkRSbnOzThAjnnliLYFFmsYkOfpTxRNEfBsoUHfoLTiqAINRPxWRqrTJhgfkKcDOH",
"output": "-1"
},
{
"input": "kGWUuguKzcvxqKTNpxeDWXpXkrXDvGMFGoXKDfPBZvWSDUyIYBynbKOUonHvmZaKeirUhfmVRKtGhAdBfKMWXDUoqvbfpfHYcg\ncvOULleuIIiYVVxcLZmHVpNGXuEpzcWZZWyMOwIwbpkKPwCfkVbKkUuosvxYCKjqfVmHfJKbdrsAcatPYgrCABaFcoBuOmMfFt",
"output": "1"
},
{
"input": "nCeNVIzHqPceNhjHeHvJvgBsNFiXBATRrjSTXJzhLMDMxiJztphxBRlDlqwDFImWeEPkggZCXSRwelOdpNrYnTepiOqpvkr\nHJbjJFtlvNxIbkKlxQUwmZHJFVNMwPAPDRslIoXISBYHHfymyIaQHLgECPxAmqnOCizwXnIUBRmpYUBVPenoUKhCobKdOjL",
"output": "1"
},
{
"input": "ttXjenUAlfixytHEOrPkgXmkKTSGYuyVXGIHYmWWYGlBYpHkujueqBSgjLguSgiMGJWATIGEUjjAjKXdMiVbHozZUmqQtFrT\nJziDBFBDmDJCcGqFsQwDFBYdOidLxxhBCtScznnDgnsiStlWFnEXQrJxqTXKPxZyIGfLIToETKWZBPUIBmLeImrlSBWCkTNo",
"output": "1"
},
{
"input": "AjQhPqSVhwQQjcgCycjKorWBgFCRuQBwgdVuAPSMJAvTyxGVuFHjfJzkKfsmfhFbKqFrFIohSZBbpjgEHebezmVlGLTPSCTMf\nXhxWuSnMmKFrCUOwkTUmvKAfbTbHWzzOTzxJatLLCdlGnHVaBUnxDlsqpvjLHMThOPAFBggVKDyKBrZAmjnjrhHlrnSkyzBja",
"output": "-1"
},
{
"input": "HCIgYtnqcMyjVngziNflxKHtdTmcRJhzMAjFAsNdWXFJYEhiTzsQUtFNkAbdrFBRmvLirkuirqTDvIpEfyiIqkrwsjvpPWTEdI\nErqiiWKsmIjyZuzgTlTqxYZwlrpvRyaVhRTOYUqtPMVGGtWOkDCOOQRKrkkRzPftyQCkYkzKkzTPqqXmeZhvvEEiEhkdOmoMvy",
"output": "1"
},
{
"input": "mtBeJYILXcECGyEVSyzLFdQJbiVnnfkbsYYsdUJSIRmyzLfTTtFwIBmRLVnwcewIqcuydkcLpflHAFyDaToLiFMgeHvQorTVbI\nClLvyejznjbRfCDcrCzkLvqQaGzTjwmWONBdCctJAPJBcQrcYvHaSLQgPIJbmkFBhFzuQLBiRzAdNHulCjIAkBvZxxlkdzUWLR",
"output": "1"
},
{
"input": "tjucSbGESVmVridTBjTmpVBCwwdWKBPeBvmgdxgIVLwQxveETnSdxkTVJpXoperWSgdpPMKNmwDiGeHfxnuqaDissgXPlMuNZIr\nHfjOOJhomqNIKHvqSgfySjlsWJQBuWYwhLQhlZYlpZwboMpoLoluGsBmhhlYgeIouwdkPfiaAIrkYRlxtiFazOPOllPsNZHcIZd",
"output": "1"
},
{
"input": "AanbDfbZNlUodtBQlvPMyomStKNhgvSGhSbTdabxGFGGXCdpsJDimsAykKjfBDPMulkhBMsqLmVKLDoesHZsRAEEdEzqigueXInY\ncwfyjoppiJNrjrOLNZkqcGimrpTsiyFBVgMWEPXsMrxLJDDbtYzerXiFGuLBcQYitLdqhGHBpdjRnkUegmnwhGHAKXGyFtscWDSI",
"output": "-1"
},
{
"input": "HRfxniwuJCaHOcaOVgjOGHXKrwxrDQxJpppeGDXnTAowyKbCsCQPbchCKeTWOcKbySSYnoaTJDnmRcyGPbfXJyZoPcARHBu\nxkLXvwkvGIWSQaFTznLOctUXNuzzBBOlqvzmVfTSejekTAlwidRrsxkbZTsGGeEWxCXHzqWVuLGoCyrGjKkQoHqduXwYQKC",
"output": "-1"
},
{
"input": "OjYwwNuPESIazoyLFREpObIaMKhCaKAMWMfRGgucEuyNYRantwdwQkmflzfqbcFRaXBnZoIUGsFqXZHGKwlaBUXABBcQEWWPvkjW\nRxLqGcTTpBwHrHltCOllnTpRKLDofBUqqHxnOtVWPgvGaeHIevgUSOeeDOJubfqonFpVNGVbHFcAhjnyFvrrqnRgKhkYqQZmRfUl",
"output": "-1"
},
{
"input": "tatuhQPIzjptlzzJpCAPXSRTKZRlwgfoCIsFjJquRoIDyZZYRSPdFUTjjUPhLBBfeEIfLQpygKXRcyQFiQsEtRtLnZErBqW\ntkHUjllbafLUWhVCnvblKjgYIEoHhsjVmrDBmAWbvtkHxDbRFvsXAjHIrujaDbYwOZmacknhZPeCcorbRgHjjgAgoJdjvLo",
"output": "-1"
},
{
"input": "cymCPGqdXKUdADEWDdUaLEEMHiXHsdAZuDnJDMUvxvrLRBrPSDpXPAgMRoGplLtniFRTomDTAHXWAdgUveTxaqKVSvnOyhOwiRN\nuhmyEWzapiRNPFDisvHTbenXMfeZaHqOFlKjrfQjUBwdFktNpeiRoDWuBftZLcCZZAVfioOihZVNqiNCNDIsUdIhvbcaxpTRWoV",
"output": "-1"
},
{
"input": "sSvpcITJAwghVfJaLKBmyjOkhltTGjYJVLWCYMFUomiJaKQYhXTajvZVHIMHbyckYROGQZzjWyWCcnmDmrkvTKfHSSzCIhsXgEZa\nvhCXkCwAmErGVBPBAnkSYEYvseFKbWSktoqaHYXUmYkHfOkRwuEyBRoGoBrOXBKVxXycjZGStuvDarnXMbZLWrbjrisDoJBdSvWJ",
"output": "-1"
},
{
"input": "hJDANKUNBisOOINDsTixJmYgHNogtpwswwcvVMptfGwIjvqgwTYFcqTdyAqaqlnhOCMtsnWXQqtjFwQlEcBtMFAtSqnqthVb\nrNquIcjNWESjpPVWmzUJFrelpUZeGDmSvCurCqVmKHKVAAPkaHksniOlzjiKYIJtvbuQWZRufMebpTFPqyxIWWjfPaWYiNlK",
"output": "-1"
},
{
"input": "ycLoapxsfsDTHMSfAAPIUpiEhQKUIXUcXEiopMBuuZLHtfPpLmCHwNMNQUwsEXxCEmKHTBSnKhtQhGWUvppUFZUgSpbeChX\ndCZhgVXofkGousCzObxZSJwXcHIaqUDSCPKzXntcVmPxtNcXmVcjsetZYxedmgQzXTZHMvzjoaXCMKsncGciSDqQWIIRlys",
"output": "1"
},
{
"input": "nvUbnrywIePXcoukIhwTfUVcHUEgXcsMyNQhmMlTltZiCooyZiIKRIGVHMCnTKgzXXIuvoNDEZswKoACOBGSyVNqTNQqMhAG\nplxuGSsyyJjdvpddrSebOARSAYcZKEaKjqbCwvjhNykuaECoQVHTVFMKXwvrQXRaqXsHsBaGVhCxGRxNyGUbMlxOarMZNXxy",
"output": "-1"
},
{
"input": "EncmXtAblQzcVRzMQqdDqXfAhXbtJKQwZVWyHoWUckohnZqfoCmNJDzexFgFJYrwNHGgzCJTzQQFnxGlhmvQTpicTkEeVICKac\nNIUNZoMLFMyAjVgQLITELJSodIXcGSDWfhFypRoGYuogJpnqGTotWxVqpvBHjFOWcDRDtARsaHarHaOkeNWEHGTaGOFCOFEwvK",
"output": "-1"
},
{
"input": "UG\nak",
"output": "1"
},
{
"input": "JZR\nVae",
"output": "-1"
},
{
"input": "a\nZ",
"output": "-1"
},
{
"input": "rk\nkv",
"output": "1"
},
{
"input": "RvuT\nbJzE",
"output": "1"
},
{
"input": "PPS\nydq",
"output": "-1"
},
{
"input": "q\nq",
"output": "0"
},
{
"input": "peOw\nIgSJ",
"output": "1"
},
{
"input": "PyK\noKN",
"output": "1"
},
{
"input": "O\ni",
"output": "1"
},
{
"input": "NmGY\npDlP",
"output": "-1"
},
{
"input": "nG\nZf",
"output": "-1"
},
{
"input": "m\na",
"output": "1"
},
{
"input": "MWyB\nWZEV",
"output": "-1"
},
{
"input": "Gre\nfxc",
"output": "1"
},
{
"input": "Ooq\nwap",
"output": "-1"
},
{
"input": "XId\nlbB",
"output": "1"
},
{
"input": "lfFpECEqUMEOJhipvkZjDPcpDNJedOVXiSMgBvBZbtfzIKekcvpWPCazKAhJyHircRtgcBIJwwstpHaLAgxFOngAWUZRgCef\nLfFPEcequmeojHIpVkzjDPcpdNJEDOVXiSmGBVBZBtfZikEKcvPwpCAzKAHJyHIrCRTgCbIJWwSTphALagXfOnGAwUzRGcEF",
"output": "0"
},
{
"input": "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZJHGtxGFxnwSvYxnTLgmKlmFVRCzyEtBVdmKpJjiVioKMDgCFhzoTODiYrKwXD",
"output": "0"
},
{
"input": "tYWRijFQSzHBpCjUzqBtNvBKyzZRnIdWEuyqnORBQTLyOQglIGfYJIRjuxnbLvkqZakNqPiGDvgpWYkfxYNXsdoKXZtRkSasfa\nTYwRiJfqsZHBPcJuZQBTnVbkyZZRnidwEuYQnorbQTLYOqGligFyjirJUxnblVKqZaknQpigDVGPwyKfxyNXSDoKxztRKSaSFA",
"output": "0"
},
{
"input": "KhScXYiErQIUtmVhNTCXSLAviefIeHIIdiGhsYnPkSBaDTvMkyanfMLBOvDWgRybLtDqvXVdVjccNunDyijhhZEAKBrdz\nkHsCXyiErqIuTMVHNTCxSLaViEFIEhIIDiGHsYNpKsBAdTvMKyANFMLBovdwGRYbLtdQVxvDVJCcNUndYiJHhzeakBrdZ",
"output": "0"
},
{
"input": "cpPQMpjRQJKQVXjWDYECXbagSmNcVfOuBWNZxihdERraVuiOpSVDCPgTGuSQALNoVjySceHcKXwOEpSzXrEqWwwrYeppNiWhDVg\nCPPqmPjRqJkQvxJwdyECXBAGsMNcVfOuBWNzxIhderRavUiOpSvDCpGTgusqAlNovjyScEhCKXwoePSZxrEQwWwryEPPniWHDvG",
"output": "0"
},
{
"input": "SajcCGMepaLjZIWLRBGFcrZRCRvvoCsIyKsQerbrwsIamxxpRmQSZSalasJLVFbCHCuXJlubciQAvLxXYBazLsMKLHLdDQ\nsaJcCgmEpaLJziWlrBgFcRzrCrVVOcSIykSQerBrwSIamxxPrMqSzSalASjLVFbChCUxjLUbCIQAVlxxybAZLsmkLhLDdQ",
"output": "0"
},
{
"input": "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ",
"output": "0"
},
{
"input": "nTomZZuTTRTAAPoUsySVFGElrpQRNLjqvFmcYytiheQnjUhPLnqNBiYtQkljbcvmjuNAVKbvQOWpqqFlQhAhULIhquoCnjUI\nntOmzZuttrtAAPOUSySVFgeLRPQrNLjQvfmCyYTiHEQnjuHPlNQNbIYtqKLJBCVmjunavkbvQOWPQQFlqHaHULIHQuOcnJUi",
"output": "0"
},
{
"input": "abac\nadaa",
"output": "-1"
},
{
"input": "Bbc\nabc",
"output": "1"
},
{
"input": "aaaba\naaaab",
"output": "1"
}
] | 1,696,578,647 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | s1=input()
a=s1.lower()
s2=input()
b=s2.lower()
os1=0
os2=0
for i in a:
os1+= ord(i)
for i in b:
os2+= ord(i)
if os1==os2:
print(0)
if os1<os2:
print('-1')
if os2<os1:
print(1)
| Title: Petya and Strings
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.
Input Specification:
Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.
Output Specification:
If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.
Demo Input:
['aaaa\naaaA\n', 'abs\nAbz\n', 'abcdefg\nAbCdEfF\n']
Demo Output:
['0\n', '-1\n', '1\n']
Note:
If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site:
- http://en.wikipedia.org/wiki/Lexicographical_order | ```python
s1=input()
a=s1.lower()
s2=input()
b=s2.lower()
os1=0
os2=0
for i in a:
os1+= ord(i)
for i in b:
os2+= ord(i)
if os1==os2:
print(0)
if os1<os2:
print('-1')
if os2<os1:
print(1)
``` | 0 |
598 | B | Queries on a String | PROGRAMMING | 1,300 | [
"implementation",
"strings"
] | null | null | You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa. | The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query. | Print the resulting string *s* after processing all *m* queries. | [
"abacaba\n2\n3 6 1\n1 4 2\n"
] | [
"baabcaa\n"
] | The sample is described in problem statement. | 0 | [
{
"input": "abacaba\n2\n3 6 1\n1 4 2",
"output": "baabcaa"
},
{
"input": "u\n1\n1 1 1",
"output": "u"
},
{
"input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4",
"output": "p"
},
{
"input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6",
"output": "ssssssssss"
},
{
"input": "tcpyzttcpo\n10\n2 3 6\n2 4 1\n2 6 9\n7 10 5\n2 3 5\n4 5 6\n3 4 5\n7 9 4\n9 10 7\n1 10 8",
"output": "zctycopttp"
},
{
"input": "yywlblbblw\n10\n4 7 2\n3 8 2\n4 10 6\n4 7 1\n3 9 6\n1 7 3\n3 7 3\n3 7 1\n1 8 7\n2 7 5",
"output": "bylwlwylbb"
},
{
"input": "thisisahacktest\n1\n1 2 1",
"output": "htisisahacktest"
},
{
"input": "ozozumuhackleyan\n1\n1 4 1",
"output": "zozoumuhackleyan"
},
{
"input": "lacongaithattuyet\n1\n1 1 1",
"output": "lacongaithattuyet"
}
] | 1,638,445,141 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 62 | 307,200 | import sys
import math
input=sys.stdin.readline
INF=int(1e9)+7
def solve(): # 123456
s=input().rstrip()
for _ in range(int(input())):
l,r,k=map(int,input().split())
l-=1
r-=1
length=r-l+1
k%=length
s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]
print(s)
t=1
while t:
t-=1
solve()
| Title: Queries on a String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given.
One operation of a cyclic shift (rotation) is equivalent to moving the last character to the position of the first character and shifting all other characters one position to the right.
For example, if the string *s* is abacaba and the query is *l*1<==<=3,<=*r*1<==<=6,<=*k*1<==<=1 then the answer is abbacaa. If after that we would process the query *l*2<==<=1,<=*r*2<==<=4,<=*k*2<==<=2 then we would get the string baabcaa.
Input Specification:
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters.
Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries.
The *i*-th of the next *m* lines contains three integers *l**i*, *r**i* and *k**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=|*s*|,<=1<=≤<=*k**i*<=≤<=1<=000<=000) — the description of the *i*-th query.
Output Specification:
Print the resulting string *s* after processing all *m* queries.
Demo Input:
['abacaba\n2\n3 6 1\n1 4 2\n']
Demo Output:
['baabcaa\n']
Note:
The sample is described in problem statement. | ```python
import sys
import math
input=sys.stdin.readline
INF=int(1e9)+7
def solve(): # 123456
s=input().rstrip()
for _ in range(int(input())):
l,r,k=map(int,input().split())
l-=1
r-=1
length=r-l+1
k%=length
s=s[:l]+s[r-k+1:r+1]+s[l:r-k+1]+s[r+1:]
print(s)
t=1
while t:
t-=1
solve()
``` | 3 |
|
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below). | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input. | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
},
{
"input": "55",
"output": "composite 6"
},
{
"input": "89",
"output": "prime 15"
},
{
"input": "3",
"output": "prime 16"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "8",
"output": "composite 2"
},
{
"input": "11",
"output": "prime 15"
},
{
"input": "12",
"output": "composite 2"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "36",
"output": "composite 2"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "51",
"output": "composite 8"
},
{
"input": "53",
"output": "prime 15"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "64",
"output": "composite 2"
},
{
"input": "81",
"output": "composite 3"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "97",
"output": "prime 15"
},
{
"input": "99",
"output": "composite 3"
},
{
"input": "100",
"output": "composite 2"
},
{
"input": "26",
"output": "composite 7"
},
{
"input": "94",
"output": "composite 16"
},
{
"input": "25",
"output": "composite 4"
},
{
"input": "46",
"output": "composite 10"
},
{
"input": "49",
"output": "composite 5"
},
{
"input": "82",
"output": "composite 14"
},
{
"input": "87",
"output": "composite 11"
},
{
"input": "85",
"output": "composite 8"
},
{
"input": "74",
"output": "composite 13"
},
{
"input": "86",
"output": "composite 15"
},
{
"input": "93",
"output": "composite 12"
},
{
"input": "58",
"output": "composite 11"
},
{
"input": "47",
"output": "prime 15"
},
{
"input": "22",
"output": "composite 6"
},
{
"input": "23",
"output": "prime 15"
},
{
"input": "62",
"output": "composite 12"
},
{
"input": "38",
"output": "composite 9"
},
{
"input": "91",
"output": "composite 7"
},
{
"input": "34",
"output": "composite 8"
},
{
"input": "95",
"output": "composite 9"
},
{
"input": "4",
"output": "composite 2"
},
{
"input": "16",
"output": "composite 2"
},
{
"input": "96",
"output": "composite 2"
},
{
"input": "69",
"output": "composite 10"
},
{
"input": "65",
"output": "composite 7"
},
{
"input": "6",
"output": "composite 4"
},
{
"input": "18",
"output": "composite 4"
}
] | 1,641,678,580 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import sys
primes = [2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37, 41, 43, 47]
count = 0
for i in primes:
sys.stdout.flush(i)
x = sys.stdin()
if x == "yes":
count += 1
if count > 1:
sys.stdout.flush("composite")
else:
sys.stdout.flush("prime")
| Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=><=1 is not prime, it's called composite.
You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".
For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.
When you are done asking queries, print "prime" or "composite" and terminate your program.
You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.
You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).
Input Specification:
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Output Specification:
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program.
To flush you can use (just after printing an integer and end-of-line):
- fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages.
Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input.
Demo Input:
['yes\nno\nyes\n', 'no\nyes\nno\nno\nno\n']
Demo Output:
['2\n80\n5\ncomposite\n', '58\n59\n78\n78\n2\nprime\n']
Note:
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/>
59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries). | ```python
import sys
primes = [2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37, 41, 43, 47]
count = 0
for i in primes:
sys.stdout.flush(i)
x = sys.stdin()
if x == "yes":
count += 1
if count > 1:
sys.stdout.flush("composite")
else:
sys.stdout.flush("prime")
``` | -1 |
|
967 | A | Mind the Gap | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff. | The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. | Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. | [
"6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n",
"16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n",
"3 17\n0 30\n1 0\n12 0\n"
] | [
"6 1\n",
"24 50\n",
"0 0\n"
] | In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | 500 | [
{
"input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40",
"output": "6 1"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "24 50"
},
{
"input": "3 17\n0 30\n1 0\n12 0",
"output": "0 0"
},
{
"input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7",
"output": "23 8"
},
{
"input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22",
"output": "6 47"
},
{
"input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37",
"output": "23 58"
},
{
"input": "66 20\n0 16\n0 45\n0 58\n1 6\n1 19\n2 7\n2 9\n3 9\n3 25\n3 57\n4 38\n4 58\n5 21\n5 40\n6 16\n6 19\n6 58\n7 6\n7 26\n7 51\n8 13\n8 36\n8 55\n9 1\n9 15\n9 33\n10 12\n10 37\n11 15\n11 34\n12 8\n12 37\n12 55\n13 26\n14 0\n14 34\n14 36\n14 48\n15 23\n15 29\n15 43\n16 8\n16 41\n16 45\n17 5\n17 7\n17 15\n17 29\n17 46\n18 12\n18 19\n18 38\n18 57\n19 32\n19 58\n20 5\n20 40\n20 44\n20 50\n21 18\n21 49\n22 18\n22 47\n23 1\n23 38\n23 50",
"output": "1 40"
},
{
"input": "1 1\n0 0",
"output": "0 2"
},
{
"input": "10 1\n0 2\n0 4\n0 5\n0 8\n0 9\n0 11\n0 13\n0 16\n0 19\n0 21",
"output": "0 0"
},
{
"input": "10 1\n0 2\n0 5\n0 8\n0 11\n0 15\n0 17\n0 25\n0 28\n0 29\n0 32",
"output": "0 0"
},
{
"input": "15 20\n0 47\n2 24\n4 19\n4 34\n5 46\n8 15\n9 8\n10 28\n17 47\n17 52\n18 32\n19 50\n20 46\n20 50\n23 21",
"output": "0 0"
},
{
"input": "1 5\n1 0",
"output": "0 0"
},
{
"input": "24 60\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "1 30\n0 29",
"output": "1 0"
},
{
"input": "1 2\n3 0",
"output": "0 0"
},
{
"input": "16 60\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59",
"output": "25 0"
},
{
"input": "1 5\n0 6",
"output": "0 0"
},
{
"input": "2 60\n0 59\n23 59",
"output": "2 0"
},
{
"input": "1 58\n0 1",
"output": "1 0"
},
{
"input": "25 60\n0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n8 0\n9 0\n10 0\n11 0\n12 0\n13 0\n14 0\n15 0\n16 0\n17 0\n18 0\n19 0\n20 0\n21 0\n22 0\n23 0\n23 59",
"output": "25 0"
},
{
"input": "2 3\n0 3\n0 30",
"output": "0 7"
},
{
"input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 9",
"output": "24 0"
},
{
"input": "1 60\n2 0",
"output": "0 0"
},
{
"input": "2 60\n0 0\n5 0",
"output": "1 1"
},
{
"input": "1 30\n0 31",
"output": "0 0"
},
{
"input": "2 60\n0 59\n3 1",
"output": "2 0"
},
{
"input": "2 60\n0 59\n5 0",
"output": "2 0"
},
{
"input": "1 59\n0 0",
"output": "1 0"
},
{
"input": "3 25\n0 0\n1 0\n2 0",
"output": "0 26"
},
{
"input": "1 2\n2 3",
"output": "0 0"
}
] | 1,565,676,503 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | R = lambda : map(int, input().split())
n,k = R()
a = 0
for _ in range(n):
h,m = R()
b = h*60+m
if _ ==0:
if b-a>=k+1:
print(0,0)
exit(0)
else:
a = b
else:
if b-a>=k*2+2:
print((a+k+1)//60,(a+k+1)%60)
exit(0)
else:
a = b
print((a+k+1)//60,(a+k+1)%60)
| Title: Mind the Gap
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute.
He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides.
Find the earliest time when Arkady can insert the takeoff.
Input Specification:
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff.
Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order.
Output Specification:
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
Demo Input:
['6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n', '16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n', '3 17\n0 30\n1 0\n12 0\n']
Demo Output:
['6 1\n', '24 50\n', '0 0\n']
Note:
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute.
In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff.
In the third example Arkady can insert the takeoff even between the first landing. | ```python
R = lambda : map(int, input().split())
n,k = R()
a = 0
for _ in range(n):
h,m = R()
b = h*60+m
if _ ==0:
if b-a>=k+1:
print(0,0)
exit(0)
else:
a = b
else:
if b-a>=k*2+2:
print((a+k+1)//60,(a+k+1)%60)
exit(0)
else:
a = b
print((a+k+1)//60,(a+k+1)%60)
``` | 3 |
|
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii". | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
"input": "99\nxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxaxxa",
"output": "0"
},
{
"input": "3\nxxx",
"output": "1"
},
{
"input": "77\naaabbbcccdddeeefffggghhhiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxyyyzzz",
"output": "0"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxxxxmrx",
"output": "41"
},
{
"input": "100\nxxxxxxxxxxxjtxxxxxxxxcxxxxxxcfxxxxzxxxxxxgxxxxxbxxxxbxxxxxxxxdycxxxxokixxxkizxxgcxxxxxxxxexxxxxfxxxc",
"output": "49"
},
{
"input": "100\nuxxxxxlmexxxxxxxwnxxexxxxxcxxfydxxxxxxvmdxxxxxxisxxxxxxxxidkxxxpxxxxxxxxmnuxxxxjxxxqcxxwmxxxxxwxxxxx",
"output": "41"
},
{
"input": "34\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"output": "0"
},
{
"input": "5\nfcyju",
"output": "0"
},
{
"input": "100\nihygyvdvyeifomhxhkhdkimquvgallbqharcyriyqkidnwykozuhvkwdldlztpabgyuflikychqpdenwzgtlzotyumjgdsrbxxxx",
"output": "2"
}
] | 1,665,572,994 | 2,147,483,647 | PyPy 3-64 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n = int(input())
s = input()
invalid = 0
for x in range(N):
if s[x] == 'x',s[x+1] == 'x',s[x+2] == 'x':
ans += 1
print(ans) | Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the social network topic. In this case, the file is not sent and an error message is displayed.
Determine the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. Print 0 if the file name does not initially contain a forbidden substring "xxx".
You can delete characters in arbitrary positions (not necessarily consecutive). If you delete a character, then the length of a string is reduced by $1$. For example, if you delete the character in the position $2$ from the string "exxxii", then the resulting string is "exxii".
Input Specification:
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Output Specification:
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
Demo Input:
['6\nxxxiii\n', '5\nxxoxx\n', '10\nxxxxxxxxxx\n']
Demo Output:
['1\n', '0\n', '8\n']
Note:
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | ```python
n = int(input())
s = input()
invalid = 0
for x in range(N):
if s[x] == 'x',s[x+1] == 'x',s[x+2] == 'x':
ans += 1
print(ans)
``` | -1 |
|
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes. | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions. | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 57 78\n66 60 45"
},
{
"input": "0 17 14\n15 0 15\n16 13 0",
"output": "14 17 14\n15 15 15\n16 13 16"
},
{
"input": "0 97 56\n69 0 71\n84 43 0",
"output": "57 97 56\n69 70 71\n84 43 83"
},
{
"input": "0 1099 1002\n1027 0 1049\n1074 977 0",
"output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063"
},
{
"input": "0 98721 99776\n99575 0 99123\n98922 99977 0",
"output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148"
},
{
"input": "0 6361 2304\n1433 0 8103\n7232 3175 0",
"output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897"
},
{
"input": "0 99626 99582\n99766 0 99258\n99442 99398 0",
"output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696"
},
{
"input": "0 99978 99920\n99950 0 99918\n99948 99890 0",
"output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964"
},
{
"input": "0 840 666\n612 0 948\n894 720 0",
"output": "834 840 666\n612 780 948\n894 720 726"
},
{
"input": "0 28 10\n12 0 24\n26 8 0",
"output": "16 28 10\n12 18 24\n26 8 20"
},
{
"input": "0 120 83\n98 0 90\n105 68 0",
"output": "79 120 83\n98 94 90\n105 68 109"
},
{
"input": "0 86900 85807\n85836 0 86842\n86871 85778 0",
"output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368"
},
{
"input": "0 74 78\n78 0 74\n74 78 0",
"output": "76 74 78\n78 76 74\n74 78 76"
},
{
"input": "0 505 681\n605 0 657\n581 757 0",
"output": "707 505 681\n605 631 657\n581 757 555"
},
{
"input": "0 662 918\n822 0 854\n758 1014 0",
"output": "934 662 918\n822 838 854\n758 1014 742"
},
{
"input": "0 93 95\n93 0 97\n95 97 0",
"output": "97 93 95\n93 95 97\n95 97 93"
},
{
"input": "0 709 712\n719 0 695\n702 705 0",
"output": "700 709 712\n719 707 695\n702 705 714"
},
{
"input": "0 7 6\n9 0 1\n4 3 0",
"output": "2 7 6\n9 5 1\n4 3 8"
},
{
"input": "0 9 2\n3 0 7\n8 1 0",
"output": "4 9 2\n3 5 7\n8 1 6"
},
{
"input": "0 1 43\n13 0 61\n31 73 0",
"output": "67 1 43\n13 37 61\n31 73 7"
},
{
"input": "0 100000 100000\n100000 0 100000\n100000 100000 0",
"output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000"
}
] | 1,626,194,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 6,963,200 | a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
g,h,i=list(map(int,input().split()))
print(f+h//2,b,c)
print(d,c+g//2,f)
print(g,h,b+d//2)
| Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.
The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.
Help the Little Elephant, restore the original magic square, given the Elephant's notes.
Input Specification:
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.
It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Output Specification:
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditions.
Demo Input:
['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n']
Demo Output:
['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n']
Note:
none | ```python
a,b,c=list(map(int,input().split()))
d,e,f=list(map(int,input().split()))
g,h,i=list(map(int,input().split()))
print(f+h//2,b,c)
print(d,c+g//2,f)
print(g,h,b+d//2)
``` | 0 |
|
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input": "3\nnjfngnrurunrgunrunvurn\njfvnjfdnvjdbfvsbdubruvbubvkdb\nksdnvidnviudbvibd",
"output": "n20n\nj27b\nk15d"
},
{
"input": "1\ntcyctkktcctrcyvbyiuhihhhgyvyvyvyvjvytchjckt",
"output": "t41t"
},
{
"input": "24\nyou\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nunofficially\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings",
"output": "you\nare\nregistered\nfor\npractice\nyou\ncan\nsolve\nproblems\nu10y\nresults\ncan\nbe\nfound\nin\nthe\ncontest\nstatus\nand\nin\nthe\nbottom\nof\nstandings"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "26\na\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz",
"output": "a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\nn\no\np\nq\nr\ns\nt\nu\nv\nw\nx\ny\nz"
},
{
"input": "1\nabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij",
"output": "a98j"
},
{
"input": "10\ngyartjdxxlcl\nfzsck\nuidwu\nxbymclornemdmtj\nilppyoapitawgje\ncibzc\ndrgbeu\nhezplmsdekhhbo\nfeuzlrimbqbytdu\nkgdco",
"output": "g10l\nfzsck\nuidwu\nx13j\ni13e\ncibzc\ndrgbeu\nh12o\nf13u\nkgdco"
},
{
"input": "20\nlkpmx\nkovxmxorlgwaomlswjxlpnbvltfv\nhykasjxqyjrmybejnmeumzha\ntuevlumpqbbhbww\nqgqsphvrmupxxc\ntrissbaf\nqfgrlinkzvzqdryckaizutd\nzzqtoaxkvwoscyx\noswytrlnhpjvvnwookx\nlpuzqgec\ngyzqfwxggtvpjhzmzmdw\nrlxjgmvdftvrmvbdwudra\nvsntnjpepnvdaxiporggmglhagv\nxlvcqkqgcrbgtgglj\nlyxwxbiszyhlsrgzeedzprbmcpduvq\nyrmqqvrkqskqukzqrwukpsifgtdc\nxpuohcsjhhuhvr\nvvlfrlxpvqejngwrbfbpmqeirxlw\nsvmasocxdvadmaxtrpakysmeaympy\nyuflqboqfdt",
"output": "lkpmx\nk26v\nh22a\nt13w\nq12c\ntrissbaf\nq21d\nz13x\no17x\nlpuzqgec\ng18w\nr19a\nv25v\nx15j\nl28q\ny26c\nx12r\nv26w\ns27y\ny9t"
},
{
"input": "100\nm\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr",
"output": "m\nz\ns\nv\nd\nr\nv\ny\ny\ne\np\nt\nc\na\nn\nm\np\ng\ni\nj\nc\na\nb\nq\ne\nn\nv\no\nk\nx\nf\ni\nl\na\nq\nr\nu\nb\ns\nl\nc\nl\ne\nv\nj\nm\nx\nb\na\nq\nb\na\nf\nj\nv\nm\nq\nc\nt\nt\nn\nx\no\ny\nr\nu\nh\nm\nj\np\nj\nq\nz\ns\nj\no\ng\nc\nm\nn\no\nm\nr\no\ns\nt\nh\nr\np\nk\nb\nz\ng\no\nc\nc\nz\nz\ng\nr"
}
] | 1,693,811,092 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | times = int(input())
words = []
# Считывание строк и добавление их в список
for i in range(times):
a = input()
words.append(a)
# Обработка каждой строки из списка
for w in words:
length = len(w) # Получение длины строки
# Проверка наличия символов в строке и формирование новой строки
if length >= 9:
result = w[0] + str(length - 2) + w[-1]
print(result)
else:
print(w) # Если в строке меньше трех символов, выводим её без изменений
| Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made like this: we write down the first and the last letter of a word and between them we write the number of letters between the first and the last letters. That number is in decimal system and doesn't contain any leading zeroes.
Thus, "localization" will be spelt as "l10n", and "internationalization» will be spelt as "i18n".
You are suggested to automatize the process of changing the words with abbreviations. At that all too long words should be replaced by the abbreviation and the words that are not too long should not undergo any changes.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Output Specification:
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
Demo Input:
['4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n']
Demo Output:
['word\nl10n\ni18n\np43s\n']
Note:
none | ```python
times = int(input())
words = []
# Считывание строк и добавление их в список
for i in range(times):
a = input()
words.append(a)
# Обработка каждой строки из списка
for w in words:
length = len(w) # Получение длины строки
# Проверка наличия символов в строке и формирование новой строки
if length >= 9:
result = w[0] + str(length - 2) + w[-1]
print(result)
else:
print(w) # Если в строке меньше трех символов, выводим её без изменений
``` | 0 |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$).
For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve? | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
"output": "0.000000000000000"
},
{
"input": "100000 1\n1000 1000",
"output": "50000500.000000000000000"
},
{
"input": "11 1\n0 -10",
"output": "-27.272727272727273"
},
{
"input": "3 1\n1 -1",
"output": "0.333333333333333"
},
{
"input": "1 2\n-1 -1\n-2 -2",
"output": "-3.000000000000000"
},
{
"input": "1 2\n0 -1\n0 1",
"output": "0.000000000000000"
},
{
"input": "1 1\n1 -2",
"output": "1.000000000000000"
},
{
"input": "3 1\n2 -1",
"output": "1.333333333333333"
},
{
"input": "3 1\n0 -1",
"output": "-0.666666666666667"
},
{
"input": "1 1\n-1000 -1000",
"output": "-1000.000000000000000"
},
{
"input": "1 1\n0 -5",
"output": "0.000000000000000"
},
{
"input": "15 3\n2 0\n2 -5\n-2 5",
"output": "18.333333333333332"
},
{
"input": "9 1\n0 -5",
"output": "-11.111111111111111"
},
{
"input": "7 1\n0 -1",
"output": "-1.714285714285714"
},
{
"input": "3 1\n-2 -2",
"output": "-3.333333333333333"
},
{
"input": "3 1\n5 -5",
"output": "1.666666666666667"
},
{
"input": "1 1\n-1 -1",
"output": "-1.000000000000000"
},
{
"input": "7 1\n-1 -5",
"output": "-9.571428571428571"
},
{
"input": "3 2\n-2 -2\n-2 -2",
"output": "-6.666666666666667"
},
{
"input": "5 1\n0 -4",
"output": "-4.800000000000000"
},
{
"input": "5 1\n-1 -5",
"output": "-7.000000000000000"
},
{
"input": "5 1\n0 -2",
"output": "-2.400000000000000"
},
{
"input": "3 5\n1 -1000\n1 -1000\n1 -1000\n1 -1000\n1 -1000",
"output": "-3328.333333333333485"
},
{
"input": "1 1\n0 -1",
"output": "0.000000000000000"
},
{
"input": "1 2\n0 -3\n0 -3",
"output": "0.000000000000000"
},
{
"input": "7 1\n2 -3",
"output": "-3.142857142857143"
},
{
"input": "3 2\n-1 -1\n-1 -1",
"output": "-3.333333333333333"
},
{
"input": "5 1\n-1 -162",
"output": "-195.400000000000006"
},
{
"input": "5 10\n-506 -243\n727 -141\n-548 -306\n740 880\n-744 -116\n-84 182\n-859 -108\n64 86\n135 446\n69 -184",
"output": "864.399999999999977"
},
{
"input": "5 1\n0 -1",
"output": "-1.200000000000000"
},
{
"input": "5 12\n634 895\n143 730\n901 245\n386 486\n395 -111\n-469 -104\n-681 -623\n-900 843\n889 -883\n476 -304\n777 986\n206 -491",
"output": "8107.800000000000182"
},
{
"input": "3 3\n4 2\n5 0\n6 -1",
"output": "16.333333333333332"
},
{
"input": "1 3\n4 2\n5 0\n6 -1",
"output": "15.000000000000000"
},
{
"input": "85 10\n-223 435\n-771 455\n72 -940\n490 -178\n400 -117\n169 -527\n836 610\n849 944\n572 -237\n-428 -428",
"output": "53047.388235294114565"
},
{
"input": "69 10\n-8 4\n-3 3\n7 5\n5 -9\n8 1\n7 -5\n-8 -8\n9 3\n1 1\n0 6",
"output": "420.579710144927560"
},
{
"input": "1 10\n1 1\n1 0\n1 0\n1 0\n-1 0\n0 1\n1 0\n0 0\n2 1\n9 2",
"output": "15.000000000000000"
},
{
"input": "5 4\n0 1\n0 2\n0 3\n0 -9",
"output": "1.200000000000000"
}
] | 1,588,184,000 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 38 | 405 | 307,200 |
entrada = input()
entrada_int = list(map(int, entrada.split(" ")))
n = entrada_int[0]
m = entrada_int[1]
soma = 0
for i in reversed(range(m)):
entrada = input()
entrada_float = list(map(float, entrada.split(" ")))
soma += entrada_float[0] * n
if entrada_float[1] > 0:
soma += entrada_float[1] * (n * (n-1)/2)
elif entrada_float[1] == 0:
continue
else:
if n % 2 == 1:
soma += entrada_float[1] * ((n * n-1) / 4)
else:
soma += entrada_float[1] * n * n/4
soma = soma / n
print(soma)
| Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$).
For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$).
Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.
What is the maximum arithmetic mean value Bob can achieve?
Input Specification:
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
Output Specification:
Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
Demo Input:
['2 3\n-1 3\n0 0\n-1 -4\n', '3 2\n0 2\n5 0\n']
Demo Output:
['-2.500000000000000\n', '7.000000000000000\n']
Note:
none | ```python
entrada = input()
entrada_int = list(map(int, entrada.split(" ")))
n = entrada_int[0]
m = entrada_int[1]
soma = 0
for i in reversed(range(m)):
entrada = input()
entrada_float = list(map(float, entrada.split(" ")))
soma += entrada_float[0] * n
if entrada_float[1] > 0:
soma += entrada_float[1] * (n * (n-1)/2)
elif entrada_float[1] == 0:
continue
else:
if n % 2 == 1:
soma += entrada_float[1] * ((n * n-1) / 4)
else:
soma += entrada_float[1] * n * n/4
soma = soma / n
print(soma)
``` | 0 |
|
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct. | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n2 3\n1 1\n3 2",
"output": "Happy Alex"
},
{
"input": "4\n4 1\n3 2\n2 3\n1 4",
"output": "Happy Alex"
},
{
"input": "2\n2 1\n1 2",
"output": "Happy Alex"
},
{
"input": "3\n3 2\n1 1\n2 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 1\n3 3",
"output": "Happy Alex"
},
{
"input": "3\n1 2\n2 3\n3 1",
"output": "Happy Alex"
}
] | 1,664,172,089 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | # -*- coding: utf-8 -*-
"""
Created on Mon Sep 26 13:50:59 2022
@author: 86158
"""
n = int(input())
list = []
for i in range(n):
list.append([int(i) for i in input().split()])
for i in range(n):
for j in range(i+1,n):
if (list[i][0]>list[j][0] and list[i][1]>list[j][1]) or (list[i][0]<list[j][0] and list[i][1]<list[j][1]):
print("Poor Alex")
break
else:
print("Happy Alex") | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop.
Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist.
Input Specification:
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality).
All *a**i* are distinct. All *b**i* are distinct.
Output Specification:
If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes).
Demo Input:
['2\n1 2\n2 1\n']
Demo Output:
['Happy Alex\n']
Note:
none | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 26 13:50:59 2022
@author: 86158
"""
n = int(input())
list = []
for i in range(n):
list.append([int(i) for i in input().split()])
for i in range(n):
for j in range(i+1,n):
if (list[i][0]>list[j][0] and list[i][1]>list[j][1]) or (list[i][0]<list[j][0] and list[i][1]<list[j][1]):
print("Poor Alex")
break
else:
print("Happy Alex")
``` | 0 |
|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make? | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
"input": "2 6 4 5 6 5 1 3",
"output": "0"
},
{
"input": "1 7 3 5 3 6 2 1",
"output": "6"
},
{
"input": "2 4 5 4 5 7 3 2",
"output": "1"
},
{
"input": "2 3 6 5 7 8 2 1",
"output": "4"
},
{
"input": "1 4 5 5 3 10 3 1",
"output": "6"
},
{
"input": "1 4 6 7 3 5 1 3",
"output": "1"
},
{
"input": "1 6 5 5 5 8 3 1",
"output": "8"
},
{
"input": "1 7 5 3 3 9 2 1",
"output": "9"
},
{
"input": "3 5 3 7 6 10 3 1",
"output": "1"
},
{
"input": "3 6 3 5 3 6 3 1",
"output": "2"
},
{
"input": "1 7 5 5 5 5 2 2",
"output": "2"
},
{
"input": "2 5 3 5 6 9 2 1",
"output": "3"
},
{
"input": "3 4 3 5 3 6 2 1",
"output": "2"
},
{
"input": "1 5 5 4 7 6 3 1",
"output": "6"
},
{
"input": "2 3 7 6 5 9 3 1",
"output": "3"
},
{
"input": "2 6 5 3 3 8 1 1",
"output": "4"
},
{
"input": "2 4 7 3 4 10 2 1",
"output": "5"
},
{
"input": "1 1000 1000 1000 1000 1000 1 1",
"output": "1000"
},
{
"input": "17 1000 1000 1000 1000 1000 3 7",
"output": "8"
},
{
"input": "115 1000 1000 1000 1000 1000 17 15",
"output": "0"
},
{
"input": "1 587 981 1 2 1 1 1",
"output": "1"
},
{
"input": "1 1 2 1 2 2 1 1",
"output": "2"
}
] | 1,689,446,827 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | n, k, l, c, d, p, nl, np = map(int, input().split())
Drink = k * l
maxDrink = Drink // nl
lime = c*d
salt = p//np
print(min(maxDrink,lime,salt)//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each friend needs *nl* milliliters of the drink, a slice of lime and *np* grams of salt. The friends want to make as many toasts as they can, provided they all drink the same amount. How many toasts can each friend make?
Input Specification:
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Output Specification:
Print a single integer — the number of toasts each friend can make.
Demo Input:
['3 4 5 10 8 100 3 1\n', '5 100 10 1 19 90 4 3\n', '10 1000 1000 25 23 1 50 1\n']
Demo Output:
['2\n', '3\n', '0\n']
Note:
A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | ```python
n, k, l, c, d, p, nl, np = map(int, input().split())
Drink = k * l
maxDrink = Drink // nl
lime = c*d
salt = p//np
print(min(maxDrink,lime,salt)//n)
``` | 3 |
|
0 | none | none | none | 0 | [
"none"
] | null | null | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
1. Value *x* and some direction are announced, and all boys move *x* positions in the corresponding direction. 1. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that *n* is even.
Your task is to determine the final position of each boy. | The first line of the input contains two integers *n* and *q* (2<=≤<=*n*<=≤<=1<=000<=000, 1<=≤<=*q*<=≤<=2<=000<=000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that *n* is even.
Next *q* lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as *x* (<=-<=*n*<=≤<=*x*<=≤<=*n*), where 0<=≤<=*x*<=≤<=*n* means all boys moves *x* girls in clockwise direction, while <=-<=*x* means all boys move *x* positions in counter-clockwise direction. There is no other input for commands of the second type. | Output *n* integers, the *i*-th of them should be equal to the index of boy the *i*-th girl is dancing with after performing all *q* moves. | [
"6 3\n1 2\n2\n1 2\n",
"2 3\n1 1\n2\n1 -2\n",
"4 2\n2\n1 3\n"
] | [
"4 3 6 5 2 1\n",
"1 2\n",
"1 4 3 2\n"
] | none | 0 | [
{
"input": "6 3\n1 2\n2\n1 2",
"output": "4 3 6 5 2 1"
},
{
"input": "2 3\n1 1\n2\n1 -2",
"output": "1 2"
},
{
"input": "4 2\n2\n1 3",
"output": "1 4 3 2"
},
{
"input": "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2",
"output": "4 3 6 5 2 1"
},
{
"input": "6 8\n1 -1\n2\n2\n1 4\n1 0\n1 -1\n1 0\n1 -1",
"output": "6 1 2 3 4 5"
},
{
"input": "10 5\n1 8\n1 -3\n1 -3\n2\n1 5",
"output": "3 6 5 8 7 10 9 2 1 4"
},
{
"input": "10 10\n1 2\n1 -10\n1 -5\n2\n2\n1 -4\n2\n2\n1 -10\n1 -9",
"output": "7 8 9 10 1 2 3 4 5 6"
},
{
"input": "6 9\n2\n1 -2\n2\n1 -6\n1 -6\n1 4\n2\n1 -1\n2",
"output": "2 5 4 1 6 3"
},
{
"input": "2 5\n2\n1 -1\n2\n1 1\n2",
"output": "2 1"
},
{
"input": "2 8\n2\n2\n2\n1 -2\n1 -1\n1 -1\n2\n1 1",
"output": "2 1"
},
{
"input": "36 86\n1 -25\n2\n2\n2\n1 16\n1 -14\n1 12\n2\n1 -21\n2\n1 -12\n1 34\n1 -4\n1 19\n1 5\n2\n2\n2\n2\n1 -1\n1 -31\n2\n1 -6\n1 1\n2\n2\n1 27\n1 19\n2\n1 -14\n2\n1 -17\n2\n2\n2\n2\n1 -35\n1 -31\n1 7\n2\n2\n2\n1 -12\n2\n2\n2\n2\n1 7\n1 -9\n1 -2\n2\n1 -3\n2\n2\n1 33\n1 -8\n1 -17\n1 2\n2\n1 -29\n1 -19\n2\n1 22\n2\n2\n2\n2\n1 -15\n1 7\n1 -29\n2\n2\n1 -30\n2\n2\n1 -6\n2\n1 -25\n2\n1 -18\n2\n1 33\n1 23\n2\n2\n2",
"output": "25 22 27 24 29 26 31 28 33 30 35 32 1 34 3 36 5 2 7 4 9 6 11 8 13 10 15 12 17 14 19 16 21 18 23 20"
},
{
"input": "10 71\n1 -4\n1 -3\n2\n2\n2\n1 -3\n1 4\n2\n2\n2\n2\n1 5\n2\n2\n2\n2\n2\n1 1\n2\n1 2\n1 1\n2\n1 -5\n2\n2\n2\n2\n1 8\n1 -9\n1 -3\n1 2\n1 3\n1 -2\n1 -6\n2\n2\n1 -2\n2\n1 -6\n1 5\n1 2\n1 -10\n1 3\n2\n1 6\n2\n2\n1 4\n1 -8\n1 -4\n1 -1\n2\n2\n1 1\n2\n2\n1 3\n1 8\n1 7\n1 4\n2\n1 -10\n2\n2\n1 5\n1 9\n1 -5\n2\n2\n1 -2\n2",
"output": "1 2 3 4 5 6 7 8 9 10"
},
{
"input": "74 85\n2\n1 -69\n2\n2\n2\n2\n2\n1 74\n2\n2\n1 -41\n2\n2\n1 15\n2\n2\n2\n1 -12\n2\n1 -3\n1 28\n1 -46\n2\n1 -39\n2\n1 6\n2\n2\n1 -30\n2\n1 16\n1 30\n1 -50\n1 -17\n1 41\n1 56\n2\n1 -45\n1 -21\n1 63\n1 -7\n2\n1 -6\n1 26\n2\n1 -71\n2\n2\n2\n1 11\n2\n1 70\n1 13\n2\n1 -51\n1 -9\n1 -72\n1 55\n2\n1 3\n2\n2\n1 47\n2\n2\n2\n1 -6\n1 -37\n2\n2\n1 -1\n1 72\n2\n1 -23\n2\n2\n2\n1 70\n1 38\n2\n2\n1 74\n1 -1\n2\n1 -9",
"output": "71 18 73 20 1 22 3 24 5 26 7 28 9 30 11 32 13 34 15 36 17 38 19 40 21 42 23 44 25 46 27 48 29 50 31 52 33 54 35 56 37 58 39 60 41 62 43 64 45 66 47 68 49 70 51 72 53 74 55 2 57 4 59 6 61 8 63 10 65 12 67 14 69 16"
},
{
"input": "24 8\n1 17\n2\n1 -10\n2\n2\n2\n2\n1 19",
"output": "22 1 24 3 2 5 4 7 6 9 8 11 10 13 12 15 14 17 16 19 18 21 20 23"
},
{
"input": "242 11\n1 -202\n1 46\n2\n1 -144\n2\n1 134\n1 104\n2\n1 -32\n2\n1 36",
"output": "59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 ..."
},
{
"input": "364 57\n1 -101\n1 110\n1 -76\n1 329\n2\n2\n2\n1 -191\n1 97\n1 189\n1 305\n1 -313\n1 312\n1 -148\n2\n1 -104\n1 85\n1 -55\n1 -79\n1 230\n1 -94\n1 58\n1 -72\n2\n2\n2\n1 -104\n1 -351\n1 23\n2\n1 215\n2\n2\n2\n1 58\n1 -237\n2\n2\n2\n1 198\n2\n1 83\n2\n1 -205\n2\n2\n2\n2\n1 -110\n2\n2\n2\n2\n1 153\n1 -344\n1 -281\n1 -159",
"output": "218 215 220 217 222 219 224 221 226 223 228 225 230 227 232 229 234 231 236 233 238 235 240 237 242 239 244 241 246 243 248 245 250 247 252 249 254 251 256 253 258 255 260 257 262 259 264 261 266 263 268 265 270 267 272 269 274 271 276 273 278 275 280 277 282 279 284 281 286 283 288 285 290 287 292 289 294 291 296 293 298 295 300 297 302 299 304 301 306 303 308 305 310 307 312 309 314 311 316 313 318 315 320 317 322 319 324 321 326 323 328 325 330 327 332 329 334 331 336 333 338 335 340 337 342 339 344 341..."
},
{
"input": "6 5\n1 5\n1 5\n1 6\n1 6\n1 6",
"output": "3 4 5 6 1 2"
}
] | 1,461,521,640 | 5,940 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 61 | 4,608,000 | # You lost the game.
n,q = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
impair = 0
pair = 0
pos = 1
for i in range(q):
if Q[i][0] == 1:
d = Q[i][1]
impair += d
pair += d
if pos == 1 and d % 2:
pos = -1
elif pos == -1 and d % 2 == 0:
pos = 1
else:
impair += pos
pair += -pos
pos = -pos
for i in range(1,n+1):
j = i-1
if pair % 2:
if i % 2:
print(1+(j-pair) % n,end=" ")
else:
print(1+(j-impair) % n,end=" ")
else:
if i % 2:
print(1+(j-impair) % n,end=" ")
else:
print(1+(j-pair) % n,end=" ")
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a girl number 2 and so on. Girls are numbered in the clockwise order. During the dance different moves are announced and all pairs perform this moves. While performing moves boys move along the circle, while girls always stay at their initial position. For the purpose of this problem we consider two different types of moves:
1. Value *x* and some direction are announced, and all boys move *x* positions in the corresponding direction. 1. Boys dancing with even-indexed girls swap positions with boys who are dancing with odd-indexed girls. That is the one who was dancing with the girl 1 swaps with the one who was dancing with the girl number 2, while the one who was dancing with girl number 3 swaps with the one who was dancing with the girl number 4 and so one. It's guaranteed that *n* is even.
Your task is to determine the final position of each boy.
Input Specification:
The first line of the input contains two integers *n* and *q* (2<=≤<=*n*<=≤<=1<=000<=000, 1<=≤<=*q*<=≤<=2<=000<=000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that *n* is even.
Next *q* lines contain the descriptions of the commands. Each command has type as the integer 1 or 2 first. Command of the first type is given as *x* (<=-<=*n*<=≤<=*x*<=≤<=*n*), where 0<=≤<=*x*<=≤<=*n* means all boys moves *x* girls in clockwise direction, while <=-<=*x* means all boys move *x* positions in counter-clockwise direction. There is no other input for commands of the second type.
Output Specification:
Output *n* integers, the *i*-th of them should be equal to the index of boy the *i*-th girl is dancing with after performing all *q* moves.
Demo Input:
['6 3\n1 2\n2\n1 2\n', '2 3\n1 1\n2\n1 -2\n', '4 2\n2\n1 3\n']
Demo Output:
['4 3 6 5 2 1\n', '1 2\n', '1 4 3 2\n']
Note:
none | ```python
# You lost the game.
n,q = map(int, input().split())
Q = [list(map(int, input().split())) for _ in range(q)]
impair = 0
pair = 0
pos = 1
for i in range(q):
if Q[i][0] == 1:
d = Q[i][1]
impair += d
pair += d
if pos == 1 and d % 2:
pos = -1
elif pos == -1 and d % 2 == 0:
pos = 1
else:
impair += pos
pair += -pos
pos = -pos
for i in range(1,n+1):
j = i-1
if pair % 2:
if i % 2:
print(1+(j-pair) % n,end=" ")
else:
print(1+(j-impair) % n,end=" ")
else:
if i % 2:
print(1+(j-impair) % n,end=" ")
else:
print(1+(j-pair) % n,end=" ")
``` | 0 |
|
770 | A | New Password | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. | The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists. | Print any password which satisfies all conditions given by Innokentiy. | [
"4 3\n",
"6 6\n",
"5 2\n"
] | [
"java\n",
"python\n",
"phphp\n"
] | In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | 500 | [
{
"input": "4 3",
"output": "abca"
},
{
"input": "6 6",
"output": "abcdef"
},
{
"input": "5 2",
"output": "ababa"
},
{
"input": "3 2",
"output": "aba"
},
{
"input": "10 2",
"output": "ababababab"
},
{
"input": "26 13",
"output": "abcdefghijklmabcdefghijklm"
},
{
"input": "100 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "100 10",
"output": "abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij"
},
{
"input": "3 3",
"output": "abc"
},
{
"input": "6 3",
"output": "abcabc"
},
{
"input": "10 3",
"output": "abcabcabca"
},
{
"input": "50 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"
},
{
"input": "90 2",
"output": "ababababababababababababababababababababababababababababababababababababababababababababab"
},
{
"input": "6 2",
"output": "ababab"
},
{
"input": "99 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabc"
},
{
"input": "4 2",
"output": "abab"
},
{
"input": "100 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "40 22",
"output": "abcdefghijklmnopqrstuvabcdefghijklmnopqr"
},
{
"input": "13 8",
"output": "abcdefghabcde"
},
{
"input": "16 15",
"output": "abcdefghijklmnoa"
},
{
"input": "17 17",
"output": "abcdefghijklmnopq"
},
{
"input": "19 4",
"output": "abcdabcdabcdabcdabc"
},
{
"input": "100 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv"
},
{
"input": "100 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy"
},
{
"input": "26 26",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "27 26",
"output": "abcdefghijklmnopqrstuvwxyza"
},
{
"input": "2 2",
"output": "ab"
},
{
"input": "26 25",
"output": "abcdefghijklmnopqrstuvwxya"
},
{
"input": "99 2",
"output": "abababababababababababababababababababababababababababababababababababababababababababababababababa"
},
{
"input": "99 26",
"output": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstu"
},
{
"input": "4 4",
"output": "abcd"
},
{
"input": "5 3",
"output": "abcab"
},
{
"input": "5 4",
"output": "abcda"
},
{
"input": "5 5",
"output": "abcde"
},
{
"input": "24 22",
"output": "abcdefghijklmnopqrstuvab"
},
{
"input": "26 14",
"output": "abcdefghijklmnabcdefghijkl"
},
{
"input": "26 15",
"output": "abcdefghijklmnoabcdefghijk"
},
{
"input": "30 12",
"output": "abcdefghijklabcdefghijklabcdef"
},
{
"input": "35 4",
"output": "abcdabcdabcdabcdabcdabcdabcdabcdabc"
},
{
"input": "79 3",
"output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabca"
},
{
"input": "79 14",
"output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghi"
},
{
"input": "85 13",
"output": "abcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefghijklmabcdefg"
},
{
"input": "90 25",
"output": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyabcdefghijklmno"
},
{
"input": "90 19",
"output": "abcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmnopqrsabcdefghijklmn"
},
{
"input": "26 24",
"output": "abcdefghijklmnopqrstuvwxab"
},
{
"input": "100 17",
"output": "abcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmnopqabcdefghijklmno"
},
{
"input": "26 2",
"output": "ababababababababababababab"
}
] | 1,666,996,980 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 46 | 0 | n,k=[int(n) for n in input().split()]
s="abcdefghijklmnopqrstuvwxyz"
p=s[0:k]
q=p*n
print(q[0:n]) | Title: New Password
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help.
Innokentiy decides that new password should satisfy the following conditions:
- the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct.
Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions.
Input Specification:
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it.
Pay attention that a desired new password always exists.
Output Specification:
Print any password which satisfies all conditions given by Innokentiy.
Demo Input:
['4 3\n', '6 6\n', '5 2\n']
Demo Output:
['java\n', 'python\n', 'phphp\n']
Note:
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it.
In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letters.
In the third test there is one of the appropriate new passwords — phphp, because its length is equal to 5 and 2 distinct lowercase letters p and h are used in it.
Pay attention the condition that no two identical symbols are consecutive is correct for all appropriate passwords in tests. | ```python
n,k=[int(n) for n in input().split()]
s="abcdefghijklmnopqrstuvwxyz"
p=s[0:k]
q=p*n
print(q[0:n])
``` | 3 |
|
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids. | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place. | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
"input": "5 12\n- 12\n+ 7\n- 6\n- 1\n+ 46",
"output": "46 0"
},
{
"input": "11 1000\n- 100\n+ 100\n+ 100\n+ 100\n+ 100\n- 100\n- 100\n- 100\n- 100\n- 100\n- 100",
"output": "700 0"
},
{
"input": "1 0\n- 526403222",
"output": "0 1"
},
{
"input": "1 897986543\n- 371188251",
"output": "526798292 0"
},
{
"input": "1 0\n+ 1",
"output": "1 0"
},
{
"input": "1 0\n- 1",
"output": "0 1"
},
{
"input": "1 10\n+ 10",
"output": "20 0"
},
{
"input": "1 3\n- 5",
"output": "3 1"
},
{
"input": "1 0\n- 5",
"output": "0 1"
},
{
"input": "1 0\n+ 5",
"output": "5 0"
}
] | 1,675,546,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 46 | 4,505,600 | n,p=input().split()
count=0
p3=int(p)
for i in range (int(n)):
sign,p2=input().split()
if(sign=='+'):
p3+=int(p2)
else:
if(int(p2)<p3):
p3-=int(p2)
else:
count+=1
print(str(p3)+" "+str(count))
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the queue wants either to take several ice cream packs for himself and his friends or to give several ice cream packs to Kay and Gerda (carriers that bring ice cream have to stand in the same queue).
If a carrier with *d* ice cream packs comes to the house, then Kay and Gerda take all his packs. If a child who wants to take *d* ice cream packs comes to the house, then Kay and Gerda will give him *d* packs if they have enough ice cream, otherwise the child will get no ice cream at all and will leave in distress.
Kay wants to find the amount of ice cream they will have after all people will leave from the queue, and Gerda wants to find the number of distressed kids.
Input Specification:
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occupies *i*-th place from the start of the queue, and record "- *d**i*" means that a child who wants to take *d**i* packs stands in *i*-th place.
Output Specification:
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
Demo Input:
['5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n', '5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n']
Demo Output:
['22 1\n', '3 2\n']
Note:
Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1. Carrier bring 40 packs, now Kay and Gerda have 42 packs. 1. Kid asks for 20 packs and receives them. There are 22 packs remaining. | ```python
n,p=input().split()
count=0
p3=int(p)
for i in range (int(n)):
sign,p2=input().split()
if(sign=='+'):
p3+=int(p2)
else:
if(int(p2)<p3):
p3-=int(p2)
else:
count+=1
print(str(p3)+" "+str(count))
``` | 0 |
|
929 | A | Прокат велосипедов | PROGRAMMING | 1,400 | [
"*special",
"greedy",
"implementation"
] | null | null | Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. | В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. | Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. | [
"4 4\n3 6 8 10\n",
"2 9\n10 20\n",
"12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n"
] | [
"2\n",
"-1\n",
"6\n"
] | В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | 500 | [
{
"input": "4 4\n3 6 8 10",
"output": "2"
},
{
"input": "2 9\n10 20",
"output": "-1"
},
{
"input": "12 3\n4 6 7 9 10 11 13 15 17 18 20 21",
"output": "6"
},
{
"input": "2 1\n11164 11165",
"output": "1"
},
{
"input": "3 7\n45823 45825 45829",
"output": "1"
},
{
"input": "2 100000\n0 100000",
"output": "1"
},
{
"input": "50 15001\n1269 1580 5431 5916 6642 14145 15760 19922 20589 22062 24138 33454 33505 35916 37012 42577 43140 49457 54720 55188 56205 56639 56870 57997 58379 59088 59297 61805 61861 63005 64013 68848 71182 71497 72715 73008 75616 76042 76614 80690 83089 85033 86408 92392 92763 93833 95085 95815 97152 99379",
"output": "8"
},
{
"input": "5 7\n6219 6222 6229 6231 6236",
"output": "3"
},
{
"input": "10 448\n78449 78573 78599 78742 78748 78759 78853 79091 79298 79324",
"output": "3"
},
{
"input": "20 19191\n11272 12386 14108 24663 24932 26547 29656 44677 45436 45654 48562 62367 71049 71238 78182 84042 88736 92026 96836 99343",
"output": "6"
},
{
"input": "2 100000\n1 100000",
"output": "1"
},
{
"input": "2 99999\n0 100000",
"output": "-1"
},
{
"input": "2 2\n1 3",
"output": "1"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "2 2\n1 4",
"output": "-1"
},
{
"input": "10 1\n1 2 3 4 5 6 7 8 9 10",
"output": "9"
}
] | 1,520,082,703 | 77,803 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 5,632,000 | n,k = map(int,input().split())
x = tuple(map(int,input().split()))
t = x[0]
p = 1
output = 1
for i in range(len(x)-1):
if x[i+1]-x[i]>k:
output = -1
if (output!=-1):
for i in range(len(x)-1):
if (x[i]>t+k) or (x[i]==t+k):
t = x[i-1]
p = p+1
output = p
print(output) | Title: Прокат велосипедов
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды.
Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=<<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=<<=*n*.
Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение.
За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы.
Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком.
Input Specification:
В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде.
В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=<<=*x*2<=<<=...<=<<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания.
Output Specification:
Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката.
Demo Input:
['4 4\n3 6 8 10\n', '2 9\n10 20\n', '12 3\n4 6 7 9 10 11 13 15 17 18 20 21\n']
Demo Output:
['2\n', '-1\n', '6\n']
Note:
В первом примере Аркадий должен взять первый велосипед в первом велопрокате и доехать на нём до второго велопроката. Во втором велопрокате он должен взять новый велосипед, на котором он сможет добраться до четвертого велопроката, рядом с которым и находится его дом. Поэтому Аркадию нужно всего два велосипеда, чтобы добраться от школы до дома.
Во втором примере всего два велопроката, расстояние между которыми 10. Но максимальное расстояние, которое можно проехать на одном велосипеде, равно 9. Поэтому Аркадий не сможет добраться от школы до дома только на велосипедах. | ```python
n,k = map(int,input().split())
x = tuple(map(int,input().split()))
t = x[0]
p = 1
output = 1
for i in range(len(x)-1):
if x[i+1]-x[i]>k:
output = -1
if (output!=-1):
for i in range(len(x)-1):
if (x[i]>t+k) or (x[i]==t+k):
t = x[i-1]
p = p+1
output = p
print(output)
``` | 0 |
|
886 | A | ACM ICPC | PROGRAMMING | 1,000 | [
"brute force"
] | null | null | In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question. | The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants | Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES"). | [
"1 3 2 1 2 1\n",
"1 1 1 1 1 99\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | 500 | [
{
"input": "1 3 2 1 2 1",
"output": "YES"
},
{
"input": "1 1 1 1 1 99",
"output": "NO"
},
{
"input": "1000 1000 1000 1000 1000 1000",
"output": "YES"
},
{
"input": "0 0 0 0 0 0",
"output": "YES"
},
{
"input": "633 609 369 704 573 416",
"output": "NO"
},
{
"input": "353 313 327 470 597 31",
"output": "NO"
},
{
"input": "835 638 673 624 232 266",
"output": "NO"
},
{
"input": "936 342 19 398 247 874",
"output": "NO"
},
{
"input": "417 666 978 553 271 488",
"output": "NO"
},
{
"input": "71 66 124 199 67 147",
"output": "YES"
},
{
"input": "54 26 0 171 239 12",
"output": "YES"
},
{
"input": "72 8 186 92 267 69",
"output": "YES"
},
{
"input": "180 179 188 50 75 214",
"output": "YES"
},
{
"input": "16 169 110 136 404 277",
"output": "YES"
},
{
"input": "101 400 9 200 300 10",
"output": "YES"
},
{
"input": "101 400 200 9 300 10",
"output": "YES"
},
{
"input": "101 200 400 9 300 10",
"output": "YES"
},
{
"input": "101 400 200 300 9 10",
"output": "YES"
},
{
"input": "101 200 400 300 9 10",
"output": "YES"
},
{
"input": "4 4 4 4 5 4",
"output": "NO"
},
{
"input": "2 2 2 2 2 1",
"output": "NO"
},
{
"input": "1000 1000 999 1000 1000 1000",
"output": "NO"
},
{
"input": "129 1 10 29 8 111",
"output": "NO"
},
{
"input": "1000 1000 1000 999 999 1000",
"output": "YES"
},
{
"input": "101 200 300 400 9 10",
"output": "YES"
},
{
"input": "101 400 200 300 10 9",
"output": "YES"
},
{
"input": "101 200 400 300 10 9",
"output": "YES"
},
{
"input": "101 200 300 400 10 9",
"output": "YES"
},
{
"input": "101 200 300 10 400 9",
"output": "YES"
},
{
"input": "1 1 1 1 1 5",
"output": "NO"
},
{
"input": "8 1 1 3 3 0",
"output": "NO"
},
{
"input": "1 1 2 2 3 3",
"output": "YES"
},
{
"input": "1 2 2 5 2 5",
"output": "NO"
},
{
"input": "1 2 3 6 6 6",
"output": "NO"
},
{
"input": "36 91 7 86 51 89",
"output": "NO"
},
{
"input": "10 1 1 1 23 24",
"output": "NO"
},
{
"input": "1 1 1 10 23 24",
"output": "NO"
},
{
"input": "20 10 1 2 3 44",
"output": "NO"
},
{
"input": "7 0 14 11 8 6",
"output": "NO"
},
{
"input": "100 496 1 1 1 1",
"output": "NO"
},
{
"input": "5 4 2 5 11 3",
"output": "NO"
},
{
"input": "1 3 7 8 8 9",
"output": "YES"
},
{
"input": "1 3 4 5 18 19",
"output": "YES"
},
{
"input": "5 5 1 2 2 15",
"output": "NO"
},
{
"input": "2 1 0 0 0 5",
"output": "NO"
},
{
"input": "1 6 6 1 20 2",
"output": "NO"
},
{
"input": "2 10 0 0 0 0",
"output": "NO"
},
{
"input": "1 1 3 1 1 11",
"output": "NO"
},
{
"input": "10 10 1 1 1 37",
"output": "NO"
},
{
"input": "1 1 0 0 0 4",
"output": "NO"
},
{
"input": "1 1 10 1 1 28",
"output": "NO"
},
{
"input": "1 5 5 5 6 8",
"output": "YES"
},
{
"input": "0 2 3 4 4 5",
"output": "YES"
}
] | 1,510,509,746 | 7,046 | Python 3 | OK | TESTS | 53 | 62 | 0 | s = sorted([int(i) for i in input().split()])
res = False
summ = sum(s)
for i in range(6):
for j in range(6):
if j == i:
continue
for k in range(6):
if k == j or k == i:
continue
if s[i] + s[j] + s[k] == summ//2:
res = True
break
if summ%2 == 1:
res = False
if res:
print('YES')
else:
print('NO')
| Title: ACM ICPC
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small but very proud high school it was decided to win ACM ICPC. This goal requires to compose as many teams of three as possible, but since there were only 6 students who wished to participate, the decision was to build exactly two teams.
After practice competition, participant number *i* got a score of *a**i*. Team score is defined as sum of scores of its participants. High school management is interested if it's possible to build two teams with equal scores. Your task is to answer that question.
Input Specification:
The single line contains six integers *a*1,<=...,<=*a*6 (0<=≤<=*a**i*<=≤<=1000) — scores of the participants
Output Specification:
Print "YES" (quotes for clarity), if it is possible to build teams with equal score, and "NO" otherwise.
You can print each character either upper- or lowercase ("YeS" and "yes" are valid when the answer is "YES").
Demo Input:
['1 3 2 1 2 1\n', '1 1 1 1 1 99\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first sample, first team can be composed of 1st, 2nd and 6th participant, second — of 3rd, 4th and 5th: team scores are 1 + 3 + 1 = 2 + 1 + 2 = 5.
In the second sample, score of participant number 6 is too high: his team score will be definitely greater. | ```python
s = sorted([int(i) for i in input().split()])
res = False
summ = sum(s)
for i in range(6):
for j in range(6):
if j == i:
continue
for k in range(6):
if k == j or k == i:
continue
if s[i] + s[j] + s[k] == summ//2:
res = True
break
if summ%2 == 1:
res = False
if res:
print('YES')
else:
print('NO')
``` | 3 |
|
47 | A | Triangular numbers | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Triangular numbers | 2 | 256 | A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number. | The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer. | If the given integer is a triangular number output YES, otherwise output NO. | [
"1\n",
"2\n",
"3\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "1",
"output": "YES"
},
{
"input": "2",
"output": "NO"
},
{
"input": "3",
"output": "YES"
},
{
"input": "4",
"output": "NO"
},
{
"input": "5",
"output": "NO"
},
{
"input": "6",
"output": "YES"
},
{
"input": "7",
"output": "NO"
},
{
"input": "8",
"output": "NO"
},
{
"input": "12",
"output": "NO"
},
{
"input": "10",
"output": "YES"
},
{
"input": "11",
"output": "NO"
},
{
"input": "9",
"output": "NO"
},
{
"input": "14",
"output": "NO"
},
{
"input": "15",
"output": "YES"
},
{
"input": "16",
"output": "NO"
},
{
"input": "20",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "22",
"output": "NO"
},
{
"input": "121",
"output": "NO"
},
{
"input": "135",
"output": "NO"
},
{
"input": "136",
"output": "YES"
},
{
"input": "137",
"output": "NO"
},
{
"input": "152",
"output": "NO"
},
{
"input": "153",
"output": "YES"
},
{
"input": "154",
"output": "NO"
},
{
"input": "171",
"output": "YES"
},
{
"input": "189",
"output": "NO"
},
{
"input": "190",
"output": "YES"
},
{
"input": "191",
"output": "NO"
},
{
"input": "210",
"output": "YES"
},
{
"input": "211",
"output": "NO"
},
{
"input": "231",
"output": "YES"
},
{
"input": "232",
"output": "NO"
},
{
"input": "252",
"output": "NO"
},
{
"input": "253",
"output": "YES"
},
{
"input": "254",
"output": "NO"
},
{
"input": "275",
"output": "NO"
},
{
"input": "276",
"output": "YES"
},
{
"input": "277",
"output": "NO"
},
{
"input": "299",
"output": "NO"
},
{
"input": "300",
"output": "YES"
},
{
"input": "301",
"output": "NO"
},
{
"input": "324",
"output": "NO"
},
{
"input": "325",
"output": "YES"
},
{
"input": "326",
"output": "NO"
},
{
"input": "350",
"output": "NO"
},
{
"input": "351",
"output": "YES"
},
{
"input": "352",
"output": "NO"
},
{
"input": "377",
"output": "NO"
},
{
"input": "378",
"output": "YES"
},
{
"input": "406",
"output": "YES"
},
{
"input": "434",
"output": "NO"
},
{
"input": "435",
"output": "YES"
},
{
"input": "464",
"output": "NO"
},
{
"input": "465",
"output": "YES"
},
{
"input": "495",
"output": "NO"
},
{
"input": "496",
"output": "YES"
},
{
"input": "497",
"output": "NO"
},
{
"input": "331",
"output": "NO"
},
{
"input": "413",
"output": "NO"
},
{
"input": "177",
"output": "NO"
},
{
"input": "122",
"output": "NO"
},
{
"input": "478",
"output": "NO"
},
{
"input": "188",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "474",
"output": "NO"
},
{
"input": "21",
"output": "YES"
},
{
"input": "48",
"output": "NO"
},
{
"input": "498",
"output": "NO"
},
{
"input": "499",
"output": "NO"
},
{
"input": "500",
"output": "NO"
}
] | 1,661,484,640 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | t = int(input())
l =[0]
for i in range(1,t+1):
s =int((i*(i+1))/2)
l.append(s)
if t in l:
print("YES")
else:
print("NO")
| Title: Triangular numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers from Wikipedia (http://en.wikipedia.org/wiki/Triangular_number).
Your task is to find out if a given integer is a triangular number.
Input Specification:
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
Output Specification:
If the given integer is a triangular number output YES, otherwise output NO.
Demo Input:
['1\n', '2\n', '3\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
t = int(input())
l =[0]
for i in range(1,t+1):
s =int((i*(i+1))/2)
l.append(s)
if t in l:
print("YES")
else:
print("NO")
``` | 3.977 |
817 | A | Treasure Hunt | PROGRAMMING | 1,200 | [
"implementation",
"math",
"number theory"
] | null | null | Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times. | The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle. | Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes). | [
"0 0 0 6\n2 3\n",
"1 1 3 6\n1 5\n"
] | [
"YES\n",
"NO\n"
] | In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | 0 | [
{
"input": "0 0 0 6\n2 3",
"output": "YES"
},
{
"input": "1 1 3 6\n1 5",
"output": "NO"
},
{
"input": "5 4 6 -10\n1 1",
"output": "NO"
},
{
"input": "6 -3 -7 -7\n1 2",
"output": "NO"
},
{
"input": "2 -5 -8 8\n2 1",
"output": "YES"
},
{
"input": "70 -81 -17 80\n87 23",
"output": "YES"
},
{
"input": "41 366 218 -240\n3456 1234",
"output": "NO"
},
{
"input": "-61972 -39646 -42371 -24854\n573 238",
"output": "NO"
},
{
"input": "-84870 -42042 94570 98028\n8972 23345",
"output": "YES"
},
{
"input": "-58533 -50999 -1007 -59169\n8972 23345",
"output": "NO"
},
{
"input": "-100000 -100000 100000 100000\n100000 100000",
"output": "YES"
},
{
"input": "-100000 -100000 100000 100000\n1 1",
"output": "YES"
},
{
"input": "5 2 5 3\n1 1",
"output": "NO"
},
{
"input": "5 5 5 5\n5 5",
"output": "YES"
},
{
"input": "0 0 1000 1000\n1 1",
"output": "YES"
},
{
"input": "0 0 0 1\n1 1",
"output": "NO"
},
{
"input": "1 1 4 4\n2 2",
"output": "NO"
},
{
"input": "100000 100000 99999 99999\n100000 100000",
"output": "NO"
},
{
"input": "1 1 1 6\n1 5",
"output": "NO"
},
{
"input": "2 9 4 0\n2 3",
"output": "YES"
},
{
"input": "0 0 0 9\n2 3",
"output": "NO"
},
{
"input": "14 88 14 88\n100 500",
"output": "YES"
},
{
"input": "-1 0 3 0\n4 4",
"output": "NO"
},
{
"input": "0 0 8 9\n2 3",
"output": "NO"
},
{
"input": "-2 5 7 -6\n1 1",
"output": "YES"
},
{
"input": "3 7 -8 8\n2 2",
"output": "NO"
},
{
"input": "-4 -8 -6 -1\n1 3",
"output": "NO"
},
{
"input": "0 8 6 2\n1 1",
"output": "YES"
},
{
"input": "-5 -2 -8 -2\n1 1",
"output": "NO"
},
{
"input": "1 4 -5 0\n1 1",
"output": "YES"
},
{
"input": "8 -4 4 -7\n1 2",
"output": "NO"
},
{
"input": "5 2 2 4\n2 2",
"output": "NO"
},
{
"input": "2 0 -4 6\n1 2",
"output": "NO"
},
{
"input": "-2 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "-6 5 10 6\n2 4",
"output": "NO"
},
{
"input": "3 -7 1 -8\n1 2",
"output": "NO"
},
{
"input": "4 1 4 -4\n9 4",
"output": "NO"
},
{
"input": "9 -3 -9 -3\n2 2",
"output": "NO"
},
{
"input": "-6 -6 -10 -5\n6 7",
"output": "NO"
},
{
"input": "-5 -2 2 2\n1 7",
"output": "NO"
},
{
"input": "9 0 8 1\n7 10",
"output": "NO"
},
{
"input": "-1 6 -7 -6\n6 4",
"output": "YES"
},
{
"input": "2 2 -3 -3\n3 1",
"output": "NO"
},
{
"input": "2 -6 7 2\n2 1",
"output": "NO"
},
{
"input": "-6 2 -7 -7\n1 2",
"output": "NO"
},
{
"input": "-5 -5 -1 -5\n2 2",
"output": "YES"
},
{
"input": "0 5 3 -6\n2 2",
"output": "NO"
},
{
"input": "0 -6 2 -1\n1 1",
"output": "NO"
},
{
"input": "-6 6 -5 -4\n1 2",
"output": "YES"
},
{
"input": "7 -7 1 -7\n2 2",
"output": "NO"
},
{
"input": "99966 -99952 -99966 99923\n1 1",
"output": "NO"
},
{
"input": "99921 99980 -99956 -99907\n3 4",
"output": "NO"
},
{
"input": "100000 100000 -100000 -100000\n1 1",
"output": "YES"
},
{
"input": "1 0 2 0\n5 1",
"output": "NO"
},
{
"input": "-3 0 -8 0\n7 2",
"output": "NO"
},
{
"input": "-9 4 -5 -1\n8 2",
"output": "NO"
},
{
"input": "-99999 -100000 100000 100000\n1 1",
"output": "NO"
},
{
"input": "0 0 -100 -100\n2 2",
"output": "YES"
},
{
"input": "9 -5 -3 -2\n1 4",
"output": "NO"
},
{
"input": "1 -10 -10 5\n7 5",
"output": "NO"
},
{
"input": "6 -9 -1 -9\n1 9",
"output": "NO"
}
] | 1,664,031,311 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 77 | 0 | xC, yC, xT, yT = input().split()
xP, yP = input().split()
dX = int(xT) - int(xC)
dY = int(yT) - int(yC)
pair1 = dX/int(xP)
pair2 = dY/int(yP)
def isEven(n):
if n%2 == 0:
return True
else:
return False
if (isEven(pair1) == isEven(pair2)):
print("YES")
else:
print("NO")
| Title: Treasure Hunt
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Captain Bill the Hummingbird and his crew recieved an interesting challenge offer. Some stranger gave them a map, potion of teleportation and said that only this potion might help them to reach the treasure.
Bottle with potion has two values *x* and *y* written on it. These values define four moves which can be performed using the potion:
- - - -
Map shows that the position of Captain Bill the Hummingbird is (*x*1,<=*y*1) and the position of the treasure is (*x*2,<=*y*2).
You task is to tell Captain Bill the Hummingbird whether he should accept this challenge or decline. If it is possible for Captain to reach the treasure using the potion then output "YES", otherwise "NO" (without quotes).
The potion can be used infinite amount of times.
Input Specification:
The first line contains four integer numbers *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=105<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=105) — positions of Captain Bill the Hummingbird and treasure respectively.
The second line contains two integer numbers *x*,<=*y* (1<=≤<=*x*,<=*y*<=≤<=105) — values on the potion bottle.
Output Specification:
Print "YES" if it is possible for Captain to reach the treasure using the potion, otherwise print "NO" (without quotes).
Demo Input:
['0 0 0 6\n2 3\n', '1 1 3 6\n1 5\n']
Demo Output:
['YES\n', 'NO\n']
Note:
In the first example there exists such sequence of moves:
1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c939890fb4ed35688177327dac981bfa9216c00.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the first type of move 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/afbfa42fbac4e0641e7466e3aac74cbbb08ed597.png" style="max-width: 100.0%;max-height: 100.0%;"/> — the third type of move | ```python
xC, yC, xT, yT = input().split()
xP, yP = input().split()
dX = int(xT) - int(xC)
dY = int(yT) - int(yC)
pair1 = dX/int(xP)
pair2 = dY/int(yP)
def isEven(n):
if n%2 == 0:
return True
else:
return False
if (isEven(pair1) == isEven(pair2)):
print("YES")
else:
print("NO")
``` | 0 |
|
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,687,933,958 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 109 | 2,355,200 | n, a, b, c = map(int, input().split())
temp = 0
for i in range(n+1):
for j in range(n+1):
if i*a + j*b <= n:
if (n - (i*a + j*b)) % c == 0:
flag = i + j + (n - (i*a + j*b)) // c
if flag > temp and flag != 0:
temp = flag
print(temp)
| 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())
temp = 0
for i in range(n+1):
for j in range(n+1):
if i*a + j*b <= n:
if (n - (i*a + j*b)) % c == 0:
flag = i + j + (n - (i*a + j*b)) // c
if flag > temp and flag != 0:
temp = flag
print(temp)
``` | 3 |
|
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even? | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "7\n7 7 7 7 7 7 7",
"output": "7"
},
{
"input": "8\n1 2 3 4 5 6 7 8",
"output": "4"
},
{
"input": "100\n1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 1 1 1 2 2 2 2 2",
"output": "50"
},
{
"input": "99\n99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99 100 99",
"output": "49"
},
{
"input": "82\n43 44 96 33 23 42 33 66 53 87 8 90 43 91 40 88 51 18 48 62 59 10 22 20 54 6 13 63 2 56 31 52 98 42 54 32 26 77 9 24 33 91 16 30 39 34 78 82 73 90 12 15 67 76 30 18 44 86 84 98 65 54 100 79 28 34 40 56 11 43 72 35 86 59 89 40 30 33 7 19 44 15",
"output": "50"
},
{
"input": "17\n50 14 17 77 74 74 38 76 41 27 45 29 66 98 38 73 38",
"output": "7"
},
{
"input": "94\n81 19 90 99 26 11 86 44 78 36 80 59 99 90 78 72 71 20 94 56 42 40 71 84 10 85 10 70 52 27 39 55 90 16 48 25 7 79 99 100 38 10 99 56 3 4 78 9 16 57 14 40 52 54 57 70 30 86 56 84 97 60 59 69 49 66 23 92 90 46 86 73 53 47 1 83 14 20 24 66 13 45 41 14 86 75 55 88 48 95 82 24 47 87",
"output": "39"
},
{
"input": "88\n64 95 12 90 40 65 98 45 52 54 79 7 81 25 98 19 68 82 41 53 35 50 5 22 32 21 8 39 8 6 72 27 81 30 12 79 21 42 60 2 66 87 46 93 62 78 52 71 76 32 78 94 86 85 55 15 34 76 41 20 32 26 94 81 89 45 74 49 11 40 40 39 49 46 80 85 90 23 80 40 86 58 70 26 48 93 23 53",
"output": "37"
},
{
"input": "84\n95 9 43 43 13 84 60 90 1 8 97 99 54 34 59 83 33 15 51 26 40 12 66 65 19 30 29 78 92 60 25 13 19 84 71 73 12 24 54 49 16 41 11 40 57 59 34 40 39 9 71 83 1 77 79 53 94 47 78 55 77 85 29 52 80 90 53 77 97 97 27 79 28 23 83 25 26 22 49 86 63 56 3 32",
"output": "51"
},
{
"input": "47\n61 97 76 94 91 22 2 68 62 73 90 47 16 79 44 71 98 68 43 6 53 52 40 27 68 67 43 96 14 91 60 61 96 24 97 13 32 65 85 96 81 77 34 18 23 14 80",
"output": "21"
},
{
"input": "69\n71 1 78 74 58 89 30 6 100 90 22 61 11 59 14 74 27 25 78 61 45 19 25 33 37 4 52 43 53 38 9 100 56 67 69 38 76 91 63 60 93 52 28 61 9 98 8 14 57 63 89 64 98 51 36 66 36 86 13 82 50 91 52 64 86 78 78 83 81",
"output": "37"
},
{
"input": "52\n38 78 36 75 19 3 56 1 39 97 24 79 84 16 93 55 96 64 12 24 1 86 80 29 12 32 36 36 73 39 76 65 53 98 30 20 28 8 86 43 70 22 75 69 62 65 81 25 53 40 71 59",
"output": "28"
},
{
"input": "74\n81 31 67 97 26 75 69 81 11 13 13 74 77 88 52 20 52 64 66 75 72 28 41 54 26 75 41 91 75 15 18 36 13 83 63 61 14 48 53 63 19 67 35 48 23 65 73 100 44 55 92 88 99 17 73 25 83 7 31 89 12 80 98 39 42 75 14 29 81 35 77 87 33 94",
"output": "47"
},
{
"input": "44\n46 56 31 31 37 71 94 2 14 100 45 72 36 72 80 3 38 54 42 98 50 32 31 42 62 31 45 50 95 100 18 17 64 22 18 25 52 56 70 57 43 40 81 28",
"output": "15"
},
{
"input": "22\n28 57 40 74 51 4 45 84 99 12 95 14 92 60 47 81 84 51 31 91 59 42",
"output": "11"
},
{
"input": "59\n73 45 94 76 41 49 65 13 74 66 36 25 47 75 40 23 92 72 11 32 32 8 81 26 68 56 41 8 76 47 96 55 70 11 84 14 83 18 70 22 30 39 28 100 48 11 92 45 78 69 86 1 54 90 98 91 13 17 35",
"output": "33"
},
{
"input": "63\n20 18 44 94 68 57 16 43 74 55 68 24 21 95 76 84 50 50 47 86 86 12 58 55 28 72 86 18 34 45 81 88 3 72 41 9 60 90 81 93 12 6 9 6 2 41 1 7 9 29 81 14 64 80 20 36 67 54 7 5 35 81 22",
"output": "37"
},
{
"input": "28\n49 84 48 19 44 91 11 82 96 95 88 90 71 82 87 25 31 23 18 13 98 45 26 65 35 12 31 14",
"output": "15"
},
{
"input": "61\n34 18 28 64 28 45 9 77 77 20 63 92 79 16 16 100 86 2 91 91 57 15 31 95 10 88 84 5 82 83 53 98 59 17 97 80 76 80 81 3 91 81 87 93 61 46 10 49 6 22 21 75 63 89 21 81 30 19 67 38 77",
"output": "35"
},
{
"input": "90\n41 90 43 1 28 75 90 50 3 70 76 64 81 63 25 69 83 82 29 91 59 66 21 61 7 55 72 49 38 69 72 20 64 58 30 81 61 29 96 14 39 5 100 20 29 98 75 29 44 78 97 45 26 77 73 59 22 99 41 6 3 96 71 20 9 18 96 18 90 62 34 78 54 5 41 6 73 33 2 54 26 21 18 6 45 57 43 73 95 75",
"output": "42"
},
{
"input": "45\n93 69 4 27 20 14 71 48 79 3 32 26 49 30 57 88 13 56 49 61 37 32 47 41 41 70 45 68 82 18 8 6 25 20 15 13 71 99 28 6 52 34 19 59 26",
"output": "23"
},
{
"input": "33\n29 95 48 49 91 10 83 71 47 25 66 36 51 12 34 10 54 74 41 96 89 26 89 1 42 33 1 62 9 32 49 65 78",
"output": "15"
},
{
"input": "34\n98 24 42 36 41 82 28 58 89 34 77 70 76 44 74 54 66 100 13 79 4 88 21 1 11 45 91 29 87 100 29 54 82 78",
"output": "13"
},
{
"input": "29\n91 84 26 84 9 63 52 9 65 56 90 2 36 7 67 33 91 14 65 38 53 36 81 83 85 14 33 95 51",
"output": "17"
},
{
"input": "100\n2 88 92 82 87 100 78 28 84 43 78 32 43 33 97 19 15 52 29 84 57 72 54 13 99 28 82 79 40 70 34 92 91 53 9 88 27 43 14 92 72 37 26 37 20 95 19 34 49 64 33 37 34 27 80 79 9 54 99 68 25 4 68 73 46 66 24 78 3 87 26 52 50 84 4 95 23 83 39 58 86 36 33 16 98 2 84 19 53 12 69 60 10 11 78 17 79 92 77 59",
"output": "45"
},
{
"input": "100\n2 95 45 73 9 54 20 97 57 82 88 26 18 71 25 27 75 54 31 11 58 85 69 75 72 91 76 5 25 80 45 49 4 73 8 81 81 38 5 12 53 77 7 96 90 35 28 80 73 94 19 69 96 17 94 49 69 9 32 19 5 12 46 29 26 40 59 59 6 95 82 50 72 2 45 69 12 5 72 29 39 72 23 96 81 28 28 56 68 58 37 41 30 1 90 84 15 24 96 43",
"output": "53"
},
{
"input": "100\n27 72 35 91 13 10 35 45 24 55 83 84 63 96 29 79 34 67 63 92 48 83 18 77 28 27 49 66 29 88 55 15 6 58 14 67 94 36 77 7 7 64 61 52 71 18 36 99 76 6 50 67 16 13 41 7 89 73 61 51 78 22 78 32 76 100 3 31 89 71 63 53 15 85 77 54 89 33 68 74 3 23 57 5 43 89 75 35 9 86 90 11 31 46 48 37 74 17 77 8",
"output": "40"
},
{
"input": "100\n69 98 69 88 11 49 55 8 25 91 17 81 47 26 15 73 96 71 18 42 42 61 48 14 92 78 35 72 4 27 62 75 83 79 17 16 46 80 96 90 82 54 37 69 85 21 67 70 96 10 46 63 21 59 56 92 54 88 77 30 75 45 44 29 86 100 51 11 65 69 66 56 82 63 27 1 51 51 13 10 3 55 26 85 34 16 87 72 13 100 81 71 90 95 86 50 83 55 55 54",
"output": "53"
},
{
"input": "100\n34 35 99 64 2 66 78 93 20 48 12 79 19 10 87 7 42 92 60 79 5 2 24 89 57 48 63 92 74 4 16 51 7 12 90 48 87 17 18 73 51 58 97 97 25 38 15 97 96 73 67 91 6 75 14 13 87 79 75 3 15 55 35 95 71 45 10 13 20 37 82 26 2 22 13 83 97 84 39 79 43 100 54 59 98 8 61 34 7 65 75 44 24 77 73 88 34 95 44 77",
"output": "55"
},
{
"input": "100\n15 86 3 1 51 26 74 85 37 87 64 58 10 6 57 26 30 47 85 65 24 72 50 40 12 35 91 47 91 60 47 87 95 34 80 91 26 3 36 39 14 86 28 70 51 44 28 21 72 79 57 61 16 71 100 94 57 67 36 74 24 21 89 85 25 2 97 67 76 53 76 80 97 64 35 13 8 32 21 52 62 61 67 14 74 73 66 44 55 76 24 3 43 42 99 61 36 80 38 66",
"output": "52"
},
{
"input": "100\n45 16 54 54 80 94 74 93 75 85 58 95 79 30 81 2 84 4 57 23 92 64 78 1 50 36 13 27 56 54 10 77 87 1 5 38 85 74 94 82 30 45 72 83 82 30 81 82 82 3 69 82 7 92 39 60 94 42 41 5 3 17 67 21 79 44 79 96 28 3 53 68 79 89 63 83 1 44 4 31 84 15 73 77 19 66 54 6 73 1 67 24 91 11 86 45 96 82 20 89",
"output": "51"
},
{
"input": "100\n84 23 50 32 90 71 92 43 58 70 6 82 7 55 85 19 70 89 12 26 29 56 74 30 2 27 4 39 63 67 91 81 11 33 75 10 82 88 39 43 43 80 68 35 55 67 53 62 73 65 86 74 43 51 14 48 42 92 83 57 22 33 24 99 5 27 78 96 7 28 11 15 8 38 85 67 5 92 24 96 57 59 14 95 91 4 9 18 45 33 74 83 64 85 14 51 51 94 29 2",
"output": "53"
},
{
"input": "100\n77 56 56 45 73 55 32 37 39 50 30 95 79 21 44 34 51 43 86 91 39 30 85 15 35 93 100 14 57 31 80 79 38 40 88 4 91 54 7 95 76 26 62 84 17 33 67 47 6 82 69 51 17 2 59 24 11 12 31 90 12 11 55 38 72 49 30 50 42 46 5 97 9 9 30 45 86 23 19 82 40 42 5 40 35 98 35 32 60 60 5 28 84 35 21 49 68 53 68 23",
"output": "48"
},
{
"input": "100\n78 38 79 61 45 86 83 83 86 90 74 69 2 84 73 39 2 5 20 71 24 80 54 89 58 34 77 40 39 62 2 47 28 53 97 75 88 98 94 96 33 71 44 90 47 36 19 89 87 98 90 87 5 85 34 79 82 3 42 88 89 63 35 7 89 30 40 48 12 41 56 76 83 60 80 80 39 56 77 4 72 96 30 55 57 51 7 19 11 1 66 1 91 87 11 62 95 85 79 25",
"output": "48"
},
{
"input": "100\n5 34 23 20 76 75 19 51 17 82 60 13 83 6 65 16 20 43 66 54 87 10 87 73 50 24 16 98 33 28 80 52 54 82 26 92 14 13 84 92 94 29 61 21 60 20 48 94 24 20 75 70 58 27 68 45 86 89 29 8 67 38 83 48 18 100 11 22 46 84 52 97 70 19 50 75 3 7 52 53 72 41 18 31 1 38 49 53 11 64 99 76 9 87 48 12 100 32 44 71",
"output": "58"
},
{
"input": "100\n76 89 68 78 24 72 73 95 98 72 58 15 2 5 56 32 9 65 50 70 94 31 29 54 89 52 31 93 43 56 26 35 72 95 51 55 78 70 11 92 17 5 54 94 81 31 78 95 73 91 95 37 59 9 53 48 65 55 84 8 45 97 64 37 96 34 36 53 66 17 72 48 99 23 27 18 92 84 44 73 60 78 53 29 68 99 19 39 61 40 69 6 77 12 47 29 15 4 8 45",
"output": "53"
},
{
"input": "100\n82 40 31 53 8 50 85 93 3 84 54 17 96 59 51 42 18 19 35 84 79 31 17 46 54 82 72 49 35 73 26 89 61 73 3 50 12 29 25 77 88 21 58 24 22 89 96 54 82 29 96 56 77 16 1 68 90 93 20 23 57 22 31 18 92 90 51 14 50 72 31 54 12 50 66 62 2 34 17 45 68 50 87 97 23 71 1 72 17 82 42 15 20 78 4 49 66 59 10 17",
"output": "54"
},
{
"input": "100\n32 82 82 24 39 53 48 5 29 24 9 37 91 37 91 95 1 97 84 52 12 56 93 47 22 20 14 17 40 22 79 34 24 2 69 30 69 29 3 89 21 46 60 92 39 29 18 24 49 18 40 22 60 13 77 50 39 64 50 70 99 8 66 31 90 38 20 54 7 21 5 56 41 68 69 20 54 89 69 62 9 53 43 89 81 97 15 2 52 78 89 65 16 61 59 42 56 25 32 52",
"output": "49"
},
{
"input": "100\n72 54 23 24 97 14 99 87 15 25 7 23 17 87 72 31 71 87 34 82 51 77 74 85 62 38 24 7 84 48 98 21 29 71 70 84 25 58 67 92 18 44 32 9 81 15 53 29 63 18 86 16 7 31 38 99 70 32 89 16 23 11 66 96 69 82 97 59 6 9 49 80 85 19 6 9 52 51 85 74 53 46 73 55 31 63 78 61 34 80 77 65 87 77 92 52 89 8 52 31",
"output": "44"
},
{
"input": "100\n56 88 8 19 7 15 11 54 35 50 19 57 63 72 51 43 50 19 57 90 40 100 8 92 11 96 30 32 59 65 93 47 62 3 50 41 30 50 72 83 61 46 83 60 20 46 33 1 5 18 83 22 34 16 41 95 63 63 7 59 55 95 91 29 64 60 64 81 45 45 10 9 88 37 69 85 21 82 41 76 42 34 47 78 51 83 65 100 13 22 59 76 63 1 26 86 36 94 99 74",
"output": "46"
},
{
"input": "100\n27 89 67 60 62 80 43 50 28 88 72 5 94 11 63 91 18 78 99 3 71 26 12 97 74 62 23 24 22 3 100 72 98 7 94 32 12 75 61 88 42 48 10 14 45 9 48 56 73 76 70 70 79 90 35 39 96 37 81 11 19 65 99 39 23 79 34 61 35 74 90 37 73 23 46 21 94 84 73 58 11 89 13 9 10 85 42 78 73 32 53 39 49 90 43 5 28 31 97 75",
"output": "53"
},
{
"input": "100\n33 24 97 96 1 14 99 51 13 65 67 20 46 88 42 44 20 49 5 89 98 83 15 40 74 83 58 3 10 79 34 2 69 28 37 100 55 52 14 8 44 94 97 89 6 42 11 28 30 33 55 56 20 57 52 25 75 1 87 42 62 41 37 12 54 85 95 80 42 36 94 96 28 76 54 36 4 17 26 24 62 15 17 79 84 36 92 78 74 91 96 77 54 92 81 91 62 98 37 37",
"output": "43"
},
{
"input": "100\n86 24 61 15 11 85 1 31 47 36 23 36 59 34 3 27 16 29 82 28 58 52 52 66 71 61 98 39 60 20 67 41 67 90 73 29 92 17 70 95 58 98 58 32 21 73 46 56 87 72 80 75 40 27 94 31 59 92 93 37 14 99 96 21 97 23 81 91 52 52 96 94 92 28 38 29 52 16 57 27 17 24 91 21 79 55 96 98 95 94 23 78 79 12 77 35 32 75 100 82",
"output": "51"
},
{
"input": "100\n88 85 41 37 69 21 7 69 36 5 92 26 64 75 22 46 67 20 70 22 62 66 38 24 47 49 68 30 90 31 67 86 86 82 9 51 43 45 48 42 73 44 31 94 45 60 54 66 20 87 11 94 34 32 87 66 56 28 75 39 37 90 72 93 55 72 31 42 30 71 87 61 4 12 12 81 23 61 56 98 71 32 30 33 96 63 92 16 8 78 47 91 47 54 49 3 81 82 41 5",
"output": "47"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 1 3 2 2",
"output": "3"
}
] | 1,543,914,656 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
if l[i]%2!=0:
ans+=1
print(n-ans) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?
Input Specification:
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag.
Output Specification:
Print in the only line the only number — the sought number of ways. If there are no such ways print 0.
Demo Input:
['1\n1\n', '10\n1 2 2 3 4 4 4 2 2 2\n', '11\n2 2 2 2 2 2 2 2 2 2 99\n']
Demo Output:
['1\n', '8\n', '1\n']
Note:
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies. | ```python
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n):
if l[i]%2!=0:
ans+=1
print(n-ans)
``` | 0 |
|
450 | B | Jzzhu and Sequences | PROGRAMMING | 1,300 | [
"implementation",
"math"
] | null | null | Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7). | The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109). | Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7). | [
"2 3\n3\n",
"0 -1\n2\n"
] | [
"1\n",
"1000000006\n"
] | In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6). | 1,000 | [
{
"input": "2 3\n3",
"output": "1"
},
{
"input": "0 -1\n2",
"output": "1000000006"
},
{
"input": "-9 -11\n12345",
"output": "1000000005"
},
{
"input": "0 0\n1000000000",
"output": "0"
},
{
"input": "-1000000000 1000000000\n2000000000",
"output": "1000000000"
},
{
"input": "-12345678 12345678\n1912345678",
"output": "12345678"
},
{
"input": "728374857 678374857\n1928374839",
"output": "950000007"
},
{
"input": "278374837 992837483\n1000000000",
"output": "721625170"
},
{
"input": "-693849384 502938493\n982838498",
"output": "502938493"
},
{
"input": "-783928374 983738273\n992837483",
"output": "16261734"
},
{
"input": "-872837483 -682738473\n999999999",
"output": "190099010"
},
{
"input": "-892837483 -998273847\n999283948",
"output": "892837483"
},
{
"input": "-283938494 738473848\n1999999999",
"output": "716061513"
},
{
"input": "-278374857 819283838\n1",
"output": "721625150"
},
{
"input": "-1000000000 123456789\n1",
"output": "7"
},
{
"input": "-529529529 -524524524\n2",
"output": "475475483"
},
{
"input": "1 2\n2000000000",
"output": "2"
},
{
"input": "-1 -2\n2000000000",
"output": "1000000005"
},
{
"input": "1 2\n1999999999",
"output": "1"
},
{
"input": "1 2\n1999999998",
"output": "1000000006"
},
{
"input": "1 2\n1999999997",
"output": "1000000005"
},
{
"input": "1 2\n1999999996",
"output": "1000000006"
},
{
"input": "69975122 366233206\n1189460676",
"output": "703741923"
},
{
"input": "812229413 904420051\n806905621",
"output": "812229413"
},
{
"input": "872099024 962697902\n1505821695",
"output": "90598878"
},
{
"input": "887387283 909670917\n754835014",
"output": "112612724"
},
{
"input": "37759824 131342932\n854621399",
"output": "868657075"
},
{
"input": "-246822123 800496170\n626323615",
"output": "753177884"
},
{
"input": "-861439463 974126967\n349411083",
"output": "835566423"
},
{
"input": "-69811049 258093841\n1412447",
"output": "741906166"
},
{
"input": "844509330 -887335829\n123329059",
"output": "844509330"
},
{
"input": "83712471 -876177148\n1213284777",
"output": "40110388"
},
{
"input": "598730524 -718984219\n1282749880",
"output": "401269483"
},
{
"input": "-474244697 -745885656\n1517883612",
"output": "271640959"
},
{
"input": "-502583588 -894906953\n1154189557",
"output": "497416419"
},
{
"input": "-636523651 -873305815\n154879215",
"output": "763217843"
},
{
"input": "721765550 594845720\n78862386",
"output": "126919830"
},
{
"input": "364141461 158854993\n1337196589",
"output": "364141461"
},
{
"input": "878985260 677031952\n394707801",
"output": "798046699"
},
{
"input": "439527072 -24854079\n1129147002",
"output": "464381151"
},
{
"input": "840435009 -612103127\n565968986",
"output": "387896880"
},
{
"input": "875035447 -826471373\n561914518",
"output": "124964560"
},
{
"input": "-342526698 305357084\n70776744",
"output": "352116225"
},
{
"input": "-903244186 899202229\n1527859274",
"output": "899202229"
},
{
"input": "-839482546 815166320\n1127472130",
"output": "839482546"
},
{
"input": "-976992569 -958313041\n1686580818",
"output": "981320479"
},
{
"input": "-497338894 -51069176\n737081851",
"output": "502661113"
},
{
"input": "-697962643 -143148799\n1287886520",
"output": "856851208"
},
{
"input": "-982572938 -482658433\n1259858332",
"output": "982572938"
},
{
"input": "123123 78817\n2000000000",
"output": "78817"
},
{
"input": "1000000000 -1000000000\n3",
"output": "14"
},
{
"input": "-1000000000 1000000000\n6",
"output": "14"
},
{
"input": "2 3\n6",
"output": "1000000006"
},
{
"input": "0 -1\n6",
"output": "1"
},
{
"input": "500000000 -1000000000\n600000003",
"output": "500000014"
},
{
"input": "-1000000000 1000000000\n3",
"output": "999999993"
},
{
"input": "1 3\n6",
"output": "1000000005"
},
{
"input": "1 2\n12",
"output": "1000000006"
},
{
"input": "7 -1000000000\n3",
"output": "0"
},
{
"input": "-999999997 999999997\n6",
"output": "20"
},
{
"input": "3 4\n6",
"output": "1000000006"
},
{
"input": "-1 2\n6",
"output": "1000000004"
},
{
"input": "2 3\n12",
"output": "1000000006"
},
{
"input": "4 18\n6",
"output": "999999993"
},
{
"input": "1 2\n6",
"output": "1000000006"
},
{
"input": "1000000000 -1000000000\n6",
"output": "999999993"
},
{
"input": "999999999 -999999999\n3",
"output": "16"
},
{
"input": "-1 0\n1",
"output": "1000000006"
},
{
"input": "1000000000 -1000000000\n9",
"output": "14"
},
{
"input": "999999999 -1000000000\n12",
"output": "999999992"
},
{
"input": "1000000000 -7\n3",
"output": "0"
},
{
"input": "-5 5\n6",
"output": "999999997"
},
{
"input": "5 9\n6",
"output": "1000000003"
},
{
"input": "-15 -10\n1",
"output": "999999992"
}
] | 1,687,969,215 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 1 | 77 | 3,072,000 | mod=int(1e9+7)
#qm=lambda x:x%mod if x%mod>=0 else x%mod+mod
class Mx:
def __init__(self,a11,a12,a21,a22):
self.a11=a11%mod;self.a12=a12%mod
self.a21=a21%mod;self.a22=a22%mod
def __mul__(self, other):
b11 = self.a11 * other.a11 + self.a12 * other.a21
b12 = self.a11 * other.a12 + self.a12 * other.a22
b21 = self.a21 * other.a11 + self.a22 * other.a21
b22 = self.a21 * other.a12 + self.a22 * other.a22
return Mx(b11,b12,b21,b22)
def __repr__(self):
return f'[{self.a11} {self.a12}]\n[{self.a21} {self.a22}]'
def get(self):
return [self.a11,self.a12,self.a21,self.a22]
def PO(M,n):
A=Mx(1,0,0,1)
while n:
if n&1:A*=M
M*=M;n=n>>1
return A
def Jzzhu_and_Sequences():
f1,f2=map(int,input().split())
n=int(input())
if n == 1:return qm(f1)
elif n == 2: return qm(f2)
n-=2;m_list=PO(Mx(0,-1,1,1),n).get()
return ((f1*m_list[1])%mod+(f2*m_list[3])%mod)%mod
print(Jzzhu_and_Sequences())
| Title: Jzzhu and Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jzzhu has invented a kind of sequences, they meet the following property:
You are given *x* and *y*, please calculate *f**n* modulo 1000000007 (109<=+<=7).
Input Specification:
The first line contains two integers *x* and *y* (|*x*|,<=|*y*|<=≤<=109). The second line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
Output Specification:
Output a single integer representing *f**n* modulo 1000000007 (109<=+<=7).
Demo Input:
['2 3\n3\n', '0 -1\n2\n']
Demo Output:
['1\n', '1000000006\n']
Note:
In the first sample, *f*<sub class="lower-index">2</sub> = *f*<sub class="lower-index">1</sub> + *f*<sub class="lower-index">3</sub>, 3 = 2 + *f*<sub class="lower-index">3</sub>, *f*<sub class="lower-index">3</sub> = 1.
In the second sample, *f*<sub class="lower-index">2</sub> = - 1; - 1 modulo (10<sup class="upper-index">9</sup> + 7) equals (10<sup class="upper-index">9</sup> + 6). | ```python
mod=int(1e9+7)
#qm=lambda x:x%mod if x%mod>=0 else x%mod+mod
class Mx:
def __init__(self,a11,a12,a21,a22):
self.a11=a11%mod;self.a12=a12%mod
self.a21=a21%mod;self.a22=a22%mod
def __mul__(self, other):
b11 = self.a11 * other.a11 + self.a12 * other.a21
b12 = self.a11 * other.a12 + self.a12 * other.a22
b21 = self.a21 * other.a11 + self.a22 * other.a21
b22 = self.a21 * other.a12 + self.a22 * other.a22
return Mx(b11,b12,b21,b22)
def __repr__(self):
return f'[{self.a11} {self.a12}]\n[{self.a21} {self.a22}]'
def get(self):
return [self.a11,self.a12,self.a21,self.a22]
def PO(M,n):
A=Mx(1,0,0,1)
while n:
if n&1:A*=M
M*=M;n=n>>1
return A
def Jzzhu_and_Sequences():
f1,f2=map(int,input().split())
n=int(input())
if n == 1:return qm(f1)
elif n == 2: return qm(f2)
n-=2;m_list=PO(Mx(0,-1,1,1),n).get()
return ((f1*m_list[1])%mod+(f2*m_list[3])%mod)%mod
print(Jzzhu_and_Sequences())
``` | -1 |
|
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},
{
"input": "7\nksjuuerbnlklcfdjeyq 312\ndthjlkrvvbyahttifpdewvyslsh -983\nksjuuerbnlklcfdjeyq 268\ndthjlkrvvbyahttifpdewvyslsh 788\nksjuuerbnlklcfdjeyq -79\nksjuuerbnlklcfdjeyq -593\nksjuuerbnlklcfdjeyq 734",
"output": "ksjuuerbnlklcfdjeyq"
},
{
"input": "12\natrtthfpcvishmqbakprquvnejr 185\natrtthfpcvishmqbakprquvnejr -699\natrtthfpcvishmqbakprquvnejr -911\natrtthfpcvishmqbakprquvnejr -220\nfcgslzkicjrpbqaifgweyzreajjfdo 132\nfcgslzkicjrpbqaifgweyzreajjfdo -242\nm 177\nm -549\natrtthfpcvishmqbakprquvnejr -242\nm 38\natrtthfpcvishmqbakprquvnejr -761\nfcgslzkicjrpbqaifgweyzreajjfdo 879",
"output": "fcgslzkicjrpbqaifgweyzreajjfdo"
},
{
"input": "15\naawtvezfntstrcpgbzjbf 681\nzhahpvqiptvksnbjkdvmknb -74\naawtvezfntstrcpgbzjbf 661\njpdwmyke 474\naawtvezfntstrcpgbzjbf -547\naawtvezfntstrcpgbzjbf 600\nzhahpvqiptvksnbjkdvmknb -11\njpdwmyke 711\nbjmj 652\naawtvezfntstrcpgbzjbf -1000\naawtvezfntstrcpgbzjbf -171\nbjmj -302\naawtvezfntstrcpgbzjbf 961\nzhahpvqiptvksnbjkdvmknb 848\nbjmj -735",
"output": "aawtvezfntstrcpgbzjbf"
},
{
"input": "17\nqdplghhx -649\nivhgbxiv 424\nivhgbxiv -72\nivhgbxiv 479\nugowfouebkelargxylsxn 83\nugowfouebkelargxylsxn -840\nivhgbxiv 382\nqdplghhx -904\nivhgbxiv -710\nugowfouebkelargxylsxn -838\nqdplghhx -974\nqdplghhx 571\nivhgbxiv -145\nugowfouebkelargxylsxn -788\nivhgbxiv 209\nivhgbxiv 420\nqdplghhx -158",
"output": "ivhgbxiv"
}
] | 1,694,070,921 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 307,200 | from collections import Counter
def parse(n):
fs = Counter()
his = []
for _ in n:
name, score = input().split()
score = int(score)
fs[name] += score
his.append((name, fs[name]))
return fs, his
n = range(int(input()))
fs, his = parse(n)
mx = max(fs.values())
win = (name for name, score in his if score >= mx)
print(next(win))
| Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points.
Input Specification:
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive.
Output Specification:
Print the name of the winner.
Demo Input:
['3\nmike 3\nandrew 5\nmike 2\n', '3\nandrew 3\nandrew 2\nmike 5\n']
Demo Output:
['andrew\n', 'andrew\n']
Note:
none | ```python
from collections import Counter
def parse(n):
fs = Counter()
his = []
for _ in n:
name, score = input().split()
score = int(score)
fs[name] += score
his.append((name, fs[name]))
return fs, his
n = range(int(input()))
fs, his = parse(n)
mx = max(fs.values())
win = (name for name, score in his if score >= mx)
print(next(win))
``` | 0 |
113 | A | Grammar Lessons | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | A. Grammar Lessons | 5 | 256 | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. - There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. - Masculine adjectives end with -lios, and feminine adjectives end with -liala. - Masculine nouns end with -etr, and feminime nouns end with -etra. - Masculine verbs end with -initis, and feminime verbs end with -inites. - Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. - It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. - There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. - A sentence is either exactly one valid language word or exactly one statement.
Statement is any sequence of the Petya's language, that satisfy both conditions:
- Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. - All words in the statement should have the same gender.
After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language. | The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language. | If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes). | [
"petr\n",
"etis atis animatis etis atis amatis\n",
"nataliala kataliala vetra feinites\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "petr",
"output": "YES"
},
{
"input": "etis atis animatis etis atis amatis",
"output": "NO"
},
{
"input": "nataliala kataliala vetra feinites",
"output": "YES"
},
{
"input": "qweasbvflios",
"output": "YES"
},
{
"input": "lios lios petr initis qwe",
"output": "NO"
},
{
"input": "lios initis",
"output": "NO"
},
{
"input": "petr initis lios",
"output": "NO"
},
{
"input": "petra petra petra",
"output": "NO"
},
{
"input": "in",
"output": "NO"
},
{
"input": "liala petra initis",
"output": "NO"
},
{
"input": "liala petra inites",
"output": "YES"
},
{
"input": "liala initis",
"output": "NO"
},
{
"input": "liala petra petr inites",
"output": "NO"
},
{
"input": "liala petr inites",
"output": "NO"
},
{
"input": "llilitos",
"output": "NO"
},
{
"input": "umeszdawsvgkjhlqwzentsphxqhdungbylhnikwviuhccbstghhxlmvcjznnkjqkugsdysjbedwpmsmxmgxlrlxctnebtbwrsvgjktkrosffwymovxvsgfmmqwfflpvbumozikroxrdgwjrnstngstxbiyyuxehrhviteptedlmyetr",
"output": "YES"
},
{
"input": "i i i i i i i i i i i i i i i a a a a a a v v v v v v v v v v v",
"output": "NO"
},
{
"input": "fbvzqonvdlqdanwliolaqfj sbauorbinites xkbfnfinitespjy phbexglblzpobtqpisyijycmtliola aosinites lbpjiwcjoqyuhglthloiniteswb mjtxhoofohzzgefvhsywojcuxtetxmojrlktodhbgyrkeejgjzxkzyvrxwmyaqkeoqnvusnlrsfffrzeoqjdfumolhksqkrtzwhnforgpenziokrxlnhcapbbupctlmuetrani pigxerwetupjbkvlmgnjhdfjliolanz tqhaidxbqmdaeincxjuliola",
"output": "NO"
},
{
"input": "mfrmqetr",
"output": "YES"
},
{
"input": "hnwvfllholxfialiola cknjtxpliola daliola gqfapnhmmworliola qhetra qrisbexsrefcwzoxqwxrevinites wwldqkqhvrgwplqinites nqdpoauitczttxoinites fgbmdfpxkhahkinites",
"output": "NO"
},
{
"input": "kcymcpgqdxkudadewddualeemhixhsdazudnjdmuvxvrlrbrpsdpxpagmrogplltnifrtomdtahxwadguvetxaqkvsvnoyhowirnluhmyewzapirnpfdisvhtbenxmfezahqoflkjrfqjubwdfktnpeirodwubftzlcczzavfiooihzvnqincndisudihvbcaxptrwovekmhiiwsgzgbxydvuldlnktxtltrlajjzietkxbnhetra",
"output": "YES"
},
{
"input": "dosiydnwxemojaavfdvlwsyhzqywqjutovygtlcleklhybczhjqfzxwdmlwqwcqqyfjkzhsizlmdarrfronxqkcknwpkvhdlgatdyjisjoopvngpjggldxjfxaauoxmqirkuphydyweoixftstlozaoywnxgriscudwlokncbmaebpssccmmmfjennyjaryqlzjknnklqketra",
"output": "YES"
},
{
"input": "etretra linites",
"output": "YES"
},
{
"input": "petretra petr",
"output": "NO"
},
{
"input": "lialalios petraveryfunnypetr",
"output": "YES"
},
{
"input": "petropetrapetr petra",
"output": "NO"
},
{
"input": "lios petrnonono",
"output": "NO"
},
{
"input": "lios petr initisandinitisandliala petrainitis",
"output": "NO"
},
{
"input": "petro",
"output": "NO"
},
{
"input": "petr initesinitis",
"output": "YES"
},
{
"input": "lios initis",
"output": "NO"
},
{
"input": "liala initespetra",
"output": "YES"
},
{
"input": "lios petrapetr",
"output": "YES"
},
{
"input": "initis petr",
"output": "NO"
},
{
"input": "lioslialapetrpetrainitisinitesliosliala initesinitislioslialapetrpetrainitisinitetra",
"output": "YES"
},
{
"input": "veryfunnyprefixpetr",
"output": "YES"
},
{
"input": "veryfunnyprefixpetra",
"output": "YES"
},
{
"input": "veryfunnyprefixinitis",
"output": "YES"
},
{
"input": "veryfunnyprefixinites",
"output": "YES"
},
{
"input": "veryfunnyprefixliala",
"output": "YES"
},
{
"input": "veryfunnyprefixlios",
"output": "YES"
},
{
"input": "veryfunnyprefixlialas",
"output": "NO"
},
{
"input": "veryfunnyprefixliala veryfunnyprefixpetretra",
"output": "YES"
},
{
"input": "veryfunnyprefixlios veryfunnyprefixinitisetr",
"output": "YES"
},
{
"input": "veryfunnyprefixlios aabbinitis",
"output": "NO"
},
{
"input": "veryfunnyprefixlios inites",
"output": "NO"
},
{
"input": "lios petr initis",
"output": "YES"
},
{
"input": "liala etra inites",
"output": "YES"
},
{
"input": "lios",
"output": "YES"
},
{
"input": "liala",
"output": "YES"
},
{
"input": "initis",
"output": "YES"
},
{
"input": "inites",
"output": "YES"
},
{
"input": "tes",
"output": "NO"
},
{
"input": "tr",
"output": "NO"
},
{
"input": "a",
"output": "NO"
},
{
"input": "lios lios",
"output": "NO"
},
{
"input": "lios",
"output": "YES"
},
{
"input": "liala",
"output": "YES"
},
{
"input": "petr",
"output": "YES"
},
{
"input": "petra",
"output": "YES"
},
{
"input": "pinitis",
"output": "YES"
},
{
"input": "pinites",
"output": "YES"
},
{
"input": "plios pliala",
"output": "NO"
},
{
"input": "plios petr",
"output": "YES"
},
{
"input": "plios petra",
"output": "NO"
},
{
"input": "plios plios",
"output": "NO"
},
{
"input": "plios initis",
"output": "NO"
},
{
"input": "plios pinites",
"output": "NO"
},
{
"input": "pliala plios",
"output": "NO"
},
{
"input": "pliala ppliala",
"output": "NO"
},
{
"input": "pliala petr",
"output": "NO"
},
{
"input": "pliala petra",
"output": "YES"
},
{
"input": "pliala pinitis",
"output": "NO"
},
{
"input": "pliala pinites",
"output": "NO"
},
{
"input": "petr plios",
"output": "NO"
},
{
"input": "petr pliala",
"output": "NO"
},
{
"input": "petr petr",
"output": "NO"
},
{
"input": "petr petra",
"output": "NO"
},
{
"input": "petr pinitis",
"output": "YES"
},
{
"input": "petr pinites",
"output": "NO"
},
{
"input": "petra lios",
"output": "NO"
},
{
"input": "petra liala",
"output": "NO"
},
{
"input": "petra petr",
"output": "NO"
},
{
"input": "petra petra",
"output": "NO"
},
{
"input": "petra initis",
"output": "NO"
},
{
"input": "petra inites",
"output": "YES"
},
{
"input": "initis lios",
"output": "NO"
},
{
"input": "initis liala",
"output": "NO"
},
{
"input": "initis petr",
"output": "NO"
},
{
"input": "initis petra",
"output": "NO"
},
{
"input": "initis initis",
"output": "NO"
},
{
"input": "initis inites",
"output": "NO"
},
{
"input": "inites lios",
"output": "NO"
},
{
"input": "inites liala",
"output": "NO"
},
{
"input": "inites petr",
"output": "NO"
},
{
"input": "inites petra",
"output": "NO"
},
{
"input": "inites initis",
"output": "NO"
},
{
"input": "inites inites",
"output": "NO"
},
{
"input": "lios lios lios",
"output": "NO"
},
{
"input": "lios lios liala",
"output": "NO"
},
{
"input": "lios lios etr",
"output": "YES"
},
{
"input": "lios lios etra",
"output": "NO"
},
{
"input": "lios lios initis",
"output": "NO"
},
{
"input": "lios lios inites",
"output": "NO"
},
{
"input": "lios liala lios",
"output": "NO"
},
{
"input": "lios liala liala",
"output": "NO"
},
{
"input": "lios liala etr",
"output": "NO"
},
{
"input": "lios liala etra",
"output": "NO"
},
{
"input": "lios liala initis",
"output": "NO"
},
{
"input": "lios liala inites",
"output": "NO"
},
{
"input": "lios etr lios",
"output": "NO"
},
{
"input": "lios etr liala",
"output": "NO"
},
{
"input": "lios etr etr",
"output": "NO"
},
{
"input": "lios etr etra",
"output": "NO"
},
{
"input": "lios etr initis",
"output": "YES"
},
{
"input": "lios etr inites",
"output": "NO"
},
{
"input": "lios etra lios",
"output": "NO"
},
{
"input": "lios etra liala",
"output": "NO"
},
{
"input": "lios etra etr",
"output": "NO"
},
{
"input": "lios etra etra",
"output": "NO"
},
{
"input": "lios etra initis",
"output": "NO"
},
{
"input": "lios etra inites",
"output": "NO"
},
{
"input": "lios initis lios",
"output": "NO"
},
{
"input": "lios initis liala",
"output": "NO"
},
{
"input": "lios initis etr",
"output": "NO"
},
{
"input": "lios initis etra",
"output": "NO"
},
{
"input": "lios initis initis",
"output": "NO"
},
{
"input": "lios initis inites",
"output": "NO"
},
{
"input": "lios inites lios",
"output": "NO"
},
{
"input": "lios inites liala",
"output": "NO"
},
{
"input": "lios inites etr",
"output": "NO"
},
{
"input": "lios inites etra",
"output": "NO"
},
{
"input": "lios inites initis",
"output": "NO"
},
{
"input": "lios inites inites",
"output": "NO"
},
{
"input": "liala lios lios",
"output": "NO"
},
{
"input": "liala lios liala",
"output": "NO"
},
{
"input": "liala lios etr",
"output": "NO"
},
{
"input": "liala lios etra",
"output": "NO"
},
{
"input": "liala lios initis",
"output": "NO"
},
{
"input": "liala lios inites",
"output": "NO"
},
{
"input": "liala liala lios",
"output": "NO"
},
{
"input": "liala liala liala",
"output": "NO"
},
{
"input": "liala liala etr",
"output": "NO"
},
{
"input": "liala liala etra",
"output": "YES"
},
{
"input": "liala liala initis",
"output": "NO"
},
{
"input": "liala liala inites",
"output": "NO"
},
{
"input": "liala etr lios",
"output": "NO"
},
{
"input": "liala etr liala",
"output": "NO"
},
{
"input": "liala etr etr",
"output": "NO"
},
{
"input": "liala etr etra",
"output": "NO"
},
{
"input": "liala etr initis",
"output": "NO"
},
{
"input": "liala etr inites",
"output": "NO"
},
{
"input": "liala etra lios",
"output": "NO"
},
{
"input": "liala etra liala",
"output": "NO"
},
{
"input": "liala etra etr",
"output": "NO"
},
{
"input": "liala etra etra",
"output": "NO"
},
{
"input": "liala etra initis",
"output": "NO"
},
{
"input": "liala etra inites",
"output": "YES"
},
{
"input": "liala initis lios",
"output": "NO"
},
{
"input": "liala initis liala",
"output": "NO"
},
{
"input": "liala initis etr",
"output": "NO"
},
{
"input": "liala initis etra",
"output": "NO"
},
{
"input": "liala initis initis",
"output": "NO"
},
{
"input": "liala initis inites",
"output": "NO"
},
{
"input": "liala inites lios",
"output": "NO"
},
{
"input": "liala inites liala",
"output": "NO"
},
{
"input": "liala inites etr",
"output": "NO"
},
{
"input": "liala inites etra",
"output": "NO"
},
{
"input": "liala inites initis",
"output": "NO"
},
{
"input": "liala inites inites",
"output": "NO"
},
{
"input": "etr lios lios",
"output": "NO"
},
{
"input": "etr lios liala",
"output": "NO"
},
{
"input": "etr lios etr",
"output": "NO"
},
{
"input": "etr lios etra",
"output": "NO"
},
{
"input": "etr lios initis",
"output": "NO"
},
{
"input": "etr lios inites",
"output": "NO"
},
{
"input": "etr liala lios",
"output": "NO"
},
{
"input": "etr liala liala",
"output": "NO"
},
{
"input": "etr liala etr",
"output": "NO"
},
{
"input": "etr liala etra",
"output": "NO"
},
{
"input": "etr liala initis",
"output": "NO"
},
{
"input": "etr liala inites",
"output": "NO"
},
{
"input": "etr etr lios",
"output": "NO"
},
{
"input": "etr etr liala",
"output": "NO"
},
{
"input": "etr etr etr",
"output": "NO"
},
{
"input": "etr etr etra",
"output": "NO"
},
{
"input": "etr etr initis",
"output": "NO"
},
{
"input": "etr etr inites",
"output": "NO"
},
{
"input": "etr etra lios",
"output": "NO"
},
{
"input": "etr etra liala",
"output": "NO"
},
{
"input": "etr etra etr",
"output": "NO"
},
{
"input": "etr etra etra",
"output": "NO"
},
{
"input": "etr etra initis",
"output": "NO"
},
{
"input": "etr etra inites",
"output": "NO"
},
{
"input": "etr initis lios",
"output": "NO"
},
{
"input": "etr initis liala",
"output": "NO"
},
{
"input": "etr initis etr",
"output": "NO"
},
{
"input": "etr initis etra",
"output": "NO"
},
{
"input": "etr initis initis",
"output": "YES"
},
{
"input": "etr initis inites",
"output": "NO"
},
{
"input": "etr inites lios",
"output": "NO"
},
{
"input": "etr inites liala",
"output": "NO"
},
{
"input": "etr inites etr",
"output": "NO"
},
{
"input": "etr inites etra",
"output": "NO"
},
{
"input": "etr inites initis",
"output": "NO"
},
{
"input": "etr inites inites",
"output": "NO"
},
{
"input": "etra lios lios",
"output": "NO"
},
{
"input": "etra lios liala",
"output": "NO"
},
{
"input": "etra lios etr",
"output": "NO"
},
{
"input": "etra lios etra",
"output": "NO"
},
{
"input": "etra lios initis",
"output": "NO"
},
{
"input": "etra lios inites",
"output": "NO"
},
{
"input": "etra liala lios",
"output": "NO"
},
{
"input": "etra liala liala",
"output": "NO"
},
{
"input": "etra liala etr",
"output": "NO"
},
{
"input": "etra liala etra",
"output": "NO"
},
{
"input": "etra liala initis",
"output": "NO"
},
{
"input": "etra liala inites",
"output": "NO"
},
{
"input": "etra etr lios",
"output": "NO"
},
{
"input": "etra etr liala",
"output": "NO"
},
{
"input": "etra etr etr",
"output": "NO"
},
{
"input": "etra etr etra",
"output": "NO"
},
{
"input": "etra etr initis",
"output": "NO"
},
{
"input": "etra etr inites",
"output": "NO"
},
{
"input": "etra etra lios",
"output": "NO"
},
{
"input": "etra etra liala",
"output": "NO"
},
{
"input": "etra etra etr",
"output": "NO"
},
{
"input": "etra etra etra",
"output": "NO"
},
{
"input": "etra etra initis",
"output": "NO"
},
{
"input": "etra etra inites",
"output": "NO"
},
{
"input": "etra initis lios",
"output": "NO"
},
{
"input": "etra initis liala",
"output": "NO"
},
{
"input": "etra initis etr",
"output": "NO"
},
{
"input": "etra initis etra",
"output": "NO"
},
{
"input": "etra initis initis",
"output": "NO"
},
{
"input": "etra initis inites",
"output": "NO"
},
{
"input": "etra inites lios",
"output": "NO"
},
{
"input": "etra inites liala",
"output": "NO"
},
{
"input": "etra inites etr",
"output": "NO"
},
{
"input": "etra inites etra",
"output": "NO"
},
{
"input": "etra inites initis",
"output": "NO"
},
{
"input": "etra inites inites",
"output": "YES"
},
{
"input": "initis lios lios",
"output": "NO"
},
{
"input": "initis lios liala",
"output": "NO"
},
{
"input": "initis lios etr",
"output": "NO"
},
{
"input": "initis lios etra",
"output": "NO"
},
{
"input": "initis lios initis",
"output": "NO"
},
{
"input": "initis lios inites",
"output": "NO"
},
{
"input": "initis liala lios",
"output": "NO"
},
{
"input": "initis liala liala",
"output": "NO"
},
{
"input": "initis liala etr",
"output": "NO"
},
{
"input": "initis liala etra",
"output": "NO"
},
{
"input": "initis liala initis",
"output": "NO"
},
{
"input": "initis liala inites",
"output": "NO"
},
{
"input": "initis etr lios",
"output": "NO"
},
{
"input": "initis etr liala",
"output": "NO"
},
{
"input": "initis etr etr",
"output": "NO"
},
{
"input": "initis etr etra",
"output": "NO"
},
{
"input": "initis etr initis",
"output": "NO"
},
{
"input": "initis etr inites",
"output": "NO"
},
{
"input": "initis etra lios",
"output": "NO"
},
{
"input": "initis etra liala",
"output": "NO"
},
{
"input": "initis etra etr",
"output": "NO"
},
{
"input": "initis etra etra",
"output": "NO"
},
{
"input": "initis etra initis",
"output": "NO"
},
{
"input": "initis etra inites",
"output": "NO"
},
{
"input": "initis initis lios",
"output": "NO"
},
{
"input": "initis initis liala",
"output": "NO"
},
{
"input": "initis initis etr",
"output": "NO"
},
{
"input": "initis initis etra",
"output": "NO"
},
{
"input": "initis initis initis",
"output": "NO"
},
{
"input": "initis initis inites",
"output": "NO"
},
{
"input": "initis inites lios",
"output": "NO"
},
{
"input": "initis inites liala",
"output": "NO"
},
{
"input": "initis inites etr",
"output": "NO"
},
{
"input": "initis inites etra",
"output": "NO"
},
{
"input": "initis inites initis",
"output": "NO"
},
{
"input": "initis inites inites",
"output": "NO"
},
{
"input": "inites lios lios",
"output": "NO"
},
{
"input": "inites lios liala",
"output": "NO"
},
{
"input": "inites lios etr",
"output": "NO"
},
{
"input": "inites lios etra",
"output": "NO"
},
{
"input": "inites lios initis",
"output": "NO"
},
{
"input": "inites lios inites",
"output": "NO"
},
{
"input": "inites liala lios",
"output": "NO"
},
{
"input": "inites liala liala",
"output": "NO"
},
{
"input": "inites liala etr",
"output": "NO"
},
{
"input": "inites liala etra",
"output": "NO"
},
{
"input": "inites liala initis",
"output": "NO"
},
{
"input": "inites liala inites",
"output": "NO"
},
{
"input": "inites etr lios",
"output": "NO"
},
{
"input": "inites etr liala",
"output": "NO"
},
{
"input": "inites etr etr",
"output": "NO"
},
{
"input": "inites etr etra",
"output": "NO"
},
{
"input": "inites etr initis",
"output": "NO"
},
{
"input": "inites etr inites",
"output": "NO"
},
{
"input": "inites etra lios",
"output": "NO"
},
{
"input": "inites etra liala",
"output": "NO"
},
{
"input": "inites etra etr",
"output": "NO"
},
{
"input": "inites etra etra",
"output": "NO"
},
{
"input": "inites etra initis",
"output": "NO"
},
{
"input": "inites etra inites",
"output": "NO"
},
{
"input": "inites initis lios",
"output": "NO"
},
{
"input": "inites initis liala",
"output": "NO"
},
{
"input": "inites initis etr",
"output": "NO"
},
{
"input": "inites initis etra",
"output": "NO"
},
{
"input": "inites initis initis",
"output": "NO"
},
{
"input": "inites initis inites",
"output": "NO"
},
{
"input": "inites inites lios",
"output": "NO"
},
{
"input": "inites inites liala",
"output": "NO"
},
{
"input": "inites inites etr",
"output": "NO"
},
{
"input": "inites inites etra",
"output": "NO"
},
{
"input": "inites inites initis",
"output": "NO"
},
{
"input": "inites inites inites",
"output": "NO"
}
] | 1,652,614,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 4,505,600 | n = input().split()
w = 0
x=y=z=0
while w<len(n):
if n[w][-4:]=="lios" or n[w][-5:]=="liala":
x+=1
w+=1
else:
break
while w<len(n):
if n[w][-3:]=="etr" or n[w][-4:]=="etra":
y+=1
w+=1
else:
break
while w<len(n):
if n[w][-6:]=="initis" or n[w][-6:]=="inites":
z+=1
w+=1
else:
break
if len(n)==1 and x+y+z==len(n):
print("YES")
else:
if y==1 and x+y+z==len(n):
print("YES")
else:
print("NO") | Title: Grammar Lessons
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of speech: the adjective, the noun, the verb. Each word in his language is an adjective, noun or verb. - There are two genders: masculine and feminine. Each word in his language has gender either masculine or feminine. - Masculine adjectives end with -lios, and feminine adjectives end with -liala. - Masculine nouns end with -etr, and feminime nouns end with -etra. - Masculine verbs end with -initis, and feminime verbs end with -inites. - Thus, each word in the Petya's language has one of the six endings, given above. There are no other endings in Petya's language. - It is accepted that the whole word consists of an ending. That is, words "lios", "liala", "etr" and so on belong to the Petya's language. - There aren't any punctuation marks, grammatical tenses, singular/plural forms or other language complications. - A sentence is either exactly one valid language word or exactly one statement.
Statement is any sequence of the Petya's language, that satisfy both conditions:
- Words in statement follow in the following order (from the left to the right): zero or more adjectives followed by exactly one noun followed by zero or more verbs. - All words in the statement should have the same gender.
After Petya's friend Vasya wrote instant messenger (an instant messaging program) that supported the Petya's language, Petya wanted to add spelling and grammar checking to the program. As Vasya was in the country and Petya didn't feel like waiting, he asked you to help him with this problem. Your task is to define by a given sequence of words, whether it is true that the given text represents exactly one sentence in Petya's language.
Input Specification:
The first line contains one or more words consisting of lowercase Latin letters. The overall number of characters (including letters and spaces) does not exceed 105.
It is guaranteed that any two consecutive words are separated by exactly one space and the input data do not contain any other spaces. It is possible that given words do not belong to the Petya's language.
Output Specification:
If some word of the given text does not belong to the Petya's language or if the text contains more that one sentence, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes).
Demo Input:
['petr\n', 'etis atis animatis etis atis amatis\n', 'nataliala kataliala vetra feinites\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
n = input().split()
w = 0
x=y=z=0
while w<len(n):
if n[w][-4:]=="lios" or n[w][-5:]=="liala":
x+=1
w+=1
else:
break
while w<len(n):
if n[w][-3:]=="etr" or n[w][-4:]=="etra":
y+=1
w+=1
else:
break
while w<len(n):
if n[w][-6:]=="initis" or n[w][-6:]=="inites":
z+=1
w+=1
else:
break
if len(n)==1 and x+y+z==len(n):
print("YES")
else:
if y==1 and x+y+z==len(n):
print("YES")
else:
print("NO")
``` | 0 |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. | Print a single integer — the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
{
"input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0",
"output": "4"
},
{
"input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1",
"output": "10"
},
{
"input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1",
"output": "29"
},
{
"input": "1\n1 1 1",
"output": "1"
},
{
"input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1",
"output": "4"
},
{
"input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1",
"output": "16"
}
] | 1,699,804,279 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 21 | 186 | 2,355,200 | a = int(input())
counter = 0
for x in range(a):
b = str(input()).split()
c = [list(map(int, b))]
for i in c:
count = sum(i)
if count >= 2:
counter += 1
print(counter)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution.
This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
Input Specification:
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Output Specification:
Print a single integer — the number of problems the friends will implement on the contest.
Demo Input:
['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n']
Demo Output:
['2\n', '1\n']
Note:
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it.
In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution. | ```python
a = int(input())
counter = 0
for x in range(a):
b = str(input()).split()
c = [list(map(int, b))]
for i in c:
count = sum(i)
if count >= 2:
counter += 1
print(counter)
``` | 3 |
|
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,637,634,550 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | def checkEquilibrium( n,matrix ):
forces = 0
i,j = 0,0
while j < 3:
while i < n:
forces += matrix[i][j]
i += 1
if not forces == 0:
return 'NO'
forces = 0
i = 0
j += 1
return 'YES'
matrix = []
n = int( input() )
for _ in range(n):
forces = [ int(x) for x in input().split() ]
matrix.append( forces )
print( checkEquilibrium( n,matrix ) )
| 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
def checkEquilibrium( n,matrix ):
forces = 0
i,j = 0,0
while j < 3:
while i < n:
forces += matrix[i][j]
i += 1
if not forces == 0:
return 'NO'
forces = 0
i = 0
j += 1
return 'YES'
matrix = []
n = int( input() )
for _ in range(n):
forces = [ int(x) for x in input().split() ]
matrix.append( forces )
print( checkEquilibrium( n,matrix ) )
``` | 3.977 |
863 | A | Quasi-palindrome | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number. | The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes. | Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes). | [
"131\n",
"320\n",
"2010200\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 0 | [
{
"input": "131",
"output": "YES"
},
{
"input": "320",
"output": "NO"
},
{
"input": "2010200",
"output": "YES"
},
{
"input": "1",
"output": "YES"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "999999999",
"output": "YES"
},
{
"input": "999999998",
"output": "NO"
},
{
"input": "102000",
"output": "NO"
},
{
"input": "210000000",
"output": "NO"
},
{
"input": "213443120",
"output": "YES"
},
{
"input": "99",
"output": "YES"
},
{
"input": "22002",
"output": "NO"
},
{
"input": "1010",
"output": "YES"
},
{
"input": "1201",
"output": "NO"
},
{
"input": "6460046",
"output": "NO"
},
{
"input": "503435",
"output": "NO"
},
{
"input": "21002",
"output": "NO"
},
{
"input": "101001",
"output": "NO"
},
{
"input": "200102",
"output": "NO"
},
{
"input": "20010002",
"output": "NO"
},
{
"input": "33003",
"output": "NO"
},
{
"input": "100101",
"output": "NO"
},
{
"input": "1021",
"output": "NO"
},
{
"input": "1101",
"output": "NO"
},
{
"input": "10101100",
"output": "NO"
},
{
"input": "101",
"output": "YES"
},
{
"input": "1011",
"output": "NO"
},
{
"input": "11010",
"output": "NO"
},
{
"input": "10110",
"output": "NO"
},
{
"input": "110000",
"output": "YES"
},
{
"input": "2011",
"output": "NO"
},
{
"input": "10020001",
"output": "NO"
},
{
"input": "12505021",
"output": "NO"
},
{
"input": "12310",
"output": "NO"
},
{
"input": "100501",
"output": "NO"
},
{
"input": "11001",
"output": "NO"
},
{
"input": "20020002",
"output": "NO"
},
{
"input": "202002",
"output": "NO"
},
{
"input": "1001",
"output": "YES"
},
{
"input": "1020021",
"output": "NO"
},
{
"input": "60660",
"output": "NO"
},
{
"input": "98809",
"output": "NO"
},
{
"input": "11000000",
"output": "YES"
},
{
"input": "807008",
"output": "NO"
}
] | 1,582,379,643 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | a = list(input())
while a[-1] == 0:
a.pop()
for i in range (len(a) // 2):
if a[i] != a[-1 - i]:
print ("NO")
print ("YES")
| Title: Quasi-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string.
String *t* is called a palindrome, if it reads the same from left to right and from right to left.
For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings "131" and "002010200", respectively, which are palindromes.
You are given some integer number *x*. Check if it's a quasi-palindromic number.
Input Specification:
The first line contains one integer number *x* (1<=≤<=*x*<=≤<=109). This number is given without any leading zeroes.
Output Specification:
Print "YES" if number *x* is quasi-palindromic. Otherwise, print "NO" (without quotes).
Demo Input:
['131\n', '320\n', '2010200\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
a = list(input())
while a[-1] == 0:
a.pop()
for i in range (len(a) // 2):
if a[i] != a[-1 - i]:
print ("NO")
print ("YES")
``` | 0 |
|
299 | B | Ksusha the Squirrel | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".". | Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). | [
"2 1\n..\n",
"5 2\n.#.#.\n",
"7 3\n.#.###.\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 1,000 | [
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "5 2\n.#.#.",
"output": "YES"
},
{
"input": "7 3\n.#.###.",
"output": "NO"
},
{
"input": "2 200\n..",
"output": "YES"
},
{
"input": "2 1\n..",
"output": "YES"
},
{
"input": "2 2\n..",
"output": "YES"
},
{
"input": "2 100000\n..",
"output": "YES"
},
{
"input": "3 1\n.#.",
"output": "NO"
},
{
"input": "3 2\n.#.",
"output": "YES"
},
{
"input": "3 10000\n.#.",
"output": "YES"
}
] | 1,630,569,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 6,963,200 | # x = input("").split() # her will input number of steps and step level
# all_step = int(x[0])
# lev_step = int(x[1])
# string = input("")
# i = 1
# while i < all_step:
# j = i
# while j <= lev_step+i:
# if string[j] == ".":
# i = j
# continue
# j += 1
# print("No")
import sys
x = input("").split() # her will input number of steps and step level
all_step = int(x[0])
lev_step = int(x[1])
string = input("")
i = 1
j = 1
while i <= all_step-1: # طالما أننا لم نصل االى آخر خطوة
while j <= lev_step+i: # طالما أن خطوته ممكنة
if string[j] == ".": # طالما أن من الممكن أن يقف ولم بتجاوز الحد الأقصى من الخطوات
if string[j] == "." and j == all_step-1:
print("Yes")
j += 1
i = j
break
elif j == lev_step+i-1 and string[j] == "#":
print("No")
sys.exit()
elif string[j] == "#": # طالما أن الخطوة التالية صخرة
j += 1
continue
| Title: Ksusha the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1.
Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks.
Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*.
Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)?
Input Specification:
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=3·105,<=1<=≤<=*k*<=≤<=3·105). The next line contains *n* characters — the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#".
It is guaranteed that the first and the last characters equal ".".
Output Specification:
Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes).
Demo Input:
['2 1\n..\n', '5 2\n.#.#.\n', '7 3\n.#.###.\n']
Demo Output:
['YES\n', 'YES\n', 'NO\n']
Note:
none | ```python
# x = input("").split() # her will input number of steps and step level
# all_step = int(x[0])
# lev_step = int(x[1])
# string = input("")
# i = 1
# while i < all_step:
# j = i
# while j <= lev_step+i:
# if string[j] == ".":
# i = j
# continue
# j += 1
# print("No")
import sys
x = input("").split() # her will input number of steps and step level
all_step = int(x[0])
lev_step = int(x[1])
string = input("")
i = 1
j = 1
while i <= all_step-1: # طالما أننا لم نصل االى آخر خطوة
while j <= lev_step+i: # طالما أن خطوته ممكنة
if string[j] == ".": # طالما أن من الممكن أن يقف ولم بتجاوز الحد الأقصى من الخطوات
if string[j] == "." and j == all_step-1:
print("Yes")
j += 1
i = j
break
elif j == lev_step+i-1 and string[j] == "#":
print("No")
sys.exit()
elif string[j] == "#": # طالما أن الخطوة التالية صخرة
j += 1
continue
``` | 0 |
|
690 | C2 | Brain Network (medium) | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of its nervous system. More precisely, we define the distance between two brains *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) as the minimum number of brain connectors used when transmitting a thought between these two brains. The brain latency of a zombie is defined to be the maximum distance between any two of its brains. Researchers conjecture that the brain latency is the crucial parameter which determines how smart a given zombie is. Help them test this conjecture by writing a program to compute brain latencies of nervous systems.
In this problem you may assume that any nervous system given in the input is valid, i.e., it satisfies conditions (1) and (2) from the easy version. | The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n* and *a*<=≠<=*b*). | Print one number – the brain latency. | [
"4 3\n1 2\n1 3\n1 4\n",
"5 4\n1 2\n2 3\n3 4\n3 5\n"
] | [
"2",
"3"
] | none | 0 | [
{
"input": "2 1\n1 2",
"output": "1"
},
{
"input": "3 2\n2 1\n3 2",
"output": "2"
},
{
"input": "10 9\n5 1\n1 2\n9 3\n10 5\n6 3\n8 5\n2 7\n2 3\n9 4",
"output": "6"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n3 5",
"output": "3"
}
] | 1,672,492,881 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | from collections import defaultdict,deque
nodes,edges = list(map(int,input().split()))
graph = defaultdict(list)
in_degree = defaultdict(int)
for edge in range(edges):
a,b = input().split()
graph[a].append(b)
graph[b].append(a)
in_degree[a] += 1
in_degree[b] += 1
queue = deque()
visited = set()
for node in range(1,nodes+1):
node = str(node)
if in_degree[node] == 1:
visited.add(node)
queue.append((node,node))
break
m = 0
while queue:
lgth = len(queue)
count = 0
while lgth:
node,prnt = queue.popleft()
for nxt in graph[node]:
if nxt != prnt:
if nxt not in visited:
count += 1
visited.add(nxt)
queue.append((nxt,node))
lgth -= 1
m += 1
print(m-1)
| Title: Brain Network (medium)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Further research on zombie thought processes yielded interesting results. As we know from the previous problem, the nervous system of a zombie consists of *n* brains and *m* brain connectors joining some pairs of brains together. It was observed that the intellectual abilities of a zombie depend mainly on the topology of its nervous system. More precisely, we define the distance between two brains *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*) as the minimum number of brain connectors used when transmitting a thought between these two brains. The brain latency of a zombie is defined to be the maximum distance between any two of its brains. Researchers conjecture that the brain latency is the crucial parameter which determines how smart a given zombie is. Help them test this conjecture by writing a program to compute brain latencies of nervous systems.
In this problem you may assume that any nervous system given in the input is valid, i.e., it satisfies conditions (1) and (2) from the easy version.
Input Specification:
The first line of the input contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100000) denoting the number of brains (which are conveniently numbered from 1 to *n*) and the number of brain connectors in the nervous system, respectively. In the next *m* lines, descriptions of brain connectors follow. Every connector is given as a pair of brains *a* *b* it connects (1<=≤<=*a*,<=*b*<=≤<=*n* and *a*<=≠<=*b*).
Output Specification:
Print one number – the brain latency.
Demo Input:
['4 3\n1 2\n1 3\n1 4\n', '5 4\n1 2\n2 3\n3 4\n3 5\n']
Demo Output:
['2', '3']
Note:
none | ```python
from collections import defaultdict,deque
nodes,edges = list(map(int,input().split()))
graph = defaultdict(list)
in_degree = defaultdict(int)
for edge in range(edges):
a,b = input().split()
graph[a].append(b)
graph[b].append(a)
in_degree[a] += 1
in_degree[b] += 1
queue = deque()
visited = set()
for node in range(1,nodes+1):
node = str(node)
if in_degree[node] == 1:
visited.add(node)
queue.append((node,node))
break
m = 0
while queue:
lgth = len(queue)
count = 0
while lgth:
node,prnt = queue.popleft()
for nxt in graph[node]:
if nxt != prnt:
if nxt not in visited:
count += 1
visited.add(nxt)
queue.append((nxt,node))
lgth -= 1
m += 1
print(m-1)
``` | 0 |
|
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,693,415,706 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 0 | k = int(input())
l = int(input())
c = 0
s = ''
while l > k:
c += 1
if k == 1 :
s = 'YES'
break
else:
l //= k
if l == k:
print('YES')
print(c)
else:
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
k = int(input())
l = int(input())
c = 0
s = ''
while l > k:
c += 1
if k == 1 :
s = 'YES'
break
else:
l //= k
if l == k:
print('YES')
print(c)
else:
print('NO')
``` | 0 |
|
219 | B | Special Offer! Super Price 999 Bourles! | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than *d* bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price. | The first line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=1018; 0<=≤<=*d*<=<<=*p*) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
The required number shouldn't have leading zeroes. | [
"1029 102\n",
"27191 17\n"
] | [
"999\n",
"27189\n"
] | none | 1,000 | [
{
"input": "1029 102",
"output": "999"
},
{
"input": "27191 17",
"output": "27189"
},
{
"input": "1 0",
"output": "1"
},
{
"input": "9 0",
"output": "9"
},
{
"input": "20 1",
"output": "19"
},
{
"input": "100 23",
"output": "99"
},
{
"input": "10281 1",
"output": "10281"
},
{
"input": "2111 21",
"output": "2099"
},
{
"input": "3021 112",
"output": "2999"
},
{
"input": "1000000000000000000 999999999999999999",
"output": "999999999999999999"
},
{
"input": "29287101 301",
"output": "29286999"
},
{
"input": "302918113 8113",
"output": "302917999"
},
{
"input": "23483247283432 47283432",
"output": "23483239999999"
},
{
"input": "47283432 7283432",
"output": "46999999"
},
{
"input": "7283432 7283431",
"output": "6999999"
},
{
"input": "2304324853947 5853947",
"output": "2304319999999"
},
{
"input": "2485348653485 123483",
"output": "2485348599999"
},
{
"input": "29845435345 34543",
"output": "29845429999"
},
{
"input": "2348723847234234 234829384234",
"output": "2348699999999999"
},
{
"input": "2348723847234234 234829384234",
"output": "2348699999999999"
},
{
"input": "596383801524465437 13997918422040",
"output": "596379999999999999"
},
{
"input": "621306590487786841 47851896849379",
"output": "621299999999999999"
},
{
"input": "990575220328844835 100861359807341",
"output": "990499999999999999"
},
{
"input": "403277728241895842 15097810739041",
"output": "403269999999999999"
},
{
"input": "287854791214303304 98046359947548",
"output": "287799999999999999"
},
{
"input": "847222126505823289 115713658562976",
"output": "847199999999999999"
},
{
"input": "991096248227872657 181679439312637",
"output": "990999999999999999"
},
{
"input": "954402996235787062 354162450334047",
"output": "954399999999999999"
},
{
"input": "220466716596033408 44952575147901",
"output": "220459999999999999"
},
{
"input": "559198116944738707 844709119308273",
"output": "558999999999999999"
},
{
"input": "363980380443991024 4242310030748",
"output": "363979999999999999"
},
{
"input": "733498827000355608 13253459808159",
"output": "733489999999999999"
},
{
"input": "757663489894439901 139905688448459",
"output": "757599999999999999"
},
{
"input": "30528581170507487 1199546082507",
"output": "30527999999999999"
},
{
"input": "534463403123444176 67776394133861",
"output": "534399999999999999"
},
{
"input": "399943891120381720 89545256475298",
"output": "399899999999999999"
},
{
"input": "697076786191991245 95935185412097",
"output": "696999999999999999"
},
{
"input": "495773842562930245 17116719198640",
"output": "495769999999999999"
},
{
"input": "343540186435799067 48368225269792",
"output": "343499999999999999"
},
{
"input": "393776794010351632 4138311260892",
"output": "393775999999999999"
},
{
"input": "830005749156754342 157633405415940",
"output": "829999999999999999"
},
{
"input": "735716632509713228 109839072010906",
"output": "735699999999999999"
},
{
"input": "925835698451819219 232827103605000",
"output": "925799999999999999"
},
{
"input": "362064657893189225 54298707317247",
"output": "362059999999999999"
},
{
"input": "286739242579659245 61808986676984",
"output": "286699999999999999"
},
{
"input": "234522568185994645 14536016333590",
"output": "234519999999999999"
},
{
"input": "989980699593228598 382407804389880",
"output": "989899999999999999"
},
{
"input": "953287447601143003 367647762226264",
"output": "952999999999999999"
},
{
"input": "369834331957505226 421031521866991",
"output": "369799999999999999"
},
{
"input": "433225528653135646 16671330805568",
"output": "433219999999999999"
},
{
"input": "664584428369850915 516656201621892",
"output": "664499999999999999"
},
{
"input": "100813383516253625 468493737928751",
"output": "100799999999999999"
},
{
"input": "63600749936231318 12287109070881",
"output": "63599999999999999"
},
{
"input": "196643334958802150 3659421793154",
"output": "196639999999999999"
},
{
"input": "803015192835672406 14043666502157",
"output": "803009999999999999"
},
{
"input": "43201857567928862 5891486380570",
"output": "43199999999999999"
},
{
"input": "142195487377202511 32209508975060",
"output": "142189999999999999"
},
{
"input": "159171676706847083 28512592184962",
"output": "159169999999999999"
},
{
"input": "377788117133266645 12127036235155",
"output": "377779999999999999"
},
{
"input": "949501478909148807 31763408418934",
"output": "949499999999999999"
},
{
"input": "955412075341421601 220849506773896",
"output": "955399999999999999"
},
{
"input": "652742935922718161 11045914932687",
"output": "652739999999999999"
},
{
"input": "371621017875752909 511452352707014",
"output": "371599999999999999"
},
{
"input": "979748686171802330 281906901894586",
"output": "979699999999999999"
},
{
"input": "987860891213585005 85386263418762",
"output": "987799999999999999"
},
{
"input": "59225847802373220 8605552735740",
"output": "59219999999999999"
},
{
"input": "22532595810287625 1459945485391",
"output": "22531999999999999"
},
{
"input": "191654878233371957 258451919478343",
"output": "191599999999999999"
},
{
"input": "796937674525939896 892734175683845",
"output": "796899999999999999"
},
{
"input": "166564871934000326 22888347028438",
"output": "166559999999999999"
},
{
"input": "559198116944738707 84470911930827",
"output": "559189999999999999"
},
{
"input": "559198116944738707 8447091193082",
"output": "559189999999999999"
},
{
"input": "559198116944738707 844709119308",
"output": "559197999999999999"
},
{
"input": "559198116944738707 84470911930",
"output": "559198099999999999"
},
{
"input": "559198116944738707 8447091193",
"output": "559198109999999999"
},
{
"input": "559198116944738707 844709119",
"output": "559198116899999999"
},
{
"input": "559198116944738707 84470911",
"output": "559198116899999999"
},
{
"input": "559198116944738707 8447091",
"output": "559198116939999999"
},
{
"input": "559198116944738707 844709",
"output": "559198116943999999"
},
{
"input": "559198116944738707 84470",
"output": "559198116944699999"
},
{
"input": "559198116944738707 8447",
"output": "559198116944737999"
},
{
"input": "559198116944738707 844",
"output": "559198116944737999"
},
{
"input": "559198116944738707 84",
"output": "559198116944738699"
},
{
"input": "559198116944738707 8",
"output": "559198116944738699"
},
{
"input": "559198116944738707 7",
"output": "559198116944738707"
},
{
"input": "559198116944738707 6",
"output": "559198116944738707"
},
{
"input": "559198116944738707 1",
"output": "559198116944738707"
},
{
"input": "559198116944738707 0",
"output": "559198116944738707"
},
{
"input": "559198116944738700 1",
"output": "559198116944738699"
},
{
"input": "559198116944738700 0",
"output": "559198116944738700"
},
{
"input": "559198116944738999 0",
"output": "559198116944738999"
},
{
"input": "559198116944738999 1",
"output": "559198116944738999"
},
{
"input": "199 100",
"output": "199"
},
{
"input": "99 10",
"output": "99"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "18 17",
"output": "9"
},
{
"input": "199 198",
"output": "199"
},
{
"input": "1000000000000000000 0",
"output": "1000000000000000000"
},
{
"input": "59 3",
"output": "59"
},
{
"input": "9999 10",
"output": "9999"
},
{
"input": "999999999999999998 999999999999999997",
"output": "899999999999999999"
},
{
"input": "8 7",
"output": "8"
}
] | 1,623,166,031 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 310 | 0 | p,d = map(int,input().split())
k=0
if d==0:
print(p)
exit()
x=[p]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
| Title: Special Offer! Super Price 999 Bourles!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is an amateur businessman. Recently he was surprised to find out that the market for paper scissors is completely free! Without further ado, Polycarpus decided to start producing and selling such scissors.
Polycaprus calculated that the optimal celling price for such scissors would be *p* bourles. However, he read somewhere that customers are attracted by prices that say something like "Special Offer! Super price 999 bourles!". So Polycarpus decided to lower the price a little if it leads to the desired effect.
Polycarpus agrees to lower the price by no more than *d* bourles so that the number of nines at the end of the resulting price is maximum. If there are several ways to do it, he chooses the maximum possible price.
Note, Polycarpus counts only the trailing nines in a price.
Input Specification:
The first line contains two integers *p* and *d* (1<=≤<=*p*<=≤<=1018; 0<=≤<=*d*<=<<=*p*) — the initial price of scissors and the maximum possible price reduction.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Output Specification:
Print the required price — the maximum price that ends with the largest number of nines and that is less than *p* by no more than *d*.
The required number shouldn't have leading zeroes.
Demo Input:
['1029 102\n', '27191 17\n']
Demo Output:
['999\n', '27189\n']
Note:
none | ```python
p,d = map(int,input().split())
k=0
if d==0:
print(p)
exit()
x=[p]
while(10**k<d):
x.append(p-(p%10**k)-1)
k+=1
print(x[-1])
``` | 0 |
|
653 | A | Bear and Three Balls | PROGRAMMING | 900 | [
"brute force",
"implementation",
"sortings"
] | null | null | Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above. | The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. | Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). | [
"4\n18 55 16 17\n",
"6\n40 41 43 44 44 44\n",
"8\n5 972 3 4 1 4 970 971\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | 500 | [
{
"input": "4\n18 55 16 17",
"output": "YES"
},
{
"input": "6\n40 41 43 44 44 44",
"output": "NO"
},
{
"input": "8\n5 972 3 4 1 4 970 971",
"output": "YES"
},
{
"input": "3\n959 747 656",
"output": "NO"
},
{
"input": "4\n1 2 2 3",
"output": "YES"
},
{
"input": "50\n998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543",
"output": "NO"
},
{
"input": "50\n941 877 987 982 966 979 984 810 811 909 872 980 957 897 845 995 924 905 984 914 824 840 868 910 815 808 872 858 883 952 823 835 860 874 959 972 931 867 866 987 982 837 800 921 887 910 982 980 828 869",
"output": "YES"
},
{
"input": "3\n408 410 409",
"output": "YES"
},
{
"input": "3\n903 902 904",
"output": "YES"
},
{
"input": "3\n399 400 398",
"output": "YES"
},
{
"input": "3\n450 448 449",
"output": "YES"
},
{
"input": "3\n390 389 388",
"output": "YES"
},
{
"input": "3\n438 439 440",
"output": "YES"
},
{
"input": "11\n488 688 490 94 564 615 641 170 489 517 669",
"output": "YES"
},
{
"input": "24\n102 672 983 82 720 501 81 721 982 312 207 897 159 964 611 956 118 984 37 271 596 403 772 954",
"output": "YES"
},
{
"input": "36\n175 551 70 479 875 480 979 32 465 402 640 116 76 687 874 678 359 785 753 401 978 629 162 963 886 641 39 845 132 930 2 372 478 947 407 318",
"output": "YES"
},
{
"input": "6\n10 79 306 334 304 305",
"output": "YES"
},
{
"input": "34\n787 62 26 683 486 364 684 891 846 801 969 837 359 800 836 359 471 637 732 91 841 836 7 799 959 405 416 841 737 803 615 483 323 365",
"output": "YES"
},
{
"input": "30\n860 238 14 543 669 100 428 789 576 484 754 274 849 850 586 377 711 386 510 408 520 693 23 477 266 851 728 711 964 73",
"output": "YES"
},
{
"input": "11\n325 325 324 324 324 325 325 324 324 324 324",
"output": "NO"
},
{
"input": "7\n517 517 518 517 518 518 518",
"output": "NO"
},
{
"input": "20\n710 710 711 711 711 711 710 710 710 710 711 710 710 710 710 710 710 711 711 710",
"output": "NO"
},
{
"input": "48\n29 30 29 29 29 30 29 30 30 30 30 29 30 30 30 29 29 30 30 29 30 29 29 30 29 30 29 30 30 29 30 29 29 30 30 29 29 30 30 29 29 30 30 30 29 29 30 29",
"output": "NO"
},
{
"input": "7\n880 880 514 536 881 881 879",
"output": "YES"
},
{
"input": "15\n377 432 262 376 261 375 377 262 263 263 261 376 262 262 375",
"output": "YES"
},
{
"input": "32\n305 426 404 961 426 425 614 304 404 425 615 403 303 304 615 303 305 405 427 614 403 303 425 615 404 304 427 403 206 616 405 404",
"output": "YES"
},
{
"input": "41\n115 686 988 744 762 519 745 519 518 83 85 115 520 44 687 686 685 596 988 687 989 988 114 745 84 519 519 746 988 84 745 744 115 114 85 115 520 746 745 116 987",
"output": "YES"
},
{
"input": "47\n1 2 483 28 7 109 270 651 464 162 353 521 224 989 721 499 56 69 197 716 313 446 580 645 828 197 100 138 789 499 147 677 384 711 783 937 300 543 540 93 669 604 739 122 632 822 116",
"output": "NO"
},
{
"input": "31\n1 2 1 373 355 692 750 920 578 666 615 232 141 129 663 929 414 704 422 559 568 731 354 811 532 618 39 879 292 602 995",
"output": "NO"
},
{
"input": "50\n5 38 41 4 15 40 27 39 20 3 44 47 30 6 36 29 35 12 19 26 10 2 21 50 11 46 48 49 17 16 33 13 32 28 31 18 23 34 7 14 24 45 9 37 1 8 42 25 43 22",
"output": "YES"
},
{
"input": "50\n967 999 972 990 969 978 963 987 954 955 973 970 959 981 995 983 986 994 979 957 965 982 992 977 953 975 956 961 993 997 998 958 980 962 960 951 996 991 1000 966 971 988 976 968 989 984 974 964 985 952",
"output": "YES"
},
{
"input": "50\n850 536 761 506 842 898 857 723 583 637 536 943 895 929 890 612 832 633 696 731 553 880 710 812 665 877 915 636 711 540 748 600 554 521 813 796 568 513 543 809 798 820 928 504 999 646 907 639 550 911",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "3\n500 999 1000",
"output": "NO"
},
{
"input": "10\n101 102 104 105 107 109 110 112 113 115",
"output": "NO"
},
{
"input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "NO"
},
{
"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000",
"output": "NO"
},
{
"input": "3\n1000 999 998",
"output": "YES"
},
{
"input": "49\n343 322 248 477 53 156 245 493 209 141 370 66 229 184 434 137 276 472 216 456 147 180 140 114 493 323 393 262 380 314 222 124 98 441 129 346 48 401 347 460 122 125 114 106 189 260 374 165 456",
"output": "NO"
},
{
"input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3",
"output": "YES"
},
{
"input": "3\n999 999 1000",
"output": "NO"
},
{
"input": "9\n2 4 5 13 25 100 200 300 400",
"output": "NO"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "NO"
},
{
"input": "3\n998 999 1000",
"output": "YES"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 2 2 4",
"output": "NO"
},
{
"input": "4\n4 3 4 5",
"output": "YES"
},
{
"input": "6\n1 1 1 2 2 2",
"output": "NO"
},
{
"input": "3\n2 3 2",
"output": "NO"
},
{
"input": "5\n10 5 6 3 2",
"output": "NO"
},
{
"input": "3\n1 2 1",
"output": "NO"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "4\n998 999 1000 1000",
"output": "YES"
},
{
"input": "5\n2 3 9 9 4",
"output": "YES"
},
{
"input": "4\n1 2 4 4",
"output": "NO"
},
{
"input": "3\n1 1 1",
"output": "NO"
},
{
"input": "3\n2 2 3",
"output": "NO"
},
{
"input": "7\n1 2 2 2 4 5 6",
"output": "YES"
},
{
"input": "5\n1 3 10 3 10",
"output": "NO"
},
{
"input": "3\n1 2 2",
"output": "NO"
},
{
"input": "4\n1000 1000 999 998",
"output": "YES"
},
{
"input": "3\n5 3 7",
"output": "NO"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "YES"
},
{
"input": "9\n6 6 6 5 5 5 4 4 4",
"output": "YES"
},
{
"input": "7\n5 6 6 6 7 7 7",
"output": "YES"
},
{
"input": "5\n2 3 3 3 4",
"output": "YES"
},
{
"input": "5\n2 1 2 1 3",
"output": "YES"
},
{
"input": "3\n1 2 7",
"output": "NO"
},
{
"input": "3\n1000 1000 1000",
"output": "NO"
},
{
"input": "5\n1 100 2 100 3",
"output": "YES"
},
{
"input": "5\n5 4 6 5 5",
"output": "YES"
},
{
"input": "12\n1 1 1 1 2 2 2 2 3 3 3 3",
"output": "YES"
},
{
"input": "5\n9 9 1 2 3",
"output": "YES"
},
{
"input": "6\n1 2 3 1 2 3",
"output": "YES"
},
{
"input": "7\n1 1 1 1 2 3 3",
"output": "YES"
},
{
"input": "3\n13 13 13",
"output": "NO"
},
{
"input": "3\n42 42 42",
"output": "NO"
},
{
"input": "8\n1 1 1 1 2 2 2 2",
"output": "NO"
},
{
"input": "6\n1 1 1 1 2 3",
"output": "YES"
},
{
"input": "6\n1 1 2 2 6 6",
"output": "NO"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "NO"
},
{
"input": "9\n1 2 3 1 2 3 1 2 3",
"output": "YES"
},
{
"input": "4\n1 2 1 100",
"output": "NO"
},
{
"input": "5\n1 1 2 2 3",
"output": "YES"
}
] | 1,458,423,123 | 2,147,483,647 | Python 3 | OK | TESTS | 84 | 62 | 5,120,000 | def main():
input()
a, b = 0, -1
for c in sorted(set(map(int, input().split()))):
if a < b < c < a + 3:
print("YES")
return
a, b = b, c
print("NO")
if __name__ == '__main__':
main()
| Title: Bear and Three Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*.
Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:
- No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2.
For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).
Your task is to check whether Limak can choose three balls that satisfy conditions above.
Input Specification:
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Output Specification:
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
Demo Input:
['4\n18 55 16 17\n', '6\n40 41 43 44 44 44\n', '8\n5 972 3 4 1 4 970 971\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.
In the second sample, there is no way to give gifts to three friends without breaking the rules.
In the third sample, there is even more than one way to choose balls:
1. Choose balls with sizes 3, 4 and 5. 1. Choose balls with sizes 972, 970, 971. | ```python
def main():
input()
a, b = 0, -1
for c in sorted(set(map(int, input().split()))):
if a < b < c < a + 3:
print("YES")
return
a, b = b, c
print("NO")
if __name__ == '__main__':
main()
``` | 3 |
|
988 | D | Points and Powers of Two | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.
In other words, you have to choose the maximum possible number of points $x_{i_1}, x_{i_2}, \dots, x_{i_m}$ such that for each pair $x_{i_j}$, $x_{i_k}$ it is true that $|x_{i_j} - x_{i_k}| = 2^d$ where $d$ is some non-negative integer number (not necessarily the same for each pair of points). | The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points.
The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points. | In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above.
In the second line print $m$ integers — the coordinates of points in the subset you have chosen.
If there are multiple answers, print any of them. | [
"6\n3 5 4 7 10 12\n",
"5\n-1 2 5 8 11\n"
] | [
"3\n7 3 5",
"1\n8\n"
] | In the first example the answer is $[7, 3, 5]$. Note, that $|7-3|=4=2^2$, $|7-5|=2=2^1$ and $|3-5|=2=2^1$. You can't find a subset having more points satisfying the required property. | 0 | [
{
"input": "6\n3 5 4 7 10 12",
"output": "3\n3 4 5 "
},
{
"input": "5\n-1 2 5 8 11",
"output": "1\n-1 "
},
{
"input": "1\n42",
"output": "1\n42 "
},
{
"input": "3\n0 -536870912 536870912",
"output": "3\n-536870912 0 536870912 "
},
{
"input": "2\n536870912 -536870912",
"output": "2\n-536870912 536870912 "
},
{
"input": "3\n1 2 3",
"output": "3\n1 2 3 "
},
{
"input": "4\n1 2 3 8",
"output": "3\n1 2 3 "
},
{
"input": "2\n1 2",
"output": "2\n1 2 "
},
{
"input": "3\n0 1 2",
"output": "3\n0 1 2 "
},
{
"input": "2\n-3 -2",
"output": "2\n-3 -2 "
},
{
"input": "2\n-4 -2",
"output": "2\n-4 -2 "
},
{
"input": "2\n2 1",
"output": "2\n1 2 "
},
{
"input": "1\n1",
"output": "1\n1 "
},
{
"input": "3\n0 2 6",
"output": "2\n0 2 "
},
{
"input": "3\n2 4 8",
"output": "2\n2 4 "
},
{
"input": "2\n1 0",
"output": "2\n0 1 "
},
{
"input": "3\n5 6 7",
"output": "3\n5 6 7 "
},
{
"input": "3\n-1 1 0",
"output": "3\n-1 0 1 "
}
] | 1,680,185,412 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 21 | 670 | 33,894,400 | from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm, log2
from copy import deepcopy
import heapq
from sys import stdin, stdout
input = stdin.readline
def main():
n = int(input())
L = list(map(int, input().split()))
L.sort()
dic = set(L)
ans = [L[0]]
for i in range(1, len(L)):
distance = 1
while L[i] - distance >= L[0] and L[i] + distance <= L[-1]:
if len(ans) == 1:
if L[i] - distance in dic:
if L[i] + distance in dic:
ans = [L[i] - distance, L[i], L[i] + distance]
else:
ans = [L[i] - distance, L[i]]
elif len(ans) == 2:
if L[i] - distance in dic and L[i] + distance in dic:
ans = [L[i] - distance, L[i], L[i] + distance]
distance = distance << 1
if len(ans) == 3:
break
print(len(ans))
print(*ans)
if __name__ == "__main__":
main()
| Title: Points and Powers of Two
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are $n$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size.
In other words, you have to choose the maximum possible number of points $x_{i_1}, x_{i_2}, \dots, x_{i_m}$ such that for each pair $x_{i_j}$, $x_{i_k}$ it is true that $|x_{i_j} - x_{i_k}| = 2^d$ where $d$ is some non-negative integer number (not necessarily the same for each pair of points).
Input Specification:
The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points.
The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points.
Output Specification:
In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above.
In the second line print $m$ integers — the coordinates of points in the subset you have chosen.
If there are multiple answers, print any of them.
Demo Input:
['6\n3 5 4 7 10 12\n', '5\n-1 2 5 8 11\n']
Demo Output:
['3\n7 3 5', '1\n8\n']
Note:
In the first example the answer is $[7, 3, 5]$. Note, that $|7-3|=4=2^2$, $|7-5|=2=2^1$ and $|3-5|=2=2^1$. You can't find a subset having more points satisfying the required property. | ```python
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from functools import lru_cache
from math import factorial, comb, sqrt, gcd, lcm, log2
from copy import deepcopy
import heapq
from sys import stdin, stdout
input = stdin.readline
def main():
n = int(input())
L = list(map(int, input().split()))
L.sort()
dic = set(L)
ans = [L[0]]
for i in range(1, len(L)):
distance = 1
while L[i] - distance >= L[0] and L[i] + distance <= L[-1]:
if len(ans) == 1:
if L[i] - distance in dic:
if L[i] + distance in dic:
ans = [L[i] - distance, L[i], L[i] + distance]
else:
ans = [L[i] - distance, L[i]]
elif len(ans) == 2:
if L[i] - distance in dic and L[i] + distance in dic:
ans = [L[i] - distance, L[i], L[i] + distance]
distance = distance << 1
if len(ans) == 3:
break
print(len(ans))
print(*ans)
if __name__ == "__main__":
main()
``` | 0 |
|
864 | A | Fair Game | PROGRAMMING | 1,000 | [
"implementation",
"sortings"
] | null | null | Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. | If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. | [
"4\n11\n27\n27\n11\n",
"2\n6\n6\n",
"6\n10\n20\n30\n20\n10\n20\n",
"6\n1\n1\n2\n2\n3\n3\n"
] | [
"YES\n11 27\n",
"NO\n",
"NO\n",
"NO\n"
] | In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards. | 500 | [
{
"input": "4\n11\n27\n27\n11",
"output": "YES\n11 27"
},
{
"input": "2\n6\n6",
"output": "NO"
},
{
"input": "6\n10\n20\n30\n20\n10\n20",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n3\n3",
"output": "NO"
},
{
"input": "2\n1\n100",
"output": "YES\n1 100"
},
{
"input": "2\n1\n1",
"output": "NO"
},
{
"input": "2\n100\n100",
"output": "NO"
},
{
"input": "14\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43\n43",
"output": "NO"
},
{
"input": "100\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n14\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32\n32",
"output": "YES\n14 32"
},
{
"input": "2\n50\n100",
"output": "YES\n50 100"
},
{
"input": "2\n99\n100",
"output": "YES\n99 100"
},
{
"input": "4\n4\n4\n5\n5",
"output": "YES\n4 5"
},
{
"input": "10\n10\n10\n10\n10\n10\n23\n23\n23\n23\n23",
"output": "YES\n10 23"
},
{
"input": "20\n34\n34\n34\n34\n34\n34\n34\n34\n34\n34\n11\n11\n11\n11\n11\n11\n11\n11\n11\n11",
"output": "YES\n11 34"
},
{
"input": "40\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n20\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30\n30",
"output": "YES\n20 30"
},
{
"input": "58\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\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",
"output": "YES\n1 100"
},
{
"input": "98\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99\n99",
"output": "YES\n2 99"
},
{
"input": "100\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\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "YES\n1 100"
},
{
"input": "100\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\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2",
"output": "YES\n1 2"
},
{
"input": "100\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n49\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12",
"output": "YES\n12 49"
},
{
"input": "100\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n15\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94\n94",
"output": "YES\n15 94"
},
{
"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42\n42",
"output": "YES\n33 42"
},
{
"input": "100\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n16\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35\n35",
"output": "YES\n16 35"
},
{
"input": "100\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n33\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44\n44",
"output": "YES\n33 44"
},
{
"input": "100\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n54\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98\n98",
"output": "YES\n54 98"
},
{
"input": "100\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n81\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12",
"output": "YES\n12 81"
},
{
"input": "100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "NO"
},
{
"input": "100\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\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",
"output": "NO"
},
{
"input": "40\n20\n20\n30\n30\n20\n20\n20\n30\n30\n20\n20\n30\n30\n30\n30\n20\n30\n30\n30\n30\n20\n20\n30\n30\n30\n20\n30\n20\n30\n20\n30\n20\n20\n20\n30\n20\n20\n20\n30\n30",
"output": "NO"
},
{
"input": "58\n100\n100\n100\n100\n100\n1\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n100\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n1\n1\n1\n1\n1",
"output": "NO"
},
{
"input": "98\n2\n99\n99\n99\n99\n2\n99\n99\n99\n2\n2\n99\n2\n2\n2\n2\n99\n99\n2\n99\n2\n2\n99\n99\n99\n99\n2\n2\n99\n2\n99\n99\n2\n2\n99\n2\n99\n2\n99\n2\n2\n2\n99\n2\n2\n2\n2\n99\n99\n99\n99\n2\n2\n2\n2\n2\n2\n2\n2\n99\n2\n99\n99\n2\n2\n99\n99\n99\n99\n99\n99\n99\n99\n2\n99\n2\n99\n2\n2\n2\n99\n99\n99\n99\n99\n99\n2\n99\n99\n2\n2\n2\n2\n2\n99\n99\n99\n2",
"output": "NO"
},
{
"input": "100\n100\n1\n100\n1\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n100\n1\n1\n1\n100\n1\n100\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n1\n100\n1\n1\n100\n100\n100\n1\n100\n100\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n100\n100\n100\n100\n1\n100\n100\n1\n100\n100\n1\n100\n1\n1\n1\n100\n100\n1\n100\n1\n100\n1\n1\n1\n1\n100\n1\n1\n100\n1\n100\n100\n1\n100\n1\n100",
"output": "NO"
},
{
"input": "100\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n100\n1\n100\n1\n100\n1\n100\n100\n100\n1\n100\n1\n1\n1\n100\n1\n1\n1\n1\n1\n100\n100\n1\n100\n1\n1\n100\n1\n1\n100\n1\n100\n100\n100\n1\n100\n100\n100\n1\n100\n1\n100\n100\n100\n1\n1\n100\n100\n100\n100\n1\n100\n36\n100\n1\n100\n1\n100\n100\n100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n100\n1\n1\n100\n100\n100\n100\n100\n1\n100\n1\n100\n1\n1\n100\n100\n1\n100",
"output": "NO"
},
{
"input": "100\n2\n1\n1\n2\n2\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n1\n1\n1\n2\n1\n2\n2\n2\n2\n1\n1\n2\n1\n1\n2\n1\n27\n1\n1\n1\n2\n2\n2\n1\n2\n1\n2\n1\n1\n2\n2\n2\n2\n2\n2\n2\n2\n1\n2\n2\n2\n2\n1\n2\n1\n1\n1\n1\n1\n2\n1\n1\n1\n2\n2\n2\n2\n2\n2\n1\n1\n1\n1\n2\n2\n1\n2\n2\n1\n1\n1\n2\n1\n2\n2\n1\n1\n2\n1\n1\n1\n2\n2\n1",
"output": "NO"
},
{
"input": "100\n99\n99\n100\n99\n99\n100\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n99\n99\n100\n100\n100\n99\n100\n100\n99\n100\n99\n100\n100\n99\n100\n99\n99\n99\n100\n99\n10\n99\n100\n100\n100\n99\n100\n100\n100\n100\n100\n100\n100\n99\n100\n100\n100\n99\n99\n100\n99\n100\n99\n100\n100\n99\n99\n99\n99\n100\n99\n100\n100\n100\n100\n100\n100\n99\n99\n100\n100\n99\n99\n99\n99\n99\n99\n100\n99\n99\n100\n100\n99\n100\n99\n99\n100\n99\n99\n99\n99\n100\n100",
"output": "NO"
},
{
"input": "100\n29\n43\n43\n29\n43\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n29\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n43\n43\n29\n29\n43\n43\n43\n29\n43\n43\n43\n29\n29\n29\n43\n29\n29\n29\n43\n43\n43\n43\n29\n29\n29\n29\n43\n29\n43\n43\n29\n29\n43\n43\n29\n29\n95\n29\n29\n29\n43\n43\n29\n29\n29\n29\n29\n43\n43\n43\n43\n29\n29\n43\n43\n43\n43\n43\n43\n29\n43\n43\n43\n43\n43\n43\n29\n43\n29\n43",
"output": "NO"
},
{
"input": "100\n98\n98\n98\n88\n88\n88\n88\n98\n98\n88\n98\n88\n98\n88\n88\n88\n88\n88\n98\n98\n88\n98\n98\n98\n88\n88\n88\n98\n98\n88\n88\n88\n98\n88\n98\n88\n98\n88\n88\n98\n98\n98\n88\n88\n98\n98\n88\n88\n88\n88\n88\n98\n98\n98\n88\n98\n88\n88\n98\n98\n88\n98\n88\n88\n98\n88\n88\n98\n27\n88\n88\n88\n98\n98\n88\n88\n98\n98\n98\n98\n98\n88\n98\n88\n98\n98\n98\n98\n88\n88\n98\n88\n98\n88\n98\n98\n88\n98\n98\n88",
"output": "NO"
},
{
"input": "100\n50\n1\n1\n50\n50\n50\n50\n1\n50\n100\n50\n50\n50\n100\n1\n100\n1\n100\n50\n50\n50\n50\n50\n1\n50\n1\n100\n1\n1\n50\n100\n50\n50\n100\n50\n50\n100\n1\n50\n50\n100\n1\n1\n50\n1\n100\n50\n50\n100\n100\n1\n100\n1\n50\n100\n50\n50\n1\n1\n50\n100\n50\n100\n100\n100\n50\n50\n1\n1\n50\n100\n1\n50\n100\n100\n1\n50\n50\n50\n100\n50\n50\n100\n1\n50\n50\n50\n50\n1\n50\n50\n50\n50\n1\n50\n50\n100\n1\n50\n100",
"output": "NO"
},
{
"input": "100\n45\n45\n45\n45\n45\n45\n44\n44\n44\n43\n45\n44\n44\n45\n44\n44\n45\n44\n43\n44\n43\n43\n43\n45\n43\n45\n44\n45\n43\n44\n45\n45\n45\n45\n45\n45\n45\n45\n43\n45\n43\n43\n45\n44\n45\n45\n45\n44\n45\n45\n45\n45\n45\n45\n44\n43\n45\n45\n43\n44\n45\n45\n45\n45\n44\n45\n45\n45\n43\n43\n44\n44\n43\n45\n43\n45\n45\n45\n44\n44\n43\n43\n44\n44\n44\n43\n45\n43\n44\n43\n45\n43\n43\n45\n45\n44\n45\n43\n43\n45",
"output": "NO"
},
{
"input": "100\n12\n12\n97\n15\n97\n12\n15\n97\n12\n97\n12\n12\n97\n12\n15\n12\n12\n15\n12\n12\n97\n12\n12\n15\n15\n12\n97\n15\n12\n97\n15\n12\n12\n15\n15\n15\n97\n15\n97\n12\n12\n12\n12\n12\n97\n12\n97\n12\n15\n15\n12\n15\n12\n15\n12\n12\n12\n12\n12\n12\n12\n12\n97\n97\n12\n12\n97\n12\n97\n97\n15\n97\n12\n97\n97\n12\n12\n12\n97\n97\n15\n12\n12\n15\n12\n15\n97\n97\n12\n15\n12\n12\n97\n12\n15\n15\n15\n15\n12\n12",
"output": "NO"
},
{
"input": "12\n2\n3\n1\n3\n3\n1\n2\n1\n2\n1\n3\n2",
"output": "NO"
},
{
"input": "48\n99\n98\n100\n100\n99\n100\n99\n100\n100\n98\n99\n98\n98\n99\n98\n99\n98\n100\n100\n98\n100\n98\n99\n100\n98\n99\n98\n99\n99\n100\n98\n99\n99\n98\n100\n99\n98\n99\n98\n100\n100\n100\n99\n98\n99\n98\n100\n100",
"output": "NO"
},
{
"input": "4\n1\n3\n3\n3",
"output": "NO"
},
{
"input": "6\n1\n1\n1\n1\n2\n2",
"output": "NO"
},
{
"input": "4\n1\n1\n1\n2",
"output": "NO"
},
{
"input": "4\n1\n2\n2\n2",
"output": "NO"
},
{
"input": "4\n1\n2\n3\n4",
"output": "NO"
},
{
"input": "8\n1\n1\n2\n2\n3\n3\n4\n4",
"output": "NO"
},
{
"input": "4\n1\n3\n2\n4",
"output": "NO"
},
{
"input": "4\n10\n10\n10\n20",
"output": "NO"
},
{
"input": "4\n11\n12\n13\n13",
"output": "NO"
},
{
"input": "4\n1\n1\n1\n3",
"output": "NO"
},
{
"input": "6\n1\n1\n2\n2\n2\n2",
"output": "NO"
},
{
"input": "10\n1\n1\n2\n2\n2\n3\n3\n4\n4\n4",
"output": "NO"
}
] | 1,602,415,413 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 108 | 307,200 | cnt = int(input())
main_list = []
second_list = []
main_dict = {}
x = 0
y = 0
z = 0
for i in range(cnt):
x = int(input())
main_list.append(x)
main_set = set(main_list)
if len(main_set) == 1 or len(main_set) >= 3:
print('NO')
else:
for i in main_set:
main_dict[i] = main_list.count(i)
for i in main_set:
second_list.append(i)
for keys in main_dict:
if keys == second_list[0]:
y = main_dict.get(keys)
else:
z = main_dict.get(keys)
if y != z:
print('NO')
else:
print('YES')
print(second_list[0], second_list[1]) | Title: Fair Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
Input Specification:
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number.
The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards.
Output Specification:
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
Demo Input:
['4\n11\n27\n27\n11\n', '2\n6\n6\n', '6\n10\n20\n30\n20\n10\n20\n', '6\n1\n1\n2\n2\n3\n3\n']
Demo Output:
['YES\n11 27\n', 'NO\n', 'NO\n', 'NO\n']
Note:
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards. | ```python
cnt = int(input())
main_list = []
second_list = []
main_dict = {}
x = 0
y = 0
z = 0
for i in range(cnt):
x = int(input())
main_list.append(x)
main_set = set(main_list)
if len(main_set) == 1 or len(main_set) >= 3:
print('NO')
else:
for i in main_set:
main_dict[i] = main_list.count(i)
for i in main_set:
second_list.append(i)
for keys in main_dict:
if keys == second_list[0]:
y = main_dict.get(keys)
else:
z = main_dict.get(keys)
if y != z:
print('NO')
else:
print('YES')
print(second_list[0], second_list[1])
``` | 3 |
|
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1. | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
},
{
"input": "999",
"output": "9"
},
{
"input": "100",
"output": "5"
},
{
"input": "123",
"output": "6"
},
{
"input": "8",
"output": "8"
},
{
"input": "157",
"output": "3"
},
{
"input": "289",
"output": "1"
},
{
"input": "179",
"output": "4"
},
{
"input": "942",
"output": "0"
},
{
"input": "879",
"output": "9"
},
{
"input": "394",
"output": "1"
},
{
"input": "423",
"output": "7"
},
{
"input": "952",
"output": "3"
},
{
"input": "121",
"output": "5"
},
{
"input": "613",
"output": "2"
},
{
"input": "945",
"output": "1"
},
{
"input": "270",
"output": "6"
},
{
"input": "781",
"output": "2"
},
{
"input": "453",
"output": "7"
},
{
"input": "171",
"output": "0"
},
{
"input": "643",
"output": "2"
},
{
"input": "570",
"output": "6"
},
{
"input": "750",
"output": "6"
},
{
"input": "500",
"output": "0"
},
{
"input": "2",
"output": "2"
},
{
"input": "1",
"output": "1"
},
{
"input": "108",
"output": "5"
},
{
"input": "500",
"output": "0"
},
{
"input": "189",
"output": "9"
},
{
"input": "491",
"output": "0"
},
{
"input": "191",
"output": "0"
}
] | 1,532,738,795 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 124 | 0 |
enteros = ''
for i in range(1000):
enteros += str(i)
ch = input("")
print(enteros[int(ch)])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to print the *n*-th digit of this string (digits are numbered starting with 1.
Input Specification:
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Output Specification:
Print the *n*-th digit of the line.
Demo Input:
['3\n', '11\n']
Demo Output:
['3\n', '0\n']
Note:
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | ```python
enteros = ''
for i in range(1000):
enteros += str(i)
ch = input("")
print(enteros[int(ch)])
``` | 3 |
|
1,009 | E | Intercity Travelling | PROGRAMMING | 2,000 | [
"combinatorics",
"math",
"probabilities"
] | null | null | Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$. | The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested. | Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$. | [
"2\n1 2\n",
"4\n1 3 3 7\n"
] | [
"5\n",
"60\n"
] | none | 0 | [
{
"input": "2\n1 2",
"output": "5"
},
{
"input": "4\n1 3 3 7",
"output": "60"
},
{
"input": "100\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 76 76 77 77 78 78 79 80 81 81 82 82 84 85 86 87 87 87 89 91 92 92 92 92 97 98 99 100 100",
"output": "758086002"
},
{
"input": "1\n12",
"output": "12"
}
] | 1,546,363,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 108 | 102,400 | #!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <[email protected]>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
# import random
import sys
from atexit import register
from bisect import bisect_left, bisect_right
# from collections import Counter, MutableSequence, defaultdict, deque
# from copy import deepcopy
# from decimal import Decimal
# from difflib import SequenceMatcher
# from fractions import Fraction
# from heapq import heappop, heappush
if sys.version_info[0] < 3:
# from cPickle import dumps
from io import BytesIO as stream
# from Queue import PriorityQueue, Queue
else:
# from functools import reduce
from io import StringIO as stream
from math import gcd
# from pickle import dumps
# from queue import PriorityQueue, Queue
if sys.version_info[0] < 3:
class dict(dict):
"""dict() -> new empty dictionary"""
def items(self):
"""D.items() -> a set-like object providing a view on D's items"""
return dict.iteritems(self)
def keys(self):
"""D.keys() -> a set-like object providing a view on D's keys"""
return dict.iterkeys(self)
def values(self):
"""D.values() -> an object providing a view on D's values"""
return dict.itervalues(self)
def gcd(x, y):
"""greatest common divisor of x and y"""
while y:
x, y = y, x % y
return x
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def sync_with_stdio(sync=True):
"""Set whether the standard Python streams are allowed to buffer their I/O.
Args:
sync (bool, optional): The new synchronization setting.
"""
global input, flush
if sync:
flush = sys.stdout.flush
else:
sys.stdin = stream(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
sys.stdout = stream()
register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
def main():
n = int(input())
a = list(map(int, input().split(' ')))
if __name__ == '__main__':
sync_with_stdio(False)
main()
| Title: Intercity Travelling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car.
The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance between Moscow and Saratov is $n$ km. Let's say that Moscow is situated at the point with coordinate $0$ km, and Saratov — at coordinate $n$ km.
Driving for a long time may be really difficult. Formally, if Leha has already covered $i$ kilometers since he stopped to have a rest, he considers the difficulty of covering $(i + 1)$-th kilometer as $a_{i + 1}$. It is guaranteed that for every $i \in [1, n - 1]$ $a_i \le a_{i + 1}$. The difficulty of the journey is denoted as the sum of difficulties of each kilometer in the journey.
Fortunately, there may be some rest sites between Moscow and Saratov. Every integer point from $1$ to $n - 1$ may contain a rest site. When Leha enters a rest site, he may have a rest, and the next kilometer will have difficulty $a_1$, the kilometer after it — difficulty $a_2$, and so on.
For example, if $n = 5$ and there is a rest site in coordinate $2$, the difficulty of journey will be $2a_1 + 2a_2 + a_3$: the first kilometer will have difficulty $a_1$, the second one — $a_2$, then Leha will have a rest, and the third kilometer will have difficulty $a_1$, the fourth — $a_2$, and the last one — $a_3$. Another example: if $n = 7$ and there are rest sites in coordinates $1$ and $5$, the difficulty of Leha's journey is $3a_1 + 2a_2 + a_3 + a_4$.
Leha doesn't know which integer points contain rest sites. So he has to consider every possible situation. Obviously, there are $2^{n - 1}$ different distributions of rest sites (two distributions are different if there exists some point $x$ such that it contains a rest site in exactly one of these distributions). Leha considers all these distributions to be equiprobable. He wants to calculate $p$ — the expected value of difficulty of his journey.
Obviously, $p \cdot 2^{n - 1}$ is an integer number. You have to calculate it modulo $998244353$.
Input Specification:
The first line contains one number $n$ ($1 \le n \le 10^6$) — the distance from Moscow to Saratov.
The second line contains $n$ integer numbers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$), where $a_i$ is the difficulty of $i$-th kilometer after Leha has rested.
Output Specification:
Print one number — $p \cdot 2^{n - 1}$, taken modulo $998244353$.
Demo Input:
['2\n1 2\n', '4\n1 3 3 7\n']
Demo Output:
['5\n', '60\n']
Note:
none | ```python
#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <[email protected]>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ import division, print_function
import cmath
import itertools
import math
import operator as op
# import random
import sys
from atexit import register
from bisect import bisect_left, bisect_right
# from collections import Counter, MutableSequence, defaultdict, deque
# from copy import deepcopy
# from decimal import Decimal
# from difflib import SequenceMatcher
# from fractions import Fraction
# from heapq import heappop, heappush
if sys.version_info[0] < 3:
# from cPickle import dumps
from io import BytesIO as stream
# from Queue import PriorityQueue, Queue
else:
# from functools import reduce
from io import StringIO as stream
from math import gcd
# from pickle import dumps
# from queue import PriorityQueue, Queue
if sys.version_info[0] < 3:
class dict(dict):
"""dict() -> new empty dictionary"""
def items(self):
"""D.items() -> a set-like object providing a view on D's items"""
return dict.iteritems(self)
def keys(self):
"""D.keys() -> a set-like object providing a view on D's keys"""
return dict.iterkeys(self)
def values(self):
"""D.values() -> an object providing a view on D's values"""
return dict.itervalues(self)
def gcd(x, y):
"""greatest common divisor of x and y"""
while y:
x, y = y, x % y
return x
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def sync_with_stdio(sync=True):
"""Set whether the standard Python streams are allowed to buffer their I/O.
Args:
sync (bool, optional): The new synchronization setting.
"""
global input, flush
if sync:
flush = sys.stdout.flush
else:
sys.stdin = stream(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
sys.stdout = stream()
register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
def main():
n = int(input())
a = list(map(int, input().split(' ')))
if __name__ == '__main__':
sync_with_stdio(False)
main()
``` | 0 |
|
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"input": "9149",
"output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..."
},
{
"input": "2877",
"output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..."
},
{
"input": "2956",
"output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..."
},
{
"input": "3035",
"output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..."
},
{
"input": "3114",
"output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..."
},
{
"input": "3193",
"output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..."
},
{
"input": "3273",
"output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..."
},
{
"input": "7000",
"output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..."
},
{
"input": "7079",
"output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..."
},
{
"input": "4653",
"output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..."
},
{
"input": "9995",
"output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..."
},
{
"input": "9996",
"output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..."
},
{
"input": "9997",
"output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..."
},
{
"input": "9998",
"output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..."
},
{
"input": "9999",
"output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..."
},
{
"input": "10000",
"output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..."
}
] | 1,680,927,247 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 22 | 154 | 5,427,200 | n = int(input())
# print(n//2+1)
if n & 1:
for i in range(1, n//2+2):
# print(i, n-i+1, end=' ')
if (i == n-i+1):
print(i, end=' ')
else:
print(i, n-i+1, end=' ')
else:
for i in range(1, n//2+1):
print(i, n-i+1, end=' ')
| Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
Input Specification:
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Output Specification:
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any.
Demo Input:
['2\n', '3\n']
Demo Output:
['1 2 ', '1 3 2 ']
Note:
none | ```python
n = int(input())
# print(n//2+1)
if n & 1:
for i in range(1, n//2+2):
# print(i, n-i+1, end=' ')
if (i == n-i+1):
print(i, end=' ')
else:
print(i, n-i+1, end=' ')
else:
for i in range(1, n//2+1):
print(i, n-i+1, end=' ')
``` | 3.951391 |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space. | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "6\n2 3 2 2 1 3",
"output": "4"
},
{
"input": "8\n2 2 5 3 4 3 3 2",
"output": "4"
},
{
"input": "7\n4 1 3 2 2 4 5",
"output": "4"
},
{
"input": "3\n3 5 1",
"output": "4"
},
{
"input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2",
"output": "5"
},
{
"input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1",
"output": "4"
},
{
"input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4",
"output": "5"
},
{
"input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3",
"output": "5"
},
{
"input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3",
"output": "4"
},
{
"input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2",
"output": "4"
},
{
"input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3",
"output": "5"
},
{
"input": "6\n4 2 3 1 3 5",
"output": "4"
},
{
"input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4",
"output": "5"
},
{
"input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2",
"output": "5"
},
{
"input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3",
"output": "5"
},
{
"input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1",
"output": "5"
},
{
"input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5",
"output": "5"
},
{
"input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3",
"output": "5"
},
{
"input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2",
"output": "5"
},
{
"input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1",
"output": "5"
},
{
"input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5",
"output": "5"
},
{
"input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3",
"output": "5"
},
{
"input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4",
"output": "4"
},
{
"input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5",
"output": "5"
}
] | 1,634,652,178 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | n = int(input())
a = [int(x) for x in input().split()]
count = 0
sumA = sum(a)
ans = 0
for i in range(1, 6):
if (sumA+i)%(n+1)!=1:
ans+=1
print(ans) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.
For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.
Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single space.
Output Specification:
In a single line print the answer to the problem.
Demo Input:
['1\n1\n', '1\n2\n', '2\n3 5\n']
Demo Output:
['3\n', '2\n', '3\n']
Note:
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | ```python
n = int(input())
a = [int(x) for x in input().split()]
count = 0
sumA = sum(a)
ans = 0
for i in range(1, 6):
if (sumA+i)%(n+1)!=1:
ans+=1
print(ans)
``` | 3 |
|
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872",
"output": "NO"
},
{
"input": "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326",
"output": "YES"
},
{
"input": "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024",
"output": "YES"
},
{
"input": "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627",
"output": "YES"
},
{
"input": "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563",
"output": "YES"
},
{
"input": "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943",
"output": "NO"
}
] | 1,645,986,430 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 156 | 4,710,400 | # n,m = map(lambda x: int(x), input().split())
# n = int(input())
import collections
n = int(input())
a=collections.defaultdict(lambda: -1)
for i in range(n):
k,d = map(lambda x: int(x), input().split())
a.setdefault(k, d+k)
col=list(a.items())
for i in col:
if a[i[1]]==i[0]:
print("YES")
exit()
print("NO")
| Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
Output Specification:
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
Demo Input:
['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n']
Demo Output:
['YES\n', 'NO\n', 'YES\n']
Note:
none | ```python
# n,m = map(lambda x: int(x), input().split())
# n = int(input())
import collections
n = int(input())
a=collections.defaultdict(lambda: -1)
for i in range(n):
k,d = map(lambda x: int(x), input().split())
a.setdefault(k, d+k)
col=list(a.items())
for i in col:
if a[i[1]]==i[0]:
print("YES")
exit()
print("NO")
``` | 3.952226 |
268 | B | Buttons | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario. | A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has. | In a single line print the number of times Manao has to push a button in the worst-case scenario. | [
"2\n",
"3\n"
] | [
"3\n",
"7\n"
] | Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | 1,000 | [
{
"input": "2",
"output": "3"
},
{
"input": "3",
"output": "7"
},
{
"input": "4",
"output": "14"
},
{
"input": "1",
"output": "1"
},
{
"input": "10",
"output": "175"
},
{
"input": "2000",
"output": "1333335000"
},
{
"input": "1747",
"output": "888644743"
},
{
"input": "889",
"output": "117099969"
},
{
"input": "1999",
"output": "1331335999"
},
{
"input": "914",
"output": "127259419"
},
{
"input": "996",
"output": "164675486"
},
{
"input": "17",
"output": "833"
},
{
"input": "50",
"output": "20875"
},
{
"input": "91",
"output": "125671"
},
{
"input": "92",
"output": "129858"
},
{
"input": "256",
"output": "2796416"
},
{
"input": "512",
"output": "22370048"
},
{
"input": "666",
"output": "49235271"
},
{
"input": "667",
"output": "49457383"
},
{
"input": "314",
"output": "5160119"
},
{
"input": "1241",
"output": "318541121"
},
{
"input": "1500",
"output": "562501250"
},
{
"input": "1837",
"output": "1033182073"
},
{
"input": "1000",
"output": "166667500"
}
] | 1,695,026,409 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 92 | 0 | n=int(input())
print(int((n*(n-1)*(n+1))/6+n)) | Title: Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao is trying to open a rather challenging lock. The lock has *n* buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.
Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.
Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.
Input Specification:
A single line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of buttons the lock has.
Output Specification:
In a single line print the number of times Manao has to push a button in the worst-case scenario.
Demo Input:
['2\n', '3\n']
Demo Output:
['3\n', '7\n']
Note:
Consider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes. | ```python
n=int(input())
print(int((n*(n-1)*(n+1))/6+n))
``` | 3 |
|
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7). | A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*). | Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"input": "50 6 3",
"output": "295630102"
},
{
"input": "10 13 6",
"output": "48"
},
{
"input": "20 16 14",
"output": "236"
},
{
"input": "1 10 1",
"output": "1"
},
{
"input": "8 11 4",
"output": "47"
},
{
"input": "16 5 4",
"output": "16175"
},
{
"input": "5 26 17",
"output": "0"
},
{
"input": "35 47 42",
"output": "0"
},
{
"input": "11 6 2",
"output": "975"
},
{
"input": "54 60 16",
"output": "931055544"
},
{
"input": "47 5 1",
"output": "164058640"
},
{
"input": "70 6 1",
"output": "592826579"
},
{
"input": "40 77 77",
"output": "0"
},
{
"input": "96 9 6",
"output": "362487247"
},
{
"input": "52 46 4",
"output": "27907693"
},
{
"input": "74 41 28",
"output": "806604424"
},
{
"input": "100 100 100",
"output": "1"
},
{
"input": "99 99 5",
"output": "700732369"
},
{
"input": "100 100 1",
"output": "988185646"
},
{
"input": "98 98 64",
"output": "237643149"
},
{
"input": "28 74 2",
"output": "134217727"
},
{
"input": "86 69 62",
"output": "217513984"
},
{
"input": "9 17 14",
"output": "0"
},
{
"input": "73 72 12",
"output": "426374014"
},
{
"input": "41 98 76",
"output": "0"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "1 100 100",
"output": "0"
},
{
"input": "1 100 1",
"output": "1"
},
{
"input": "1 100 2",
"output": "0"
},
{
"input": "2 100 2",
"output": "1"
},
{
"input": "2 100 1",
"output": "2"
},
{
"input": "50 50 1",
"output": "949480669"
},
{
"input": "100 50 50",
"output": "661237556"
},
{
"input": "3 2 2",
"output": "2"
},
{
"input": "100 50 3",
"output": "494224664"
},
{
"input": "90 97 24",
"output": "413496885"
},
{
"input": "31 8 8",
"output": "52532592"
},
{
"input": "78 90 38",
"output": "744021655"
},
{
"input": "100 13 11",
"output": "883875774"
},
{
"input": "100 45 8",
"output": "367847193"
},
{
"input": "31 8 4",
"output": "924947104"
},
{
"input": "35 95 9",
"output": "927164672"
},
{
"input": "45 5 3",
"output": "252804490"
},
{
"input": "1 5 5",
"output": "0"
},
{
"input": "89 75 59",
"output": "179807625"
},
{
"input": "90 100 30",
"output": "697322870"
},
{
"input": "89 73 32",
"output": "152673180"
},
{
"input": "100 90 80",
"output": "11531520"
}
] | 1,699,848,566 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 77 | 2,150,400 | #author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
mod = (10 ** 9) + 7
def answer():
dp = [[0 , 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1 , n + 1):
for j in range(k , 0 , -1):
if(i - j < 0):continue
if(j < d):
dp[i][0] += dp[i - j][0]
dp[i][0] %= mod
else:
dp[i][1] += dp[i - j][0]
dp[i][1] %= mod
dp[i][1] += dp[i - j][1]
dp[i][1] %= mod
return dp[n][1]
for T in range(1):
n , k , d = inp()
print(answer())
| Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes from some vertex to its children (exactly *k* edges), then their weights will equal 1,<=2,<=3,<=...,<=*k*.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109<=+<=7).
Input Specification:
A single line contains three space-separated integers: *n*, *k* and *d* (1<=≤<=*n*,<=*k*<=≤<=100; 1<=≤<=*d*<=≤<=*k*).
Output Specification:
Print a single integer — the answer to the problem modulo 1000000007 (109<=+<=7).
Demo Input:
['3 3 2\n', '3 3 3\n', '4 3 2\n', '4 5 2\n']
Demo Output:
['3\n', '1\n', '6\n', '7\n']
Note:
none | ```python
#author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
mod = (10 ** 9) + 7
def answer():
dp = [[0 , 0] for i in range(n + 1)]
dp[0][0] = 1
for i in range(1 , n + 1):
for j in range(k , 0 , -1):
if(i - j < 0):continue
if(j < d):
dp[i][0] += dp[i - j][0]
dp[i][0] %= mod
else:
dp[i][1] += dp[i - j][0]
dp[i][1] %= mod
dp[i][1] += dp[i - j][1]
dp[i][1] %= mod
return dp[n][1]
for T in range(1):
n , k , d = inp()
print(answer())
``` | 3 |
|
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24",
"output": "644 500"
},
{
"input": "1\n3",
"output": "3 0"
},
{
"input": "45\n553 40 94 225 415 471 126 190 647 394 515 303 189 159 308 6 139 132 326 78 455 75 85 295 135 613 360 614 351 228 578 259 258 591 444 29 33 463 561 174 368 183 140 168 646",
"output": "6848 6568"
},
{
"input": "44\n849 373 112 307 479 608 856 769 526 82 168 143 573 762 115 501 688 36 214 450 396 496 236 309 287 786 397 43 811 141 745 846 350 270 276 677 420 459 403 722 267 54 394 727",
"output": "9562 9561"
},
{
"input": "35\n10 15 18 1 28 16 2 33 6 22 23 4 9 25 35 8 7 26 3 20 30 14 31 19 27 32 11 5 29 24 21 34 13 17 12",
"output": "315 315"
},
{
"input": "17\n580 376 191 496 73 44 520 357 483 149 81 178 514 300 216 598 304",
"output": "3238 2222"
},
{
"input": "30\n334 443 223 424 168 549 189 303 429 559 516 220 459 134 344 346 316 446 209 148 487 526 69 286 102 366 518 280 392 325",
"output": "5246 4864"
},
{
"input": "95\n122 29 188 265 292 287 183 225 222 187 155 256 64 148 173 278 218 136 290 17 31 130 2 87 57 283 255 280 68 166 174 142 102 39 116 206 288 154 26 78 296 172 184 232 77 91 277 8 249 186 94 93 207 251 257 195 101 299 193 124 293 65 58 35 24 302 220 189 252 125 27 284 247 182 141 103 198 97 234 83 281 216 85 180 267 236 109 143 149 239 79 300 191 244 71",
"output": "8147 7807"
},
{
"input": "1\n1",
"output": "1 0"
}
] | 1,690,885,172 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 61 | 1,536,000 | from typing import List
from collections import namedtuple
import sys
class Solution:
def sereja_and_dima(self, nums: List):
result = [0, 0]
left, right = 0, len(nums) - 1
index = 0
while left <= right:
if nums[left] > nums[right]:
result[index] += nums[left]
index = index + 1 if index == 0 else 0
left += 1
else:
result[index] += nums[right]
index = index + 1 if index == 0 else 0
right -= 1
print(result[0], result[1])
return result
TestCase = namedtuple('TestCase', 'nums correct')
def read_test_cases(input_file, output_file):
results = []
test_cases = []
with open(output_file) as f:
while True:
line = f.readline()
if not line:
break
nums = line.strip().split(' ')
results.append([int(n) for n in nums])
with open(input_file) as f:
i = 0
while True:
line = f.readline()
if not line:
break
arr_len = int(line.strip())
nums = f.readline().strip().split(' ')
nums = [int(n) for n in nums]
test_cases.append(TestCase(nums, results[i]))
i += 1
return test_cases
if __name__ == '__main__':
input_file = 'data/input.txt'
output_file = 'data/output.txt'
if len(sys.argv) > 1 and '--debug' in sys.argv:
test_cases = read_test_cases(input_file, output_file)
for t in test_cases:
result = Solution().sereja_and_dima(t.nums)
else:
arr_len = int(input().strip())
nums = input().strip().split(' ')
nums = [int(n) for n in nums]
Solution().sereja_and_dima(nums) | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins.
Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move.
Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her.
Input Specification:
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
Output Specification:
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
Demo Input:
['4\n4 1 2 10\n', '7\n1 2 3 4 5 6 7\n']
Demo Output:
['12 5\n', '16 12\n']
Note:
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | ```python
from typing import List
from collections import namedtuple
import sys
class Solution:
def sereja_and_dima(self, nums: List):
result = [0, 0]
left, right = 0, len(nums) - 1
index = 0
while left <= right:
if nums[left] > nums[right]:
result[index] += nums[left]
index = index + 1 if index == 0 else 0
left += 1
else:
result[index] += nums[right]
index = index + 1 if index == 0 else 0
right -= 1
print(result[0], result[1])
return result
TestCase = namedtuple('TestCase', 'nums correct')
def read_test_cases(input_file, output_file):
results = []
test_cases = []
with open(output_file) as f:
while True:
line = f.readline()
if not line:
break
nums = line.strip().split(' ')
results.append([int(n) for n in nums])
with open(input_file) as f:
i = 0
while True:
line = f.readline()
if not line:
break
arr_len = int(line.strip())
nums = f.readline().strip().split(' ')
nums = [int(n) for n in nums]
test_cases.append(TestCase(nums, results[i]))
i += 1
return test_cases
if __name__ == '__main__':
input_file = 'data/input.txt'
output_file = 'data/output.txt'
if len(sys.argv) > 1 and '--debug' in sys.argv:
test_cases = read_test_cases(input_file, output_file)
for t in test_cases:
result = Solution().sereja_and_dima(t.nums)
else:
arr_len = int(input().strip())
nums = input().strip().split(' ')
nums = [int(n) for n in nums]
Solution().sereja_and_dima(nums)
``` | 3 |
|
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer. | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively. | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{
"input": "16 112 50 114 68\n1 4 8 4 9\n19 11",
"output": "5178"
},
{
"input": "55 66 75 44 47\n6 0 6 6 10\n19 0",
"output": "6414"
},
{
"input": "47 11 88 5 110\n6 10 4 2 3\n10 6",
"output": "5188"
},
{
"input": "5 44 61 103 92\n9 0 10 4 8\n15 7",
"output": "4914"
},
{
"input": "115 53 96 62 110\n7 8 1 7 9\n7 16",
"output": "3416"
},
{
"input": "102 83 26 6 11\n3 4 1 8 3\n17 14",
"output": "6704"
},
{
"input": "36 102 73 101 19\n5 9 2 2 6\n4 13",
"output": "4292"
},
{
"input": "40 115 93 107 113\n5 7 2 6 8\n6 17",
"output": "2876"
},
{
"input": "53 34 53 107 81\n4 3 1 10 8\n7 7",
"output": "4324"
},
{
"input": "113 37 4 84 66\n2 0 10 3 0\n20 19",
"output": "6070"
},
{
"input": "10 53 101 62 1\n8 0 9 7 9\n0 11",
"output": "4032"
},
{
"input": "45 45 75 36 76\n6 2 2 0 0\n8 17",
"output": "5222"
},
{
"input": "47 16 44 78 111\n7 9 8 0 2\n1 19",
"output": "3288"
},
{
"input": "7 54 39 102 31\n6 0 2 10 1\n18 3",
"output": "6610"
},
{
"input": "0 46 86 72 40\n1 5 5 5 9\n6 5",
"output": "4924"
},
{
"input": "114 4 45 78 113\n0 4 8 10 2\n10 12",
"output": "4432"
},
{
"input": "56 56 96 105 107\n4 9 10 4 8\n2 1",
"output": "3104"
},
{
"input": "113 107 59 50 56\n3 7 10 6 3\n10 12",
"output": "4586"
},
{
"input": "96 104 9 94 84\n6 10 7 8 3\n14 11",
"output": "4754"
},
{
"input": "98 15 116 43 55\n4 3 0 9 3\n10 7",
"output": "5400"
},
{
"input": "0 26 99 108 35\n0 4 3 0 10\n9 5",
"output": "5388"
},
{
"input": "89 24 51 49 84\n5 6 2 2 9\n2 14",
"output": "4066"
},
{
"input": "57 51 76 45 96\n1 0 4 3 6\n12 15",
"output": "5156"
},
{
"input": "79 112 37 36 116\n2 8 4 7 5\n4 12",
"output": "3872"
},
{
"input": "71 42 60 20 7\n7 1 1 10 6\n1 7",
"output": "5242"
},
{
"input": "86 10 66 80 55\n0 2 5 10 5\n15 6",
"output": "5802"
},
{
"input": "66 109 22 22 62\n3 1 5 4 5\n10 5",
"output": "5854"
},
{
"input": "97 17 43 84 58\n2 8 3 8 6\n10 7",
"output": "5028"
},
{
"input": "109 83 5 114 104\n6 0 3 9 5\n5 2",
"output": "4386"
},
{
"input": "94 18 24 91 105\n2 0 7 10 3\n1 4",
"output": "4118"
},
{
"input": "64 17 86 59 45\n8 0 10 2 2\n4 4",
"output": "5144"
},
{
"input": "70 84 31 57 2\n7 0 0 2 7\n12 5",
"output": "6652"
},
{
"input": "98 118 117 86 4\n2 10 9 7 5\n11 15",
"output": "4476"
},
{
"input": "103 110 101 97 70\n4 2 1 0 5\n7 5",
"output": "4678"
},
{
"input": "78 96 6 97 62\n7 7 9 2 9\n10 3",
"output": "4868"
},
{
"input": "95 28 3 31 115\n1 9 0 7 3\n10 13",
"output": "5132"
},
{
"input": "45 17 116 58 3\n8 8 7 6 4\n3 19",
"output": "3992"
},
{
"input": "19 12 0 113 77\n3 0 10 9 2\n8 6",
"output": "5040"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0",
"output": "7500"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n20 0",
"output": "9500"
},
{
"input": "119 119 119 119 119\n10 10 10 10 10\n0 20",
"output": "1310"
},
{
"input": "0 0 0 0 0\n10 10 10 10 10\n0 20",
"output": "4150"
},
{
"input": "119 0 0 0 0\n10 0 0 0 0\n5 5",
"output": "7400"
},
{
"input": "0 119 0 0 0\n0 10 0 0 0\n5 5",
"output": "7050"
},
{
"input": "0 0 119 0 0\n0 0 10 0 0\n0 0",
"output": "6450"
},
{
"input": "0 0 0 119 0\n0 0 0 10 0\n5 5",
"output": "6350"
},
{
"input": "0 0 0 0 119\n0 0 0 0 10\n5 5",
"output": "6060"
},
{
"input": "119 0 0 0 0\n2 0 0 0 0\n5 5",
"output": "7412"
},
{
"input": "0 119 0 0 0\n0 2 0 0 0\n5 5",
"output": "7174"
},
{
"input": "0 0 119 0 0\n0 0 2 0 0\n5 5",
"output": "6936"
},
{
"input": "0 0 0 119 0\n0 0 0 2 0\n5 5",
"output": "6698"
},
{
"input": "0 0 0 0 119\n0 0 0 0 2\n5 5",
"output": "6460"
},
{
"input": "119 0 0 0 0\n0 0 0 0 0\n4 9",
"output": "7212"
}
] | 1,448,984,405 | 305 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | def g(w,m,x):
return max(0.3*x,(1-m/250)*x-50*w)
m1,m2,m3,m4,m5=map(int,input().split())
w1,w2,w3,w4,w5=map(int,input().split())
h1,h2=map(int,input().split())
print(g(w1,m1,500)+g(w2,m2,1000)+g(w3,m3,1500)+g(w4,m4,2000)+g(w5,m5,2500)+h1*100-h2*50) | Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.
Codeforces scores are computed as follows: If the maximum point value of a problem is *x*, and Kevin submitted correctly at minute *m* but made *w* wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.
All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.
Input Specification:
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≤<=*m**i*<=≤<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, *w*4, *w*5, where *w**i* (0<=≤<=*w**i*<=≤<=10) is Kevin's number of wrong submissions on problem *i*.
The last line contains two space-separated integers *h**s* and *h**u* (0<=≤<=*h**s*,<=*h**u*<=≤<=20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.
Output Specification:
Print a single integer, the value of Kevin's final score.
Demo Input:
['20 40 60 80 100\n0 1 2 3 4\n1 0\n', '119 119 119 119 119\n0 0 0 0 0\n10 0\n']
Demo Output:
['4900\n', '4930\n']
Note:
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving problems is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fdf392d8508500b57f8057ac0c4c892ab5f925a2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930. | ```python
def g(w,m,x):
return max(0.3*x,(1-m/250)*x-50*w)
m1,m2,m3,m4,m5=map(int,input().split())
w1,w2,w3,w4,w5=map(int,input().split())
h1,h2=map(int,input().split())
print(g(w1,m1,500)+g(w2,m2,1000)+g(w3,m3,1500)+g(w4,m4,2000)+g(w5,m5,2500)+h1*100-h2*50)
``` | 0 |
|
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,666,698,681 | 2,147,483,647 | Python 3 | OK | TESTS | 3 | 62 | 0 | import math
for _ in range( int(input()) ):
a = int(input())
n = (360)/(180-a)
print('YNEOS'[not math.floor(n)==n::2])
| Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*?
Input Specification:
The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees.
Output Specification:
For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible.
Demo Input:
['3\n30\n60\n90\n']
Demo Output:
['NO\nYES\nYES\n']
Note:
In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a regular triangle, and in the last test case — a square. | ```python
import math
for _ in range( int(input()) ):
a = int(input())
n = (360)/(180-a)
print('YNEOS'[not math.floor(n)==n::2])
``` | 3 |
|
768 | A | Oath of the Night's Watch | PROGRAMMING | 900 | [
"constructive algorithms",
"sortings"
] | null | null | "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support? | First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. | Output a single integer representing the number of stewards which Jon will feed. | [
"2\n1 5\n",
"3\n1 2 5\n"
] | [
"0",
"1"
] | In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | 500 | [
{
"input": "2\n1 5",
"output": "0"
},
{
"input": "3\n1 2 5",
"output": "1"
},
{
"input": "4\n1 2 3 4",
"output": "2"
},
{
"input": "8\n7 8 9 4 5 6 1 2",
"output": "6"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "1\n100",
"output": "0"
},
{
"input": "205\n5 5 3 3 6 2 9 3 8 9 6 6 10 8 1 5 3 3 1 2 9 9 9 3 9 10 3 9 8 3 5 6 6 4 6 9 2 9 10 9 5 6 6 7 4 2 6 3 4 1 10 1 7 2 7 7 3 2 6 5 5 2 9 3 8 8 7 6 6 4 2 2 6 2 3 5 7 2 2 10 1 4 6 9 2 3 7 2 2 7 4 4 9 10 7 5 8 6 5 3 6 10 2 7 5 6 6 8 3 3 9 4 3 5 7 9 3 2 1 1 3 2 1 9 3 1 4 4 10 2 5 5 8 1 4 8 5 3 1 10 8 6 5 8 3 5 4 5 4 4 6 7 2 8 10 8 7 6 6 9 6 7 1 10 3 2 5 10 4 4 5 4 3 4 8 5 3 8 10 3 10 9 7 2 1 8 6 4 6 5 8 10 2 6 7 4 9 4 5 1 8 7 10 3 1",
"output": "174"
},
{
"input": "4\n1000000000 99999999 1000000000 1000000000",
"output": "0"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "5\n1 1 1 1 1",
"output": "0"
},
{
"input": "3\n1 1 1",
"output": "0"
},
{
"input": "6\n1 1 3 3 2 2",
"output": "2"
},
{
"input": "7\n1 1 1 1 1 1 1",
"output": "0"
},
{
"input": "4\n1 1 2 5",
"output": "1"
},
{
"input": "3\n0 0 0",
"output": "0"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "5\n1 1 1 1 5",
"output": "0"
},
{
"input": "5\n1 1 2 3 3",
"output": "1"
},
{
"input": "3\n1 1 3",
"output": "0"
},
{
"input": "3\n2 2 3",
"output": "0"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "5\n1 5 3 5 1",
"output": "1"
},
{
"input": "7\n1 2 2 2 2 2 3",
"output": "5"
},
{
"input": "4\n2 2 2 2",
"output": "0"
},
{
"input": "9\n2 2 2 3 4 5 6 6 6",
"output": "3"
},
{
"input": "10\n1 1 1 2 3 3 3 3 3 3",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1",
"output": "0"
},
{
"input": "3\n0 0 1",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 3 3 3",
"output": "3"
},
{
"input": "3\n1 2 2",
"output": "0"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "0"
},
{
"input": "5\n2 2 2 2 2",
"output": "0"
},
{
"input": "5\n5 5 5 5 5",
"output": "0"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "6\n1 2 5 5 5 5",
"output": "1"
},
{
"input": "5\n1 2 3 3 3",
"output": "1"
},
{
"input": "3\n1 1 2",
"output": "0"
},
{
"input": "6\n1 1 1 1 1 2",
"output": "0"
},
{
"input": "5\n1 1 2 4 4",
"output": "1"
},
{
"input": "3\n999999 5999999 9999999",
"output": "1"
},
{
"input": "4\n1 1 5 5",
"output": "0"
},
{
"input": "9\n1 1 1 2 2 2 4 4 4",
"output": "3"
},
{
"input": "5\n1 3 4 5 1",
"output": "2"
},
{
"input": "5\n3 3 3 3 3",
"output": "0"
},
{
"input": "5\n1 1 2 2 2",
"output": "0"
},
{
"input": "5\n2 1 1 1 3",
"output": "1"
},
{
"input": "5\n0 0 0 1 2",
"output": "1"
},
{
"input": "4\n2 2 2 3",
"output": "0"
},
{
"input": "7\n1 1 1 1 5 5 5",
"output": "0"
},
{
"input": "5\n1 2 3 4 4",
"output": "2"
},
{
"input": "2\n5 4",
"output": "0"
},
{
"input": "4\n5 5 5 5",
"output": "0"
},
{
"input": "5\n1 1 1 5 5",
"output": "0"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "1\n3",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "4\n1 2 2 2",
"output": "0"
},
{
"input": "8\n1000000000 1000000000 1000000000 999999999 999999999 999999999 999999998 999999998",
"output": "3"
},
{
"input": "5\n1 1 3 4 4",
"output": "1"
},
{
"input": "6\n1 1 2 2 3 3",
"output": "2"
},
{
"input": "4\n1 1 1 1",
"output": "0"
},
{
"input": "9\n1 2 3 4 1 5 6 7 8",
"output": "6"
},
{
"input": "8\n5 4 4 6 6 4 4 3",
"output": "5"
},
{
"input": "8\n4 3 3 3 3 3 3 3",
"output": "0"
},
{
"input": "7\n4 3 3 3 3 3 3",
"output": "0"
},
{
"input": "6\n4 3 3 3 3 3",
"output": "0"
},
{
"input": "5\n4 3 3 3 3",
"output": "0"
}
] | 1,691,239,912 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 61 | 2,764,800 | stewards_number = int(input())
stewards = set(sorted([int(x) for x in input().split()]))
print(max(len(set)-2 , 0))
| Title: Oath of the Night's Watch
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.
With that begins the watch of Jon Snow. He is assigned the task to support the stewards.
This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.
Can you find how many stewards will Jon support?
Input Specification:
First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow.
Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards.
Output Specification:
Output a single integer representing the number of stewards which Jon will feed.
Demo Input:
['2\n1 5\n', '3\n1 2 5\n']
Demo Output:
['0', '1']
Note:
In the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.
In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2. | ```python
stewards_number = int(input())
stewards = set(sorted([int(x) for x in input().split()]))
print(max(len(set)-2 , 0))
``` | -1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.