contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 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 listlengths 0 7 | demo-output listlengths 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,692,522,210 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 1,228,800 | n = int(input())
cit = list(map(int,input().split()))
c = 0
cit.sort()
for i in range(len(cit)-1):
c += max(cit) - cit[i]
print(c) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = int(input())
cit = list(map(int,input().split()))
c = 0
cit.sort()
for i in range(len(cit)-1):
c += max(cit) - cit[i]
print(c)
``` | 3 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,659,568,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | #one day im gonna in sha allah
import math
def main():
line = input().split("|")
line2 = input()
if(len(line[0]) + len(line2) == len(line[1])):
print(line[0]+ line2 + "|" + line[1])
elif(len(line[0]) == len(line[1]) + len(line2)):
print(line[0] + "|" + line[1] + line2)
... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
#one day im gonna in sha allah
import math
def main():
line = input().split("|")
line2 = input()
if(len(line[0]) + len(line2) == len(line[1])):
print(line[0]+ line2 + "|" + line[1])
elif(len(line[0]) == len(line[1]) + len(line2)):
print(line[0] + "|" + line[1] +... | 0 | |
747 | C | Servers | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three integers: *t**i* — the moment in seconds in which the task will come, *k**i* — the number of se... | The first line contains two positive integers *n* and *q* (1<=≤<=*n*<=≤<=100, 1<=≤<=*q*<=≤<=105) — the number of servers and the number of tasks.
Next *q* lines contains three integers each, the *i*-th line contains integers *t**i*, *k**i* and *d**i* (1<=≤<=*t**i*<=≤<=106, 1<=≤<=*k**i*<=≤<=*n*, 1<=≤<=*d**i*<=≤<=1000)... | Print *q* lines. If the *i*-th task will be performed by the servers, print in the *i*-th line the sum of servers' ids on which this task will be performed. Otherwise, print -1. | [
"4 3\n1 3 2\n2 2 1\n3 4 3\n",
"3 2\n3 2 3\n5 1 2\n",
"8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8\n"
] | [
"6\n-1\n10\n",
"3\n3\n",
"6\n9\n30\n-1\n15\n36\n"
] | In the first example in the second 1 the first task will come, it will be performed on the servers with ids 1, 2 and 3 (the sum of the ids equals 6) during two seconds. In the second 2 the second task will come, it will be ignored, because only the server 4 will be unoccupied at that second. In the second 3 the third t... | 1,500 | [
{
"input": "4 3\n1 3 2\n2 2 1\n3 4 3",
"output": "6\n-1\n10"
},
{
"input": "3 2\n3 2 3\n5 1 2",
"output": "3\n3"
},
{
"input": "8 6\n1 3 20\n4 2 1\n6 5 5\n10 1 1\n15 3 6\n21 8 8",
"output": "6\n9\n30\n-1\n15\n36"
},
{
"input": "4 1\n6 1 1",
"output": "1"
},
{
"inp... | 1,482,229,172 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 4,608,000 | def main():
n, k = map(int, input().split())
ser = [0] * n
for i in range(k):
t, ki, v = map(int, input().split())
ans = 0
for el in ser:
if el < t:
ans += 1
if ans > ki: break
if ans >= ki:
ans = 0
j... | Title: Servers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* servers in a laboratory, each of them can perform tasks. Each server has a unique id — integer from 1 to *n*.
It is known that during the day *q* tasks will come, the *i*-th of them is characterized with three in... | ```python
def main():
n, k = map(int, input().split())
ser = [0] * n
for i in range(k):
t, ki, v = map(int, input().split())
ans = 0
for el in ser:
if el < t:
ans += 1
if ans > ki: break
if ans >= ki:
ans = 0
... | 0 | |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,672,820,778 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 46 | 0 | k,m = map(int,input().split())
lst = [int(i) for i in str(k)]
if 10**m > k:
print(len(lst)-1)
else:
i = str(k)
z = len(lst)-1
while int(i) % 10**m != 0:
if lst[z] != 0:
i = i[:z] + i[z+1:]
z -= 1
print(len(lst)-len(i))
# Wed Jan 04 2023 11:26:17 GMT+0300 (Mos... | Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
k,m = map(int,input().split())
lst = [int(i) for i in str(k)]
if 10**m > k:
print(len(lst)-1)
else:
i = str(k)
z = len(lst)-1
while int(i) % 10**m != 0:
if lst[z] != 0:
i = i[:z] + i[z+1:]
z -= 1
print(len(lst)-len(i))
# Wed Jan 04 2023 11:26:17 GMT... | 0 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,467,910,539 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 307,200 | #!/usr/bin/python
def get250(n):
t = n
c2 = 0
while t > 0 and t%2 == 0:
c2 += 1
t /= 2
t = n
c5 = 0
while t > 0 and t%5 == 0:
c5 += 1
t /= 5
return [c2, c5]
def main():
n = int(input())
a = [None] * n
z = [None] * n
... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
#!/usr/bin/python
def get250(n):
t = n
c2 = 0
while t > 0 and t%2 == 0:
c2 += 1
t /= 2
t = n
c5 = 0
while t > 0 and t%5 == 0:
c5 += 1
t /= 5
return [c2, c5]
def main():
n = int(input())
a = [None] * n
z = [... | 0 |
139 | A | Petr and Book | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S... | The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book.
The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and... | Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. | [
"100\n15 20 20 15 10 30 45\n",
"2\n1 0 0 0 0 0 0\n"
] | [
"6\n",
"1\n"
] | Note to the first sample:
By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else).
Note to the second... | 500 | [
{
"input": "100\n15 20 20 15 10 30 45",
"output": "6"
},
{
"input": "2\n1 0 0 0 0 0 0",
"output": "1"
},
{
"input": "100\n100 200 100 200 300 400 500",
"output": "1"
},
{
"input": "3\n1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "1\n1 1 1 1 1 1 1",
"output": "1... | 1,662,484,755 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | n = int(input())
day = list(map(int,input().split()))
week = sum(day)
n = n%week
pages = n
if n==0:
print(1)
quit()
i = 0
while n>0:
print("printing i",i)
print("printing n before loop",n)
n -= day[(i%7)]
i+=1
print("printing n after loop",n)
print(i)
| Title: Petr and Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages.
Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s... | ```python
n = int(input())
day = list(map(int,input().split()))
week = sum(day)
n = n%week
pages = n
if n==0:
print(1)
quit()
i = 0
while n>0:
print("printing i",i)
print("printing n before loop",n)
n -= day[(i%7)]
i+=1
print("printing n after loop",n)
print(i)
`... | 0 | |
510 | B | Fox And Two Dots | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase Latin characters to express different colors.
The key of this game is to find a cycle that contain dots... | The first line contains two integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50): the number of rows and columns of the board.
Then *n* lines follow, each line contains a string consisting of *m* characters, expressing colors of dots in each line. Each character is an uppercase Latin letter. | Output "Yes" if there exists a cycle, and "No" otherwise. | [
"3 4\nAAAA\nABCA\nAAAA\n",
"3 4\nAAAA\nABCA\nAADA\n",
"4 4\nYYYR\nBYBY\nBBBY\nBBBY\n",
"7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB\n",
"2 13\nABCDEFGHIJKLM\nNOPQRSTUVWXYZ\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n"
] | In first sample test all 'A' form a cycle.
In second sample there is no such cycle.
The third sample is displayed on the picture above ('Y' = Yellow, 'B' = Blue, 'R' = Red). | 1,000 | [
{
"input": "3 4\nAAAA\nABCA\nAAAA",
"output": "Yes"
},
{
"input": "3 4\nAAAA\nABCA\nAADA",
"output": "No"
},
{
"input": "4 4\nYYYR\nBYBY\nBBBY\nBBBY",
"output": "Yes"
},
{
"input": "7 6\nAAAAAB\nABBBAB\nABAAAB\nABABBB\nABAAAB\nABBBAB\nAAAAAB",
"output": "Yes"
},
{
... | 1,683,632,224 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 1,843,200 | import sys
sys.setrecursionlimit(1000000)
def search(i,j,pi = -1,pj = -1):
game[i][j] = True
di = [-1,1,0,0]
dj = [0,0,-1,1]
for k in range(4):
ni = i + di[k]
nj = j + dj[k]
if (0<=ni<n and 0<=nj<m) and (ni != pi or nj != pj) and dot[i][j] == dot[ni][nj]:
... | Title: Fox And Two Dots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel is playing a mobile puzzle game called "Two Dots". The basic levels are played on a board of size *n*<=×<=*m* cells, like this:
Each cell contains a dot that has some color. We will use different uppercase La... | ```python
import sys
sys.setrecursionlimit(1000000)
def search(i,j,pi = -1,pj = -1):
game[i][j] = True
di = [-1,1,0,0]
dj = [0,0,-1,1]
for k in range(4):
ni = i + di[k]
nj = j + dj[k]
if (0<=ni<n and 0<=nj<m) and (ni != pi or nj != pj) and dot[i][j] == dot[ni][nj]:
... | 3 | |
818 | F | Level Generation | PROGRAMMING | 2,100 | [
"binary search",
"math",
"ternary search"
] | null | null | Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be exactly *n**i* vertices in the graph representing level *i*, and the edges have to be bidirectional. ... | The first line of input file contains a positive integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of graphs Ivan needs to construct.
Then *q* lines follow, *i*-th line contains one positive integer *n**i* (1<=≤<=*n**i*<=≤<=2·109) — the number of vertices in *i*-th graph.
Note that in hacks you have to use *q*<==<=1. | Output *q* numbers, *i*-th of them must be equal to the maximum number of edges in *i*-th graph. | [
"3\n3\n4\n6\n"
] | [
"2\n3\n6\n"
] | In the first example it is possible to construct these graphs:
1. 1 - 2, 1 - 3; 1. 1 - 2, 1 - 3, 2 - 4; 1. 1 - 2, 1 - 3, 2 - 3, 1 - 4, 2 - 5, 3 - 6. | 0 | [
{
"input": "3\n3\n4\n6",
"output": "2\n3\n6"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "0\n1\n2\n3\n4\n6\n7\n8\n10\n12"
},
{
"input": "1\n212055293",
"output": "424069398"
},
{
"input": "1\n508427854",
"output": "1016791932"
},
{
"input": "1\n39... | 1,606,923,578 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | q = int(input())
for i in range(q):
n = int(input())
x = (n - 3) // 3
print(n - 1 + x)
| Title: Level Generation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan is developing his own computer game. Now he tries to create some levels for his game. But firstly for each level he needs to draw a graph representing the structure of the level.
Ivan decided that there should be... | ```python
q = int(input())
for i in range(q):
n = int(input())
x = (n - 3) // 3
print(n - 1 + x)
``` | 0 | |
651 | A | Joysticks | PROGRAMMING | 1,100 | [
"dp",
"greedy",
"implementation",
"math"
] | null | null | Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if n... | The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. | Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. | [
"3 5\n",
"4 4\n"
] | [
"6\n",
"5\n"
] | In the first sample game lasts for 6 minute by using the following algorithm:
- at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joyst... | 500 | [
{
"input": "3 5",
"output": "6"
},
{
"input": "4 4",
"output": "5"
},
{
"input": "100 100",
"output": "197"
},
{
"input": "1 100",
"output": "98"
},
{
"input": "100 1",
"output": "98"
},
{
"input": "1 4",
"output": "2"
},
{
"input": "1 1",
... | 1,598,251,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 108 | 6,656,000 | a1,a2 = map(int,input().split())
count = 0
while(a1 > 0 and a2 >0):
if(a1 >= a2):
a1-=2
a2+=1
else:
a1 +=1
a2-=2
count+=1
print(count) | Title: Joysticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick on... | ```python
a1,a2 = map(int,input().split())
count = 0
while(a1 > 0 and a2 >0):
if(a1 >= a2):
a1-=2
a2+=1
else:
a1 +=1
a2-=2
count+=1
print(count)
``` | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,693,896,142 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | a=int(input())
total,d=[],''
for i in range(1,a+1):
if i%2==0:
total.append("I love")
else:
total.append("I hate")
for i in range(len(total)-1):
d+=f"{total[i]} that "
d+=f"{total[-1]} it"
print(d) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
a=int(input())
total,d=[],''
for i in range(1,a+1):
if i%2==0:
total.append("I love")
else:
total.append("I hate")
for i in range(len(total)-1):
d+=f"{total[i]} that "
d+=f"{total[-1]} it"
print(d)
``` | 3 | |
34 | B | Sale | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | B. Sale | 2 | 256 | Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. | Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. | [
"5 3\n-6 0 35 -2 4\n",
"4 2\n7 0 0 -7\n"
] | [
"8\n",
"7\n"
] | none | 1,000 | [
{
"input": "5 3\n-6 0 35 -2 4",
"output": "8"
},
{
"input": "4 2\n7 0 0 -7",
"output": "7"
},
{
"input": "6 6\n756 -611 251 -66 572 -818",
"output": "1495"
},
{
"input": "5 5\n976 437 937 788 518",
"output": "0"
},
{
"input": "5 3\n-2 -2 -2 -2 -2",
"output": "... | 1,691,592,153 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 92 | 0 | n,x = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
s = 0
for i in arr:
if i < 0 and cnt < x:
s += abs(i)
cnt += 1
print(s) | Title: Sale
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can... | ```python
n,x = map(int, input().split())
arr = list(map(int, input().split()))
cnt = 0
s = 0
for i in arr:
if i < 0 and cnt < x:
s += abs(i)
cnt += 1
print(s)
``` | 0 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,605,033,268 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 0 | d={}
count=0
for i in range(int(input())):
team_name=input()
if team_name not in d:
d[team_name]=1
count+=1
else:
d[team_name]+=1
l=list(d.keys())
if count==2:
print(l[0] if d[l[0]]>d[l[1]] else d[l[1]])
else:
print(l[0]) | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
d={}
count=0
for i in range(int(input())):
team_name=input()
if team_name not in d:
d[team_name]=1
count+=1
else:
d[team_name]+=1
l=list(d.keys())
if count==2:
print(l[0] if d[l[0]]>d[l[1]] else d[l[1]])
else:
print(l[0])
``` | 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.... | 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 numbe... | 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 ta... | 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"
},
... | 1,699,268,782 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | si=int(input())
ct=0
for i in range(si):
p,q,r=map(int,input().split())
if p+q+r>=2:
ct+=1
print(ct)
| 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 decid... | ```python
si=int(input())
ct=0
for i in range(si):
p,q,r=map(int,input().split())
if p+q+r>=2:
ct+=1
print(ct)
``` | 3 | |
266 | A | Stones on the Table | PROGRAMMING | 800 | [
"implementation"
] | null | null | There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table.
The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red... | Print a single integer — the answer to the problem. | [
"3\nRRG\n",
"5\nRRRRR\n",
"4\nBRBG\n"
] | [
"1\n",
"4\n",
"0\n"
] | none | 500 | [
{
"input": "3\nRRG",
"output": "1"
},
{
"input": "5\nRRRRR",
"output": "4"
},
{
"input": "4\nBRBG",
"output": "0"
},
{
"input": "1\nB",
"output": "0"
},
{
"input": "2\nBG",
"output": "0"
},
{
"input": "3\nBGB",
"output": "0"
},
{
"input": "... | 1,698,463,668 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n=int(input())
s=input()
count=0
list1=list()
for i in range(0,n-1):
if ((s[i]=='R'and s[i+1]=='R')or(s[i]=='G'and s[i+1]=='G')or(s[i]=='B'and s[i+1]=='B')):
list1.append(s[i])
count=len(list1)
print(count) | Title: Stones on the Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ... | ```python
n=int(input())
s=input()
count=0
list1=list()
for i in range(0,n-1):
if ((s[i]=='R'and s[i+1]=='R')or(s[i]=='G'and s[i+1]=='G')or(s[i]=='B'and s[i+1]=='B')):
list1.append(s[i])
count=len(list1)
print(count)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null |
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, *f*0... ∞.
*f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people know about it, so she defines *f**i*<==<= "What are you doing while sending "*f**i*<=-<=1"? ... | The first line contains one integer *q* (1<=≤<=*q*<=≤<=10) — the number of Nephren's questions.
Each of the next *q* lines describes Nephren's question and contains two integers *n* and *k* (0<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=1018). | One line containing *q* characters. The *i*-th character in it should be the answer for the *i*-th query. | [
"3\n1 1\n1 2\n1 111111111111\n",
"5\n0 69\n1 194\n1 139\n0 47\n1 66\n",
"10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n"
] | [
"Wh.",
"abdef",
"Areyoubusy"
] | For the first two examples, refer to *f*<sub class="lower-index">0</sub> and *f*<sub class="lower-index">1</sub> given in the legend. | 0 | [
{
"input": "3\n1 1\n1 2\n1 111111111111",
"output": "Wh."
},
{
"input": "5\n0 69\n1 194\n1 139\n0 47\n1 66",
"output": "abdef"
},
{
"input": "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474",
"output": "Areyoubusy"
},
{
"input": "1\n0 1",
"outpu... | 1,512,235,306 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 5,529,600 | tmp = [""] * 3
tmp[0] = "What are you doing while sending \""
tmp[1] = "\"? Are you busy? Will you send \""
tmp[2] = "\"?"
def fun(s):
return tmp[0] + s + tmp[1] + s + tmp[2]
MAX = 60
f = [""] * 3
f[0] = "What are you doing at the end of the world? Are you busy? Will you save us?"
f[1] = fun(f[0])
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nephren is playing a game with little leprechauns.
She gives them an infinite array of strings, *f*0... ∞.
*f*0 is "What are you doing at the end of the world? Are you busy? Will you save us?".
She wants to let more people kn... | ```python
tmp = [""] * 3
tmp[0] = "What are you doing while sending \""
tmp[1] = "\"? Are you busy? Will you send \""
tmp[2] = "\"?"
def fun(s):
return tmp[0] + s + tmp[1] + s + tmp[2]
MAX = 60
f = [""] * 3
f[0] = "What are you doing at the end of the world? Are you busy? Will you save us?"
f[1] = ... | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | 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"
},
{
... | 1,685,330,713 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 62 | 0 | import math
n, k, l, c, d, p, nl, np = map(int,
input().split())
drink = k*l
toasts = drink/n
limes = c*d
salt = p/np
ans = min(toasts, limes, salt)/n
print(math.trunc(ans)) | 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... | ```python
import math
n, k, l, c, d, p, nl, np = map(int,
input().split())
drink = k*l
toasts = drink/n
limes = c*d
salt = p/np
ans = min(toasts, limes, salt)/n
print(math.trunc(ans))
``` | 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 lik... | 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":... | 1,683,579,227 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | num = int(input())
words = []
for i in range(num):
words.append(input())
for word in words[1:]:
if len(word) > 10:
print(f"{word[0]}{len(word)-2}{word[-1]}")
else:
print(word) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
num = int(input())
words = []
for i in range(num):
words.append(input())
for word in words[1:]:
if len(word) > 10:
print(f"{word[0]}{len(word)-2}{word[-1]}")
else:
print(word)
``` | 0 |
570 | B | Simple Game | PROGRAMMING | 1,300 | [
"constructive algorithms",
"games",
"greedy",
"implementation",
"math"
] | null | null | One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random generator they choose a random integer *c* in the range between 1 and *n* (any integer from 1 to *n*... | The first line contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the range of numbers in the game, and the number selected by Misha respectively. | Print a single number — such value *a*, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them. | [
"3 1\n",
"4 3\n"
] | [
"2",
"2"
] | In the first sample test: Andrew wins if *c* is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses *a* = 3, the probability of winning will be 1 / 3. If *a* = 1, the probability of winning is 0.
In the second sample test: Andrew wins if *c* is equal to 1 and 2. The probability that Andrew wi... | 1,000 | [
{
"input": "3 1",
"output": "2"
},
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "4"
},
{
"input": "10 5",
"output": "6"
},
{
"input": "20 13",
"output": "12"
},
{
"input": "51 1",
"output": "2"
},
{
"input": "100 50",
... | 1,537,270,676 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 155 | 409,600 | n,m=map(int,input().split())
x=m-1
y=n-m
if(x>y):
print(m-1)
elif(y>x):
print(m+1)
elif(n//2+1==m and n!=m):
print(n-m)
else:
print(m) | Title: Simple Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to *n*. Let's assume that Misha chose number *m*, and Andrew chose number *a*.
Then, by using a random gen... | ```python
n,m=map(int,input().split())
x=m-1
y=n-m
if(x>y):
print(m-1)
elif(y>x):
print(m+1)
elif(n//2+1==m and n!=m):
print(n-m)
else:
print(m)
``` | 3 | |
46 | C | Hamsters and Tigers | PROGRAMMING | 1,600 | [
"two pointers"
] | C. Hamsters and Tigers | 2 | 256 | Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together... | The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at ... | Print the single number which is the minimal number of swaps that let the trainer to achieve his goal. | [
"3\nHTH\n",
"9\nHTHTHTHHT\n"
] | [
"0\n",
"2\n"
] | In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7. | 0 | [
{
"input": "3\nHTH",
"output": "0"
},
{
"input": "9\nHTHTHTHHT",
"output": "2"
},
{
"input": "2\nTH",
"output": "0"
},
{
"input": "4\nHTTH",
"output": "0"
},
{
"input": "4\nHTHT",
"output": "1"
},
{
"input": "7\nTTTHTTT",
"output": "0"
},
{
... | 1,679,210,005 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 1,843,200 | n = int(input())
s = input()
c_h = s.count('H')
ans = float('inf')
for i in range(n):
cur_ans = 0
for j in range(i,i+c_h):
if s[j%n] == 'T':
cur_ans += 1
ans = min(cur_ans, ans)
print(ans)
| Title: Hamsters and Tigers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap ... | ```python
n = int(input())
s = input()
c_h = s.count('H')
ans = float('inf')
for i in range(n):
cur_ans = 0
for j in range(i,i+c_h):
if s[j%n] == 'T':
cur_ans += 1
ans = min(cur_ans, ans)
print(ans)
``` | 3.965567 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,601,564,289 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 216 | 307,200 | def gcd(x,y):
if (x==y):
return x
if (x>y):
return gcd(x-y,y)
else:
return gcd(x,y-x)
if __name__=="__main__":
l=[int(i) for i in input().split()]
f=0
a=l[0]
b=l[1]
n=l[2]
while n!=0:
n-=gcd(a,n)
if n==0:
f=1
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
def gcd(x,y):
if (x==y):
return x
if (x>y):
return gcd(x-y,y)
else:
return gcd(x,y-x)
if __name__=="__main__":
l=[int(i) for i in input().split()]
f=0
a=l[0]
b=l[1]
n=l[2]
while n!=0:
n-=gcd(a,n)
if n==0:
... | 3 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,651,778,309 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 154 | 512,000 | #ord('A') is 65
#Given `X>Y`` or `Y<X``, returns 0,1,2 if X is A,B,C resp
def winner(descr):
if descr[1] == '>':
return ord(descr[0]) - 65
else:
return ord(descr[2]) - 65
inputs = [0,0,0]
for i in range(3):
inputs[i] = input()
wins = [0,0,0]
for descr in inputs:
wins[... | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
#ord('A') is 65
#Given `X>Y`` or `Y<X``, returns 0,1,2 if X is A,B,C resp
def winner(descr):
if descr[1] == '>':
return ord(descr[0]) - 65
else:
return ord(descr[2]) - 65
inputs = [0,0,0]
for i in range(3):
inputs[i] = input()
wins = [0,0,0]
for descr in inputs:
... | 3.960546 |
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 Vasy... | 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... | 1,608,730,187 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 248 | 307,200 | n=int(input())
l=[]
k=[]
x=0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(3):
for j in range(n):
x=x+l[j][i]
k.append(x)
x=0
for i in range(3):
if k[i]==0:
x=x+1
if(x>=3):
print('YES')
else:
print('NO')
| Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n=int(input())
l=[]
k=[]
x=0
for i in range(n):
l.append(list(map(int,input().split())))
for i in range(3):
for j in range(n):
x=x+l[j][i]
k.append(x)
x=0
for i in range(3):
if k[i]==0:
x=x+1
if(x>=3):
print('YES')
else:
print('NO')
``` | 3.937428 |
0 | none | none | none | 0 | [
"none"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 0 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,682,861,933 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 154 | 3,072,000 | n,d=map(int,input().split())
a=list(map(int,input().split()))
ans=0
def check(idx):
if idx>=n:
return 0
l,r=idx,n-1
while l<=r:
mid=(l+r)>>1
if a[mid]-s>d:
r=mid-1
else:
l=mid+1
return l
l = 0
while(l<n):
r = check(x+2)
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of th... | ```python
n,d=map(int,input().split())
a=list(map(int,input().split()))
ans=0
def check(idx):
if idx>=n:
return 0
l,r=idx,n-1
while l<=r:
mid=(l+r)>>1
if a[mid]-s>d:
r=mid-1
else:
l=mid+1
return l
l = 0
while(l<n):
r = che... | -1 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,662,314,639 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import math as mt
from collections import defaultdict,deque
from posixpath import split
import sys
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l
mod=1000000007
INT_MAX = sys.maxsize-1
INT_MIN = -sys.maxsize
def solve():
n=map(int,input().split())
a=list(map(int,... | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
import math as mt
from collections import defaultdict,deque
from posixpath import split
import sys
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l
mod=1000000007
INT_MAX = sys.maxsize-1
INT_MIN = -sys.maxsize
def solve():
n=map(int,input().split())
a=lis... | 0 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,698,151,954 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
in_list = map(int, input().split())
MAX_N = max(in_list)
dp = [0 for i in range(MAX_N)]
counts = [0 for i in range(MAX_N)]
for num in in_list:
counts[num] += 1
dp[0] = 0
dp[1] = counts[1]
for i in range(2, MAX_N):
dp[i] = max(dp[i - 1], dp[i - 2] + (i * counts[i]))
print(dp[... | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
in_list = map(int, input().split())
MAX_N = max(in_list)
dp = [0 for i in range(MAX_N)]
counts = [0 for i in range(MAX_N)]
for num in in_list:
counts[num] += 1
dp[0] = 0
dp[1] = counts[1]
for i in range(2, MAX_N):
dp[i] = max(dp[i - 1], dp[i - 2] + (i * counts[i]))
... | 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 ex... | 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... | 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 ... | 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... | 1,699,454,721 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 186 | 1,945,600 | n = int(input())
mx = 0
curr = 0
for i in range(n):
a,b = [int(x) for x in input().split()]
curr += b
curr -= a
if curr > mx:
mx = curr
print(mx) | 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 ... | ```python
n = int(input())
mx = 0
curr = 0
for i in range(n):
a,b = [int(x) for x in input().split()]
curr += b
curr -= a
if curr > mx:
mx = curr
print(mx)
``` | 3 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,684,091,191 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import heapq
n, m = map(int, input().split())
grf = list(list() for _ in range(n))
for _ in range(m):
a, b, w = map(int, input().split())
grf[a-1].append((b-1, w))
grf[b-1].append((a-1, w))
pq = list()
dis = [(float('inf'), -1)] * n
dis[0] = (0, -1)
heapq.heappush(pq, (0, 0, -1))
while ... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
import heapq
n, m = map(int, input().split())
grf = list(list() for _ in range(n))
for _ in range(m):
a, b, w = map(int, input().split())
grf[a-1].append((b-1, w))
grf[b-1].append((a-1, w))
pq = list()
dis = [(float('inf'), -1)] * n
dis[0] = (0, -1)
heapq.heappush(pq, (0, 0, -1))... | 0 |
990 | B | Micro-World | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer c... | The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$.
The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. | Print the only integer — minimal possible number of bacteria can remain. | [
"7 1\n101 53 42 102 101 55 54\n",
"6 5\n20 15 10 15 20 25\n",
"7 1000000\n1 1 1 1 1 1 1\n"
] | [
"3\n",
"1\n",
"7\n"
] | The first example is clarified in the problem statement.
In the second example an optimal possible sequence of swallows is: $[20, 15, 10, 15, \underline{20}, 25]$ $\to$ $[20, 15, 10, \underline{15}, 25]$ $\to$ $[20, 15, \underline{10}, 25]$ $\to$ $[20, \underline{15}, 25]$ $\to$ $[\underline{20}, 25]$ $\to$ $[25]$.
I... | 0 | [
{
"input": "7 1\n101 53 42 102 101 55 54",
"output": "3"
},
{
"input": "6 5\n20 15 10 15 20 25",
"output": "1"
},
{
"input": "7 1000000\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 4\n8",
"output": "1"
},
{
"inp... | 1,528,632,917 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | import math as ma
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=0
ll=len(a)
#print(*a)
for i in range(len(a)):
if(a[i+1]>a[i] and (a[i]+k)>=a[i+1]):
c+=1
print(ll-c) | Title: Micro-World
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.
You know that you have $n$ bacteria in the Pe... | ```python
import math as ma
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=0
ll=len(a)
#print(*a)
for i in range(len(a)):
if(a[i+1]>a[i] and (a[i]+k)>=a[i+1]):
c+=1
print(ll-c)
``` | -1 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,650,395,058 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 61 | 307,200 | a, b, n = map(int, input().split())
a *= 10
flag = False
for i in range(10):
if (a+i) % b == 0:
print(a+i, end = "")
flag = True
break
if(flag):
s = "0" * (n-1)
print(s)
else:
print(-1)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a, b, n = map(int, input().split())
a *= 10
flag = False
for i in range(10):
if (a+i) % b == 0:
print(a+i, end = "")
flag = True
break
if(flag):
s = "0" * (n-1)
print(s)
else:
print(-1)
``` | 3 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | 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 r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,637,088,718 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 3 | 124 | 0 | def solve(a):
if a < 60:
return "NO"
if 360 % (180 - a) == 0:
return "YES"
return "NO"
def main():
t = int(input())
for i in range(t):
a = int(input())
print(solve(a))
if __name__ == '__main__':
main()
| 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... | ```python
def solve(a):
if a < 60:
return "NO"
if 360 % (180 - a) == 0:
return "YES"
return "NO"
def main():
t = int(input())
for i in range(t):
a = int(input())
print(solve(a))
if __name__ == '__main__':
main()
``` | 3 | |
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"
},
{
"... | 1,686,867,248 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 46 | 102,400 | s = input()
found = False
# Check for non-overlapping "AB" and "BA" substrings
if "AB" in s:
index = s.index("AB")
if "BA" in s[index + 2:]:
found = True
if not found and "BA" in s:
index = s.index("BA")
if "AB" in s[index + 2:]:
found = True
if found:
print("YES")
... | 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 contain... | ```python
s = input()
found = False
# Check for non-overlapping "AB" and "BA" substrings
if "AB" in s:
index = s.index("AB")
if "BA" in s[index + 2:]:
found = True
if not found and "BA" in s:
index = s.index("BA")
if "AB" in s[index + 2:]:
found = True
if found:
pri... | 3 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,628,490,245 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 218 | 20,172,800 | n = int(input())
l = list(map(int, input().split()))
fiveCount = 0
zeroCount = 0
for num in l:
if (num == 5):
fiveCount += 1
elif (num == 0):
zeroCount += 1
if (fiveCount < 9 or zeroCount == 0):
print("0")
else:
fivesReq = fiveCount // 9
res = ""
res += "5" * ( five... | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n = int(input())
l = list(map(int, input().split()))
fiveCount = 0
zeroCount = 0
for num in l:
if (num == 5):
fiveCount += 1
elif (num == 0):
zeroCount += 1
if (fiveCount < 9 or zeroCount == 0):
print("0")
else:
fivesReq = fiveCount // 9
res = ""
res += "5... | 0 | |
416 | C | Booking System | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"greedy",
"implementation"
] | null | null | Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are *n* booking requests received by now. Each request is characterized by two numbers: *c**i*... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of requests from visitors. Then *n* lines follow. Each line contains two integers: *c**i*,<=*p**i* (1<=≤<=*c**i*,<=*p**i*<=≤<=1000) — the size of the group of visitors who will come by the *i*-th request and the total sum of money they w... | In the first line print two integers: *m*,<=*s* — the number of accepted requests and the total money you get from these requests, correspondingly.
Then print *m* lines — each line must contain two space-separated integers: the number of the accepted request and the number of the table to seat people who come via this... | [
"3\n10 50\n2 100\n5 30\n3\n4 6 9\n"
] | [
"2 130\n2 1\n3 2\n"
] | none | 1,500 | [
{
"input": "3\n10 50\n2 100\n5 30\n3\n4 6 9",
"output": "2 130\n2 1\n3 2"
},
{
"input": "1\n1 1\n1\n1",
"output": "1 1\n1 1"
},
{
"input": "1\n2 1\n1\n1",
"output": "0 0"
},
{
"input": "2\n10 10\n5 5\n1\n5",
"output": "1 5\n2 1"
},
{
"input": "2\n10 10\n5 5\n1\n10... | 1,618,612,974 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n=int(input())
cp=[list(map(int,input().split())) for i in range(n)]
k=int(input())
r=list(map(int,input().split()))
cp.sort(key=lambda x:x[1],reverse=True)
use=[False]*k
ans=[]
m,s=0,0
for i in range(n):
c,p=cp[i]
for j in range(k):
if r[j]>=c and not use[j]:
use[j]=True
m+=1
s+... | Title: Booking System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
... | ```python
n=int(input())
cp=[list(map(int,input().split())) for i in range(n)]
k=int(input())
r=list(map(int,input().split()))
cp.sort(key=lambda x:x[1],reverse=True)
use=[False]*k
ans=[]
m,s=0,0
for i in range(n):
c,p=cp[i]
for j in range(k):
if r[j]>=c and not use[j]:
use[j]=True
m+=1... | 0 | |
394 | B | Very Beautiful Number | PROGRAMMING | 0 | [
"math"
] | null | null | Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office.
The teacher remembers that the "very beau... | The single line contains integers *p*, *x* (1<=≤<=*p*<=≤<=106,<=1<=≤<=*x*<=≤<=9). | If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes. | [
"6 5\n",
"1 2\n",
"6 4\n"
] | [
"142857",
"Impossible\n",
"102564"
] | Sample 1: 142857·5 = 714285.
Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible". | 1,000 | [
{
"input": "6 5",
"output": "142857"
},
{
"input": "1 2",
"output": "Impossible"
},
{
"input": "6 4",
"output": "102564"
},
{
"input": "11 1",
"output": "11111111111"
},
{
"input": "42 5",
"output": "102040816326530612244897959183673469387755"
},
{
"in... | 1,580,825,631 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | #! /usr/bin/python3
import time
def gcd(a, b):
if a % b == 0:
return b
if b % a == 0:
return a
else:
return gcd(max(a, b) % min(a, b), min(a, b))
p, x = map(int, input().split())
a = (10 * x - 1) // gcd(10**p - 1, 10 * x - 1)
if a < 10 and a > 0:
ans = a * (10**... | Title: Very Beautiful Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem ... | ```python
#! /usr/bin/python3
import time
def gcd(a, b):
if a % b == 0:
return b
if b % a == 0:
return a
else:
return gcd(max(a, b) % min(a, b), min(a, b))
p, x = map(int, input().split())
a = (10 * x - 1) // gcd(10**p - 1, 10 * x - 1)
if a < 10 and a > 0:
ans =... | 0 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,605,676,981 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 307,200 | n = int(input())
org = list(map(int,list(input())))
secret = list(map(int,list(input())))
moves = 0
for i in range(n):
if org[i]==0:
if secret[i]==0:
moves += 0
elif secret[i]<=5:
moves += secret[i]
else:
moves += 10-secret[i]
elif secret[i... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n = int(input())
org = list(map(int,list(input())))
secret = list(map(int,list(input())))
moves = 0
for i in range(n):
if org[i]==0:
if secret[i]==0:
moves += 0
elif secret[i]<=5:
moves += secret[i]
else:
moves += 10-secret[i]
eli... | 3 | |
278 | B | New Problem | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You've got the titles of *n* last problems — the strings, consisting of lowercase English letters. Yo... | The first line contains integer *n* (1<=≤<=*n*<=≤<=30) — the number of titles you've got to consider. Then follow *n* problem titles, one per line. Each title only consists of lowercase English letters (specifically, it doesn't contain any spaces) and has the length from 1 to 20, inclusive. | Print a string, consisting of lowercase English letters — the lexicographically minimum shortest original title. | [
"5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear\n",
"4\naa\nbdefghijklmn\nopqrstuvwxyz\nc\n"
] | [
"j\n",
"ab\n"
] | In the first sample the first 9 letters of the English alphabet (a, b, c, d, e, f, g, h, i) occur in the problem titles, so the answer is letter j.
In the second sample the titles contain 26 English letters, so the shortest original title cannot have length 1. Title aa occurs as a substring in the first title. | 1,000 | [
{
"input": "5\nthreehorses\ngoodsubstrings\nsecret\nprimematrix\nbeautifulyear",
"output": "j"
},
{
"input": "4\naa\nbdefghijklmn\nopqrstuvwxyz\nc",
"output": "ab"
},
{
"input": "1\na",
"output": "b"
},
{
"input": "1\nb",
"output": "a"
},
{
"input": "1\nz",
"o... | 1,627,156,321 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 124 | 6,963,200 | n=int(input())
d=dict()
f=[]
for i in range(n):
s=input()
for i in s:
f.append(i)
if i in d:
d[i]+=1
else:
d[i]=1
f.append(' ')
if len(d)<=25:
s='abcdefghijklmnopqrstuvwxyz'
for i in s:
if i not in d:
print(i)
break
else:
num=97
for i in range(25):
sk=['a']
sk.append... | Title: New Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems.
You'... | ```python
n=int(input())
d=dict()
f=[]
for i in range(n):
s=input()
for i in s:
f.append(i)
if i in d:
d[i]+=1
else:
d[i]=1
f.append(' ')
if len(d)<=25:
s='abcdefghijklmnopqrstuvwxyz'
for i in s:
if i not in d:
print(i)
break
else:
num=97
for i in range(25):
sk=['a']
... | 0 | |
214 | A | System of Equations | PROGRAMMING | 800 | [
"brute force"
] | null | null | Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?
You are given a system of equations:
You should count, how many there are pairs of int... | A single line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the parameters of the system. The numbers on the line are separated by a space. | On a single line print the answer to the problem. | [
"9 3\n",
"14 28\n",
"4 20\n"
] | [
"1\n",
"1\n",
"0\n"
] | In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair. | 500 | [
{
"input": "9 3",
"output": "1"
},
{
"input": "14 28",
"output": "1"
},
{
"input": "4 20",
"output": "0"
},
{
"input": "18 198",
"output": "1"
},
{
"input": "22 326",
"output": "1"
},
{
"input": "26 104",
"output": "1"
},
{
"input": "14 10"... | 1,625,307,880 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 530 | 0 | n=list(map(int,input().split()))
x=0
for a in range(n[1]+1):
for b in range(n[0]+1):
if a*a+b==n[0] and a+b*b==n[1]:
x+=1
print(x)
| Title: System of Equations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi... | ```python
n=list(map(int,input().split()))
x=0
for a in range(n[1]+1):
for b in range(n[0]+1):
if a*a+b==n[0] and a+b*b==n[1]:
x+=1
print(x)
``` | 3 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,505,297,673 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 62 | 0 | # your code goes here
n=int(input())
l=list(map(int,input().split()))
def find_ans(l):
m=0
for i in range(1,len(l)):
d=l[i]-l[i-1]
m=max(m,d)
return m
t=l
f_ans=100000000000000000000000000000000
for i in range(1,n-1):
temp=l[0:i]+l[i+1:n]
ans=find_ans(temp)
f_ans=min(f_ans,ans)
print(f_ans)
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
# your code goes here
n=int(input())
l=list(map(int,input().split()))
def find_ans(l):
m=0
for i in range(1,len(l)):
d=l[i]-l[i-1]
m=max(m,d)
return m
t=l
f_ans=100000000000000000000000000000000
for i in range(1,n-1):
temp=l[0:i]+l[i+1:n]
ans=find_ans(temp)
f_ans=min(f_ans,ans)
print(... | 3 | |
312 | A | Whose sentence is it? | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100. | For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG>.< I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditi... | [
"5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n"
] | [
"Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!\n"
] | none | 500 | [
{
"input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .",
"output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!"
},
{
"input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iape... | 1,370,996,648 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 93 | 102,400 | import re
Fe = re.compile('.*lala\.')
FeA = "Freda's"
Ra = re.compile('miao\..*')
RaA = "Rainbow's"
NotSure = "OMG>.< I don't know!"
if __name__ == '__main__':
N = int(input())
for times in range(N):
inp = input()
inp = inp.strip()
f1 = Fe.search(inp) != None
f2 = Ra.search(inp... | Title: Whose sentence is it?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Fr... | ```python
import re
Fe = re.compile('.*lala\.')
FeA = "Freda's"
Ra = re.compile('miao\..*')
RaA = "Rainbow's"
NotSure = "OMG>.< I don't know!"
if __name__ == '__main__':
N = int(input())
for times in range(N):
inp = input()
inp = inp.strip()
f1 = Fe.search(inp) != None
f2 = Ra.... | 0 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,511,460,163 | 163 | Python 3 | OK | TESTS | 16 | 62 | 5,529,600 | n=input().split()
n[0]=int(n[0])
n[1]=int(n[1])
li=list(map(int,input().split()))
c=1
x=0
while(n[1]>0):
if(li[x]<86400):
n[1]-=(86400-li[x])
if(n[1]>0):
x+=1
c+=1
else:
c+=1
x+=1
print(c)
| Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
n=input().split()
n[0]=int(n[0])
n[1]=int(n[1])
li=list(map(int,input().split()))
c=1
x=0
while(n[1]>0):
if(li[x]<86400):
n[1]-=(86400-li[x])
if(n[1]>0):
x+=1
c+=1
else:
c+=1
x+=1
print(c)
``` | 3 | |
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
... | 1,585,286,925 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 248 | 0 | l=[]
for _ in range(3):
l.append(list(input()))
d={}
d[('h',0)]=[]
d[('h',1)]=[]
d[('h',2)]=[]
d[('v',0)]=[]
d[('v',1)]=[]
d[('v',2)]=[]
d[('d',0)]=[]
d[('d',-1)]=[]
countX=0
count0=0
for i in range(3):
for j in range(3):
if l[i][j]=='X' :
countX+=1
d[('h',i)].a... | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ... | ```python
l=[]
for _ in range(3):
l.append(list(input()))
d={}
d[('h',0)]=[]
d[('h',1)]=[]
d[('h',2)]=[]
d[('v',0)]=[]
d[('v',1)]=[]
d[('v',2)]=[]
d[('d',0)]=[]
d[('d',-1)]=[]
countX=0
count0=0
for i in range(3):
for j in range(3):
if l[i][j]=='X' :
countX+=1
d[... | 0 |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,625,838,016 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 124 | 0 | n=int(input())
a=list(map(int, input().split()))
a.sort()
a=list(dict.fromkeys(a))
if len(a)<1: print("NO")
else : print(a[1])
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n=int(input())
a=list(map(int, input().split()))
a.sort()
a=list(dict.fromkeys(a))
if len(a)<1: print("NO")
else : print(a[1])
``` | -1 |
331 | C1 | The Great Julya Calendar | PROGRAMMING | 1,100 | [
"dp"
] | null | null | Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows:
"May the Great Beaver bless you! May your chacres open ... | The single line contains the magic integer *n*, 0<=≤<=*n*.
- to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co... | Print a single integer — the minimum number of subtractions that turns the magic number to a zero. | [
"24\n"
] | [
"5"
] | In the first test sample the minimum number of operations can be reached by the following sequence of subtractions: | 20 | [
{
"input": "24",
"output": "5"
},
{
"input": "0",
"output": "0"
},
{
"input": "3",
"output": "1"
},
{
"input": "8",
"output": "1"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "31",
"output": "6"
},
... | 1,648,434,028 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS1 | 1 | 60 | 0 | n = int(input())
count = 0
def subs(n):
global count
x = [int(a) for a in str(n)]
n -= max(x)
count += 1
if n == 0:
print(count)
else:
subs(n)
subs(n) | Title: The Great Julya Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar.
The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i... | ```python
n = int(input())
count = 0
def subs(n):
global count
x = [int(a) for a in str(n)]
n -= max(x)
count += 1
if n == 0:
print(count)
else:
subs(n)
subs(n)
``` | 0 | |
934 | A | A Compatible Pair | PROGRAMMING | 1,400 | [
"brute force",
"games"
] | null | null | Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming.
Little Tommy has *n* lanterns and Big B... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=50).
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*.
The third line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m*.
All the integers range from <=-<=109 to 109. | Print a single integer — the brightness of the chosen pair. | [
"2 2\n20 18\n2 14\n",
"5 3\n-1 0 1 2 3\n-1 0 1\n"
] | [
"252\n",
"2\n"
] | In the first example, Tommy will hide 20 and Banban will choose 18 from Tommy and 14 from himself.
In the second example, Tommy will hide 3 and Banban will choose 2 from Tommy and 1 from himself. | 500 | [
{
"input": "2 2\n20 18\n2 14",
"output": "252"
},
{
"input": "5 3\n-1 0 1 2 3\n-1 0 1",
"output": "2"
},
{
"input": "10 2\n1 6 2 10 2 3 2 10 6 4\n5 7",
"output": "70"
},
{
"input": "50 50\n1 6 2 10 2 3 2 10 6 4 5 0 3 1 7 3 2 4 4 2 1 5 0 6 10 1 8 0 10 9 0 4 10 5 5 7 4 9 9 5 5 ... | 1,518,615,459 | 5,559 | Python 3 | WRONG_ANSWER | CHALLENGES | 0 | 61 | 5,632,000 | n,m = input().split(' ')
arr1 = []
a = input().split(' ')
for i in a:
arr1.append(int(i))
arr2 = []
b= input().split(' ')
for i in b:
arr2.append(int(i))
arr1.sort()
arr2.sort()
ans = arr1[0]*arr2[0]
for i in range(int(n)-1):
for j in range(int(m)):
ans = max(arr1[int(i)]*arr2[in... | Title: A Compatible Pair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cr... | ```python
n,m = input().split(' ')
arr1 = []
a = input().split(' ')
for i in a:
arr1.append(int(i))
arr2 = []
b= input().split(' ')
for i in b:
arr2.append(int(i))
arr1.sort()
arr2.sort()
ans = arr1[0]*arr2[0]
for i in range(int(n)-1):
for j in range(int(m)):
ans = max(arr1[int(i... | 0 | |
742 | A | Arpa’s hard exam and Mehrdad’s naive cheat | PROGRAMMING | 1,000 | [
"implementation",
"math",
"number theory"
] | null | null | There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*.
Mehrdad has become quite confused and wants you to help him. Please help, al... | The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). | Print single integer — the last digit of 1378*n*. | [
"1\n",
"2\n"
] | [
"8",
"4"
] | In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8.
In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4. | 500 | [
{
"input": "1",
"output": "8"
},
{
"input": "2",
"output": "4"
},
{
"input": "1000",
"output": "6"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "6"
},
{
"input": "1000000000",
"output": "6"
},
{
"input": "5",
"output": ... | 1,666,882,462 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | n=int(input())
a=8
for i in range(n-1):
a=a*8
a=list(str(a))
a=int(a[len(a)-1])
print(a)
| Title: Arpa’s hard exam and Mehrdad’s naive cheat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do.
Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques... | ```python
n=int(input())
a=8
for i in range(n-1):
a=a*8
a=list(str(a))
a=int(a[len(a)-1])
print(a)
``` | 0 | |
246 | D | Colorful Graph | PROGRAMMING | 1,600 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*.
Let's consider all vertices of the graph, that are painted some color *k*. Let... | The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105) — the colors of the graph vertices. The numbers on the line are sep... | Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color. | [
"6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6\n",
"5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4\n"
] | [
"3\n",
"2\n"
] | none | 2,000 | [
{
"input": "6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6",
"output": "3"
},
{
"input": "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4",
"output": "2"
},
{
"input": "3 1\n13 13 4\n1 2",
"output": "4"
},
{
"input": "2 1\n500 300\n1 2",
"output": "300"
},
{
"input":... | 1,640,334,732 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 186 | 0 | n, m = map(int, input().split())
colors = list(map(int, input().split()))
ar = [[] for i in range(n)]
d = dict()
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
if colors[a] not in d.keys():
d[colors[a]] = [colors[b]]
else:
d[colors[a]].append(colors[b])
... | Title: Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex i... | ```python
n, m = map(int, input().split())
colors = list(map(int, input().split()))
ar = [[] for i in range(n)]
d = dict()
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
if colors[a] not in d.keys():
d[colors[a]] = [colors[b]]
else:
d[colors[a]].append(c... | 0 | |
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. Th... | 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,695,052,974 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 2,048,000 | n=int(input())
list=input().split()
Sereja_points=0
Dima_points=0
for i in range(0,n):
if(i%2==0):
if(list[0]>list[-1]):
Sereja_points+=list[0]
list.pop(list[0])
else:
Sereja_points+=list[-1]
list.pop(list[-1])
else:
if(list[0]... | 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. Du... | ```python
n=int(input())
list=input().split()
Sereja_points=0
Dima_points=0
for i in range(0,n):
if(i%2==0):
if(list[0]>list[-1]):
Sereja_points+=list[0]
list.pop(list[0])
else:
Sereja_points+=list[-1]
list.pop(list[-1])
else:
... | -1 | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,655,295,361 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 409,600 | #!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
t = int(wtf[0])
for s in wtf[1:]:
n = int(s)
a = 2**(int(math.log2(n))+1)-1
b = (n**2+n)//2
prin... | Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
#!/usr/bin/env python
import math
import sys
import itertools
import fractions
if __name__ == '__main__':
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
t = int(wtf[0])
for s in wtf[1:]:
n = int(s)
a = 2**(int(math.log2(n))+1)-1
b = (n**2+n)//2
... | 3 | |
45 | I | TCMCF+++ | PROGRAMMING | 1,400 | [
"greedy"
] | I. TCMCF+++ | 2 | 256 | Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of po... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of the suggested problems. The next line contains *n* space-separated integers *c**i* (<=-<=100<=≤<=*c**i*<=≤<=100) — the cost of the *i*-th task. The tasks' costs may coinсide. | Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them. | [
"5\n1 2 -3 3 3\n",
"13\n100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"4\n-2 -2 -2 -2\n"
] | [
"3 1 2 3 \n",
"100 100 100 100 100 100 100 100 100 100 100 100 100 \n",
"-2 -2 -2 -2 \n"
] | none | 0 | [
{
"input": "5\n1 2 -3 3 3",
"output": "3 1 2 3 "
},
{
"input": "13\n100 100 100 100 100 100 100 100 100 100 100 100 100",
"output": "100 100 100 100 100 100 100 100 100 100 100 100 100 "
},
{
"input": "4\n-2 -2 -2 -2",
"output": "-2 -2 -2 -2 "
},
{
"input": "1\n1",
"outpu... | 1,649,997,940 | 3,040 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 512,000 | n=int(input())
a=[int(i) for i in input().split()]
otr=0
v=[]
b1,b2,b3=[],[],[]
for i in range(len(a)):
if a[i]==0:
b3.append(a[i])
elif a[i]>0:
b1.append(a[i])
elif a[i]<0:
b2.append(a[i])
if len(b1)==0:
if len(b3)==0:
if len(b2)%2==0:
print(*b... | Title: TCMCF+++
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest *n* problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). Accord... | ```python
n=int(input())
a=[int(i) for i in input().split()]
otr=0
v=[]
b1,b2,b3=[],[],[]
for i in range(len(a)):
if a[i]==0:
b3.append(a[i])
elif a[i]>0:
b1.append(a[i])
elif a[i]<0:
b2.append(a[i])
if len(b1)==0:
if len(b3)==0:
if len(b2)%2==0:
... | 0 |
239 | A | Two Bags of Potatoes | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"math"
] | null | null | Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first... | The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). | Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once.
If there are no such values of *x* print a single integer -1. | [
"10 1 10\n",
"10 6 40\n"
] | [
"-1\n",
"2 8 14 20 26 \n"
] | none | 500 | [
{
"input": "10 1 10",
"output": "-1"
},
{
"input": "10 6 40",
"output": "2 8 14 20 26 "
},
{
"input": "10 1 20",
"output": "1 2 3 4 5 6 7 8 9 10 "
},
{
"input": "1 10000 1000000000",
"output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999... | 1,673,118,889 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 1,000 | 0 |
def mi():
y,k,n = [int(x) for x in input().split()]
count = 0
x = 1
while x+y <= n:
if (x+y)%k == 0:
count += 1
print(x,end=" ")
x += 1
if count == 0:
print(-1)
mi() | Title: Two Bags of Potatoes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota... | ```python
def mi():
y,k,n = [int(x) for x in input().split()]
count = 0
x = 1
while x+y <= n:
if (x+y)%k == 0:
count += 1
print(x,end=" ")
x += 1
if count == 0:
print(-1)
mi()
``` | 0 | |
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two give... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All num... | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the se... | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"i... | 1,617,697,541 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 122 | 0 | try:
n,k=map(int,input().split())
j=[]
for i in range(n):
p,t=map(int,input().split())
j.append(p)
j.sort(reverse=True)
print(j.count(j[k-1]))
except:
pass
| Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for... | ```python
try:
n,k=map(int,input().split())
j=[]
for i in range(n):
p,t=map(int,input().split())
j.append(p)
j.sort(reverse=True)
print(j.count(j[k-1]))
except:
pass
``` | 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 ... | 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"
},
... | 1,697,974,766 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n=int(input())
a=n-2
print(2,a) | 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 statemen... | ```python
n=int(input())
a=n-2
print(2,a)
``` | 0 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,628,816,939 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 62 | 6,758,400 | #758A (40No. Problem A)
n = int(input())
m = 1
ans = (n*m)+1
if (n == 1):
m = 3
else:
for i in range(2,ans):
if (ans%i == 0):
break
else:
if (i == ans-1):
m+=1
ans = (n*m)+1
print(m) | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
#758A (40No. Problem A)
n = int(input())
m = 1
ans = (n*m)+1
if (n == 1):
m = 3
else:
for i in range(2,ans):
if (ans%i == 0):
break
else:
if (i == ans-1):
m+=1
ans = (n*m)+1
print(m)
``` | 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 consis... | 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 cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,657,574,358 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 154 | 0 | s = input()
k = True
for i in range(len(s)):
if(s[i]=='0' and k):
k = False
continue
print(s[i],end="")
| 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... | ```python
s = input()
k = True
for i in range(len(s)):
if(s[i]=='0' and k):
k = False
continue
print(s[i],end="")
``` | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,688,820,815 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def solve(a):
l="HQ9+"
c=0
for i in range(len(l)):
for j in range(len(a)):
x=l[i]
y=a[j]
if x==y:
c+=1
if c>0:
print("YES")
else:
print("NO")
a=input("")
solution=solve(a) | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
def solve(a):
l="HQ9+"
c=0
for i in range(len(l)):
for j in range(len(a)):
x=l[i]
y=a[j]
if x==y:
c+=1
if c>0:
print("YES")
else:
print("NO")
a=input("")
solution=solve(a)
``` | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,... | В первой строке входных данных следует целое положительное число *n* (3<=≤<=*n*<=≤<=1000) — количество оценок, полученных Васей.
Во второй строке входных данных следует последовательность из *n* чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вас... | Выведите одно целое число — количество подарков, полученных Васей. | [
"6\n4 5 4 5 4 4\n",
"14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n"
] | [
"2\n",
"3\n"
] | В первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно. | 0 | [
{
"input": "6\n4 5 4 5 4 4",
"output": "2"
},
{
"input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5",
"output": "3"
},
{
"input": "3\n4 5 4",
"output": "1"
},
{
"input": "3\n4 5 1",
"output": "0"
},
{
"input": "4\n5 4 3 5",
"output": "0"
},
{
"input": "10\n4 4 5... | 1,458,820,539 | 14,139 | Python 3 | OK | TESTS | 118 | 77 | 5,120,000 | n = int(input())
cnt = 0
ans = 0
for i in list(map(int, input().split()))+[1]:
if (i < 4):
ans += cnt // 3
cnt = 0
else:
cnt += 1
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи ... | ```python
n = int(input())
cnt = 0
ans = 0
for i in list(map(int, input().split()))+[1]:
if (i < 4):
ans += cnt // 3
cnt = 0
else:
cnt += 1
print(ans)
``` | 3 | |
803 | C | Maximal GCD | PROGRAMMING | 1,900 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010). | If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them. | [
"6 3\n",
"8 2\n",
"5 3\n"
] | [
"1 2 3\n",
"2 6\n",
"-1\n"
] | none | 0 | [
{
"input": "6 3",
"output": "1 2 3"
},
{
"input": "8 2",
"output": "2 6"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "2 1",
"output": "2"
},
{
"input": "2 10000000... | 1,640,317,876 | 2,147,483,647 | PyPy 3 | OK | TESTS | 138 | 233 | 9,216,000 | n, k = map(int, input().split())
d = 1
md = -1
while (d * d <= n):
if (n % d == 0):
s = d * (k - 1) * k // 2
if (n - s > (k - 1) * d):
md = max(md, d)
d = n // d
s = d * (k - 1) * k // 2
if (n - s > (k - 1) * d):
md = max(md, d)
d =... | Title: Maximal GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal.
Grea... | ```python
n, k = map(int, input().split())
d = 1
md = -1
while (d * d <= n):
if (n % d == 0):
s = d * (k - 1) * k // 2
if (n - s > (k - 1) * d):
md = max(md, d)
d = n // d
s = d * (k - 1) * k // 2
if (n - s > (k - 1) * d):
md = max(md, d)
... | 3 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,689,022,523 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | dollars = int(input())
bills = 0
for i in range(0,1000000000):
if dollars >= 100 :
dollars -= 100
bills += 1
elif dollars >= 20 :
dollars -= 20
bills += 1
elif dollars >= 10 :
dollars -= 10
bills += 1
elif dollars >= 5 :
dol... | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
dollars = int(input())
bills = 0
for i in range(0,1000000000):
if dollars >= 100 :
dollars -= 100
bills += 1
elif dollars >= 20 :
dollars -= 20
bills += 1
elif dollars >= 10 :
dollars -= 10
bills += 1
elif dollars >= 5 :
... | 0 | |
612 | C | Replace To Make Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"data structures",
"expression parsing",
"math"
] | null | null | You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.
The following d... | The only line contains a non empty string *s*, consisting of only opening and closing brackets of four kinds. The length of *s* does not exceed 106. | If it's impossible to get RBS from *s* print Impossible.
Otherwise print the least number of replaces needed to get RBS from *s*. | [
"[<}){}\n",
"{()}[]\n",
"]]\n"
] | [
"2",
"0",
"Impossible"
] | none | 0 | [
{
"input": "[<}){}",
"output": "2"
},
{
"input": "{()}[]",
"output": "0"
},
{
"input": "]]",
"output": "Impossible"
},
{
"input": ">",
"output": "Impossible"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{}",
"output": "0"
},
{
"input": ... | 1,554,289,478 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 109 | 0 | s = input()
d = ['<', '{', '[', '(']
d2 = ['>', '}', ']', ')']
a = []
k = 0
for i in s:
if i in d:
a.append(d.index(i))
else:
if len(a) == 0:
k = 'Impossible'
break
else:
if a[-1] == d2.index(i):
a.pop()
elif ... | Title: Replace To Make Regular Bracket Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s* consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another... | ```python
s = input()
d = ['<', '{', '[', '(']
d2 = ['>', '}', ']', ')']
a = []
k = 0
for i in s:
if i in d:
a.append(d.index(i))
else:
if len(a) == 0:
k = 'Impossible'
break
else:
if a[-1] == d2.index(i):
a.pop()
... | 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 int... | 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",
... | 1,559,917,289 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 498 | 0 | from math import floor,ceil
n,m = list(map(int,input().split()))
answer = 0
for _ in range(m):
x,d = list(map(int,input().split()))
answer += n * x
answer += (d*n*(n-1))//2
if d < 0:
answer += d * (n + ((n+1)//2) * (((n+1)//2)-n-1) )
print (answer/n) | 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 c... | ```python
from math import floor,ceil
n,m = list(map(int,input().split()))
answer = 0
for _ in range(m):
x,d = list(map(int,input().split()))
answer += n * x
answer += (d*n*(n-1))//2
if d < 0:
answer += d * (n + ((n+1)//2) * (((n+1)//2)-n-1) )
print (answer/n)
``` | 3 | |
108 | B | Datatypes | PROGRAMMING | 1,400 | [
"math",
"sortings"
] | B. Datatypes | 2 | 256 | Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of *n* integers (1<=≤<=*a**i*<=≤<=109) — sizes of datatypes in bits. Some datatypes may have equal sizes. | Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise. | [
"3\n64 16 32\n",
"4\n4 2 1 3\n"
] | [
"NO\n",
"YES\n"
] | In the second example, *x* = 7 (111<sub class="lower-index">2</sub>) fits in 3 bits, but *x*<sup class="upper-index">2</sup> = 49 (110001<sub class="lower-index">2</sub>) does not fit in 4 bits. | 1,000 | [
{
"input": "3\n64 16 32",
"output": "NO"
},
{
"input": "4\n4 2 1 3",
"output": "YES"
},
{
"input": "5\n1 5 3 3 2",
"output": "YES"
},
{
"input": "52\n474 24 24 954 9 234 474 114 24 114 234 24 114 114 234 9 9 24 9 54 234 54 9 954 474 9 54 54 54 234 9 114 24 54 114 954 954 474 ... | 1,678,957,960 | 2,147,483,647 | PyPy 3 | OK | TESTS | 65 | 374 | 12,697,600 |
n = int(input())
A = sorted(list(set(map(int, input().split()))))
good = True
for i in range(1, len(A)):
if A[i - 1] * 2 > A[i]:
good = False
if not good:
print("YES")
else:
print("NO")
| Title: Datatypes
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to wr... | ```python
n = int(input())
A = sorted(list(set(map(int, input().split()))))
good = True
for i in range(1, len(A)):
if A[i - 1] * 2 > A[i]:
good = False
if not good:
print("YES")
else:
print("NO")
``` | 3.882849 |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≤<=|*name*|<=≤<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,642,524,104 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 28 | 171 | 5,632,000 | n, m = map(int, input().split())
server = []
for i in range(n):
ls1 = input().split()
server.append(ls1)
my_dict = {}
for i in server:
my_dict[i[1]] = i[0]
command = []
for j in range(m):
ls1 = input().split()
command.append(ls1)
for i in range(len(command)):
k = command[i][1]... | Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
n, m = map(int, input().split())
server = []
for i in range(n):
ls1 = input().split()
server.append(ls1)
my_dict = {}
for i in server:
my_dict[i[1]] = i[0]
command = []
for j in range(m):
ls1 = input().split()
command.append(ls1)
for i in range(len(command)):
k = com... | 3 | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,645,977,750 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 23 | 124 | 14,848,000 | # n,m = map(lambda x: int(x), input().split())
# n = int(input())
n = int(input())
a = list(map(lambda x: int(x), input().split()))
m,mi = min(a),n-1
for i in range(n-1):
if a[i]>a[i+1]:
mi = i
if a[i+1]!=m:
print(-1)
break
else:
if mi != n-1 and a[0] < ... | Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
# n,m = map(lambda x: int(x), input().split())
# n = int(input())
n = int(input())
a = list(map(lambda x: int(x), input().split()))
m,mi = min(a),n-1
for i in range(n-1):
if a[i]>a[i+1]:
mi = i
if a[i+1]!=m:
print(-1)
break
else:
if mi != n-1 a... | 0 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,681,295,259 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 |
def sol():
a,b,c,d=map(int,input().split(" "))
if (a!=c and b!=d and abs(a-c)!=abs(b-d)):
print(-1)
elif a==c:
print(a+abs(b-d),b,c+abs(b-d))
elif b==d:
print(a,b+abs(a-b),c,d+abs(b-d))
else:
print(a,d,c,b)
sol()
| Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
def sol():
a,b,c,d=map(int,input().split(" "))
if (a!=c and b!=d and abs(a-c)!=abs(b-d)):
print(-1)
elif a==c:
print(a+abs(b-d),b,c+abs(b-d))
elif b==d:
print(a,b+abs(a-b),c,d+abs(b-d))
else:
print(a,d,c,b)
sol()
``` | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,617,869,312 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 216 | 0 | g1 = list(input())
g2 = list(input())
l1 = []
l2 = []
for i in range(0, len(g1)):
if g1[i] != g2[i]:
l1.append(g1[i])
l2.append(g2[i])
if l1.sort() == l2.sort() and len(l1) > 1:
print('YES')
elif g1 == g2:
print('YES')
else:
print('NO')
| Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
g1 = list(input())
g2 = list(input())
l1 = []
l2 = []
for i in range(0, len(g1)):
if g1[i] != g2[i]:
l1.append(g1[i])
l2.append(g2[i])
if l1.sort() == l2.sort() and len(l1) > 1:
print('YES')
elif g1 == g2:
print('YES')
else:
print('NO')
``` | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,695,904,908 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 31 | 0 | n=int(input())
sentence=[]
x=1
while x<=n:
if x%2==1:
sentence.append('that I hate')
else:
sentence.append('that I love')
x+=1
sentence=' '.join(sentence).split()
del sentence[0]
sentence.append('it')
print(' '.join(sentence)) | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n=int(input())
sentence=[]
x=1
while x<=n:
if x%2==1:
sentence.append('that I hate')
else:
sentence.append('that I love')
x+=1
sentence=' '.join(sentence).split()
del sentence[0]
sentence.append('it')
print(' '.join(sentence))
``` | 3 | |
19 | A | World Football Cup | PROGRAMMING | 1,400 | [
"implementation"
] | A. World Football Cup | 2 | 64 | Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations:
- the final tournament features *n* teams (*n* is always even) - the first *n*<=/<=2 t... | The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=50) — amount of the teams, taking part in the final tournament of World Cup. The following *n* lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following *... | Output *n*<=/<=2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity. | [
"4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n",
"2\na\nA\na-A 2:1\n"
] | [
"A\nD\n",
"a\n"
] | none | 0 | [
{
"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3",
"output": "A\nD"
},
{
"input": "2\na\nA\na-A 2:1",
"output": "a"
},
{
"input": "2\nEULEUbCmfrmqxtzvg\nuHGRmKUhDcxcfqyruwzen\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92",
"output": "EULEUbCmfrmqxtzvg"... | 1,587,901,882 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 404 | 3,379,200 | n = int(input())
teams = dict()
for i in range(n):
teams[input()] = [0, 0, 0]
for i in range(n * (n - 1) // 2):
team, score = input().split()
t1, t2 = team.split('-')
s1, s2 = [int(x) for x in score.split(':')]
a = teams[t1]
b = teams[t2]
a[2] += s1
b[2] += s2
a[1] += s1 ... | Title: World Football Cup
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup reg... | ```python
n = int(input())
teams = dict()
for i in range(n):
teams[input()] = [0, 0, 0]
for i in range(n * (n - 1) // 2):
team, score = input().split()
t1, t2 = team.split('-')
s1, s2 = [int(x) for x in score.split(':')]
a = teams[t1]
b = teams[t2]
a[2] += s1
b[2] += s2
a... | 3.873823 |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,699,420,232 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | k,n,w=map(int,input().split())
c=0
for i in range(w):
s=i*k
c+=s
if c>n:
print(n-c)
| Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,n,w=map(int,input().split())
c=0
for i in range(w):
s=i*k
c+=s
if c>n:
print(n-c)
``` | 0 | |
36 | A | Extra-terrestrial Intelligence | PROGRAMMING | 1,300 | [
"implementation"
] | A. Extra-terrestrial Intelligence | 2 | 64 | Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* days Vasya wrote a 1 in his notebook if he had received a signal that day and a 0 if he hadn’t. Vasya thinks that... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of days during which Vasya checked if there were any signals. The second line contains *n* characters 1 or 0 — the record Vasya kept each of those *n* days. It’s guaranteed that the given record sequence contains at least three 1s. | If Vasya has found extra-terrestrial intelligence, output YES, otherwise output NO. | [
"8\n00111000\n",
"7\n1001011\n",
"7\n1010100\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "8\n00111000",
"output": "YES"
},
{
"input": "7\n1001011",
"output": "NO"
},
{
"input": "7\n1010100",
"output": "YES"
},
{
"input": "5\n10101",
"output": "YES"
},
{
"input": "3\n111",
"output": "YES"
},
{
"input": "10\n0011111011",
"outp... | 1,602,681,177 | 477 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 307,200 | import sys
from array import array # noqa: F401
from itertools import groupby
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 ... | Title: Extra-terrestrial Intelligence
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Recently Vasya got interested in finding extra-terrestrial intelligence. He made a simple extra-terrestrial signals’ receiver and was keeping a record of the signals for *n* days in a row. Each of those *n* da... | ```python
import sys
from array import array # noqa: F401
from itertools import groupby
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('ut... | -1 |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,694,338,346 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 92 | 0 | s = input()
ans = [''] * len(s) * 2
idx = 0
for i in s:
c = i.lower()
if 'a' <= c <= 'z' and c not in ('a', 'o', 'y', 'e', 'u', 'i'):
ans[idx] = '.'
ans[idx+1] = c
idx += 2
print("".join(ans))
| Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
s = input()
ans = [''] * len(s) * 2
idx = 0
for i in s:
c = i.lower()
if 'a' <= c <= 'z' and c not in ('a', 'o', 'y', 'e', 'u', 'i'):
ans[idx] = '.'
ans[idx+1] = c
idx += 2
print("".join(ans))
``` | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,692,353,983 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | s1,s2,s3,s4=map(int,input().split())
lst=[]
lst.append(s1)
lst.append(s2)
lst.append(s3)
lst.append(s4)
s=set(lst)
print(4-len(s)) | Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
s1,s2,s3,s4=map(int,input().split())
lst=[]
lst.append(s1)
lst.append(s2)
lst.append(s3)
lst.append(s4)
s=set(lst)
print(4-len(s))
``` | 3 | |
987 | C | Three displays | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation"
] | null | null | It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ... | The first line contains a single integer $n$ ($3 \le n \le 3\,000$) — the number of displays.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$) — the font sizes on the displays in the order they stand along the road.
The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \... | If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integer — the minimum total rent cost of three displays with indices $i < j < k$ such that $s_i < s_j < s_k$. | [
"5\n2 4 5 4 10\n40 30 20 10 40\n",
"3\n100 101 100\n2 4 5\n",
"10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n"
] | [
"90\n",
"-1\n",
"33\n"
] | In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 < s_4 < s_5$ ($2 < 4 < 10$), and the rent cost is $40 + 10 + 40 = 90$.
In the second example you can't select a valid triple of indices, so the answer is -1. | 1,250 | [
{
"input": "5\n2 4 5 4 10\n40 30 20 10 40",
"output": "90"
},
{
"input": "3\n100 101 100\n2 4 5",
"output": "-1"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13",
"output": "33"
},
{
"input": "3\n1 2 3\n100000000 100000000 100000000",
"output": "300... | 1,671,633,249 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 140 | 3,993,600 | n = int(input())
s = list(map(int, input().split()))
c = list(map(int, input().split()))
# mini = 1e10
# d = dict()
mini = 10**10
for j in range(1, n-1):
i = j - 1
k = j + 1
min1 = 10**10
min2 = 10**10
while (i >= 0):
if s[i] < s[j]:
min1 = min(min1, c[i])
... | Title: Three displays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, ... | ```python
n = int(input())
s = list(map(int, input().split()))
c = list(map(int, input().split()))
# mini = 1e10
# d = dict()
mini = 10**10
for j in range(1, n-1):
i = j - 1
k = j + 1
min1 = 10**10
min2 = 10**10
while (i >= 0):
if s[i] < s[j]:
min1 = min(min1, c[i... | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=≤<=*x*<=≤<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,685,110,908 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | x=int(input())
x=bin(x)
bacteria=0
for i in x:
if i=='1':
bacteria+=1
print(bacteria) | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
x=int(input())
x=bin(x)
bacteria=0
for i in x:
if i=='1':
bacteria+=1
print(bacteria)
``` | 3 | |
118 | A | String Task | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels, - inserts a character "." before each consonant, - replaces ... | The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive. | Print the resulting string. It is guaranteed that this string is not empty. | [
"tour\n",
"Codeforces\n",
"aBAcAba\n"
] | [
".t.r\n",
".c.d.f.r.c.s\n",
".b.c.b\n"
] | none | 500 | [
{
"input": "tour",
"output": ".t.r"
},
{
"input": "Codeforces",
"output": ".c.d.f.r.c.s"
},
{
"input": "aBAcAba",
"output": ".b.c.b"
},
{
"input": "obn",
"output": ".b.n"
},
{
"input": "wpwl",
"output": ".w.p.w.l"
},
{
"input": "ggdvq",
"output": "... | 1,695,708,253 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 92 | 0 | #118A:String task
def vowel(x):
if x=="a" or x=="i" or x=="o" or x=="e" or x=="u":
return True
else:
return False
a=input()
a=a.lower()
for i in range(len(a)):
if vowel(a[i])==True:
continue
else:
print(".",end="")
print(a[i],end="") | Title: String Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters... | ```python
#118A:String task
def vowel(x):
if x=="a" or x=="i" or x=="o" or x=="e" or x=="u":
return True
else:
return False
a=input()
a=a.lower()
for i in range(len(a)):
if vowel(a[i])==True:
continue
else:
print(".",end="")
print(a[i],end="")
``` | 0 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,687,785,277 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | line = input()
distinct_letters = set()
for char in line:
if char.isalpha():
distinct_letters.add(char)
print(len(distinct_letters))
| Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
line = input()
distinct_letters = set()
for char in line:
if char.isalpha():
distinct_letters.add(char)
print(len(distinct_letters))
``` | 3 | |
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... | 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 ... | 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\nReal... | 1,586,444,548 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 109 | 0 | def Thanos():
powers = {"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"}
n = int(input())
for i in range(n):
powers.pop(input())
print(len(powers))
for key, val in powers.items():
print(val)
Thanos() | 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 So... | ```python
def Thanos():
powers = {"purple":"Power", "green":"Time", "blue":"Space", "orange":"Soul", "red":"Reality", "yellow":"Mind"}
n = int(input())
for i in range(n):
powers.pop(input())
print(len(powers))
for key, val in powers.items():
print(val)
Thanos()
``` | 3 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,648,321,541 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 218 | 5,324,800 | n=int(input())
list1=[int(x)for x in input().split()]
if sum(list1)%n:
print(n-1)
else:
print(n)
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n=int(input())
list1=[int(x)for x in input().split()]
if sum(list1)%n:
print(n-1)
else:
print(n)
``` | 3 | |
81 | A | Plug-in | PROGRAMMING | 1,400 | [
"implementation"
] | A. Plug-in | 1 | 256 | Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy... | The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. | Print the given string after it is processed. It is guaranteed that the result will contain at least one character. | [
"hhoowaaaareyyoouu\n",
"reallazy\n",
"abacabaabacabaa\n"
] | [
"wre",
"rezy",
"a"
] | none | 500 | [
{
"input": "hhoowaaaareyyoouu",
"output": "wre"
},
{
"input": "reallazy",
"output": "rezy"
},
{
"input": "abacabaabacabaa",
"output": "a"
},
{
"input": "xraccabccbry",
"output": "xy"
},
{
"input": "a",
"output": "a"
},
{
"input": "b",
"output": "b"... | 1,684,764,108 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 184 | 4,915,200 | import sys
INF = 2e18 + 99
def debug(n):
print(n)
def main():
s = input()
st = []
for i in range(len(s) - 1, -1, -1):
if st and st[-1] == s[i]:
st.pop()
else:
st.append(s[i])
ans = ""
while st:
ans += st[-1]
st.pop(... | Title: Plug-in
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed... | ```python
import sys
INF = 2e18 + 99
def debug(n):
print(n)
def main():
s = input()
st = []
for i in range(len(s) - 1, -1, -1):
if st and st[-1] == s[i]:
st.pop()
else:
st.append(s[i])
ans = ""
while st:
ans += st[-1]
... | 3.898845 |
574 | A | Bear and Elections | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=100) - number of candidates.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) - number of votes for each candidate. Limak is candidate number 1.
Note that after bribing number of votes for some candidate ... | Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. | [
"5\n5 1 11 2 8\n",
"4\n1 8 8 8\n",
"2\n7 6\n"
] | [
"4\n",
"6\n",
"0\n"
] | In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ... | 500 | [
{
"input": "5\n5 1 11 2 8",
"output": "4"
},
{
"input": "4\n1 8 8 8",
"output": "6"
},
{
"input": "2\n7 6",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "10\n100 200 57 99 1 1000 200 200 200 500",
"output": "451"
},
{
"input": "16\... | 1,441,307,673 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 186 | 4,505,600 | from queue import PriorityQueue as PQ
n = int(input())
r, *a = [int(x) for x in input().split()]
pq = PQ()
for x in a:
pq.put((-x, x))
ans = 0
while True:
p, x = pq.get()
if x < r:
break
r += 1
x -= 1
pq.put((-x, x))
ans += 1
print(ans)
| Title: Bear and Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland.
There are *n* candidates, including Limak. We know how many citizens are going to vote for e... | ```python
from queue import PriorityQueue as PQ
n = int(input())
r, *a = [int(x) for x in input().split()]
pq = PQ()
for x in a:
pq.put((-x, x))
ans = 0
while True:
p, x = pq.get()
if x < r:
break
r += 1
x -= 1
pq.put((-x, x))
ans += 1
print(ans)
``` | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,663,706,152 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | a, b, c = map(int,input().split())
x, y, z = map(int,input().split())
q, w, e = map(int,input().split())
line1 = []
line2 = []
line3 = []
if int(a+b+x+y)%2 == 1:
line1.append("0")
if int(a+b+x+y)%2==0:
line1.append("1")
if int(b+a+c+y+x+z)%2 == 0:
line1.append("1")
if int(b+a+c+y+x+z)%2==1:
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
a, b, c = map(int,input().split())
x, y, z = map(int,input().split())
q, w, e = map(int,input().split())
line1 = []
line2 = []
line3 = []
if int(a+b+x+y)%2 == 1:
line1.append("0")
if int(a+b+x+y)%2==0:
line1.append("1")
if int(b+a+c+y+x+z)%2 == 0:
line1.append("1")
if int(b+a+c+y+x+z)%... | 0 | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,590,145,988 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 108 | 0 | S = input()
s = set(S)
for i in range(len(S)):
tmp = s[i:]+s[:i]
s.add(tmp)
print(len(s)) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
S = input()
s = set(S)
for i in range(len(S)):
tmp = s[i:]+s[:i]
s.add(tmp)
print(len(s))
``` | -1 | |
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... | 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": "... | 1,605,883,884 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 140 | 0 | a, b = input(), input()
print(*map(lambda x, y: '1' if x != y else '0', a, b), sep='')
| 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 10... | ```python
a, b = input(), input()
print(*map(lambda x, y: '1' if x != y else '0', a, b), sep='')
``` | 3.965 |
830 | B | Cards Sorting | PROGRAMMING | 1,600 | [
"data structures",
"implementation",
"sortings"
] | null | null | Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decided to sort the cards. To do this, he repeatedly takes the top card from the deck, and if the number... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cards in the deck.
The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000), where *a**i* is the number written on the *i*-th from top card in the deck. | Print the total number of times Vasily takes the top card from the deck. | [
"4\n6 3 1 2\n",
"1\n1000\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"7\n",
"1\n",
"7\n"
] | In the first example Vasily at first looks at the card with number 6 on it, puts it under the deck, then on the card with number 3, puts it under the deck, and then on the card with number 1. He places away the card with 1, because the number written on it is the minimum among the remaining cards. After that the cards ... | 1,000 | [
{
"input": "4\n6 3 1 2",
"output": "7"
},
{
"input": "1\n1000",
"output": "1"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "7"
},
{
"input": "64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 289 384 625 695 416 944 162 939 164 1047 359 114 499 99 713 300 268 316 256... | 1,532,425,060 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 6,553,600 | num_card=eval(input())
written_card=list(map(int,input().split()))
queue_card=written_card
written_card=sorted(written_card)
count=0
while len(queue_card)!=0:
if queue_card[0]!=written_card[0]:
top=queue_card[0]
queue_card.append(top)
queue_card.pop(0)
count=count+1
el... | Title: Cards Sorting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a deck of cards consisting of *n* cards. There is an integer on each of the cards, this integer is between 1 and 100<=000, inclusive. It is possible that some cards have the same integers on them.
Vasily decid... | ```python
num_card=eval(input())
written_card=list(map(int,input().split()))
queue_card=written_card
written_card=sorted(written_card)
count=0
while len(queue_card)!=0:
if queue_card[0]!=written_card[0]:
top=queue_card[0]
queue_card.append(top)
queue_card.pop(0)
count=count... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,696,275,322 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | n, m, a = map(int, input().split())
if(n<a & m<a):
print("1")
elif(n>=a & m<a):
y=int((n//a)+1)
print(y)
elif(m>=a & n<a):
z=int((m//a)+1)
print(z)
else:
if (n % a != 0) and (m % a != 0):
n = ((n // a) + 1) * a
m = ((m // a) + 1) * a
elif (n % a != 0) and (m % a == 0):
n = ((n /... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n, m, a = map(int, input().split())
if(n<a & m<a):
print("1")
elif(n>=a & m<a):
y=int((n//a)+1)
print(y)
elif(m>=a & n<a):
z=int((m//a)+1)
print(z)
else:
if (n % a != 0) and (m % a != 0):
n = ((n // a) + 1) * a
m = ((m // a) + 1) * a
elif (n % a != 0) and (m % a == 0):
... | 0 |
854 | A | Fraction | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"math"
] | null | null | Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co... | In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction. | Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum. | [
"3\n",
"4\n",
"12\n"
] | [
"1 2\n",
"1 3\n",
"5 7\n"
] | none | 500 | [
{
"input": "3",
"output": "1 2"
},
{
"input": "4",
"output": "1 3"
},
{
"input": "12",
"output": "5 7"
},
{
"input": "34",
"output": "15 19"
},
{
"input": "13",
"output": "6 7"
},
{
"input": "11",
"output": "5 6"
},
{
"input": "24",
"ou... | 1,589,312,485 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 6,963,200 | li = [1]*1001
li[0] = 0
for a in range(2,int(1001**0.5) +1):
if li[a] == 1:
for b in range(a,1001-a,a):
li[a + b] = 0
x = int(input())
b = x//2 -1 if x%2 == 0 else x//2
for a in range(b,0, -1):
if li[a] != 0 and li[x-a] != 0 and a != x-a:
print(a, x-a)
break
| Title: Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=<<=*b*) and that the fraction is cal... | ```python
li = [1]*1001
li[0] = 0
for a in range(2,int(1001**0.5) +1):
if li[a] == 1:
for b in range(a,1001-a,a):
li[a + b] = 0
x = int(input())
b = x//2 -1 if x%2 == 0 else x//2
for a in range(b,0, -1):
if li[a] != 0 and li[x-a] != 0 and a != x-a:
print(a, x-a)
... | 0 | |
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... | 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 requirem... | 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 wi... | 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 97... | 1,417,065,738 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | n, m=map(int, input().split())
listn=list(map(int, input().split()))
listj=list(map(int, input().split()))
cnt=0
for i in listn:
if not i in listj:
cnt+=1
print(cnt) | 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*.
T... | ```python
n, m=map(int, input().split())
listn=list(map(int, input().split()))
listj=list(map(int, input().split()))
cnt=0
for i in listn:
if not i in listj:
cnt+=1
print(cnt)
``` | 0 | |
633 | C | Spy Syndrome 2 | PROGRAMMING | 1,900 | [
"data structures",
"dp",
"hashing",
"implementation",
"sortings",
"string suffix structures",
"strings"
] | null | null | After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique.
For a given sentence, the ciphe... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10<=000) — the length of the ciphered text. The second line consists of *n* lowercase English letters — the ciphered text *t*.
The third line contains a single integer *m* (1<=≤<=*m*<=≤<=100<=000) — the number of words which will be considered wh... | Print one line — the original sentence. It is guaranteed that at least one solution exists. If there are multiple solutions, you may output any of those. | [
"30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote\n",
"12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello\n"
] | [
"Kira is childish and he hates losing \n",
"HI there HeLLo \n"
] | In sample case 2 there may be multiple accepted outputs, "HI there HeLLo" and "HI there hello" you may output any of them. | 1,500 | [
{
"input": "30\nariksihsidlihcdnaehsetahgnisol\n10\nKira\nhates\nis\nhe\nlosing\ndeath\nchildish\nL\nand\nNote",
"output": "Kira is childish and he hates losing "
},
{
"input": "12\niherehtolleh\n5\nHI\nHo\nthere\nHeLLo\nhello",
"output": "HI there HeLLo "
},
{
"input": "71\nbaaaaaaaaaaa... | 1,653,739,252 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 93 | 13,516,800 | import sys
p=sys.stdin.read().split()
n,t=int(p[0]),p[1][::-1]
d={q.lower(): q for q in p[3:]}
k,s=0,[]
l=sorted(set(map(len,d)))
while n:
k-=1
if len(l)+k<0: k,n=s.pop()
elif n>=l[k] and t[n-l[k]:n] in d:
s.append((k,n))
n-=l[k]
k=0
print(*[d[t[n-l[i]:n]] for i,n in s]) | Title: Spy Syndrome 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observati... | ```python
import sys
p=sys.stdin.read().split()
n,t=int(p[0]),p[1][::-1]
d={q.lower(): q for q in p[3:]}
k,s=0,[]
l=sorted(set(map(len,d)))
while n:
k-=1
if len(l)+k<0: k,n=s.pop()
elif n>=l[k] and t[n-l[k]:n] in d:
s.append((k,n))
n-=l[k]
k=0
print(*[d[t[n-l[i]:n]] for ... | 3 | |
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 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",
"... | 1,697,381,090 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = input()
counter = 0
start = 0
for i in range(len(word)):
next = letters.index(word[i])
forward = abs(start - next )
backword = 26 - forward
counter+= min(... | 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 devis... | ```python
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
word = input()
counter = 0
start = 0
for i in range(len(word)):
next = letters.index(word[i])
forward = abs(start - next )
backword = 26 - forward
coun... | 3 | |
931 | A | Friends Meeting | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation",
"math"
] | null | null | Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend.
The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend.
It is guaranteed that *a*<=≠<=*b*. | Print the minimum possible total tiredness if the friends meet in the same point. | [
"3\n4\n",
"101\n99\n",
"5\n10\n"
] | [
"1\n",
"2\n",
"9\n"
] | In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.
In the second example the first friend should move by one to the left, an... | 500 | [
{
"input": "3\n4",
"output": "1"
},
{
"input": "101\n99",
"output": "2"
},
{
"input": "5\n10",
"output": "9"
},
{
"input": "1\n2",
"output": "1"
},
{
"input": "1\n1000",
"output": "250000"
},
{
"input": "999\n1000",
"output": "1"
},
{
"inpu... | 1,646,875,835 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | a=int(input());b=int(input());A=abs((a+b>>1-a)*(a+b>>1-a+1))>>1;B=abs((a+b>>1-b)*(a+b>>1-b+1))>>1;print(A+B) | Title: Friends Meeting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*.
Each of the friends can move by one along the line in... | ```python
a=int(input());b=int(input());A=abs((a+b>>1-a)*(a+b>>1-a+1))>>1;B=abs((a+b>>1-b)*(a+b>>1-b+1))>>1;print(A+B)
``` | -1 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,677,799,055 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 186 | 5,120,000 | #code
n=int(input())
line=[int(i) for i in input().split()]
a=0
b=0
c=0
comp=1
for i in line:
if i==25:
a+=1
elif i==50:
b+=1
a-=1
else:
c+=1
if b>0 and a>0:
b-=1
a-=1
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
#code
n=int(input())
line=[int(i) for i in input().split()]
a=0
b=0
c=0
comp=1
for i in line:
if i==25:
a+=1
elif i==50:
b+=1
a-=1
else:
c+=1
if b>0 and a>0:
b-=1
a-=1
... | 0 | |
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ... | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
... | 1,437,992,680 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a=input()
b="CODEFORCES"
for i in range(len(a)-len(b)+2):
c=a
s=a[i:len(a)-len(b)+i]
s=c.replace(s,'' )
if s==b:
print("YES")
break
else:
print("NO") | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ... | ```python
a=input()
b="CODEFORCES"
for i in range(len(a)-len(b)+2):
c=a
s=a[i:len(a)-len(b)+i]
s=c.replace(s,'' )
if s==b:
print("YES")
break
else:
print("NO")
``` | 0 | |
846 | B | Math Show | PROGRAMMING | 1,800 | [
"brute force",
"greedy"
] | null | null | Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
... | The first line contains three integer numbers *n*, *k* and *M* (1<=≤<=*n*<=≤<=45, 1<=≤<=*k*<=≤<=45, 0<=≤<=*M*<=≤<=2·109).
The second line contains *k* integer numbers, values *t**j* (1<=≤<=*t**j*<=≤<=1000000), where *t**j* is the time in minutes required to solve *j*-th subtask of any task. | Print the maximum amount of points Polycarp can earn in *M* minutes. | [
"3 4 11\n1 2 3 4\n",
"5 5 10\n1 2 4 8 16\n"
] | [
"6\n",
"7\n"
] | In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of tw... | 0 | [
{
"input": "3 4 11\n1 2 3 4",
"output": "6"
},
{
"input": "5 5 10\n1 2 4 8 16",
"output": "7"
},
{
"input": "1 1 0\n2",
"output": "0"
},
{
"input": "1 1 1\n1",
"output": "2"
},
{
"input": "2 1 0\n2",
"output": "0"
},
{
"input": "2 2 2\n2 3",
"outpu... | 1,504,625,049 | 1,149 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 109 | 0 | n, k, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = sum(l)
ans = 0
for i in range(n):
mi = m - s * i
if mi < 0:
break
cnt = (k + 1) * i
for j in range(k):
x = min(mi // l[j], n - i)
cnt += x
mi -= l[j] * x
ans = max(ans, cnt)
print(an... | Title: Math Show
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a math show. He is given *n* tasks, each consists of *k* subtasks, numbered 1 through *k*. It takes him *t**j* minutes to solve the *j*-th subtask of any task. Thus, time required to solve a subtask dep... | ```python
n, k, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = sum(l)
ans = 0
for i in range(n):
mi = m - s * i
if mi < 0:
break
cnt = (k + 1) * i
for j in range(k):
x = min(mi // l[j], n - i)
cnt += x
mi -= l[j] * x
ans = max(ans, cnt... | 0 | |
12 | B | Correct Solution? | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | B. Correct Solution? | 2 | 256 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe... | The first line contains one integer *n* (0<=≤<=*n*<=≤<=109) without leading zeroes. The second lines contains one integer *m* (0<=≤<=*m*<=≤<=109) — Bob's answer, possibly with leading zeroes. | Print OK if Bob's answer is correct and WRONG_ANSWER otherwise. | [
"3310\n1033\n",
"4\n5\n"
] | [
"OK\n",
"WRONG_ANSWER\n"
] | none | 0 | [
{
"input": "3310\n1033",
"output": "OK"
},
{
"input": "4\n5",
"output": "WRONG_ANSWER"
},
{
"input": "40\n04",
"output": "WRONG_ANSWER"
},
{
"input": "12\n12",
"output": "OK"
},
{
"input": "432\n234",
"output": "OK"
},
{
"input": "17109\n01179",
"o... | 1,531,245,432 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n=list(input())
p=input()
n.sort()
i=0
while i<len(n):
if n[i]=='0':
i+=1
else:
break
x=''
x+=str(n[i])
for k in range(i):
x+=n[k]
for k in range(i+1,len(n)):
x+=n[k]
if x==p:
print('YES')
else:
print('NO')
| Title: Correct Solution?
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said:
—Shuf... | ```python
n=list(input())
p=input()
n.sort()
i=0
while i<len(n):
if n[i]=='0':
i+=1
else:
break
x=''
x+=str(n[i])
for k in range(i):
x+=n[k]
for k in range(i+1,len(n)):
x+=n[k]
if x==p:
print('YES')
else:
print('NO')
``` | 0 |
296 | A | Yaroslav and Permutations | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.
Help Yaroslav. | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. | In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. | [
"1\n1\n",
"3\n1 1 2\n",
"4\n7 7 7 7\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the initial array fits well.
In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.
In the third sample Yarosav can't get the array he needs. | 500 | [
{
"input": "1\n1",
"output": "YES"
},
{
"input": "3\n1 1 2",
"output": "YES"
},
{
"input": "4\n7 7 7 7",
"output": "NO"
},
{
"input": "4\n479 170 465 146",
"output": "YES"
},
{
"input": "5\n996 437 605 996 293",
"output": "YES"
},
{
"input": "6\n727 53... | 1,684,732,179 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 186 | 0 | #from dust i have come, dust i will be
n=int(input())
a=list(map(int,input().split()))
dict={}
for i in range(n):
try:
x=dict[a[i]]
dict[a[i]]+=1
except:
dict[a[i]]=1
if dict[a[i]]>(n+1)//2:
print("NO")
exit(0)
print("YES")
| Title: Yaroslav and Permutations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would... | ```python
#from dust i have come, dust i will be
n=int(input())
a=list(map(int,input().split()))
dict={}
for i in range(n):
try:
x=dict[a[i]]
dict[a[i]]+=1
except:
dict[a[i]]=1
if dict[a[i]]>(n+1)//2:
print("NO")
exit(0)
print("YES")
``` | 3 | |
614 | A | Link/Cut Tree | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agre... | The first line of the input contains three space-separated integers *l*, *r* and *k* (1<=≤<=*l*<=≤<=*r*<=≤<=1018, 2<=≤<=*k*<=≤<=109). | Print all powers of number *k*, that lie within range from *l* to *r* in the increasing order. If there are no such numbers, print "-1" (without the quotes). | [
"1 10 2\n",
"2 4 5\n"
] | [
"1 2 4 8 ",
"-1"
] | Note to the first sample: numbers 2<sup class="upper-index">0</sup> = 1, 2<sup class="upper-index">1</sup> = 2, 2<sup class="upper-index">2</sup> = 4, 2<sup class="upper-index">3</sup> = 8 lie within the specified range. The number 2<sup class="upper-index">4</sup> = 16 is greater then 10, thus it shouldn't be printed. | 500 | [
{
"input": "1 10 2",
"output": "1 2 4 8 "
},
{
"input": "2 4 5",
"output": "-1"
},
{
"input": "18102 43332383920 28554",
"output": "28554 815330916 "
},
{
"input": "19562 31702689720 17701",
"output": "313325401 "
},
{
"input": "11729 55221128400 313",
"output... | 1,458,403,294 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 62 | 5,120,000 | from math import log
l,r,k = map(int,input().split())
start=int(log(l,k))
ans=[]
if k**start<l:
start+=1
while (k**start)<=r:
ans.append(str(k**start))
start+=1
if len(ans)==0:
ans.append("-1")
print(' '.join(ans)) | Title: Link/Cut Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the *expose* procedure.
Unfortunately, Rostislav is unable to understand ... | ```python
from math import log
l,r,k = map(int,input().split())
start=int(log(l,k))
ans=[]
if k**start<l:
start+=1
while (k**start)<=r:
ans.append(str(k**start))
start+=1
if len(ans)==0:
ans.append("-1")
print(' '.join(ans))
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,586,823,834 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | # -*- coding: utf-8 -*-
"""
Created on Tue Apr 14 03:18:55 2020
@author: DELL
"""
n=input()
p=0
l=''
for i in range(len(n)):
if p:
p=0
continue
if n[i]=='.':
l+='0'
elif n[i]+n[i+1]=='-.':
l+='1'
p=1
elif n[i]+n[i+1]=='--':
l+='2'
... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 14 03:18:55 2020
@author: DELL
"""
n=input()
p=0
l=''
for i in range(len(n)):
if p:
p=0
continue
if n[i]=='.':
l+='0'
elif n[i]+n[i+1]=='-.':
l+='1'
p=1
elif n[i]+n[i+1]=='--':
l+... | 3.9455 |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,586,080,002 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 109 | 307,200 | #!/usr/bin/python3
current = str(input())
sleepingDur = str(input())
H1 = int(current[0:2])
M1 = int(current[3:5])
H2 = int(sleepingDur[0:2])
M2 = int(sleepingDur[3:5])
sleepingHour = H1 - H2
sleepingMinute = M1 - M2
if sleepingMinute < 0:
sleepingMinute += 60; sleepingHour -= 1
if sleepingHour <... | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
#!/usr/bin/python3
current = str(input())
sleepingDur = str(input())
H1 = int(current[0:2])
M1 = int(current[3:5])
H2 = int(sleepingDur[0:2])
M2 = int(sleepingDur[3:5])
sleepingHour = H1 - H2
sleepingMinute = M1 - M2
if sleepingMinute < 0:
sleepingMinute += 60; sleepingHour -= 1
if slee... | 3 | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,657,879,044 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 68 | 62 | 1,433,600 | n,s = [int(x) for x in input().split()]
lbound = 1
ubound = n + 1
num = (ubound + lbound)//2
def getSum(n):
sum = 0
for digit in str(n):
sum += int(digit)
return sum
while num != lbound or num!= ubound:
if num - getSum(num) >= s:
ubound = num
if num-1 - getSum(num-1... | Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
n,s = [int(x) for x in input().split()]
lbound = 1
ubound = n + 1
num = (ubound + lbound)//2
def getSum(n):
sum = 0
for digit in str(n):
sum += int(digit)
return sum
while num != lbound or num!= ubound:
if num - getSum(num) >= s:
ubound = num
if num-1 - ge... | 3 | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,415,209,616 | 4,616 | Python 3 | OK | TESTS | 45 | 77 | 0 | n = int(input())
minx, maxx, miny, maxy = (10**10), -(10**10), (10**10), -(10**10)
for i in range(n):
x, y = list(map(int, input().split()))
if x > maxx:
maxx = x
if y > maxy:
maxy = y
if x < minx:
minx = x
if y < miny:
miny = y
print(max(maxx - minx, maxy... | Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
n = int(input())
minx, maxx, miny, maxy = (10**10), -(10**10), (10**10), -(10**10)
for i in range(n):
x, y = list(map(int, input().split()))
if x > maxx:
maxx = x
if y > maxy:
maxy = y
if x < minx:
minx = x
if y < miny:
miny = y
print(max(maxx - ... | 3 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,652,523,538 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | s = input()
l = len(s)
m = int(input())
a = list(map(int, input().split(' ')))
for i in range(m):
r = s[0:a[i] - 1]
r1 = s[l - a[i]:a[i]-2:-1]
r2 = s[l - a[i] + 1:]
s = r + r1 + r2
print(s)
| Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
s = input()
l = len(s)
m = int(input())
a = list(map(int, input().split(' ')))
for i in range(m):
r = s[0:a[i] - 1]
r1 = s[l - a[i]:a[i]-2:-1]
r2 = s[l - a[i] + 1:]
s = r + r1 + r2
print(s)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.