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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,563,617,762 | 2,147,483,647 | PyPy 3 | OK | TESTS | 13 | 310 | 1,433,600 | s = [[0, 0], [0, 0]]
for _ in range(int(input())):
t, x, y = map(int, input().split())
s[t - 1][0] += x
s[t - 1][1] += y
for i in range(2):
print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]])
| Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
s = [[0, 0], [0, 0]]
for _ in range(int(input())):
t, x, y = map(int, input().split())
s[t - 1][0] += x
s[t - 1][1] += y
for i in range(2):
print(('DEAD', 'LIVE')[s[i][0] >= s[i][1]])
``` | 3 | |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,622,615,343 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 218 | 0 | n,m=map(int,input().split())
a=[int(i) for i in input().split()]
b=[i for i in a]
b.sort(reverse=True)
c=[i for i in a]
c.sort()
cv=0
s=0
for i in range(n):
# if cv==m-1:
# cv=0
# print(b[cv])
# print(b)
s=s+b[cv]
b[cv]-=1
if cv==m-1 and b[m-1]<b[0]:
cv=0
eli... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
b=[i for i in a]
b.sort(reverse=True)
c=[i for i in a]
c.sort()
cv=0
s=0
for i in range(n):
# if cv==m-1:
# cv=0
# print(b[cv])
# print(b)
s=s+b[cv]
b[cv]-=1
if cv==m-1 and b[m-1]<b[0]:
cv=... | 0 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,669,224,565 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 0 | n,m=map(int,input().split())
a=set()
b=set()
for i in range(n):
s=input()
for j in range(m):
if s[j]=="S":
a.add(i),b.add(j)
print((n*m)-(len(a)*len(b))) | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n,m=map(int,input().split())
a=set()
b=set()
for i in range(n):
s=input()
for j in range(m):
if s[j]=="S":
a.add(i),b.add(j)
print((n*m)-(len(a)*len(b)))
``` | 3 | |
88 | A | Chord | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | A. Chord | 2 | 256 | Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note aft... | The only line contains 3 space-separated notes in the above-given notation. | Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously. | [
"C E G\n",
"C# B F\n",
"A B H\n"
] | [
"major\n",
"minor\n",
"strange\n"
] | none | 500 | [
{
"input": "C E G",
"output": "major"
},
{
"input": "C# B F",
"output": "minor"
},
{
"input": "A B H",
"output": "strange"
},
{
"input": "G H E",
"output": "minor"
},
{
"input": "D# B G",
"output": "major"
},
{
"input": "D# B F#",
"output": "minor"... | 1,574,060,659 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 310 | 0 | import sys
arr = sys.stdin.readline().strip().split()
accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
def whatTheAccord(arr):
global accords
positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])]
for i in range(len(accords)):
if ac... | Title: Chord
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya studies music.
He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and b... | ```python
import sys
arr = sys.stdin.readline().strip().split()
accords = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'B', 'H']
def whatTheAccord(arr):
global accords
positions = [accords.index(arr[0]),accords.index(arr[1]),accords.index(arr[2])]
for i in range(len(accords)):
... | 3.9225 |
995 | A | Tesla | PROGRAMMING | 2,100 | [
"constructive algorithms",
"implementation"
] | null | null | Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will arrange them, he realizes that he has a problem.
Allen's future parking lot can be repre... | The first line of the input contains two space-separated integers $n$ and $k$ ($1 \le n \le 50$, $1 \le k \le 2n$), representing the number of columns and the number of cars, respectively.
The next four lines will contain $n$ integers each between $0$ and $k$ inclusive, representing the initial state of the parking lo... | If there is a sequence of moves that brings all of the cars to their parking spaces, with at most $20000$ car moves, then print $m$, the number of moves, on the first line. On the following $m$ lines, print the moves (one move per line) in the format $i$ $r$ $c$, which corresponds to Allen moving car $i$ to the neighbo... | [
"4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3\n",
"1 2\n1\n2\n1\n2\n",
"1 2\n1\n1\n2\n2\n"
] | [
"6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2\n",
"-1\n",
"2\n1 1 1\n2 4 1\n"
] | In the first sample test case, all cars are in front of their spots except car $5$, which is in front of the parking spot adjacent. The example shows the shortest possible sequence of moves, but any sequence of length at most $20000$ will be accepted.
In the second sample test case, there is only one column, and the c... | 500 | [
{
"input": "4 5\n1 2 0 4\n1 2 0 4\n5 0 0 3\n0 5 0 3",
"output": "6\n1 1 1\n2 1 2\n4 1 4\n3 4 4\n5 3 2\n5 4 2"
},
{
"input": "1 2\n1\n2\n1\n2",
"output": "-1"
},
{
"input": "1 2\n1\n1\n2\n2",
"output": "2\n1 1 1\n2 4 1"
},
{
"input": "2 2\n1 0\n0 2\n0 1\n0 2",
"output": "7... | 1,544,712,164 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 124 | 1,126,400 | def f(p, v = -10):
global a
if v == -10:
return a[p[0]][p[1]]
else:
a[p[0]][p[1]] = v
def ins(i, x, y):
global mov, cnt
mov[cnt][0] = i
mov[cnt][1] = x + 1
cnt += 1
mov[cnt][2] = y + 1
def move_in(i):
global A, B, tot
if f(B[i]) == f(A[i]... | Title: Tesla
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen dreams of one day owning a enormous fleet of electric cars, the car of the future! He knows that this will give him a big status boost. As Allen is planning out all of the different types of cars he will own and how he will... | ```python
def f(p, v = -10):
global a
if v == -10:
return a[p[0]][p[1]]
else:
a[p[0]][p[1]] = v
def ins(i, x, y):
global mov, cnt
mov[cnt][0] = i
mov[cnt][1] = x + 1
cnt += 1
mov[cnt][2] = y + 1
def move_in(i):
global A, B, tot
if f(B[i])... | 0 | |
992 | A | Nastya and an Array | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. | Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. | [
"5\n1 1 1 1 1\n",
"3\n2 0 -1\n",
"4\n5 -6 -5 1\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first example you can add - 1 to all non-zero elements in one second and make them equal to zero.
In the second example you can add - 2 on the first second, then the array becomes equal to [0, 0, - 3]. On the second second you can add 3 to the third (the only non-zero) element. | 500 | [
{
"input": "5\n1 1 1 1 1",
"output": "1"
},
{
"input": "3\n2 0 -1",
"output": "2"
},
{
"input": "4\n5 -6 -5 1",
"output": "4"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "2\n21794 -79194",
"output": "2"
},
{
"input": "3\n-63526 95085 -5239",
... | 1,641,495,400 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | l = int(input('L : '))
temp = []
for i in range(l):
n = int(input('n : '))
if n not in temp and n != 0:
temp.append(n)
print(len(temp))
| Title: Nastya and an Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:
- In one second ... | ```python
l = int(input('L : '))
temp = []
for i in range(l):
n = int(input('n : '))
if n not in temp and n != 0:
temp.append(n)
print(len(temp))
``` | -1 | |
165 | B | Burning Midnight Oil | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of code, drinks a cup of tea, then he writes as much as lines, drinks another cup of tea, then he writes lin... | The input consists of two integers *n* and *k*, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1<=≤<=*n*<=≤<=109, 2<=≤<=*k*<=≤<=10. | Print the only integer — the minimum value of *v* that lets Vasya write the program in one night. | [
"7 2\n",
"59 9\n"
] | [
"4\n",
"54\n"
] | In the first sample the answer is *v* = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.
In the second sample the answer is *v* = 54. Vasya writes the code in the following por... | 1,000 | [
{
"input": "7 2",
"output": "4"
},
{
"input": "59 9",
"output": "54"
},
{
"input": "1 9",
"output": "1"
},
{
"input": "11 2",
"output": "7"
},
{
"input": "747 2",
"output": "376"
},
{
"input": "6578 2",
"output": "3293"
},
{
"input": "37212... | 1,676,241,837 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 154 | 0 | n, k = map(int, input().split())
curMin = float('inf')
v = n
r = n//2
def calc(v):
count = 0
for i in range(n+1):
count += v // k**i
if v // k**i == 0:
if count >= n:
return True
else:
return False
while(r>=0):
ans = calc(v)
if an... | Title: Burning Midnight Oil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of *n* lines of code. Vasya is already exhausted, so he works like that: first he writes *v* lines of c... | ```python
n, k = map(int, input().split())
curMin = float('inf')
v = n
r = n//2
def calc(v):
count = 0
for i in range(n+1):
count += v // k**i
if v // k**i == 0:
if count >= n:
return True
else:
return False
while(r>=0):
ans = calc(v)... | 0 | |
747 | A | Display Size | PROGRAMMING | 800 | [
"brute force",
"math"
] | null | null | A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that:
- there are exactly *n* pixels o... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. | Print two integers — the number of rows and columns on the display. | [
"8\n",
"64\n",
"5\n",
"999999\n"
] | [
"2 4\n",
"8 8\n",
"1 5\n",
"999 1001\n"
] | In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.
In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.
In the third example the minimum possible difference equals 4, so on the display should be 1 ro... | 500 | [
{
"input": "8",
"output": "2 4"
},
{
"input": "64",
"output": "8 8"
},
{
"input": "5",
"output": "1 5"
},
{
"input": "999999",
"output": "999 1001"
},
{
"input": "716539",
"output": "97 7387"
},
{
"input": "1",
"output": "1 1"
},
{
"input":... | 1,562,523,917 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | n = int(input())
a = 1
ans = 10**18
while a*a <= n:
if n%a == 0:
b = n//a
if b-a < ans:
ans = b-a
ans_a = a
a+=1
print(ans_a, n//ans_a) | Title: Display Size
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels.
Your task is to determine the size of the rectangular display — the number of lines (rows) ... | ```python
n = int(input())
a = 1
ans = 10**18
while a*a <= n:
if n%a == 0:
b = n//a
if b-a < ans:
ans = b-a
ans_a = a
a+=1
print(ans_a, n//ans_a)
``` | 3 | |
218 | A | Mountain Scenery | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordinates (1,<=*y*1), (2,<=*y*2), ..., (2*n*<=+<=1,<=*y*2*n*<=+<=1), with the *i*-th segment connecting th... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100). The next line contains 2*n*<=+<=1 space-separated integers *r*1,<=*r*2,<=...,<=*r*2*n*<=+<=1 (0<=≤<=*r**i*<=≤<=100) — the *y* coordinates of the polyline vertices on Bolek's picture.
It is guaranteed that we can obtain the gi... | Print 2*n*<=+<=1 integers *y*1,<=*y*2,<=...,<=*y*2*n*<=+<=1 — the *y* coordinates of the vertices of the polyline on the initial picture. If there are multiple answers, output any one of them. | [
"3 2\n0 5 3 5 1 5 2\n",
"1 1\n0 2 0\n"
] | [
"0 5 3 4 1 4 2 \n",
"0 1 0 \n"
] | none | 500 | [
{
"input": "3 2\n0 5 3 5 1 5 2",
"output": "0 5 3 4 1 4 2 "
},
{
"input": "1 1\n0 2 0",
"output": "0 1 0 "
},
{
"input": "1 1\n1 100 0",
"output": "1 99 0 "
},
{
"input": "3 1\n0 1 0 1 0 2 0",
"output": "0 1 0 1 0 1 0 "
},
{
"input": "3 1\n0 1 0 2 0 1 0",
"out... | 1,656,334,880 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 2 | 154 | 31,744,000 | x=input()
x=x.split(" ")
z=input()
z=z.split(" ")
b=1
for i in range(int(x[1])):
z[b]=chr(ord(z[b])-1)
b+=2
for k in z:
print(k,end=" ")
| Title: Mountain Scenery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Bolek has found a picture with *n* mountain peaks painted on it. The *n* painted peaks are represented by a non-closed polyline, consisting of 2*n* segments. The segments go through 2*n*<=+<=1 points with coordi... | ```python
x=input()
x=x.split(" ")
z=input()
z=z.split(" ")
b=1
for i in range(int(x[1])):
z[b]=chr(ord(z[b])-1)
b+=2
for k in z:
print(k,end=" ")
``` | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,643,830,088 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 2,121 | 6,553,600 | # cook your dish heret
n=int(input())
x=[int(x) for x in input().split()]
v=[int(v) for v in input().split()]
def rightmost_left_ep(t):
return max([x[i]-(v[i]*t) for i in range(n)])
def leftmost_right_ep(t):
return min([x[i]+(v[i]*t) for i in range(n)])
def is_feasible(k):
return leftmost_right_ep(... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
# cook your dish heret
n=int(input())
x=[int(x) for x in input().split()]
v=[int(v) for v in input().split()]
def rightmost_left_ep(t):
return max([x[i]-(v[i]*t) for i in range(n)])
def leftmost_right_ep(t):
return min([x[i]+(v[i]*t) for i in range(n)])
def is_feasible(k):
return leftmost... | 3 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,675,178,120 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n,m=map(int,input().split())
minu=0
sot=0
o=0
t=0
for i in range(1,n+1):
t=t+i*5
if m+t<=240:
print(n)
elif m+t>240:
o=m+t-(i*5)
print(n-1)
| Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n,m=map(int,input().split())
minu=0
sot=0
o=0
t=0
for i in range(1,n+1):
t=t+i*5
if m+t<=240:
print(n)
elif m+t>240:
o=m+t-(i*5)
print(n-1)
``` | 0 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell.
The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample — with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,569,919,711 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 155 | 819,200 | import re
cv=0
s2=''
n=int(input())
s1=input()
for x in range(n):
if int(s1[x])==1:
s2=s2+'0'
else:
s2=s2+'1'
s2=s2+s1[x+1:n]
break;
for x in range(n):
if re.match(s1[x],s2[x]):
cv=cv+1
print(n-cv)
| Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
import re
cv=0
s2=''
n=int(input())
s1=input()
for x in range(n):
if int(s1[x])==1:
s2=s2+'0'
else:
s2=s2+'1'
s2=s2+s1[x+1:n]
break;
for x in range(n):
if re.match(s1[x],s2[x]):
cv=cv+1
print(n-cv)
``` | 3 | |
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,527,173,573 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 186 | 0 | # python 3
"""
Note that after applying the operations of the exchange, we can get any permutation of the elements of the array.
It is not difficult to understand that the answer would be "YES" if there were at least another different
number between the same-valued number, and this means that at most the same-valued nu... | 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
# python 3
"""
Note that after applying the operations of the exchange, we can get any permutation of the elements of the array.
It is not difficult to understand that the answer would be "YES" if there were at least another different
number between the same-valued number, and this means that at most the same... | 3 | |
593 | A | 2Char | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sendi... | The first line of the input contains number *n* (1<=≤<=*n*<=≤<=100) — the number of words in the article chosen by Andrew. Following are *n* lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct,... | Print a single integer — the maximum possible total length of words in Andrew's article. | [
"4\nabb\ncacc\naaa\nbbb\n",
"5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa\n"
] | [
"9",
"6"
] | In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}. | 250 | [
{
"input": "4\nabb\ncacc\naaa\nbbb",
"output": "9"
},
{
"input": "5\na\na\nbcbcb\ncdecdecdecdecdecde\naaaa",
"output": "6"
},
{
"input": "1\na",
"output": "1"
},
{
"input": "2\nz\nz",
"output": "2"
},
{
"input": "5\nabcde\nfghij\nklmno\npqrst\nuvwxy",
"output"... | 1,446,657,893 | 2,393 | Python 3 | WRONG_ANSWER | PRETESTS | 11 | 62 | 307,200 | n = int(input())
s = []
one = dict()
two = dict()
for i in range(n):
f = input()
q = set()
for j in f:
if j not in q:
q.add(j)
if len(q) > 2:
break
else:
if len(q) == 1:
if ''.join(sorted(list(q))) in one:
one[''.... | Title: 2Char
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written an... | ```python
n = int(input())
s = []
one = dict()
two = dict()
for i in range(n):
f = input()
q = set()
for j in f:
if j not in q:
q.add(j)
if len(q) > 2:
break
else:
if len(q) == 1:
if ''.join(sorted(list(q))) in one:
... | 0 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,595,173,643 | 2,147,483,647 | PyPy 3 | OK | TESTS | 24 | 140 | 20,172,800 | s = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
c = 0
f = 0
for i in s:
f+=1
c += l[ord(i)-97] * (f)
for i in range(k):
f+=1
c += m * f
print(c) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s = input()
k = int(input())
l = list(map(int, input().split()))
m = max(l)
c = 0
f = 0
for i in s:
f+=1
c += l[ord(i)-97] * (f)
for i in range(k):
f+=1
c += m * f
print(c)
``` | 3 | |
939 | B | Hamster Farm | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters.
Dima can buy boxes at a factory. The factory ... | The first line contains two integers *N* and *K* (0<=≤<=*N*<=≤<=1018, 1<=≤<=*K*<=≤<=105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces.
The second line contains *K* integers *a*1, *a*2, ..., *a**K* (1<=≤<=*a**i*<=≤<=1018 for all *i*) — the capaciti... | Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to *K* in the order they are given in input.
If there are many correct answers, output any of them. | [
"19 3\n5 4 10\n",
"28 3\n5 6 30\n"
] | [
"2 4\n",
"1 5\n"
] | none | 1,000 | [
{
"input": "19 3\n5 4 10",
"output": "2 4"
},
{
"input": "28 3\n5 6 30",
"output": "1 5"
},
{
"input": "1 1\n1",
"output": "1 1"
},
{
"input": "0 2\n2 3",
"output": "1 0"
},
{
"input": "30 4\n4 5 5 4",
"output": "2 6"
},
{
"input": "120 7\n109 92 38 38... | 1,696,337,196 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 93 | 14,950,400 | n, k = map(int, input().split())
a = list(map(int, input().split()))
max_total = -1
maxAmnt = 0
index = 0
for i in range(len(a)):
local_ans = (n // a[i])
closest_value = local_ans * a[i]
if closest_value > max_total:
max_total = closest_value
maxAmnt = local_ans
index ... | Title: Hamster Farm
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima has a hamsters farm. Soon *N* hamsters will grow up on it and Dima will sell them in a city nearby.
Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's wh... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
max_total = -1
maxAmnt = 0
index = 0
for i in range(len(a)):
local_ans = (n // a[i])
closest_value = local_ans * a[i]
if closest_value > max_total:
max_total = closest_value
maxAmnt = local_ans
... | 3 | |
21 | A | Jabber ID | PROGRAMMING | 1,900 | [
"implementation",
"strings"
] | A. Jabber ID | 0 | 256 | Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. - <hostname> — is... | The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive. | Print YES or NO. | [
"[email protected]\n",
"[email protected]/contest.icpc/12\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "mike@codeforces.com",
"output": "YES"
},
{
"input": "john.smith@codeforces.ru/contest.icpc/12",
"output": "NO"
},
{
"input": "test@test.ri/abacaba",
"output": "YES"
},
{
"input": "@ops",
"output": "NO"
},
{
"input": "this-is-the-test",
"output": "N... | 1,669,182,821 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #coding=utf-8
import os
import sys
def isOk(ch):
if (ch.isalpha() or ch.isdigit() or ch == '_'):
return True
return False
# solve
def solve():
str = raw_input()
# judge username
pos = str.find('@')
if pos <= 0 or str.count('@') != 1:
return "NO"
for i in r... | Title: Jabber ID
Time Limit: 0 seconds
Memory Limit: 256 megabytes
Problem Description:
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where
- <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «... | ```python
#coding=utf-8
import os
import sys
def isOk(ch):
if (ch.isalpha() or ch.isdigit() or ch == '_'):
return True
return False
# solve
def solve():
str = raw_input()
# judge username
pos = str.find('@')
if pos <= 0 or str.count('@') != 1:
return "NO"
... | -1 |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,680,637,844 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 358 | 16,076,800 | num = int(input())
aux1 = [0] * num
aux2 = [0] * num
aux3 = [0] * num
list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
list3 = [int(x) for x in input().split()]
for i in range(len(list1)):
aux1[i] = list1[i]
for i in range(len(list2)):
aux2[i] = list2[i]
for i in range(le... | Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
num = int(input())
aux1 = [0] * num
aux2 = [0] * num
aux3 = [0] * num
list1 = [int(x) for x in input().split()]
list2 = [int(x) for x in input().split()]
list3 = [int(x) for x in input().split()]
for i in range(len(list1)):
aux1[i] = list1[i]
for i in range(len(list2)):
aux2[i] = list2[i]
for i i... | 3 | |
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,620,288,728 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 154 | 6,758,400 | n=int(input())
x=list(map(int,input().split()))
i=0
while n>x[i]:
n-=x[i]
i=(i+1)%7
print(i+1) | 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())
x=list(map(int,input().split()))
i=0
while n>x[i]:
n-=x[i]
i=(i+1)%7
print(i+1)
``` | 3 | |
912 | A | Tricky Alchemy | PROGRAMMING | 800 | [
"implementation"
] | null | null | During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ... | The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal.
The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. | Print a single integer — the minimum number of crystals that Grisha should acquire in addition. | [
"4 3\n2 1 1\n",
"3 9\n1 1 3\n",
"12345678 87654321\n43043751 1000000000 53798715\n"
] | [
"2\n",
"1\n",
"2147483648\n"
] | In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue. | 500 | [
{
"input": "4 3\n2 1 1",
"output": "2"
},
{
"input": "3 9\n1 1 3",
"output": "1"
},
{
"input": "12345678 87654321\n43043751 1000000000 53798715",
"output": "2147483648"
},
{
"input": "12 12\n3 5 2",
"output": "0"
},
{
"input": "770 1390\n170 442 311",
"output"... | 1,535,948,210 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 108 | 0 | A, B = input().split()
A = int(A)
B = int(B)
x, y, z = input().split()
x = int(x)
y = int(y)
z = int(z)
reqYellowCrystal = 2*x + y
reqBlueCrystal = y + 3*z
output = (reqYellowCrystal-A) + (reqBlueCrystal-B)
print (output) | Title: Tricky Alchemy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.
Grisha needs to obta... | ```python
A, B = input().split()
A = int(A)
B = int(B)
x, y, z = input().split()
x = int(x)
y = int(y)
z = int(z)
reqYellowCrystal = 2*x + y
reqBlueCrystal = y + 3*z
output = (reqYellowCrystal-A) + (reqBlueCrystal-B)
print (output)
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,689,334,812 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | print("_RANDOM_GUESS_1689334812.225019")# 1689334812.225037 | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
print("_RANDOM_GUESS_1689334812.225019")# 1689334812.225037
``` | 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,696,492,452 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | '''def thanhtung(x,y,n,m):
so_hit=0
sat_thuong=x
mau=m
while n>0:
so_hit=so_hit+1
mau=mau-sat_thuong
if mau <= 0:
sat_thuong = sat_thuong+y
mau =m
n =n-1
return so_hit
x,y,n,m = map(int,input().split())
ket_qua=thanhtung(x,y,n,... | 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
'''def thanhtung(x,y,n,m):
so_hit=0
sat_thuong=x
mau=m
while n>0:
so_hit=so_hit+1
mau=mau-sat_thuong
if mau <= 0:
sat_thuong = sat_thuong+y
mau =m
n =n-1
return so_hit
x,y,n,m = map(int,input().split())
ket_qua=thanht... | 3.977 |
859 | A | Declined Finalists | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ... | The first line of input contains *K* (1<=≤<=*K*<=≤<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≤<=*r**i*<=≤<=106), the qualifying ranks of the finalists you know. All these ranks are distinct. | Print the minimum possible number of contestants that declined the invitation to compete onsite. | [
"25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n",
"5\n16 23 8 15 4\n",
"3\n14 15 92\n"
] | [
"3\n",
"0\n",
"67\n"
] | In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3. | 500 | [
{
"input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28",
"output": "3"
},
{
"input": "5\n16 23 8 15 4",
"output": "0"
},
{
"input": "3\n14 15 92",
"output": "67"
},
{
"input": "1\n1000000",
"output": "999975"
},
{
"input": "25\n1000000 ... | 1,668,786,621 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 61 | 0 | k=int(input())
a=[int(i) for i in input().split()]
a.sort()
if a[-1]<=25:
print(0)
else :
print(a[-1]-25) | Title: Declined Finalists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t... | ```python
k=int(input())
a=[int(i) for i in input().split()]
a.sort()
if a[-1]<=25:
print(0)
else :
print(a[-1]-25)
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,694,160,268 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import math
a=int(input())
b=int(input())
c=int(input())
l=[a*(b+c),(a*b)+c,a*b*c,a+b*c,(a+b)*c]
m=max(l)
print(m) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
import math
a=int(input())
b=int(input())
c=int(input())
l=[a*(b+c),(a*b)+c,a*b*c,a+b*c,(a+b)*c]
m=max(l)
print(m)
``` | 0 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,686,922,482 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<stdio.h>
int main()
{
int n,t=0,i;
scanf("%d", &n);
int a[n];
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
int mx=0,mn=101,pos1,pos2,temp;
for (i=0; i<n; i++)
{
if (mx<=a[i])
{
mx=a[i];
pos1=i;
}
}... | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
#include<stdio.h>
int main()
{
int n,t=0,i;
scanf("%d", &n);
int a[n];
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
}
int mx=0,mn=101,pos1,pos2,temp;
for (i=0; i<n; i++)
{
if (mx<=a[i])
{
mx=a[i];
pos1=i;
... | -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,672,384,367 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 409,600 | #!/usr/bin/env python
import math,collections,re
from sys import exit,stdin,stdout
from collections import Counter,defaultdict,deque
input = stdin.readline
def inp():
return(int(input()))
def inplst(nospaces=False):
if nospaces:
return list(map(int,list(input().rstrip())))
return(list(map(int,input(... | 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
#!/usr/bin/env python
import math,collections,re
from sys import exit,stdin,stdout
from collections import Counter,defaultdict,deque
input = stdin.readline
def inp():
return(int(input()))
def inplst(nospaces=False):
if nospaces:
return list(map(int,list(input().rstrip())))
return(list(map(... | 3.983737 |
505 | A | Mr. Kitayuta's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"strings"
] | null | null | Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "tes... | The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. | If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. | [
"revive\n",
"ee\n",
"kitayuta\n"
] | [
"reviver\n",
"eye",
"NA\n"
] | For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".
For the second sample, there is more than one solution. For example, "eve" will also be accepted.
For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter. | 500 | [
{
"input": "revive",
"output": "reviver"
},
{
"input": "ee",
"output": "eee"
},
{
"input": "kitayuta",
"output": "NA"
},
{
"input": "evima",
"output": "NA"
},
{
"input": "a",
"output": "aa"
},
{
"input": "yutampo",
"output": "NA"
},
{
"inpu... | 1,593,629,522 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 93 | 307,200 | s = input()
li = list(s)
length = len(s)
if s[::] == s[::-1]:
if length & 1 == 0:
li.insert(length//2,'a')
else:
li.insert((length//2)+1,li[length//2])
else:
for i in range(length//2):
if li[i] != li[length - 1 - i]:
if length - i > length:
li.... | Title: Mr. Kitayuta's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that re... | ```python
s = input()
li = list(s)
length = len(s)
if s[::] == s[::-1]:
if length & 1 == 0:
li.insert(length//2,'a')
else:
li.insert((length//2)+1,li[length//2])
else:
for i in range(length//2):
if li[i] != li[length - 1 - i]:
if length - i > length:
... | 0 | |
626 | A | Robot Sequence | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the s... | The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands.
The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code. | Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square. | [
"6\nURLLDR\n",
"4\nDLUU\n",
"7\nRLRLRLR\n"
] | [
"2\n",
"0\n",
"12\n"
] | In the first case, the entire source code works, as well as the "RL" substring in the second and third characters.
Note that, in the third case, the substring "LR" appears three times, and is therefore counted three times to the total result. | 500 | [
{
"input": "6\nURLLDR",
"output": "2"
},
{
"input": "4\nDLUU",
"output": "0"
},
{
"input": "7\nRLRLRLR",
"output": "12"
},
{
"input": "1\nR",
"output": "0"
},
{
"input": "100\nURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDLURDL... | 1,571,176,799 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 156 | 4,300,800 | tam = int(input())
string = input()
total = 0
substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)]
#print(substrings)
multiplas = []
for sub in substrings:
if len(sub) % 2 == 0:
multiplas.append(sub)
#print(multiplas)
for palavra in multiplas:
countD = 0
countU = 0... | Title: Robot Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively... | ```python
tam = int(input())
string = input()
total = 0
substrings = [string[i: j] for i in range(len(string)) for j in range(i + 1, len(string) + 1)]
#print(substrings)
multiplas = []
for sub in substrings:
if len(sub) % 2 == 0:
multiplas.append(sub)
#print(multiplas)
for palavra in multiplas:
countD = 0
... | 3 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,691,590,883 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 154 | 0 | k = int(input())
s = input()
if len(s) % k != 0:
print(-1)
else:
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
string = ""
score = 0
for m in list(d.values()):
if m % k != 0:
score = -1
break
if score == 0:
for l in range(k):
... | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
k = int(input())
s = input()
if len(s) % k != 0:
print(-1)
else:
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
string = ""
score = 0
for m in list(d.values()):
if m % k != 0:
score = -1
break
if score == 0:
for l in range(k... | 3 | |
358 | B | Dima and Text Messages | PROGRAMMING | 1,500 | [
"brute force",
"strings"
] | null | null | Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other.
Dima and Inna are using a secret code in their text messages. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105.
The last line contains non-empty text message that Inna has got... | In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. | [
"3\ni\nlove\nyou\n<3i<3love<23you<3\n",
"7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3\n"
] | [
"yes\n",
"no\n"
] | Please note that Dima got a good old kick in the pants for the second sample from the statement. | 1,000 | [
{
"input": "3\ni\nlove\nyou\n<3i<3love<23you<3",
"output": "yes"
},
{
"input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3",
"output": "no"
},
{
"input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3",
"output": "yes"
},
{
"input": "4\na\n... | 1,556,876,042 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | n = int(input())
s = ''.join([input() for _ in range(n)])
k = input()
i = 0; j = len(k)-1
while(k[i] in '<>0123456789'): i += 1
while(k[j] in '<>0123456789'): j -= 1
t1 = k[:i]; t2 = k[j+1:]
def r(t):
return t.find('<') > -1 and t.find('<') < t.rfind('3')
if not r(t1) or not r(t2): print('no'); exit() ... | Title: Dima and Text Messages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today t... | ```python
n = int(input())
s = ''.join([input() for _ in range(n)])
k = input()
i = 0; j = len(k)-1
while(k[i] in '<>0123456789'): i += 1
while(k[j] in '<>0123456789'): j -= 1
t1 = k[:i]; t2 = k[j+1:]
def r(t):
return t.find('<') > -1 and t.find('<') < t.rfind('3')
if not r(t1) or not r(t2): print('no'... | 0 | |
761 | B | Dasha and friends | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"math"
] | null | null | Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinct points of which there are *n* barriers. Athlete always run the track in counterclockwise direction if... | The first line contains two integers *n* and *L* (1<=≤<=*n*<=≤<=50, *n*<=≤<=*L*<=≤<=100) — the number of barriers on a track and its length.
The second line contains *n* distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the ra... | Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes). | [
"3 8\n2 4 6\n1 5 7\n",
"4 9\n2 3 5 8\n0 1 3 6\n",
"2 4\n1 3\n1 2\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | The first test is analyzed in the statement. | 1,000 | [
{
"input": "3 8\n2 4 6\n1 5 7",
"output": "YES"
},
{
"input": "4 9\n2 3 5 8\n0 1 3 6",
"output": "YES"
},
{
"input": "2 4\n1 3\n1 2",
"output": "NO"
},
{
"input": "5 9\n0 2 5 6 7\n1 3 6 7 8",
"output": "YES"
},
{
"input": "5 60\n7 26 27 40 59\n14 22 41 42 55",
... | 1,660,597,888 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | def main():
n, l = map(int, fin().split())
*a, = map(int, fin().split())
*b, = map(int, fin().split())
const = abs(a[0]-b[0])
for i in range(1, n):
if abs(a[i]-b[i]) != const:
return fout("NO")
fout("YES")
# FastIO
from sys import stdin, stdout
try: input, output... | Title: Dasha and friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length *L*, in distinc... | ```python
def main():
n, l = map(int, fin().split())
*a, = map(int, fin().split())
*b, = map(int, fin().split())
const = abs(a[0]-b[0])
for i in range(1, n):
if abs(a[i]-b[i]) != const:
return fout("NO")
fout("YES")
# FastIO
from sys import stdin, stdout
try: inp... | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,696,304,767 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 |
b1,b2,b3 = map(int,input().split())
print( (b3*(b3+1)//2)*b1 - b2) | 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
b1,b2,b3 = map(int,input().split())
print( (b3*(b3+1)//2)*b1 - b2)
``` | 0 | |
109 | A | Lucky Sum of Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | A. Lucky Sum of Digits | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope wi... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. | Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. | [
"11\n",
"10\n"
] | [
"47\n",
"-1\n"
] | none | 500 | [
{
"input": "11",
"output": "47"
},
{
"input": "10",
"output": "-1"
},
{
"input": "64",
"output": "4477777777"
},
{
"input": "1",
"output": "-1"
},
{
"input": "4",
"output": "4"
},
{
"input": "7",
"output": "7"
},
{
"input": "12",
"outpu... | 1,449,519,931 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 184 | 1,126,400 | from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
setrecursionlimit(10**7)
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
n=RI()[0]
ans=""
while n%7!=0:
n-=4
ans+='4'
prin... | Title: Lucky Sum of Digits
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
from functools import reduce
from operator import *
from math import *
from sys import *
from string import *
setrecursionlimit(10**7)
RI=lambda: list(map(int,input().split()))
RS=lambda: input().rstrip().split()
#################################################
n=RI()[0]
ans=""
while n%7!=0:
n-=4
ans... | 3.951902 |
287 | A | IQ Test | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the... | Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. | Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. | [
"####\n.#..\n####\n....\n",
"####\n....\n####\n....\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column. | 500 | [
{
"input": "###.\n...#\n###.\n...#",
"output": "NO"
},
{
"input": ".##.\n#..#\n.##.\n#..#",
"output": "NO"
},
{
"input": ".#.#\n#.#.\n.#.#\n#.#.",
"output": "NO"
},
{
"input": "##..\n..##\n##..\n..##",
"output": "NO"
},
{
"input": "#.#.\n#.#.\n.#.#\n.#.#",
"ou... | 1,675,616,771 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | x=[input() for i in range(4)]
m=0
for i in range(3):
for j in range(3):
if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2:
m=1
break
if m:
break
if m:
print("YES")
else:
print("NO") | Title: IQ Test
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the city of Ultima Thule job applicants are often offered an IQ test.
The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and o... | ```python
x=[input() for i in range(4)]
m=0
for i in range(3):
for j in range(3):
if (x[i][j]+x[i][j+1]+x[i+1][j]+x[i+1][j+1]).count("#")!=2:
m=1
break
if m:
break
if m:
print("YES")
else:
print("NO")
``` | 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,623,849,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | class Graph:
def __init__(self,mat,unconn=0):
vnum=len(mat)
for x in mat:
if len(x)!=vnum:
raise ValueError("Argument for class 'Graph' is bad.")
self._mat=[mat[i][:] for i in range(vnum)]
self._unconn=unconn
self._vnum=vnum
def _out_edges(row,... | 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
class Graph:
def __init__(self,mat,unconn=0):
vnum=len(mat)
for x in mat:
if len(x)!=vnum:
raise ValueError("Argument for class 'Graph' is bad.")
self._mat=[mat[i][:] for i in range(vnum)]
self._unconn=unconn
self._vnum=vnum
def _out_... | 0 |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,508,644,617 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 1,000 | 5,529,600 | n = 0
k = 0
totalk = 0
n,k = input().split()
n = int(n)
k = int(k)
totalk = k + 1
dip = 0
cert = 0
left = 0
half = int(n/2)
for i in range(half,0,-1):
if i % totalk == 0:
dip = i/totalk;
cert= i - dip
break;
left = n -(dip + cert)
dip = int(dip)
cert = int(cert)
left = int... | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
n = 0
k = 0
totalk = 0
n,k = input().split()
n = int(n)
k = int(k)
totalk = k + 1
dip = 0
cert = 0
left = 0
half = int(n/2)
for i in range(half,0,-1):
if i % totalk == 0:
dip = i/totalk;
cert= i - dip
break;
left = n -(dip + cert)
dip = int(dip)
cert = int(cert)
... | 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,690,042,421 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | x, y, z = [int(x) for x in input().split()]
resx = 0
resy = 0
if x % z == 0:
resx += x/z
else:
resx += int(x/z) +1
if y % z == 0:
resy += y/z
else:
resy += int(y/z) +1
print(int(resx * resy)) | 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
x, y, z = [int(x) for x in input().split()]
resx = 0
resy = 0
if x % z == 0:
resx += x/z
else:
resx += int(x/z) +1
if y % z == 0:
resy += y/z
else:
resy += int(y/z) +1
print(int(resx * resy))
``` | 3.977 |
710 | C | Magic Odd Square | PROGRAMMING | 1,500 | [
"constructive algorithms",
"math"
] | null | null | Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd. | The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49). | Print *n* lines with *n* integers. All the integers should be different and from 1 to *n*2. The sum in each row, column and both main diagonals should be odd. | [
"1\n",
"3\n"
] | [
"1\n",
"2 1 4\n3 5 7\n6 9 8\n"
] | none | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "3",
"output": "2 1 4\n3 5 7\n6 9 8"
},
{
"input": "5",
"output": "2 4 1 6 8\n10 3 5 7 12\n9 11 13 15 17\n14 19 21 23 16\n18 20 25 22 24"
},
{
"input": "7",
"output": "2 4 6 1 8 10 12\n14 16 3 5 7 18 20\n22 9 11 13 15 17 24\n19 ... | 1,624,863,054 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 124 | 2,764,800 | n=int(input())
mxc=((n*n+1)//2-(2*n-1))//4
m=[]
for i in range(n):
l=[0]*n
m.append(l)
odd=1
i=n//2
j=0
while(j<n):
m[i][j]=odd
j+=1
odd+=2
j=0
while(j<n):
if i==j:
j+=1
continue
m[j][i]=odd
j+=1
odd+=2
i=0
j=0
c=0
while(c<mxc):
c+=1
m[i][j]=odd
odd+=2
m[i][n-1-j]=odd
odd+... | Title: Magic Odd Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Find an *n*<=×<=*n* matrix with different numbers from 1 to *n*2, so the sum in each row, column and both main diagonals are odd.
Input Specification:
The only line contains odd integer *n* (1<=≤<=*n*<=≤<=49).
Output... | ```python
n=int(input())
mxc=((n*n+1)//2-(2*n-1))//4
m=[]
for i in range(n):
l=[0]*n
m.append(l)
odd=1
i=n//2
j=0
while(j<n):
m[i][j]=odd
j+=1
odd+=2
j=0
while(j<n):
if i==j:
j+=1
continue
m[j][i]=odd
j+=1
odd+=2
i=0
j=0
c=0
while(c<mxc):
c+=1
m[i][j]=odd
odd+=2
m[i][n-1-j]=... | 3 | |
220 | A | Little Elephant and Problem | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he co... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, — array *a*.
Note that the elements of the array are not necessarily distinct numbers. | In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. | [
"2\n1 2\n",
"3\n3 2 1\n",
"4\n4 3 2 1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".
In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".
In the third sample we ... | 500 | [
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n3 2 1",
"output": "YES"
},
{
"input": "4\n4 3 2 1",
"output": "NO"
},
{
"input": "3\n1 3 2",
"output": "YES"
},
{
"input": "2\n2 1",
"output": "YES"
},
{
"input": "9\n7 7 8 8 10 10 10 10 1000000000... | 1,689,168,459 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | import sys
sys.setrecursionlimit(2000000)
def clc():
n = int(input())
arr = list(map(int,input().split()))
def check(arr):
maxi = arr[0]
maxind = 0
for i in range(1,len(arr)):
if arr[i]>=maxi:
maxind = i
maxi = max(maxi,arr[i])
... | Title: Little Elephant and Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array.
The Little Elephant doesn't want to c... | ```python
import sys
sys.setrecursionlimit(2000000)
def clc():
n = int(input())
arr = list(map(int,input().split()))
def check(arr):
maxi = arr[0]
maxind = 0
for i in range(1,len(arr)):
if arr[i]>=maxi:
maxind = i
maxi = max(max... | 0 | |
897 | A | Scarborough Fair | PROGRAMMING | 800 | [
"implementation"
] | null | null | Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there.
Willem asks his friend, Grick for directions, Grick helped them, and gave them a task.
Althou... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
The second line contains a string *s* of length *n*, consisting of lowercase English letters.
Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ... | Output string *s* after performing *m* operations described above. | [
"3 1\nioi\n1 1 i n\n",
"5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n"
] | [
"noi",
"gaaak"
] | For the second example:
After the first operation, the string is wxxak.
After the second operation, the string is waaak.
After the third operation, the string is gaaak. | 500 | [
{
"input": "3 1\nioi\n1 1 i n",
"output": "noi"
},
{
"input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g",
"output": "gaaak"
},
{
"input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n... | 1,612,370,813 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 0 | n,m=(int(x) for x in input().split())
s=input()
new_str=s
for j in range(m):
l,r,c1,c2=input().split()
le=int(l)
ri=int(r)
new_str=new_str.replace(c1,c2,ri+1-le)
print(new_str) | Title: Scarborough Fair
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Parsley, sage, rosemary and thyme.
Remember me to one who lives there.
He once was the true love of mine.
Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ... | ```python
n,m=(int(x) for x in input().split())
s=input()
new_str=s
for j in range(m):
l,r,c1,c2=input().split()
le=int(l)
ri=int(r)
new_str=new_str.replace(c1,c2,ri+1-le)
print(new_str)
``` | 0 | |
628 | B | New Skateboard | PROGRAMMING | 1,300 | [
"dp"
] | null | null | Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which... | The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. | Print integer *a* — the number of substrings of the string *s* that are divisible by 4.
Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"124\n",
"04\n",
"5810438174\n"
] | [
"4\n",
"3\n",
"9\n"
] | none | 0 | [
{
"input": "124",
"output": "4"
},
{
"input": "04",
"output": "3"
},
{
"input": "5810438174",
"output": "9"
},
{
"input": "1",
"output": "0"
},
{
"input": "039",
"output": "1"
},
{
"input": "97247",
"output": "6"
},
{
"input": "5810438174",... | 1,575,612,614 | 974 | Python 3 | OK | TESTS | 22 | 421 | 1,024,000 | s= input()
ans = 0
for i in s:
if int(i)%4 == 0:
ans+=1
n = len(s)
for i in range(0,n-1):
if int(s[i:i+2])%4 == 0:
ans+=i+1
print(ans) | Title: New Skateboard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother... | ```python
s= input()
ans = 0
for i in s:
if int(i)%4 == 0:
ans+=1
n = len(s)
for i in range(0,n-1):
if int(s[i:i+2])%4 == 0:
ans+=i+1
print(ans)
``` | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,586,331,266 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 93 | 0 | s,v1,v2,t1,t2 = map(int,input().split())
player1 = (s*v1)+(t1*2)
player2 = (s*v2)+(t2*2)
if player1<player2:
print('First')
elif player2<player1:
print('Second')
else:
print("Friendship") | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s,v1,v2,t1,t2 = map(int,input().split())
player1 = (s*v1)+(t1*2)
player2 = (s*v2)+(t2*2)
if player1<player2:
print('First')
elif player2<player1:
print('Second')
else:
print("Friendship")
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,659,417,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 512,000 | from fractions import Fraction
(yakko, wakko) = map(int, input().split(' '))
dot = ((6 - max(yakko, wakko) + 1) / 6)
convert_to_fraction = Fraction(dot)
numerator = convert_to_fraction.numerator
denominator = convert_to_fraction.denominator
print(str(numerator) + '/' + str(denominator)) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
from fractions import Fraction
(yakko, wakko) = map(int, input().split(' '))
dot = ((6 - max(yakko, wakko) + 1) / 6)
convert_to_fraction = Fraction(dot)
numerator = convert_to_fraction.numerator
denominator = convert_to_fraction.denominator
print(str(numerator) + '/' + str(denominator))
``` | 0 |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,652,544,762 | 2,147,483,647 | PyPy 3 | OK | TESTS | 159 | 124 | 0 | n=input()
s=input().split()
M=s.index(n)
n=int(n)
m=s.index('1')
print(max(m,M,n-m-1,n-1-M)) | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
n=input()
s=input().split()
M=s.index(n)
n=int(n)
m=s.index('1')
print(max(m,M,n-m-1,n-1-M))
``` | 3 | |
600 | B | Queries about less or equal elements | PROGRAMMING | 1,300 | [
"binary search",
"data structures",
"sortings",
"two pointers"
] | null | null | You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*.
The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109).
The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109). | Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. | [
"5 4\n1 3 5 7 9\n6 4 2 8\n",
"5 5\n1 2 1 2 5\n3 1 4 1 5\n"
] | [
"3 2 1 4\n",
"4 2 4 2 5\n"
] | none | 0 | [
{
"input": "5 4\n1 3 5 7 9\n6 4 2 8",
"output": "3 2 1 4"
},
{
"input": "5 5\n1 2 1 2 5\n3 1 4 1 5",
"output": "4 2 4 2 5"
},
{
"input": "1 1\n-1\n-2",
"output": "0"
},
{
"input": "1 1\n-80890826\n686519510",
"output": "1"
},
{
"input": "11 11\n237468511 -77918754... | 1,671,007,780 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 1,715 | 19,660,800 | def binsearch(x):
l, r = 0, n
while l<r:
m = (l+r)//2
if a[m] <= x:
l = m+1
else:
r = m
return l
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
b = [int(i) for i in input().split()]
for i in range(m... | Title: Queries about less or equal elements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
In... | ```python
def binsearch(x):
l, r = 0, n
while l<r:
m = (l+r)//2
if a[m] <= x:
l = m+1
else:
r = m
return l
n, m = map(int, input().split())
a = sorted([int(i) for i in input().split()])
b = [int(i) for i in input().split()]
for i ... | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,643,215,464 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 0 | n = int(input()) - 7
print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4]) | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n = int(input()) - 7
print('ROYGBIV' + 'GBIV' * (n // 4) + 'GBIV'[:n % 4])
``` | 3.969 |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,689,650,498 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 4 | 61 | 2,867,200 | import sys
read = sys.stdin.readline
write = sys.stdout.write
def solve():
n = int(read())
arr = list(map(int, read().split()))
comp = sorted(arr)
counter = 0
ind = 0
for i in range(n):
if arr[i] != comp[i]:
if counter == 0:
ind = i + 1
... | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
import sys
read = sys.stdin.readline
write = sys.stdout.write
def solve():
n = int(read())
arr = list(map(int, read().split()))
comp = sorted(arr)
counter = 0
ind = 0
for i in range(n):
if arr[i] != comp[i]:
if counter == 0:
ind =... | -1 | |
676 | A | Nicholas and Permutation | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integer *n*) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100) — the size of the permutation.
The second line of the input contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is equal to the element at the *i*-th position. | Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap. | [
"5\n4 5 1 3 2\n",
"7\n1 6 5 3 4 7 2\n",
"6\n6 5 4 3 2 1\n"
] | [
"3\n",
"6\n",
"5\n"
] | In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possib... | 500 | [
{
"input": "5\n4 5 1 3 2",
"output": "3"
},
{
"input": "7\n1 6 5 3 4 7 2",
"output": "6"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "5"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n2 3 1",
"output": "... | 1,632,826,418 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 6,963,200 | t = int(input())
a = input().split()
b = min(a)
c = max(a)
emin = a.index(b)
emax = a.index(c)
if emin > emax:
if t - emax > emax :emin = t-1
else:emax = 0
print(abs(emin - emax))
else:
if t - emin > emin :emax = t-1
else:emin = 0
print(abs(emax - emin)) | Title: Nicholas and Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Nicholas has an array *a* that contains *n* distinct integers from 1 to *n*. In other words, Nicholas has a permutation of size *n*.
Nicholas want the minimum element (integer 1) and the maximum element (integ... | ```python
t = int(input())
a = input().split()
b = min(a)
c = max(a)
emin = a.index(b)
emax = a.index(c)
if emin > emax:
if t - emax > emax :emin = t-1
else:emax = 0
print(abs(emin - emax))
else:
if t - emin > emin :emax = t-1
else:emin = 0
print(abs(emax - emin))
``` | 0 | |
90 | B | African Crossword | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. African Crossword | 2 | 256 | An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid. | Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter. | [
"3 3\ncba\nbcd\ncbc\n",
"5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n"
] | [
"abcd",
"codeforces"
] | none | 1,000 | [
{
"input": "3 3\ncba\nbcd\ncbc",
"output": "abcd"
},
{
"input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf",
"output": "codeforces"
},
{
"input": "4 4\nusah\nusha\nhasu\nsuha",
"output": "ahhasusu"
},
{
"input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz",
"output... | 1,531,576,796 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 342 | 512,000 | inds=set()
def is_not_clone(words,x,z):
clone=1
sim=words[z][x]
#print('cursim=',sim)
n=len(words)
if (x,z) in inds:
return 0
for c,item in enumerate(words[z]):
#print('c=%s sim=%s '%(c,item))
if sim==item and c!=x:
inds.add((c,z))
cl... | Title: African Crossword
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded.
To s... | ```python
inds=set()
def is_not_clone(words,x,z):
clone=1
sim=words[z][x]
#print('cursim=',sim)
n=len(words)
if (x,z) in inds:
return 0
for c,item in enumerate(words[z]):
#print('c=%s sim=%s '%(c,item))
if sim==item and c!=x:
inds.add((c,z))
... | 3.913546 |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,679,499,000 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 122 | 102,400 | import math
n=int(input())
l=[i+1 for i in range(n)]
l2=[]
for i in range(int(n/2)):
l2.append(l[i])
l2.append(l[-(i+1)])
if n%2==1:
l2.append(math.ceil(n/2))
print(*l2)
| Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
import math
n=int(input())
l=[i+1 for i in range(n)]
l2=[]
for i in range(int(n/2)):
l2.append(l[i])
l2.append(l[-(i+1)])
if n%2==1:
l2.append(math.ceil(n/2))
print(*l2)
``` | 3.969309 |
10 | A | Power Consumption Calculation | PROGRAMMING | 900 | [
"implementation"
] | A. Power Consumption Calculation | 1 | 256 | Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T... | The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=<... | Output the answer to the problem. | [
"1 3 2 1 5 10\n0 10\n",
"2 8 4 2 5 10\n20 30\n50 100\n"
] | [
"30",
"570"
] | none | 0 | [
{
"input": "1 3 2 1 5 10\n0 10",
"output": "30"
},
{
"input": "2 8 4 2 5 10\n20 30\n50 100",
"output": "570"
},
{
"input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436",
"output": "8445"
},
{
"input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945",
"output": "5287... | 1,673,735,430 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 154 | 0 | [n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()];
rold=-1;
ans=0;
for _ in range(n):
[l,r]=[int(x) for x in input().split()];
ans+=(r-l)*p1;
if rold>0:
if l-rold>=t1+t2:
ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2);
elif l-rold>=t1:
ans+=p1*t1+p2*(l-rold-t1);
... | Title: Power Consumption Calculation
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f... | ```python
[n,p1,p2,p3,t1,t2]=[int(x) for x in input().split()];
rold=-1;
ans=0;
for _ in range(n):
[l,r]=[int(x) for x in input().split()];
ans+=(r-l)*p1;
if rold>0:
if l-rold>=t1+t2:
ans+=p1*t1+p2*t2+p3*(l-rold-t1-t2);
elif l-rold>=t1:
ans+=p1*t1+p2*(l-ro... | 3.923 |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,568,378,574 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 109 | 0 | #code
n=int(input())
x,y=input().split()
x,y = int(x),int(y)
l=list(range(x,y))
s=set(l)
for i in range (1,n):
p,q=input().split()
p,q=int(p),int(q)
l1=list(range(p,q))
s1=set(l1)
s=s-s1
print(len(s)) | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
#code
n=int(input())
x,y=input().split()
x,y = int(x),int(y)
l=list(range(x,y))
s=set(l)
for i in range (1,n):
p,q=input().split()
p,q=int(p),int(q)
l1=list(range(p,q))
s1=set(l1)
s=s-s1
print(len(s))
``` | 3 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at 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,661,313,778 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 81 | 154 | 0 | x = y = z = 0
for _ in range(int(input())):
forces = tuple(map(int, input().split()))
x += forces[0]
y += forces[1]
z += forces[2]
print("YES" if x == y == z == 0 else "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
x = y = z = 0
for _ in range(int(input())):
forces = tuple(map(int, input().split()))
x += forces[0]
y += forces[1]
z += forces[2]
print("YES" if x == y == z == 0 else "NO")
``` | 3.9615 |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,658,662,417 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
n=int(input())
if a1+a2+a3==0 or b1+b2+b3==0:
print("NO")
elif n/2>=1:
if a1+a2+a3<=5 or b1+b2+b3<=10:
print("YES")
else:
print("NO")
else:
print("NO") | Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
n=int(input())
if a1+a2+a3==0 or b1+b2+b3==0:
print("NO")
elif n/2>=1:
if a1+a2+a3<=5 or b1+b2+b3<=10:
print("YES")
else:
print("NO")
else:
print("NO")
``` | 0 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,689,070,731 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 46 | 0 | l = int(input())
p = int(input())
q = int(input())
x = p*l/(p+q)
print(x) | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
l = int(input())
p = int(input())
q = int(input())
x = p*l/(p+q)
print(x)
``` | 3 | |
784 | F | Crunching Numbers Just for You | PROGRAMMING | 1,900 | [
"*special",
"implementation"
] | null | null | You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...
You are given an array of integers. Sort it in non-descending order. | The input consists of a single line of space-separated integers. The first number is *n* (1<=≤<=*n*<=≤<=10) — the size of the array. The following *n* numbers are the elements of the array (1<=≤<=*a**i*<=≤<=100). | Output space-separated elements of the sorted array. | [
"3 3 1 2\n"
] | [
"1 2 3 \n"
] | Remember, this is a very important feature, and you have to make sure the customers appreciate it! | 0 | [
{
"input": "3 3 1 2",
"output": "1 2 3 "
},
{
"input": "10 54 100 27 1 33 27 80 49 27 6",
"output": "1 6 27 27 27 33 49 54 80 100 "
}
] | 1,617,285,165 | 5,505 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 93 | 0 | a = input().split(' ')
b = [int(x) for x in a]
for x in sorted(b):
print(x, end=' ') | Title: Crunching Numbers Just for You
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done.... | ```python
a = input().split(' ')
b = [int(x) for x in a]
for x in sorted(b):
print(x, end=' ')
``` | 0 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,696,960,436 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 42 | 2,000 | 13,414,400 | import sys
input = sys.stdin.readline
def lower_bound(arr, x):
n = len(arr)
left = -1
right = n
while left + 1 < right:
mid = (left + right)
if x >= arr[mid]:
left = mid
else:
right = mid
return left
def main():
n = int(inpu... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
import sys
input = sys.stdin.readline
def lower_bound(arr, x):
n = len(arr)
left = -1
right = n
while left + 1 < right:
mid = (left + right)
if x >= arr[mid]:
left = mid
else:
right = mid
return left
def main():
n ... | 0 | |
483 | B | Friends and Presents | PROGRAMMING | 1,800 | [
"binary search",
"math"
] | null | null | You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the... | The only line contains four positive integers *cnt*1, *cnt*2, *x*, *y* (1<=≤<=*cnt*1,<=*cnt*2<=<<=109; *cnt*1<=+<=*cnt*2<=≤<=109; 2<=≤<=*x*<=<<=*y*<=≤<=3·104) — the numbers that are described in the statement. It is guaranteed that numbers *x*, *y* are prime. | Print a single integer — the answer to the problem. | [
"3 1 2 3\n",
"1 3 2 3\n"
] | [
"5\n",
"4\n"
] | In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.
In the second sample you give the set of numbers {3} to the first... | 1,000 | [
{
"input": "3 1 2 3",
"output": "5"
},
{
"input": "1 3 2 3",
"output": "4"
},
{
"input": "916200 69682 2 3",
"output": "1832399"
},
{
"input": "808351 17767 433 509",
"output": "826121"
},
{
"input": "8851 901 20897 26183",
"output": "9752"
},
{
"input... | 1,556,776,736 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 109 | 0 | def judge(n,m,sum):
cnt=int(sum/x/y)
if x==y:
cnt=int(sum/x)
#print(cnt)
n=max(0, n-int(sum/y)+cnt)
m=max(0, m-int(sum/x)+cnt)
#print(n,m)
if(sum-int(sum/x)-int(sum/y)+cnt>=n+m):
tmp=0
else:
tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt)
#print(tmp)
return tm... | Title: Friends and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have two friends. You want to present each of them several positive integers. You want to present *cnt*1 numbers to the first friend and *cnt*2 numbers to the second friend. Moreover, you want all presented num... | ```python
def judge(n,m,sum):
cnt=int(sum/x/y)
if x==y:
cnt=int(sum/x)
#print(cnt)
n=max(0, n-int(sum/y)+cnt)
m=max(0, m-int(sum/x)+cnt)
#print(n,m)
if(sum-int(sum/x)-int(sum/y)+cnt>=n+m):
tmp=0
else:
tmp=m+n-(sum-int(sum/x)-int(sum/y)+cnt)
#print(tmp)
... | 3 | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,580,318,696 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 307,200 | n = int(input())
i = 0
while i*(i+1) < 2*n:
i += 1
print(n - i*(i-1)//2) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
n = int(input())
i = 0
while i*(i+1) < 2*n:
i += 1
print(n - i*(i-1)//2)
``` | 0 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,699,078,015 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n=int(input())
m=[]
l=list(map(int,input().split()))
for i in range(1,len(l)+1):
m.append(l.index(i)+1)
for j in m:
print(j,end=" ")
print() | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
m=[]
l=list(map(int,input().split()))
for i in range(1,len(l)+1):
m.append(l.index(i)+1)
for j in m:
print(j,end=" ")
print()
``` | 3 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,672,343,145 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 184 | 5,222,400 | from collections import deque,Counter,OrderedDict
import math
import sys
import random
import bisect
from functools import reduce
from sys import stdin
import heapq
import copy
import os
import sys
import operator
from io import BytesIO, IOBase
def main():
class DisjointSetUnion:
def __init__(self, n):
... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
from collections import deque,Counter,OrderedDict
import math
import sys
import random
import bisect
from functools import reduce
from sys import stdin
import heapq
import copy
import os
import sys
import operator
from io import BytesIO, IOBase
def main():
class DisjointSetUnion:
def __init__(se... | 0 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,693,686,967 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 92 | 0 | n, m = [int(x) for x in input().split()]
nomes = []
output = 1
for i in range(n):
nomes.append(input())
for l in range(m):
letras = set()
for i in range(n):
letras.add(nomes[i][l])
output *= len(letras)
print(output)
| Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
n, m = [int(x) for x in input().split()]
nomes = []
output = 1
for i in range(n):
nomes.append(input())
for l in range(m):
letras = set()
for i in range(n):
letras.add(nomes[i][l])
output *= len(letras)
print(output)
``` | 0 | |
549 | A | Face Detection | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<... | The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively.
Next *n* lines define the image. Each line contains *m* lowercase Latin letters. | In the single line print the number of faces on the image. | [
"4 4\nxxxx\nxfax\nxcex\nxxxx\n",
"4 2\nxx\ncf\nae\nxx\n",
"2 3\nfac\ncef\n",
"1 4\nface\n"
] | [
"1\n",
"1\n",
"2\n",
"0\n"
] | In the first sample the image contains a single face, located in a square with the upper left corner at the second line and the second column:
In the second sample the image also contains exactly one face, its upper left corner is at the second row and the first column.
In the third sample two faces are shown:
In ... | 250 | [
{
"input": "4 4\nxxxx\nxfax\nxcex\nxxxx",
"output": "1"
},
{
"input": "4 2\nxx\ncf\nae\nxx",
"output": "1"
},
{
"input": "2 3\nfac\ncef",
"output": "2"
},
{
"input": "1 4\nface",
"output": "0"
},
{
"input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx",
"output": "... | 1,660,026,265 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 9 | 62 | 1,536,000 | import sys
input = sys.stdin.readline
n,m = map(int,input().strip().split())
a = []
for _ in range(n):
a.append(input().strip())
let = {'f','a','c','e'}
c=0
for i in range(n):
for j in range(m):
try:
if a[i][j] in let and a[i][j+1] in let and a[i+1][j] in let and a[i+1][j+1] in ... | Title: Face Detection
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem a... | ```python
import sys
input = sys.stdin.readline
n,m = map(int,input().strip().split())
a = []
for _ in range(n):
a.append(input().strip())
let = {'f','a','c','e'}
c=0
for i in range(n):
for j in range(m):
try:
if a[i][j] in let and a[i][j+1] in let and a[i+1][j] in let and a[i+1... | 0 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,696,985,248 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | f = open("input.txt", "r")
door = str(f.readline())[0:-1]
rail = int(str(f.readline()))
f.close()
if (door == "front" and rail == 1) or (door == "back" and rail == 0):
out = "L"
else:
out = "R"
f = open("output.txt", "w")
f.write(out) | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
f = open("input.txt", "r")
door = str(f.readline())[0:-1]
rail = int(str(f.readline()))
f.close()
if (door == "front" and rail == 1) or (door == "back" and rail == 0):
out = "L"
else:
out = "R"
f = open("output.txt", "w")
f.write(out)
``` | 0 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=≤<=*a*,<=*b*<=≤<=100,<=1<=≤<=*c*<=≤<=10<=000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,456,509,617 | 2,717 | Python 3 | WRONG_ANSWER | TESTS | 25 | 62 | 0 | from math import floor as F
if __name__=='__main__':
a,b,k= map(int,input().split(' '))
X,Y = ((k/a),0),(0,(k/b))
#print (X,Y)
found = False
#print (X[0]/Y[1])
x,y=(X[0]),0
while x>=0:
#print (x,y)
if F(x)*a+b*y==k:
found=True
break
... | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
from math import floor as F
if __name__=='__main__':
a,b,k= map(int,input().split(' '))
X,Y = ((k/a),0),(0,(k/b))
#print (X,Y)
found = False
#print (X[0]/Y[1])
x,y=(X[0]),0
while x>=0:
#print (x,y)
if F(x)*a+b*y==k:
found=True
b... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,570,914,816 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 11 | 5,000 | 4,812,800 | n = int(input())
x = list(map(int, input().split()))
v = list(map(int, input().split()))
l = -1
r = 10000000000
for e in range(100):
m = (l + r) / 2
left = x[0] - m * v[0]
right = x[0] + m * v[0]
f = 1
for i in range(1, n):
l1 = x[i] - m * v[i]
r1 = x[i] + m * v[i]
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
n = int(input())
x = list(map(int, input().split()))
v = list(map(int, input().split()))
l = -1
r = 10000000000
for e in range(100):
m = (l + r) / 2
left = x[0] - m * v[0]
right = x[0] + m * v[0]
f = 1
for i in range(1, n):
l1 = x[i] - m * v[i]
r1 = x[i] + m * v... | 0 | |
911 | D | Inversion Counting | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* and *a**i*<=<<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=1500) — the size of the permutation.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of the permutation. These integers are pairwise distinct.
The third line contains one integer *m* (1<=≤<=*m*<=≤<=2·105) — the... | Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise. | [
"3\n1 2 3\n2\n1 2\n2 3\n",
"4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n"
] | [
"odd\neven\n",
"odd\nodd\nodd\neven\n"
] | The first example:
1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2).
The second example:
1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], i... | 0 | [
{
"input": "3\n1 2 3\n2\n1 2\n2 3",
"output": "odd\neven"
},
{
"input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3",
"output": "odd\nodd\nodd\neven"
},
{
"input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5",
"output": "odd\nodd\neven\nodd\neven"
},
{
"input": "3\n2 1 3\n3\n2 3\n1 ... | 1,523,042,919 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 1,263 | 7,782,400 | from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
cnt = 0
for i in range(n):
for j in range(i + 1, n):
if values[i] > values[j]:
cnt += 1
m = int(stdin.readline())
for i in range(m):
l, r = map(int, stdin.readline().spli... | Title: Inversion Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=><=*j* an... | ```python
from sys import stdin, stdout
n = int(stdin.readline())
values = list(map(int, stdin.readline().split()))
cnt = 0
for i in range(n):
for j in range(i + 1, n):
if values[i] > values[j]:
cnt += 1
m = int(stdin.readline())
for i in range(m):
l, r = map(int, stdin.readl... | 3 | |
802 | G | Fake News (easy) | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it... | The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z). | Output YES if the string *s* contains heidi as a subsequence and NO otherwise. | [
"abcheaibcdi\n",
"hiedi\n"
] | [
"YES",
"NO"
] | A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*. | 0 | [
{
"input": "abcheaibcdi",
"output": "YES"
},
{
"input": "hiedi",
"output": "NO"
},
{
"input": "ihied",
"output": "NO"
},
{
"input": "diehi",
"output": "NO"
},
{
"input": "deiih",
"output": "NO"
},
{
"input": "iheid",
"output": "NO"
},
{
"in... | 1,575,366,354 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 202 | 2,150,400 | s = input()
a = 'heidi'
q = 0
for i in s:
if i == a[q]:
q += 1
print('YES' if q == 5 else 'NO')
# FMZJMSOMPMSL
| Title: Fake News (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ... | ```python
s = input()
a = 'heidi'
q = 0
for i in s:
if i == a[q]:
q += 1
print('YES' if q == 5 else 'NO')
# FMZJMSOMPMSL
``` | -1 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,652,534,002 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 31 | 0 | n, k = input().split()
n, k = int(n), int(k)
rez = 0
a = input().split()
for i in range(len(a)):
a[i] = int(a[i]) + k
for i in a:
if i <= 5:
rez += 1
print(rez // 3)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = input().split()
n, k = int(n), int(k)
rez = 0
a = input().split()
for i in range(len(a)):
a[i] = int(a[i]) + k
for i in a:
if i <= 5:
rez += 1
print(rez // 3)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,689,331,376 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | import collections
n = int(input())
d = collections.defaultdict(int)
l = list()
for i in range(n):
x, y = input().split(' ')
d[x] += int(y)
l.append((x, y))
m = 0
name = list()
for key, val in d.items():
if val == m:
name.append(key)
elif val > m:
name.clear()
... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
import collections
n = int(input())
d = collections.defaultdict(int)
l = list()
for i in range(n):
x, y = input().split(' ')
d[x] += int(y)
l.append((x, y))
m = 0
name = list()
for key, val in d.items():
if val == m:
name.append(key)
elif val > m:
name.cl... | 0 |
313 | B | Ilya and Queries | PROGRAMMING | 1,100 | [
"dp",
"implementation"
] | null | null | Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<... | The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#".
The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t... | Print *m* integers — the answers to the queries in the order in which they are given in the input. | [
"......\n4\n3 4\n2 3\n1 6\n2 6\n",
"#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n"
] | [
"1\n1\n5\n4\n",
"1\n1\n2\n2\n0\n"
] | none | 1,000 | [
{
"input": "......\n4\n3 4\n2 3\n1 6\n2 6",
"output": "1\n1\n5\n4"
},
{
"input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4",
"output": "1\n1\n2\n2\n0"
},
{
"input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3",
"output": "2\n0\n0\n1\n2\n0"
},
{
"input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5... | 1,693,565,132 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 404 | 14,950,400 | from sys import stdin
def input(): return stdin.readline()[:-1]
a=list(input())
n=len(a)
p=[0]*(n+1)
if a[0]==a[1]:
p[1]=1
for i in range(1,n-1):
if a[i]==a[i+1]:
p[i+1]=p[i]+1
else:
p[i+1]=p[i]
q=int(input())
for i in range(q):
l,r=map(int,input().split())
print(p[r-1]-p[l-1]) | Title: Ilya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam.
You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ... | ```python
from sys import stdin
def input(): return stdin.readline()[:-1]
a=list(input())
n=len(a)
p=[0]*(n+1)
if a[0]==a[1]:
p[1]=1
for i in range(1,n-1):
if a[i]==a[i+1]:
p[i+1]=p[i]+1
else:
p[i+1]=p[i]
q=int(input())
for i in range(q):
l,r=map(int,input().split())
print(p[r-1]-p[l-1])
``` | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,661,953,570 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | # cook your dish here
y,w = map(int,input().split())
if y>w:
res = y
else:
res = w
res = (6-res) + 1
l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"]
print(l[res]) | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
# cook your dish here
y,w = map(int,input().split())
if y>w:
res = y
else:
res = w
res = (6-res) + 1
l = ["0/1","1/6","1/3","1/2","2/3","5/6","1/1"]
print(l[res])
``` | 3.954 |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,514,031,794 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 5,529,600 | m=int(input())
cnt=0
cnt1=0
for i in range(m):
m,n=map(int,input().split())
if m>0:
cnt+=1
if m<0:
cnt1+=1
if cnt==m or cnt==m-1 or cnt==0 or cnt==1:
print("Yes")
else:
print("No")
| Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
m=int(input())
cnt=0
cnt1=0
for i in range(m):
m,n=map(int,input().split())
if m>0:
cnt+=1
if m<0:
cnt1+=1
if cnt==m or cnt==m-1 or cnt==0 or cnt==1:
print("Yes")
else:
print("No")
``` | 0 | |
245 | A | System Administrator | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x... | In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes).
In the second line print the state of server *b* in the similar format. | [
"2\n1 5 5\n2 6 4\n",
"3\n1 0 10\n2 0 10\n1 10 0\n"
] | [
"LIVE\nLIVE\n",
"LIVE\nDEAD\n"
] | Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t... | 0 | [
{
"input": "2\n1 5 5\n2 6 4",
"output": "LIVE\nLIVE"
},
{
"input": "3\n1 0 10\n2 0 10\n1 10 0",
"output": "LIVE\nDEAD"
},
{
"input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9",
"output": "DEAD\nLIVE"
},
{
"input": "11\n1 8 2\n1 6 4\n1 9 1\n1... | 1,599,983,351 | 2,147,483,647 | Python 3 | OK | TESTS | 13 | 218 | 307,200 | def check(n1, n2):
if n1 >= n2:
print("LIVE")
else:
print("DEAD")
a_rec, a_nrec = 0, 0
b_rec, b_nrec = 0, 0
for _ in range(int(input())):
t, x, y = [int(j) for j in input().split()]
if t == 1:
a_rec += x
a_nrec += y
else:
b_rec += x
b_nre... | Title: System Administrator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co... | ```python
def check(n1, n2):
if n1 >= n2:
print("LIVE")
else:
print("DEAD")
a_rec, a_nrec = 0, 0
b_rec, b_nrec = 0, 0
for _ in range(int(input())):
t, x, y = [int(j) for j in input().split()]
if t == 1:
a_rec += x
a_nrec += y
else:
b_rec += x
... | 3 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,513,694,802 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 5,836,800 | import math
n,pos = map(int,input().split())
times = n
nums = []
for i in range(1,times+1):
if(n%i == 0):
nums.append(i)
if(len(nums)>0 and len(nums)>=pos):
print(nums[pos-1])
else:
print("-1")
| Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
import math
n,pos = map(int,input().split())
times = n
nums = []
for i in range(1,times+1):
if(n%i == 0):
nums.append(i)
if(len(nums)>0 and len(nums)>=pos):
print(nums[pos-1])
else:
print("-1")
``` | 0 | |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,680,920,229 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 307,200 | n = int(input())
times = [input() for _ in range(n)]
print(max(times.count(time) for time in times)) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n = int(input())
times = [input() for _ in range(n)]
print(max(times.count(time) for time in times))
``` | 0 | |
440 | B | Balancer | PROGRAMMING | 1,600 | [
"greedy",
"implementation"
] | null | null | Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move. How many such moves does he need to achieve the desired c... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). The second line contains *n* non-negative numbers that do not exceed 109, the *i*-th written number is the number of matches in the *i*-th matchbox. It is guaranteed that the total number of matches is divisible by *n*. | Print the total minimum number of moves. | [
"6\n1 6 2 5 3 7\n"
] | [
"12\n"
] | none | 1,000 | [
{
"input": "6\n1 6 2 5 3 7",
"output": "12"
},
{
"input": "6\n6 6 6 0 0 0",
"output": "27"
},
{
"input": "6\n0 0 0 6 6 6",
"output": "27"
},
{
"input": "6\n6 6 0 0 6 6",
"output": "12"
},
{
"input": "5\n0 0 0 0 0",
"output": "0"
},
{
"input": "10\n0 10... | 1,401,812,532 | 3,132 | Python 3 | OK | TESTS | 53 | 218 | 4,198,400 | import itertools
n = int(input())
a = map(int, input().split())
a = list(itertools.accumulate(a))
need_one = a[-1] // n
ans = 0
for i in range(len(a) - 1):
ans += abs((i + 1) * need_one - a[i])
print(ans)
| Title: Balancer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has *k* matches, placed in *n* matchboxes lying in a line from left to right. We know that *k* is divisible by *n*. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its ... | ```python
import itertools
n = int(input())
a = map(int, input().split())
a = list(itertools.accumulate(a))
need_one = a[-1] // n
ans = 0
for i in range(len(a) - 1):
ans += abs((i + 1) * need_one - a[i])
print(ans)
``` | 3 | |
549 | H | Degenerate Matrix | PROGRAMMING | 2,100 | [
"binary search",
"math"
] | null | null | The determinant of a matrix 2<=×<=2 is defined as follows:
A matrix is called degenerate if its determinant is equal to zero.
The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its elements.
You are given a matrix . Consider any degenerate matrix *B* such that norm ||*A*<=-<=*B*|| is min... | The first line contains two integers *a* and *b* (|*a*|,<=|*b*|<=≤<=109), the elements of the first row of matrix *A*.
The second line contains two integers *c* and *d* (|*c*|,<=|*d*|<=≤<=109) the elements of the second row of matrix *A*. | Output a single real number, the minimum possible value of ||*A*<=-<=*B*||. Your answer is considered to be correct if its absolute or relative error does not exceed 10<=-<=9. | [
"1 2\n3 4\n",
"1 0\n0 1\n"
] | [
"0.2000000000\n",
"0.5000000000\n"
] | In the first sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ce214ad27bde5d77f87492eedd74d34c745f72a1.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In the second sample matrix *B* is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a0... | 1,500 | [
{
"input": "1 2\n3 4",
"output": "0.2000000000"
},
{
"input": "1 0\n0 1",
"output": "0.5000000000"
},
{
"input": "1000000000 0\n0 1000000000",
"output": "500000000.0000000000"
},
{
"input": "8205 9482\n11 -63",
"output": "35.0198432832"
},
{
"input": "0 0\n0 0",
... | 1,512,313,808 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 5,529,600 | f = lambda: map(int, input().split())
a, b = f()
c, d = f()
x = abs((a * d - b * c) / (a - c))
y = abs((a * d - b * c) / (d - b))
u = abs(a * a - c * c) / 2
v = abs(b * b - d * d) / 2
print(min(x * y / (x + y), abs((u - v) / (a + b + c + d)))) | Title: Degenerate Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The determinant of a matrix 2<=×<=2 is defined as follows:
A matrix is called degenerate if its determinant is equal to zero.
The norm ||*A*|| of a matrix *A* is defined as a maximum of absolute values of its eleme... | ```python
f = lambda: map(int, input().split())
a, b = f()
c, d = f()
x = abs((a * d - b * c) / (a - c))
y = abs((a * d - b * c) / (d - b))
u = abs(a * a - c * c) / 2
v = abs(b * b - d * d) / 2
print(min(x * y / (x + y), abs((u - v) / (a + b + c + d))))
``` | 0 | |
180 | C | Letter | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.
Patrick believes that a message is fancy if any uppercase letter stands to... | The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. | Print a single number — the least number of actions needed to make the message fancy. | [
"PRuvetSTAaYA\n",
"OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n",
"helloworld\n"
] | [
"5\n",
"0\n",
"0\n"
] | none | 0 | [
{
"input": "PRuvetSTAaYA",
"output": "5"
},
{
"input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA",
"output": "0"
},
{
"input": "helloworld",
"output": "0"
},
{
"input": "P",
"output": "0"
},
{
"input": "t",
"output": "0"
},
{
"input": "XdJ",
"output": "1... | 1,575,117,428 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 310 | 2,355,200 | s = input()
up_cnt = 0
low_cnt = 0
for i in s:
if i.isupper():
up_cnt += 1
else:
low_cnt += 1
cur_up = 0
cur_low = 0
ans = 1000000000
cost = up_cnt
for i in s:
if i.isupper():
cur_up += 1
else:
cur_low += 1
a = cur_low + up_cnt - cur_up
if a < an... | Title: Letter
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them... | ```python
s = input()
up_cnt = 0
low_cnt = 0
for i in s:
if i.isupper():
up_cnt += 1
else:
low_cnt += 1
cur_up = 0
cur_low = 0
ans = 1000000000
cost = up_cnt
for i in s:
if i.isupper():
cur_up += 1
else:
cur_low += 1
a = cur_low + up_cnt - cur_up
... | 3 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=≤<=*h**i*,<=*v**i*<=≤<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,443,893,347 | 2,647 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | #!/usr/bin/python3
'''
Created on Sep 25, 2015
@author: kate
'''
n = int(input())
x = y = [0 for i in range(n+1)]
res = []
for i in range(n ** 2):
roads =[int(j) for j in input().split()]
if x[roads[0]] == 0 and y[roads[1]] == 0:
res.append(i + 1)
x[roads[0]] = y[roads[1]] = 1
print (sorted(re... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=×<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
#!/usr/bin/python3
'''
Created on Sep 25, 2015
@author: kate
'''
n = int(input())
x = y = [0 for i in range(n+1)]
res = []
for i in range(n ** 2):
roads =[int(j) for j in input().split()]
if x[roads[0]] == 0 and y[roads[1]] == 0:
res.append(i + 1)
x[roads[0]] = y[roads[1]] = 1
print ... | 0 | |
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result... | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"in... | 1,580,477,676 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | s = input()
l = list(s)
s1 = set(l)
if(len(l)!=len(s1)):
print("NO")
else:
print("YES")
| Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont... | ```python
s = input()
l = list(s)
s1 = set(l)
if(len(l)!=len(s1)):
print("NO")
else:
print("YES")
``` | 0 | |
598 | D | Igor In the Museum | PROGRAMMING | 1,700 | [
"dfs and similar",
"graphs",
"shortest paths"
] | null | null | Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i... | First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process.
Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ... | Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position. | [
"5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n",
"4 4 1\n****\n*..*\n*.**\n****\n3 2\n"
] | [
"6\n4\n10\n",
"8\n"
] | none | 0 | [
{
"input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3",
"output": "6\n4\n10"
},
{
"input": "4 4 1\n****\n*..*\n*.**\n****\n3 2",
"output": "8"
},
{
"input": "3 3 1\n***\n*.*\n***\n2 2",
"output": "4"
},
{
"input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\... | 1,650,679,378 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 614,400 | from sys import stdin
input=lambda :stdin.readline()[:-1]
#UnionFind
from collections import defaultdict
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
... | Title: Igor In the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'... | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
#UnionFind
from collections import defaultdict
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
... | 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,541,589,931 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 109 | 0 | a=int(input())
if a/2==0:
b=a/2-1
c=a-b
else:
b=a//2
c=a-b
print(b+" "+c) | 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
a=int(input())
if a/2==0:
b=a/2-1
c=a-b
else:
b=a//2
c=a-b
print(b+" "+c)
``` | -1 | |
946 | C | String Transformation | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter.
Your target is to make some number... | The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters. | If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes). | [
"aacceeggiikkmmooqqssuuwwyy\n",
"thereisnoanswer\n"
] | [
"abcdefghijklmnopqrstuvwxyz\n",
"-1\n"
] | none | 0 | [
{
"input": "aacceeggiikkmmooqqssuuwwyy",
"output": "abcdefghijklmnopqrstuvwxyz"
},
{
"input": "thereisnoanswer",
"output": "-1"
},
{
"input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs",
"output": "-1"
},
{
"input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen... | 1,669,052,833 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | import bisect
def transform_str(s):
if len(s) < 26:
return None
pos_list = []
for i in range(26):
pos_list.append([])
for i in range(len(s)):
pos_list[ord(s[i]) - ord('a')] += [i]
not_greater_pos = []
for i in range(26):
if i == 0:
... | Title: String Transformation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *s* consisting of |*s*| small english letters.
In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep... | ```python
import bisect
def transform_str(s):
if len(s) < 26:
return None
pos_list = []
for i in range(26):
pos_list.append([])
for i in range(len(s)):
pos_list[ord(s[i]) - ord('a')] += [i]
not_greater_pos = []
for i in range(26):
if i == ... | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,639,826,389 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,k = map(int,input().split())
count = 0
for i in range(n):
a = input()
a = list(map(int,a))
if sorted(list(a)) == [b for b in range(k+1)]:
count+=1
print(count)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n,k = map(int,input().split())
count = 0
for i in range(n):
a = input()
a = list(map(int,a))
if sorted(list(a)) == [b for b in range(k+1)]:
count+=1
print(count)
``` | 0 | |
911 | A | Nearest Minimums | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. | The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times. | Print the only number — distance between two nearest minimums in the array. | [
"2\n3 3\n",
"3\n5 6 5\n",
"9\n2 1 3 5 4 1 2 3 1\n"
] | [
"1\n",
"2\n",
"3\n"
] | none | 0 | [
{
"input": "2\n3 3",
"output": "1"
},
{
"input": "3\n5 6 5",
"output": "2"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1",
"output": "3"
},
{
"input": "6\n4 6 7 8 6 4",
"output": "5"
},
{
"input": "2\n1000000000 1000000000",
"output": "1"
},
{
"input": "42\n1 1 ... | 1,589,237,582 | 2,147,483,647 | Python 3 | OK | TESTS | 140 | 187 | 9,523,200 | _=int(input())
A=list(map(int,input().split()))
xmin=min(*A)
index=[]
for i in range(len(A)):
if A[i]==xmin:
index.append(i)
m=[]
for i in range(len(index)-1):
m.append(index[i+1]-index[i])
print(min(m)) | Title: Nearest Minimums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
I... | ```python
_=int(input())
A=list(map(int,input().split()))
xmin=min(*A)
index=[]
for i in range(len(A)):
if A[i]==xmin:
index.append(i)
m=[]
for i in range(len(index)-1):
m.append(index[i+1]-index[i])
print(min(m))
``` | 3 | |
779 | A | Pupils Redistribution | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consists of exactly *n* students. An academic performance of each student is known — integer value between 1 and ... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=100) — number of students in both groups.
The second line contains sequence of integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5), where *a**i* is academic performance of the *i*-th student of the group *A*.
The third line contains se... | Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. | [
"4\n5 4 4 4\n5 5 4 5\n",
"6\n1 1 1 1 1 1\n5 5 5 5 5 5\n",
"1\n5\n3\n",
"9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1\n"
] | [
"1\n",
"3\n",
"-1\n",
"4\n"
] | none | 500 | [
{
"input": "4\n5 4 4 4\n5 5 4 5",
"output": "1"
},
{
"input": "6\n1 1 1 1 1 1\n5 5 5 5 5 5",
"output": "3"
},
{
"input": "1\n5\n3",
"output": "-1"
},
{
"input": "9\n3 2 5 5 2 3 3 3 2\n4 1 4 1 1 2 4 4 1",
"output": "4"
},
{
"input": "1\n1\n2",
"output": "-1"
... | 1,488,108,543 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 62 | 4,608,000 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]*6
for v in a: aa[v] += 1
bb = [0]*6
for v in b: bb[v] += 1
res = sum(map(lambda x, y: max(x-y, 0), aa, bb))
if any(map(lambda x, y: (x-y) & 1, aa, bb)):
print(-1)
else:
print(res//2) | Title: Pupils Redistribution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland each high school student is characterized by academic performance — integer value between 1 and 5.
In high school 0xFF there are two groups of pupils: the group *A* and the group *B*. Each group consis... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aa = [0]*6
for v in a: aa[v] += 1
bb = [0]*6
for v in b: bb[v] += 1
res = sum(map(lambda x, y: max(x-y, 0), aa, bb))
if any(map(lambda x, y: (x-y) & 1, aa, bb)):
print(-1)
else:
print(res//2)
``` | 3 | |
808 | C | Tea Party | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"sortings"
] | null | null | Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<=*a*2<=+<=...<=+<=*a**n*). Polycarp wants to pour tea in cups in such a way that:
- Every cup... | The first line contains two integer numbers *n* and *w* (1<=≤<=*n*<=≤<=100, ).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output how many milliliters of tea every cup should contain. If there are multiple answers, print any of them.
If it's impossible to pour all the tea and satisfy all conditions then output -1. | [
"2 10\n8 7\n",
"4 4\n1 1 1 1\n",
"3 10\n9 8 10\n"
] | [
"6 4 \n",
"1 1 1 1 \n",
"-1\n"
] | In the third example you should pour to the first cup at least 5 milliliters, to the second one at least 4, to the third one at least 5. It sums up to 14, which is greater than 10 milliliters available. | 0 | [
{
"input": "2 10\n8 7",
"output": "6 4 "
},
{
"input": "4 4\n1 1 1 1",
"output": "1 1 1 1 "
},
{
"input": "3 10\n9 8 10",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "1 "
},
{
"input": "1 1\n2",
"output": "1 "
},
{
"input": "1 10\n20",
"output... | 1,638,711,156 | 1,056 | PyPy 3 | OK | TESTS | 29 | 93 | 0 | n, w = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i, a in enumerate(A):
B.append((a, i))
B.sort(key=lambda x: x[0])
m = 0
ans = [0]*n
for a, i in B:
ans[i] = (a+1)//2
m += (a+1)//2
if m > w:
print(-1)
exit()
r = w-m
for j in reversed(range(n)):
if r ... | Title: Tea Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has *n* cups, one for each of his *n* friends, with volumes *a*1,<=*a*2,<=...,<=*a**n*. His teapot stores *w* milliliters of tea (*w*<=≤<=*a*1<=+<... | ```python
n, w = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i, a in enumerate(A):
B.append((a, i))
B.sort(key=lambda x: x[0])
m = 0
ans = [0]*n
for a, i in B:
ans[i] = (a+1)//2
m += (a+1)//2
if m > w:
print(-1)
exit()
r = w-m
for j in reversed(range(n)):
... | 3 | |
181 | A | Series of Crimes | PROGRAMMING | 800 | [
"brute force",
"geometry",
"implementation"
] | null | null | The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital.
The capital's main detective Polycarpus took a map and m... | The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly.
Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact... | Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. | [
"3 2\n.*\n..\n**\n",
"3 3\n*.*\n*..\n...\n"
] | [
"1 1\n",
"2 3\n"
] | none | 500 | [
{
"input": "3 2\n.*\n..\n**",
"output": "1 1"
},
{
"input": "2 5\n*....\n*...*",
"output": "1 5"
},
{
"input": "7 2\n..\n**\n..\n..\n..\n..\n.*",
"output": "7 1"
},
{
"input": "7 2\n*.\n..\n..\n..\n..\n..\n**",
"output": "1 2"
},
{
"input": "2 10\n*......*..\n....... | 1,661,187,562 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | L = [int(h) for h in input().split(' ')]
n = L[0]; m = L[1]
if ((n >= 2) and (n <= 100) and (m >= 2) and (m <= 100)):
N = M = list()
for i in range(0, n):
R = list()
s = input()
for j in range(0, len(s)):
R = R + [s[j]]
for k in range(0, len(R)):
... | Title: Series of Crimes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang.
The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma... | ```python
L = [int(h) for h in input().split(' ')]
n = L[0]; m = L[1]
if ((n >= 2) and (n <= 100) and (m >= 2) and (m <= 100)):
N = M = list()
for i in range(0, n):
R = list()
s = input()
for j in range(0, len(s)):
R = R + [s[j]]
for k in range(0, len(R)):
... | 3 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,660,387,243 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | s = input()
short = " "*200
ll = list()
for i in range(int(input())):
l = input()
if l.startswith(s) and len(l) < len(short):
short = l
ll.append(short)
if len(ll) == 0:
print(s)
else: min(ll) | Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s = input()
short = " "*200
ll = list()
for i in range(int(input())):
l = input()
if l.startswith(s) and len(l) < len(short):
short = l
ll.append(short)
if len(ll) == 0:
print(s)
else: min(ll)
``` | 0 |
1,010 | A | Fly | PROGRAMMING | 1,500 | [
"binary search",
"math"
] | null | null | Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will make exactly $n$ flights: $1 \to 2 \to \ldots n \to 1$.
Flight from $x$ to $y$ consists ... | The first line contains a single integer $n$ ($2 \le n \le 1000$) — number of planets.
The second line contains the only integer $m$ ($1 \le m \le 1000$) — weight of the payload.
The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 1000$), where $a_i$ is the number of tons, which can be lifted... | If Natasha can fly to Mars through $(n - 2)$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $-1$.
It is guaranteed, that if Natasha can make a flight, then it takes no more than $10^9$ tons of fuel.
The answer will be considered correct... | [
"2\n12\n11 8\n7 5\n",
"3\n1\n1 4 1\n2 5 3\n",
"6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3\n"
] | [
"10.0000000000\n",
"-1\n",
"85.4800000000\n"
] | Let's consider the first example.
Initially, the mass of a rocket with fuel is $22$ tons.
- At take-off from Earth one ton of fuel can lift off $11$ tons of cargo, so to lift off $22$ tons you need to burn $2$ tons of fuel. Remaining weight of the rocket with fuel is $20$ tons.- During landing on Mars, one ton of fu... | 500 | [
{
"input": "2\n12\n11 8\n7 5",
"output": "10.0000000000"
},
{
"input": "3\n1\n1 4 1\n2 5 3",
"output": "-1"
},
{
"input": "6\n2\n4 6 3 3 5 6\n2 6 3 6 5 3",
"output": "85.4800000000"
},
{
"input": "3\n3\n1 2 1\n2 2 2",
"output": "-1"
},
{
"input": "4\n4\n2 3 2 2\n2... | 1,542,195,237 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 0 | p=[]
b=int(input())
a=str(input())
p=a.split(" ")
p.sort()
p.reverse()
if p[1]=='1':
print('HARD')
else:
print('EASY')
| Title: Fly
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $n - 2$ intermediate planets. Formally: we number all the planets from $1$ to $n$. $1$ is Earth, $n$ is Mars. Natasha will ... | ```python
p=[]
b=int(input())
a=str(input())
p=a.split(" ")
p.sort()
p.reverse()
if p[1]=='1':
print('HARD')
else:
print('EASY')
``` | -1 | |
762 | A | k-th divisor | PROGRAMMING | 1,400 | [
"math",
"number theory"
] | null | null | You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). | If *n* has less than *k* divisors, output -1.
Otherwise, output the *k*-th smallest divisor of *n*. | [
"4 2\n",
"5 3\n",
"12 5\n"
] | [
"2\n",
"-1\n",
"6\n"
] | In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. | 0 | [
{
"input": "4 2",
"output": "2"
},
{
"input": "5 3",
"output": "-1"
},
{
"input": "12 5",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "866421317361600 26880",
"output": "866421317361600"
},
{
"input": "866421317361600 26881",
"ou... | 1,559,319,746 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 78 | 0 | s=[int(n) for n in input().split()]
n=s[0]
k=s[1]
z=[]
for a in range(1,int(n**.5)+1):
if n%a==0:
z.append(a)
if n/a!=a:
z.append(n//a)
if k>len(z):
print(-1)
else:
print(z[k-1]) | Title: k-th divisor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist.
Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
Input Specificatio... | ```python
s=[int(n) for n in input().split()]
n=s[0]
k=s[1]
z=[]
for a in range(1,int(n**.5)+1):
if n%a==0:
z.append(a)
if n/a!=a:
z.append(n//a)
if k>len(z):
print(-1)
else:
print(z[k-1])
``` | 0 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The 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,637,992,189 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a = list(map(ord,input()))
A = ord("A")
Z = ord("Z")
ans = 0
curr = 0
for i in a:
x = i - A
curr = x
ans += min(abs(x-curr), 26 -(x- curr))
print(ans)
| 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
a = list(map(ord,input()))
A = ord("A")
Z = ord("Z")
ans = 0
curr = 0
for i in a:
x = i - A
curr = x
ans += min(abs(x-curr), 26 -(x- curr))
print(ans)
``` | 0 | |
933 | B | A Determined Cleanup | PROGRAMMING | 2,000 | [
"math"
] | null | null | In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this...
Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficien... | The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000). | If the polynomial does not exist, print a single integer -1, or output two lines otherwise.
In the first line print a non-negative integer *d* — the number of coefficients in the polynomial.
In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the... | [
"46 2\n",
"2018 214\n"
] | [
"7\n0 1 0 0 1 1 1\n",
"3\n92 205 1\n"
] | In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·... | 750 | [
{
"input": "46 2",
"output": "7\n0 1 0 0 1 1 1"
},
{
"input": "2018 214",
"output": "3\n92 205 1"
},
{
"input": "4 2",
"output": "3\n0 0 1"
},
{
"input": "5 2",
"output": "3\n1 0 1"
},
{
"input": "10 3",
"output": "3\n1 0 1"
},
{
"input": "250 1958",
... | 1,626,710,156 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 39 | 109 | 20,172,800 | import sys
import math
from math import *
import builtins
input = sys.stdin.readline
def print(x, end='\n'):
sys.stdout.write(str(x) + end)
# IO helpers
def get_int():
return int(input())
def get_list_ints():
return list(map(int, input().split()))
def get_char_list():
s = ... | Title: A Determined Cleanup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must.
Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doin... | ```python
import sys
import math
from math import *
import builtins
input = sys.stdin.readline
def print(x, end='\n'):
sys.stdout.write(str(x) + end)
# IO helpers
def get_int():
return int(input())
def get_list_ints():
return list(map(int, input().split()))
def get_char_list():... | 0 | |
650 | A | Watchmen | PROGRAMMING | 1,400 | [
"data structures",
"geometry",
"math"
] | null | null | Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen.
Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109).
Some positions may coincide. | Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. | [
"3\n1 1\n7 5\n1 5\n",
"6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n"
] | [
"2\n",
"11\n"
] | In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs... | 500 | [
{
"input": "3\n1 1\n7 5\n1 5",
"output": "2"
},
{
"input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1",
"output": "11"
},
{
"input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55",
"output": "33"
},
{
"input": "1\n-5 -90",
"output": "0"
},
{
... | 1,612,437,564 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 2,215 | 34,816,000 | """ import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w') """
q = {}
w = {}
e = {}
r = 0
for _ in range(int(input())):
x, y = map(int, input().split())
a, s, d = q.get(x, 0), w.get(y, 0), e.get((x, y), 0)
r += a + s - d
q[x], w[y], e[x, y] = a + 1, s + 1, d + 1
p... | Title: Watchmen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*).
They n... | ```python
""" import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w') """
q = {}
w = {}
e = {}
r = 0
for _ in range(int(input())):
x, y = map(int, input().split())
a, s, d = q.get(x, 0), w.get(y, 0), e.get((x, y), 0)
r += a + s - d
q[x], w[y], e[x, y] = a + 1, s + 1... | 3 | |
202 | A | LLPS | PROGRAMMING | 800 | [
"binary search",
"bitmasks",
"brute force",
"greedy",
"implementation",
"strings"
] | null | null | This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*... | The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. | Print the lexicographically largest palindromic subsequence of string *s*. | [
"radar\n",
"bowwowwow\n",
"codeforces\n",
"mississipp\n"
] | [
"rr\n",
"wwwww\n",
"s\n",
"ssss\n"
] | Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr". | 500 | [
{
"input": "radar",
"output": "rr"
},
{
"input": "bowwowwow",
"output": "wwwww"
},
{
"input": "codeforces",
"output": "s"
},
{
"input": "mississipp",
"output": "ssss"
},
{
"input": "tourist",
"output": "u"
},
{
"input": "romka",
"output": "r"
},
... | 1,658,052,044 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 124 | 0 | s = input()
M = sorted(list(s))[-1]
ans = ""
for c in s:
if c == M:
ans += M
print(ans)
| Title: LLPS
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest ... | ```python
s = input()
M = sorted(list(s))[-1]
ans = ""
for c in s:
if c == M:
ans += M
print(ans)
``` | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,641,832,999 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 155 | 716,800 | a = input()
b = input()
c = len(a)
d = len(b)
while c * d * (a[c - 1] == b[d - 1]):
c = c - 1
d = d - 1
print(c + d)
| Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
a = input()
b = input()
c = len(a)
d = len(b)
while c * d * (a[c - 1] == b[d - 1]):
c = c - 1
d = d - 1
print(c + d)
``` | 3 | |
991 | C | Candies | PROGRAMMING | 1,500 | [
"binary search",
"implementation"
] | null | null | After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for himself.
This means the process of eating candies is the following: in the beginning Vasya cho... | The first line contains a single integer $n$ ($1 \leq n \leq 10^{18}$) — the initial amount of candies in the box. | Output a single integer — the minimal amount of $k$ that would allow Vasya to eat at least half of candies he got. | [
"68\n"
] | [
"3\n"
] | In the sample, the amount of candies, with $k=3$, would change in the following way (Vasya eats first):
$68 \to 65 \to 59 \to 56 \to 51 \to 48 \to 44 \to 41 \\ \to 37 \to 34 \to 31 \to 28 \to 26 \to 23 \to 21 \to 18 \to 17 \to 14 \\ \to 13 \to 10 \to 9 \to 6 \to 6 \to 3 \to 3 \to 0$.
In total, Vasya would eat $39$ ca... | 1,250 | [
{
"input": "68",
"output": "3"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "42",
"output": "1"
},
{
"input": "43",
"output": "2"
},
{
"input": "756",
"output": "29"
},
{
"input": "999999972",
"output"... | 1,538,552,977 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | n = int(input())
lo = 1
hi = n
def check(k):
global n
cp = n
a = 0
b = 0
while n>0:
a += min(n, k)
n -= min(n, k)
if n==0:
break
b += n//10
n -= n//10
if n<=0:
break
#print('for',k,a,b)
n = cp
... | Title: Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After passing a test, Vasya got himself a box of $n$ candies. He decided to eat an equal amount of candies each morning until there are no more candies. However, Petya also noticed the box and decided to get some candies for hi... | ```python
n = int(input())
lo = 1
hi = n
def check(k):
global n
cp = n
a = 0
b = 0
while n>0:
a += min(n, k)
n -= min(n, k)
if n==0:
break
b += n//10
n -= n//10
if n<=0:
break
#print('for',k,a,b)
n ... | 0 | |
958 | F1 | Lightsabers (easy) | PROGRAMMING | 1,500 | [
"implementation"
] | null | null | There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that the success of any peacekeeping mission depends on the colors of th... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=100) and *m* (1<=≤<=*m*<=≤<=*n*). The second line contains *n* integers in the range {1,<=2,<=...,<=*m*} representing colors of the lightsabers of the subsequent Jedi Knights. The third line contains *m* integers *k*1,<=*k*2,<=...,<=*k**m* (with ) – the desired co... | Output YES if an interval with prescribed color counts exists, or output NO if there is none. | [
"5 2\n1 1 2 2 1\n1 2\n"
] | [
"YES\n"
] | none | 0 | [
{
"input": "5 2\n1 1 2 2 1\n1 2",
"output": "YES"
},
{
"input": "1 1\n1\n1",
"output": "YES"
},
{
"input": "2 1\n1 1\n1",
"output": "YES"
},
{
"input": "2 1\n1 1\n2",
"output": "YES"
},
{
"input": "2 2\n1 2\n1 1",
"output": "YES"
},
{
"input": "3 3\n1 ... | 1,523,700,240 | 10,740 | PyPy 3 | RUNTIME_ERROR | TESTS | 5 | 155 | 22,425,600 | n,m = map(int,input().split())
l = list(map(int,input().split()))
k = list(map(int,input().split()))
temp = l[0]
j = 0
cnt = {l[0]:[1]}
for i in range(1,n):
if l[i] == temp:
cnt[temp][j] += 1
else:
temp = l[i]
if temp in cnt.keys():
cnt[temp].append(1)
... | Title: Lightsabers (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions througho... | ```python
n,m = map(int,input().split())
l = list(map(int,input().split()))
k = list(map(int,input().split()))
temp = l[0]
j = 0
cnt = {l[0]:[1]}
for i in range(1,n):
if l[i] == temp:
cnt[temp][j] += 1
else:
temp = l[i]
if temp in cnt.keys():
cnt[temp].append(1)
... | -1 | |
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,697,630,751 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x= int(input())
n =[]
y =[]
count = 0
while x:
if len(y) <= 3:
y.append(x)
if len(y) == 3:
n.append(y)
y=[]
for i in n:
for j in i:
if j == 1:
count +=1
if count >=2:
count = 1
return count
| 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
x= int(input())
n =[]
y =[]
count = 0
while x:
if len(y) <= 3:
y.append(x)
if len(y) == 3:
n.append(y)
y=[]
for i in n:
for j in i:
if j == 1:
count +=1
if count >=2:
count = 1
return count
... | -1 |
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.