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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
753 | A | Santa Claus and Candies | PROGRAMMING | 1,000 | [
"dp",
"greedy",
"math"
] | null | null | Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. | The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. | Print to the first line integer number *k* — maximal number of kids which can get candies.
Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*.
If there are many solutions, print any of them. | [
"5\n",
"9\n",
"2\n"
] | [
"2\n2 3\n",
"3\n3 5 1\n",
"1\n2 \n"
] | none | 500 | [
{
"input": "5",
"output": "2\n1 4 "
},
{
"input": "9",
"output": "3\n1 2 6 "
},
{
"input": "2",
"output": "1\n2 "
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "3",
"output": "2\n1 2 "
},
{
"input": "1000",
"output": "44\n1 2 3 4 5 6 7 8 9 10 ... | 1,633,246,774 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 6,758,400 | n = int(input())
nums = (-1 + int((1 + 8*n)**0.5))//2
res = ""
s = 0
for i in range(1, nums):
res += str(i) + " "
s += i
res += str(n - s)
print(nums)
print(res)
| Title: Santa Claus and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus has *n* candies, he dreams to give them as gifts to children.
What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n... | ```python
n = int(input())
nums = (-1 + int((1 + 8*n)**0.5))//2
res = ""
s = 0
for i in range(1, nums):
res += str(i) + " "
s += i
res += str(n - s)
print(nums)
print(res)
``` | 3 | |
580 | C | Kefa and Park | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs",
"trees"
] | null | null | Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v... | The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ... | A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats. | [
"4 1\n1 1 0 0\n1 2\n1 3\n1 4\n",
"7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n"
] | [
"2\n",
"2\n"
] | Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i... | 1,500 | [
{
"input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4",
"output": "2"
},
{
"input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7",
"output": "2"
},
{
"input": "3 2\n1 1 1\n1 2\n2 3",
"output": "0"
},
{
"input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5",
"output": "1"
},
{
"inpu... | 1,696,708,736 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 307,200 | from collections import defaultdict
n , k = list(map(int, input().split()))
cats = list(map(int, input().split()))
graph = defaultdict(list)
for _ in range(n-1):
start, end = list(map(int, input().split()))
graph[start].append(end)
graph[end].append(start)
visited = set()
def dfs(node, cat... | Title: Kefa and Park
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kefa decided to celebrate his first big salary by going to the restaurant.
He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house... | ```python
from collections import defaultdict
n , k = list(map(int, input().split()))
cats = list(map(int, input().split()))
graph = defaultdict(list)
for _ in range(n-1):
start, end = list(map(int, input().split()))
graph[start].append(end)
graph[end].append(start)
visited = set()
def dfs... | 0 | |
519 | A | A and B and Chess | PROGRAMMING | 900 | [
"implementation"
] | null | null | A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
- the queen's weight is 9, - the rook's weight is 5, - the bisho... | The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the kni... | Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. | [
"...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n",
"rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n",
"rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n"
] | [
"White\n",
"Draw\n",
"Black\n"
] | In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white piece... | 500 | [
{
"input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR",
"output": "Draw"
},
{
"input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..",
"output": "White"
},
{
"input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\... | 1,664,733,356 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | black = {'q':9, 'r':5, 'b':3, 'n':3, 'p':1, 'k':0}
white = {'Q':9, 'R':5, 'B':3, 'N':3, 'P':1, 'K':0}
b = 0
w = 0
doska = ''.join([input() for _ in range(8)])
for i in doska:
if i in black:
b += black[i]
elif i in white:
w += white[i]
if b == w:
print("Draw")
else:
print... | Title: A and B and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For eac... | ```python
black = {'q':9, 'r':5, 'b':3, 'n':3, 'p':1, 'k':0}
white = {'Q':9, 'R':5, 'B':3, 'N':3, 'P':1, 'K':0}
b = 0
w = 0
doska = ''.join([input() for _ in range(8)])
for i in doska:
if i in black:
b += black[i]
elif i in white:
w += white[i]
if b == w:
print("Draw")
else:
... | 3 | |
143 | A | Help Vasilisa the Wise 2 | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha... | The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum... | Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any. | [
"3 7\n4 6\n5 5\n",
"11 10\n13 8\n5 16\n",
"1 2\n3 4\n5 6\n",
"10 10\n10 10\n10 10\n"
] | [
"1 2\n3 4\n",
"4 7\n9 1\n",
"-1\n",
"-1\n"
] | Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | 500 | [
{
"input": "3 7\n4 6\n5 5",
"output": "1 2\n3 4"
},
{
"input": "11 10\n13 8\n5 16",
"output": "4 7\n9 1"
},
{
"input": "1 2\n3 4\n5 6",
"output": "-1"
},
{
"input": "10 10\n10 10\n10 10",
"output": "-1"
},
{
"input": "5 13\n8 10\n11 7",
"output": "3 2\n5 8"
... | 1,550,670,030 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 186 | 307,200 | r1, r2 = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())
m = min(r1, r2, c1, c2, d1, d2)
i = 1
while 1:
if m == c1:
x1 = m - i
x2 = c1 - x1
y1 = r1 - x1
y2 = c2 - y1
elif m == c2:
y1 = m - i
y2 = c2 - y1... | Title: Help Vasilisa the Wise 2
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha... | ```python
r1, r2 = map(int, input().split())
c1, c2 = map(int, input().split())
d1, d2 = map(int, input().split())
m = min(r1, r2, c1, c2, d1, d2)
i = 1
while 1:
if m == c1:
x1 = m - i
x2 = c1 - x1
y1 = r1 - x1
y2 = c2 - y1
elif m == c2:
y1 = m - i
y2... | 0 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* = - 2, *B* - *C* = 3.
In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,588,710,683 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 155 | 0 | n = int(input())
a = [int(x) for x in input().split()]
l = []
for i in a:
if i<0:
l.append(i)
else:
continue
print(sum(a)-2*sum(l)) | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n = int(input())
a = [int(x) for x in input().split()]
l = []
for i in a:
if i<0:
l.append(i)
else:
continue
print(sum(a)-2*sum(l))
``` | 3 | |
513 | A | Game | PROGRAMMING | 800 | [
"constructive algorithms",
"math"
] | null | null | Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2... | The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50.
This problem doesn't have subproblems. You will get 3 points for the correct submission. | Output "First" if the first player wins and "Second" otherwise. | [
"2 2 1 2\n",
"2 1 1 1\n"
] | [
"Second\n",
"First\n"
] | Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely. | 3 | [
{
"input": "2 2 1 2",
"output": "Second"
},
{
"input": "2 1 1 1",
"output": "First"
},
{
"input": "5 7 4 1",
"output": "Second"
},
{
"input": "5 7 1 4",
"output": "Second"
},
{
"input": "5 7 10 10",
"output": "Second"
},
{
"input": "5 7 1 10",
"out... | 1,630,321,648 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 6,963,200 | x=input()
n1=int((x.split(' '))[0])
n2=int((x.split(' '))[1])
k1=int((x.split(' '))[2])
k2=int((x.split(' '))[3])
if n1-n2>=1:
print('First')
elif (n2-n1>=1):
print('second')
elif(n1==n2):
if k1-k2>=1:
print('First')
elif (k2-k1>=1):
print('second') | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba... | ```python
x=input()
n1=int((x.split(' '))[0])
n2=int((x.split(' '))[1])
k1=int((x.split(' '))[2])
k2=int((x.split(' '))[3])
if n1-n2>=1:
print('First')
elif (n2-n1>=1):
print('second')
elif(n1==n2):
if k1-k2>=1:
print('First')
elif (k2-k1>=1):
print('second')
``` | 0 | |
641 | C | Little Artem and Dance | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a... | The first line of the input contains two integers *n* and *q* (2<=≤<=*n*<=≤<=1<=000<=000, 1<=≤<=*q*<=≤<=2<=000<=000) — the number of couples in the rueda and the number of commands to perform, respectively. It's guaranteed that *n* is even.
Next *q* lines contain the descriptions of the commands. Each command has type... | Output *n* integers, the *i*-th of them should be equal to the index of boy the *i*-th girl is dancing with after performing all *q* moves. | [
"6 3\n1 2\n2\n1 2\n",
"2 3\n1 1\n2\n1 -2\n",
"4 2\n2\n1 3\n"
] | [
"4 3 6 5 2 1\n",
"1 2\n",
"1 4 3 2\n"
] | none | 1,000 | [
{
"input": "6 3\n1 2\n2\n1 2",
"output": "4 3 6 5 2 1"
},
{
"input": "2 3\n1 1\n2\n1 -2",
"output": "1 2"
},
{
"input": "4 2\n2\n1 3",
"output": "1 4 3 2"
},
{
"input": "6 8\n1 2\n2\n2\n2\n2\n1 1\n1 -5\n2",
"output": "4 3 6 5 2 1"
},
{
"input": "6 8\n1 -1\n2\n2\n1... | 1,502,899,809 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 307,200 | # IAWT
n, q = list(map(int, input().split()))
one, two = 1, 2
for i in range(q):
l = list(map(int, input().split()))
if l == [2]:
if one % 2 == 1:
one += 1
two -= 1
else:
one -= 1
two += 1
else:
one += l[1]
two +... | Title: Little Artem and Dance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together.
More detailed, there are *n* pairs of boys and... | ```python
# IAWT
n, q = list(map(int, input().split()))
one, two = 1, 2
for i in range(q):
l = list(map(int, input().split()))
if l == [2]:
if one % 2 == 1:
one += 1
two -= 1
else:
one -= 1
two += 1
else:
one += l[1]
... | 0 | |
15 | A | Cottage Village | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Cottage Village | 2 | 64 | A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other.
The architect bureau, wher... | The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000... | Output the amount of possible positions of the new house. | [
"2 2\n0 4\n6 2\n",
"2 2\n0 4\n5 2\n",
"2 3\n0 4\n5 2\n"
] | [
"4\n",
"3\n",
"2\n"
] | It is possible for the *x*-coordinate of the new house to have non-integer value. | 0 | [
{
"input": "2 2\n0 4\n6 2",
"output": "4"
},
{
"input": "2 2\n0 4\n5 2",
"output": "3"
},
{
"input": "2 3\n0 4\n5 2",
"output": "2"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 2\n2 1",
"output": "2"
},
{
"input": "2 1\n2 1\n1 1",
"outp... | 1,624,035,793 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 124 | 0 | def main():
n, t = map(int, input().split()) #n:Número de casas, t:Lado de la casa que se quiere
spa = [] #Espacios entre las casas
x0, a0 = 0, 0 #Coordenadas de la casa anterior
for _ in range(n):
x1, a1 = map(float, input().split()) #x:Coordenada del centro de la casa, a:Lado de la ... | Title: Cottage Village
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. I... | ```python
def main():
n, t = map(int, input().split()) #n:Número de casas, t:Lado de la casa que se quiere
spa = [] #Espacios entre las casas
x0, a0 = 0, 0 #Coordenadas de la casa anterior
for _ in range(n):
x1, a1 = map(float, input().split()) #x:Coordenada del centro de la casa, a:L... | 0 |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,676,648,093 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 358 | 8,396,800 | n=int(input())
l1=[]
l2=[]
l3=[]
s1=0
s2=0
for i in range(n):
x=int(input())
if(x>=0):
l1.append(x)
s1+=x
else:
l2.append(abs(x))
s2+=abs(x)
l3.append(x)
if(s1>s2):
print("first")
elif(s2>s1):
print("second")
else:
if(l1>l2):
pri... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
n=int(input())
l1=[]
l2=[]
l3=[]
s1=0
s2=0
for i in range(n):
x=int(input())
if(x>=0):
l1.append(x)
s1+=x
else:
l2.append(abs(x))
s2+=abs(x)
l3.append(x)
if(s1>s2):
print("first")
elif(s2>s1):
print("second")
else:
if(l1>l2):
... | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,599,822,611 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 109 | 307,200 | n=int(input())
a=[]
a.append([1]*n)
for i in range (n-1):
b=[]
for i in range(n):
b.append(0)
a.append(b)
for i in range (1,n):
for j in range (n):
if j==0:
a[i][j]=1
else:
a[i][j]=a[i][j-1]+a[i-1][j]
print(a[n-1][n-1])
| Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n=int(input())
a=[]
a.append([1]*n)
for i in range (n-1):
b=[]
for i in range(n):
b.append(0)
a.append(b)
for i in range (1,n):
for j in range (n):
if j==0:
a[i][j]=1
else:
a[i][j]=a[i][j-1]+a[i-1][j]
print(a[n-1][n-1])
``` | 3 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,669,288,575 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 92 | 5,017,600 | n = int(input())
#n = input()
m = input()
#n = [int(x) for x in n]
#m = [int(x) for x in m]
t = [m.count('1')]
t.append( m.count('2'))
t.append( m.count('3'))
t.sort()
print( t[0]+t[1]) | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
n = int(input())
#n = input()
m = input()
#n = [int(x) for x in n]
#m = [int(x) for x in m]
t = [m.count('1')]
t.append( m.count('2'))
t.append( m.count('3'))
t.sort()
print( t[0]+t[1])
``` | 3.967654 |
898 | A | Rounding | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct.
For given *n* find out to which int... | The first line contains single integer *n* (0<=≤<=*n*<=≤<=109) — number that Vasya has. | Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. | [
"5\n",
"113\n",
"1000000000\n",
"5432359\n"
] | [
"0\n",
"110\n",
"1000000000\n",
"5432360\n"
] | In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10. | 500 | [
{
"input": "5",
"output": "0"
},
{
"input": "113",
"output": "110"
},
{
"input": "1000000000",
"output": "1000000000"
},
{
"input": "5432359",
"output": "5432360"
},
{
"input": "999999994",
"output": "999999990"
},
{
"input": "10",
"output": "10"
... | 1,621,266,711 | 2,147,483,647 | Python 3 | OK | TESTS | 64 | 62 | 0 | n=int(input())
r=n%10
q=n//10
if(r>5):
print((q+1)*10)
else:
print(q*10)
| Title: Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded.
For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5... | ```python
n=int(input())
r=n%10
q=n//10
if(r>5):
print((q+1)*10)
else:
print(q*10)
``` | 3 | |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,631,330,437 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 122 | 6,963,200 | res = ""
s = input()
i = 1
l = len(s)
min_len = (l+1)//2
x = 0
while i < l:
if s[i-1]+s[i] == "--":
res += "2"
i += 1
elif s[i-1]+s[i] == "-.":
res += "1"
i += 1
else:
res += "0"
i += 1
x += 1
print(res+"0"*(min_len > x))
| Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
res = ""
s = input()
i = 1
l = len(s)
min_len = (l+1)//2
x = 0
while i < l:
if s[i-1]+s[i] == "--":
res += "2"
i += 1
elif s[i-1]+s[i] == "-.":
res += "1"
i += 1
else:
res += "0"
i += 1
x += 1
print(res+"0"*(min_len > x))
``` | 0 |
433 | A | Kitahara Haruki's Gift | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple. | In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes). | [
"3\n100 200 100\n",
"4\n100 100 100 200\n"
] | [
"YES\n",
"NO\n"
] | In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | 500 | [
{
"input": "3\n100 200 100",
"output": "YES"
},
{
"input": "4\n100 100 100 200",
"output": "NO"
},
{
"input": "1\n100",
"output": "NO"
},
{
"input": "1\n200",
"output": "NO"
},
{
"input": "2\n100 100",
"output": "YES"
},
{
"input": "2\n200 200",
"o... | 1,673,150,350 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n=int(input())
w=list(map(int, input().split()))
if(w.count(100)*100==w.count(200)*200):
print("YES")
else:
print("NO")
| Title: Kitahara Haruki's Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w... | ```python
n=int(input())
w=list(map(int, input().split()))
if(w.count(100)*100==w.count(200)*200):
print("YES")
else:
print("NO")
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,669,437,774 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 92 | 0 | word = str(input())
upper = 0
lower = 0
for i in word:
if ((i > 'Z') & (i <= 'z')):
lower += 1
elif ((i >= 'a') & (i < 'A')):
upper += 1
if upper > lower:
print(word.upper())
else:
print(word.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = str(input())
upper = 0
lower = 0
for i in word:
if ((i > 'Z') & (i <= 'z')):
lower += 1
elif ((i >= 'a') & (i < 'A')):
upper += 1
if upper > lower:
print(word.upper())
else:
print(word.lower())
``` | 0 |
386 | A | Second-Price Auction | PROGRAMMING | 800 | [
"implementation"
] | null | null | In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the au... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. | The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. | [
"2\n5 7\n",
"3\n10 2 8\n",
"6\n3 8 2 9 4 14\n"
] | [
"2 5\n",
"1 8\n",
"6 9\n"
] | none | 500 | [
{
"input": "2\n5 7",
"output": "2 5"
},
{
"input": "3\n10 2 8",
"output": "1 8"
},
{
"input": "6\n3 8 2 9 4 14",
"output": "6 9"
},
{
"input": "4\n4707 7586 4221 5842",
"output": "2 5842"
},
{
"input": "5\n3304 4227 4869 6937 6002",
"output": "4 6002"
},
{... | 1,595,934,130 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 6,963,200 | n = int(input())
p = list(map(int, input().split()))
maxi = max(p)
mas = 0
for x in range(len(p)):
if mas < p[x] < maxi:
mas = p[x]
print(p.index(maxi) + 1, mas) | Title: Second-Price Auction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is... | ```python
n = int(input())
p = list(map(int, input().split()))
maxi = max(p)
mas = 0
for x in range(len(p)):
if mas < p[x] < maxi:
mas = p[x]
print(p.index(maxi) + 1, mas)
``` | 3 | |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal stra... | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input"... | 1,565,151,493 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if(a[-1]-a[0]<=k):
print(0)
else:
min_cnt=n
cnt=0
for i in range(n-1):
min_cnt=min(min_cnt,n-1-bisect.bisect_right(a[i+1:],a[i]+k))
for i in range(1,n):
min_cnt=min(min_cnt,i-1+bisect.bi... | Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest dista... | ```python
import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
if(a[-1]-a[0]<=k):
print(0)
else:
min_cnt=n
cnt=0
for i in range(n-1):
min_cnt=min(min_cnt,n-1-bisect.bisect_right(a[i+1:],a[i]+k))
for i in range(1,n):
min_cnt=min(min_cnt,i-1... | 3 | |
525 | B | Pasha and String | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"math",
"strings"
] | null | null | Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given string.
Pasha didn't like his present very much so he decided to change it. After his birthday Pasha ... | The first line of the input contains Pasha's string *s* of length from 2 to 2·105 characters, consisting of lowercase Latin letters.
The second line contains a single integer *m* (1<=≤<=*m*<=≤<=105) — the number of days when Pasha changed his string.
The third line contains *m* space-separated elements *a**i* (1<=≤<... | In the first line of the output print what Pasha's string *s* will look like after *m* days. | [
"abcdef\n1\n2\n",
"vwxyz\n2\n2 2\n",
"abcdef\n3\n1 2 3\n"
] | [
"aedcbf\n",
"vwxyz\n",
"fbdcea\n"
] | none | 750 | [
{
"input": "abcdef\n1\n2",
"output": "aedcbf"
},
{
"input": "vwxyz\n2\n2 2",
"output": "vwxyz"
},
{
"input": "abcdef\n3\n1 2 3",
"output": "fbdcea"
},
{
"input": "jc\n5\n1 1 1 1 1",
"output": "cj"
},
{
"input": "wljqgdlxyc\n13\n3 4 3 3 5 4 4 2 4 4 5 3 3",
"out... | 1,668,106,055 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 19,353,600 | s = list(input())
m = int(input())
transformations = [int(i)-1 for i in input().split()]
affected = set()
for i in range(len(s)//2):
if len([k for k in transformations if k <= i]) % 2 == 1:
affected.add(i)
for position in affected:
s[position], s[len(s)-position-1] = s[len(s)-position-1], s[position]
... | Title: Pasha and String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha got a very beautiful string *s* for his birthday, the string consists of lowercase Latin letters. The letters in the string are numbered from 1 to |*s*| from left to right, where |*s*| is the length of the given ... | ```python
s = list(input())
m = int(input())
transformations = [int(i)-1 for i in input().split()]
affected = set()
for i in range(len(s)//2):
if len([k for k in transformations if k <= i]) % 2 == 1:
affected.add(i)
for position in affected:
s[position], s[len(s)-position-1] = s[len(s)-position-1], s[... | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,695,512,169 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 60 | 0 | n,a = map(int, input().split())
std = list(map(int, input().split()))
print(min(std))
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,a = map(int, input().split())
std = list(map(int, input().split()))
print(min(std))
``` | 0 | |
656 | F | Ace It! | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer. | The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). | Output a single integer. | [
"A221033\n",
"A223635\n",
"A232726\n"
] | [
"21\n",
"22\n",
"23\n"
] | none | 0 | [
{
"input": "A221033",
"output": "21"
},
{
"input": "A223635",
"output": "22"
},
{
"input": "A232726",
"output": "23"
},
{
"input": "A102210",
"output": "25"
},
{
"input": "A231010",
"output": "26"
},
{
"input": "A222222",
"output": "13"
},
{
... | 1,529,238,099 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 78 | 0 | a=list(input())
b=int(0)
for i in range(len(a)):
if a[i]=="1":
b+=10
elif a[i]=="2":
b+=2
elif a[i]=="3":
b+=3
elif a[i]=="4":
b+=4
elif a[i]=="5":
b+=5
elif a[i]=="6":
b+=6
elif a[i]=="7":
b+=7
elif a[i]=="8":
b+=8
elif... | Title: Ace It!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
Input Specificat... | ```python
a=list(input())
b=int(0)
for i in range(len(a)):
if a[i]=="1":
b+=10
elif a[i]=="2":
b+=2
elif a[i]=="3":
b+=3
elif a[i]=="4":
b+=4
elif a[i]=="5":
b+=5
elif a[i]=="6":
b+=6
elif a[i]=="7":
b+=7
elif a[i]=="8":
b+=... | 3 | |
980 | B | Marlin | PROGRAMMING | 1,600 | [
"constructive algorithms"
] | null | null | The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bottom-right cell $(4, n)$. The second village is located at $(4, 1)$ and its people love the ... | The first line of input contain two integers, $n$ and $k$ ($3 \leq n \leq 99$, $0 \leq k \leq 2\times(n-2)$), $n$ is odd, the width of the city, and the number of hotels to be placed, respectively. | Print "YES", if it is possible to place all the hotels in a way that satisfies the problem statement, otherwise print "NO".
If it is possible, print an extra $4$ lines that describe the city, each line should have $n$ characters, each of which is "#" if that cell has a hotel on it, or "." if not. | [
"7 2\n",
"5 3\n"
] | [
"YES\n.......\n.#.....\n.#.....\n.......\n",
"YES\n.....\n.###.\n.....\n.....\n"
] | none | 1,000 | [
{
"input": "7 2",
"output": "YES\n.......\n.#.....\n.#.....\n......."
},
{
"input": "5 3",
"output": "YES\n.....\n.###.\n.....\n....."
},
{
"input": "3 2",
"output": "YES\n...\n.#.\n.#.\n..."
},
{
"input": "3 0",
"output": "YES\n...\n...\n...\n..."
},
{
"input": "... | 1,525,797,816 | 5,916 | Python 3 | WRONG_ANSWER | PRETESTS | 7 | 78 | 7,065,600 | n,k=map(int,input().split())
if(k>(n-2)*2):
print("NO")
elif(k==(n-2)*2-1):
print("No")
else:
print("YES")
if(k%2==0):
for i in range(4):
for j in range(n):
if(i==0 or i==3):
print('.',end='')
elif(j>0 and j<k//2+1):
print('#',end='')
else:
print('.',end='')
print('')
elif(k<=(n-... | Title: Marlin
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The city of Fishtopia can be imagined as a grid of $4$ rows and an odd number of columns. It has two main villages; the first is located at the top-left cell $(1,1)$, people who stay there love fishing at the Tuna pond at the bo... | ```python
n,k=map(int,input().split())
if(k>(n-2)*2):
print("NO")
elif(k==(n-2)*2-1):
print("No")
else:
print("YES")
if(k%2==0):
for i in range(4):
for j in range(n):
if(i==0 or i==3):
print('.',end='')
elif(j>0 and j<k//2+1):
print('#',end='')
else:
print('.',end='')
print('')
e... | 0 | |
549 | D | Haar Features | PROGRAMMING | 1,900 | [
"greedy",
"implementation"
] | null | null | The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept.
Let's consider a rectangular image that is represent... | The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the feature.
Next *n* lines contain the description of the feature. Each line consists of *m* characters, the *j*-th character of the *i*-th line equals to "W", if this element of the feature ... | Print a single number — the minimum number of operations that you need to make to calculate the value of the feature. | [
"6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n",
"3 3\nWBW\nBWW\nWWW\n",
"3 6\nWWBBWW\nWWBBWW\nWWBBWW\n",
"4 4\nBBBB\nBBBB\nBBBB\nBBBW\n"
] | [
"2\n",
"4\n",
"3\n",
"4\n"
] | The first sample corresponds to feature *B*, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations:
1. add the sum of pixels... | 1,000 | [
{
"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "2"
},
{
"input": "3 3\nWBW\nBWW\nWWW",
"output": "4"
},
{
"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW",
"output": "3"
},
{
"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW",
"output": "4"
},
{
... | 1,507,659,419 | 6,719 | Python 3 | WRONG_ANSWER | TESTS | 4 | 61 | 307,200 | n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
def fun():
global l
l1=[[0 for i in range(m)] for j in range(n)]
for i in range(n):
for j in range(m):
c=l[i][j]
if j+1<m and l[i][j+1]!=c:
if i+1>=n or (l[i+1][j]!=... | Title: Haar Features
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we... | ```python
n,m=[int(i) for i in input().split()]
l=[]
for i in range(n):
l.append(input())
def fun():
global l
l1=[[0 for i in range(m)] for j in range(n)]
for i in range(n):
for j in range(m):
c=l[i][j]
if j+1<m and l[i][j+1]!=c:
if i+1>=n or (l... | 0 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,616,975,050 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 78 | 307,200 | def ceil(a, b):
return -(-a // b)
def answer(n, m):
#for n == 1 only:
#ans = (m+1) // 5
#for n == 2 only:
#ans = (m+2) // 5
num_of_ns_like_1 = max(((n-1) // 5) + 1, 0)
num_of_ns_like_2 = max(((n-2) // 5) + 1, 0)
num_of_ns_like_3 = max(((n-3) // 5) + 1, 0)
num_of_ns_li... | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
def ceil(a, b):
return -(-a // b)
def answer(n, m):
#for n == 1 only:
#ans = (m+1) // 5
#for n == 2 only:
#ans = (m+2) // 5
num_of_ns_like_1 = max(((n-1) // 5) + 1, 0)
num_of_ns_like_2 = max(((n-2) // 5) + 1, 0)
num_of_ns_like_3 = max(((n-3) // 5) + 1, 0)
nu... | 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,666,525,479 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 62 | 716,800 | from typing import List
def solve(string: str):
needle = "heidi"
if needle == string:
print("NO")
return
curr_index = 0
for char in string:
if char == needle[curr_index]:
curr_index += 1
if curr_index >= len(needle):
print("YES... | 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
from typing import List
def solve(string: str):
needle = "heidi"
if needle == string:
print("NO")
return
curr_index = 0
for char in string:
if char == needle[curr_index]:
curr_index += 1
if curr_index >= len(needle):
... | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,692,364,887 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 |
n, m, a, b = map(int, input().split())
one_ride_cost = n * a
m_ride_tickets_needed = n // m
remaining_rides = n % m
m_ride_cost = m_ride_tickets_needed * b + remaining_rides * a
min_cost = min(one_ride_cost, m_ride_cost)
print(min_cost)
| Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n, m, a, b = map(int, input().split())
one_ride_cost = n * a
m_ride_tickets_needed = n // m
remaining_rides = n % m
m_ride_cost = m_ride_tickets_needed * b + remaining_rides * a
min_cost = min(one_ride_cost, m_ride_cost)
print(min_cost)
``` | 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,607,942,043 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 124 | 0 | n,k=list(map(int,input().split()))
no_of_nonWinners=n//2
no_of_diplomas=no_of_nonWinners//(k+1)
no_of_certificates=(k)*no_of_diplomas
no_of_nonWinners=n-(no_of_certificates+no_of_diplomas)
print(no_of_diplomas,end=" ")
print(no_of_certificates,end=" ")
print(no_of_nonWinners,end=" ")
| 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,k=list(map(int,input().split()))
no_of_nonWinners=n//2
no_of_diplomas=no_of_nonWinners//(k+1)
no_of_certificates=(k)*no_of_diplomas
no_of_nonWinners=n-(no_of_certificates+no_of_diplomas)
print(no_of_diplomas,end=" ")
print(no_of_certificates,end=" ")
print(no_of_nonWinners,end=" ")
``` | 3 | |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 ... | 1,607,811,890 | 2,147,483,647 | PyPy 3 | OK | TESTS | 23 | 155 | 11,264,000 | import sys
input = sys.stdin.readline
'''
'''
a, m = map(int, input().split())
seen = set()
r = (a % m)
while not r in seen and r != 0:
seen.add(r)
a += r
r = (a % m)
#print(a, r)
if r == 0:
print("Yes")
else:
print("No") | Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac... | ```python
import sys
input = sys.stdin.readline
'''
'''
a, m = map(int, input().split())
seen = set()
r = (a % m)
while not r in seen and r != 0:
seen.add(r)
a += r
r = (a % m)
#print(a, r)
if r == 0:
print("Yes")
else:
print("No")
``` | 3 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,532,801 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n=int(input())
lst=list(map(int,input().split()))
S=sum(lst)
if S%3!=0 or n<3:
print(0)
elif S==0:
answer=0
for j in range(1,lst.count(0)-1):
answer+=j
print(answer)
else:
a=S//3
for i in range(1,n//2):
lst[i]+=lst[i-1]
lst[n-1-i]=lst[n-i]
if n%2=... | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n=int(input())
lst=list(map(int,input().split()))
S=sum(lst)
if S%3!=0 or n<3:
print(0)
elif S==0:
answer=0
for j in range(1,lst.count(0)-1):
answer+=j
print(answer)
else:
a=S//3
for i in range(1,n//2):
lst[i]+=lst[i-1]
lst[n-1-i]=lst[n-i]
... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes... | In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad.
In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ... | Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. | [
"5\n1 3 2 1 2\n",
"6\n2 1 2 2 4 1\n"
] | [
"3\n",
"2\n"
] | In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer.
In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in... | 0 | [
{
"input": "5\n1 3 2 1 2",
"output": "3"
},
{
"input": "6\n2 1 2 2 4 1",
"output": "2"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "1\n200000",
"output": "200000"
},
{
"input": "2\n2018 2017",
"output": "2018"
},
{
"input": "5\n100 1000 1000 1000... | 1,510,504,473 | 1,773 | Python 3 | OK | TESTS | 33 | 202 | 18,124,800 | n=int(input())
array=[]
array=list(map(int, input().split()))
my_dict={}
for i in range(len(array)):
my_dict[array[i]]=i
result=min(my_dict,key=my_dict.get)
print(result) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research.
First o... | ```python
n=int(input())
array=[]
array=list(map(int, input().split()))
my_dict={}
for i in range(len(array)):
my_dict[array[i]]=i
result=min(my_dict,key=my_dict.get)
print(result)
``` | 3 | |
733 | A | Grasshopper And the String | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ... | The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100. | Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels. | [
"ABABBBACFEYUKOTT\n",
"AAA\n"
] | [
"4",
"1"
] | none | 500 | [
{
"input": "ABABBBACFEYUKOTT",
"output": "4"
},
{
"input": "AAA",
"output": "1"
},
{
"input": "A",
"output": "1"
},
{
"input": "B",
"output": "2"
},
{
"input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU",
... | 1,624,956,753 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 77 | 0 | a = input()
vowels = "AEIOUY"
count = 1
temp = 1
for i in range(len(a)):
if a[i] in vowels:
temp = 1
else:
temp += 1
count = max(count, temp)
print(count)
| Title: Grasshopper And the String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en... | ```python
a = input()
vowels = "AEIOUY"
count = 1
temp = 1
for i in range(len(a)):
if a[i] in vowels:
temp = 1
else:
temp += 1
count = max(count, temp)
print(count)
``` | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,609,690,501 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 310 | 0 | import sys
import math
a, b, n = map(int, input().split())
c = 0
while n != 0:
if c % 2 == 0:
n -= math.gcd(a, n)
else:
n -= math.gcd(b, n)
c += 1
print(*[0 if c % 2 != 0 else 1]) # Ak je pocet tahov parny, vyhrava 1, inak 0
| Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import sys
import math
a, b, n = map(int, input().split())
c = 0
while n != 0:
if c % 2 == 0:
n -= math.gcd(a, n)
else:
n -= math.gcd(b, n)
c += 1
print(*[0 if c % 2 != 0 else 1]) # Ak je pocet tahov parny, vyhrava 1, inak 0
``` | 3 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,639,220,726 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
def is_(n):
d = n%7
if d%3 == 0:
return True
else:
return False
for i in range(n):
a = input()
if is_(int(a)):
print('YES')
else:print('NO') | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n = int(input())
def is_(n):
d = n%7
if d%3 == 0:
return True
else:
return False
for i in range(n):
a = input()
if is_(int(a)):
print('YES')
else:print('NO')
``` | 0 | |
125 | B | Simple XML | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.
Let's d... | The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces. | Print the given XML-text according to the above-given rules. | [
"<a><b><c></c></b></a>\n",
"<a><b></b><d><c></c></d></a>\n"
] | [
"<a>\n <b>\n <c>\n </c>\n </b>\n</a>\n",
"<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>\n"
] | none | 1,500 | [
{
"input": "<a><b><c></c></b></a>",
"output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>"
},
{
"input": "<a><b></b><d><c></c></d></a>",
"output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>"
},
{
"input": "<z></z>",
"output": "<z>\n</z>"
},
{
"input": "<u><d... | 1,693,494,502 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 248 | 9,318,400 | s = input()
word= ""
divs = []
for c in s:
if '<' in word and '>' in word:
divs.append(word)
word = ''
word += c
divs.append(word)
stack = []
h = 0
for div in divs:
if '/' not in div:
stack.append(div)
h = 2* (len(stack)-1)
for _ in range(h):
print(" ", end ... | Title: Simple XML
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into ea... | ```python
s = input()
word= ""
divs = []
for c in s:
if '<' in word and '>' in word:
divs.append(word)
word = ''
word += c
divs.append(word)
stack = []
h = 0
for div in divs:
if '/' not in div:
stack.append(div)
h = 2* (len(stack)-1)
for _ in range(h):
print... | 3 | |
454 | B | Little Pony and Sort by Shift | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning:
Help Twilight Sparkle to calculate: what ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105). | If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it. | [
"2\n2 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"1\n",
"-1\n",
"0\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 3 2",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "6\n3 4 5 6 3 2",
"output": "-1"
},
{
"input": "3\n1 2 1",
"output": "1"
},
{
"input": "5\n1 1 2 1 1",
"output": "2"
}... | 1,660,284,079 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 109 | 14,233,600 | n=int(input())
li=list(map(int,input().split()))
lst=li.copy()
lst.sort()
if(li==lst):
print(0)
quit()
r=[]
for i in range(n):
if li[i]==lst[0]:
r.append(i)
y=r[len(r)-1]
sub=li[y:]
# print(sub)
if(sub+li[:y])==lst:
print(len(sub))
else:print(-1)
| Title: Little Pony and Sort by Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ... | ```python
n=int(input())
li=list(map(int,input().split()))
lst=li.copy()
lst.sort()
if(li==lst):
print(0)
quit()
r=[]
for i in range(n):
if li[i]==lst[0]:
r.append(i)
y=r[len(r)-1]
sub=li[y:]
# print(sub)
if(sub+li[:y])==lst:
print(len(sub))
else:print(-1)
``` | 0 | |
1,011 | A | Stages | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.
There are $n$ stages available. The ro... | The first line of input contains two integers — $n$ and $k$ ($1 \le k \le n \le 50$) – the number of available stages and the number of stages to use in the rocket.
The second line contains string $s$, which consists of exactly $n$ lowercase Latin letters. Each letter defines a new stage, which can be used to build th... | Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all. | [
"5 3\nxyabd\n",
"7 4\nproblem\n",
"2 2\nab\n",
"12 1\nabaabbaaabbb\n"
] | [
"29",
"34",
"-1",
"1"
] | In the first example, the following rockets satisfy the condition:
- "adx" (weight is $1+4+24=29$);- "ady" (weight is $1+4+25=30$);- "bdx" (weight is $2+4+24=30$);- "bdy" (weight is $2+4+25=31$).
Rocket "adx" has the minimal weight, so the answer is $29$.
In the second example, target rocket is "belo". Its weight ... | 500 | [
{
"input": "5 3\nxyabd",
"output": "29"
},
{
"input": "7 4\nproblem",
"output": "34"
},
{
"input": "2 2\nab",
"output": "-1"
},
{
"input": "12 1\nabaabbaaabbb",
"output": "1"
},
{
"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa",
"output": ... | 1,647,950,663 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n, k = map(int, input().split())
lst = input()
a = b = 0
for i in map(ord,sorted(lst)):
if i - b > 1:
a += i - 96
b = i
k -= 1
if k == 0:
break
if k > 0:
print(-1)
else:
print(a) | Title: Stages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — conca... | ```python
n, k = map(int, input().split())
lst = input()
a = b = 0
for i in map(ord,sorted(lst)):
if i - b > 1:
a += i - 96
b = i
k -= 1
if k == 0:
break
if k > 0:
print(-1)
else:
print(a)
``` | 3 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,528,541,136 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 0 | n = int(input())
l = [int(i) for i in input().split()]
a , b = map(int , input().split())
ans = 0
while a != b:
ans+=l[a]
a+=1
print(ans) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n = int(input())
l = [int(i) for i in input().split()]
a , b = map(int , input().split())
ans = 0
while a != b:
ans+=l[a]
a+=1
print(ans)
``` | 0 |
700 | D | Huffman Coding on Segment | PROGRAMMING | 3,100 | [
"data structures",
"greedy"
] | null | null | Alice wants to send an important message to Bob. Message *a*<==<=(*a*1,<=...,<=*a**n*) is a sequence of positive integers (characters).
To compress the message Alice wants to use binary Huffman coding. We recall that binary Huffman code, or binary prefix code is a function *f*, that maps each letter that appears in th... | The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the initial message. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000) — characters of the message.
Next line contains the single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the nu... | Print *q* lines. Each line should contain a single integer — the minimum possible length of the Huffman encoding of the substring *a**l**i*... *a**r**i*. | [
"7\n1 2 1 3 1 2 1\n5\n1 7\n1 3\n3 5\n2 4\n4 4\n"
] | [
"10\n3\n3\n5\n0\n"
] | In the first query, one of the optimal ways to encode the substring is to map 1 to "0", 2 to "10" and 3 to "11".
Note that it is correct to map the letter to the empty substring (as in the fifth query from the sample). | 2,250 | [] | 1,685,237,615 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 2,252,800 | import heapq
from collections import defaultdict
class Node:
def __init__(self, freq, char=None):
self.freq = freq
self.char = char
self.left = None
self.right = None
def __lt__(self, other):
return self.freq < other.freq
def build_huffman_tree(freq_map):
pq... | Title: Huffman Coding on Segment
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice wants to send an important message to Bob. Message *a*<==<=(*a*1,<=...,<=*a**n*) is a sequence of positive integers (characters).
To compress the message Alice wants to use binary Huffman coding. We rec... | ```python
import heapq
from collections import defaultdict
class Node:
def __init__(self, freq, char=None):
self.freq = freq
self.char = char
self.left = None
self.right = None
def __lt__(self, other):
return self.freq < other.freq
def build_huffman_tree(freq_ma... | -1 | |
869 | C | The Intriguing Obsession | PROGRAMMING | 1,800 | [
"combinatorics",
"dp",
"math"
] | null | null | — This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — Karen and Tsukihi — is heading for somewhere they've never reached — water-surrounded islands!
There are three... | The first and only line of input contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=5<=000) — the number of islands in the red, blue and purple clusters, respectively. | Output one line containing an integer — the number of different ways to build bridges, modulo 998<=244<=353. | [
"1 1 1\n",
"1 2 2\n",
"1 3 5\n",
"6 2 9\n"
] | [
"8\n",
"63\n",
"3264\n",
"813023575\n"
] | In the first example, there are 3 bridges that can possibly be built, and no setup of bridges violates the restrictions. Thus the answer is 2<sup class="upper-index">3</sup> = 8.
In the second example, the upper two structures in the figure below are instances of valid ones, while the lower two are invalid due to the ... | 1,500 | [
{
"input": "1 1 1",
"output": "8"
},
{
"input": "1 2 2",
"output": "63"
},
{
"input": "1 3 5",
"output": "3264"
},
{
"input": "6 2 9",
"output": "813023575"
},
{
"input": "7 3 7",
"output": "807577560"
},
{
"input": "135 14 39",
"output": "41484950... | 1,507,540,887 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 116,838,400 | a, b, c = sorted([int(x) for x in input().split()])
modulo = 998244353
from collections import defaultdict
comb = defaultdict(int)
inj = defaultdict(int)
comb[(0,0)]=1
inj[(0,0)]=1
for i in range(1, c+1):
comb[i, 0] = 1
inj[i,0] = 1
fact=1
for j in range(1, i+1):
comb[(i,j)] = (comb[(i-1, j-1)]... | Title: The Intriguing Obsession
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
— This is not playing but duty as allies of justice, Nii-chan!
— Not allies but justice itself, Onii-chan!
With hands joined, go everywhere at a speed faster than our thoughts! This time, the Fire Sisters — K... | ```python
a, b, c = sorted([int(x) for x in input().split()])
modulo = 998244353
from collections import defaultdict
comb = defaultdict(int)
inj = defaultdict(int)
comb[(0,0)]=1
inj[(0,0)]=1
for i in range(1, c+1):
comb[i, 0] = 1
inj[i,0] = 1
fact=1
for j in range(1, i+1):
comb[(i,j)] = (comb[(... | 0 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,531,914,150 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 467 | 8,601,600 | input()
A = list(map(int, input().split()))
for x, y in zip(A, A[1:] + [0]):
print(x + y, end=' ') | Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
input()
A = list(map(int, input().split()))
for x, y in zip(A, A[1:] + [0]):
print(x + y, end=' ')
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | 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,461,532,037 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 77 | 5,120,000 | s1=input()
s2=input()
for i in range(len(s1)):
if (s1[i]=='1') and (s2[i]=='0') or (s1[i]=='0') and (s2[i]=='1'):
print(1, end='')
else:
print(0, end='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
s1=input()
s2=input()
for i in range(len(s1)):
if (s1[i]=='1') and (s2[i]=='0') or (s1[i]=='0') and (s2[i]=='1'):
print(1, end='')
else:
print(0, end='')
``` | 3.971213 |
978 | E | Bus Video System | PROGRAMMING | 1,400 | [
"combinatorics",
"math"
] | null | null | The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, th... | The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus.
The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system aft... | Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. | [
"3 5\n2 1 -3\n",
"2 4\n-1 1\n",
"4 10\n2 4 1 2\n"
] | [
"3\n",
"4\n",
"2\n"
] | In the first example initially in the bus could be $0$, $1$ or $2$ passengers.
In the second example initially in the bus could be $1$, $2$, $3$ or $4$ passengers.
In the third example initially in the bus could be $0$ or $1$ passenger. | 0 | [
{
"input": "3 5\n2 1 -3",
"output": "3"
},
{
"input": "2 4\n-1 1",
"output": "4"
},
{
"input": "4 10\n2 4 1 2",
"output": "2"
},
{
"input": "2 10\n-1 2",
"output": "9"
},
{
"input": "3 4\n-3 -4 4",
"output": "0"
},
{
"input": "10 1\n-1 -1 3 -4 2 3 0 -3... | 1,672,817,810 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 46 | 0 | n, m = map(int,input().split())
a = list(map(int,input().split()))
mn = 0
mx = 0
s = 0
for i in range(n):
s += a[i]
if s > mx:
mx = s
if s < mn:
mn = s
if m - mx + mn + 1 < 0:
print(0)
else:
print(m - mx + mn +1) | Title: Bus Video System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.
If $x$ is the number of passengers in a bus just befo... | ```python
n, m = map(int,input().split())
a = list(map(int,input().split()))
mn = 0
mx = 0
s = 0
for i in range(n):
s += a[i]
if s > mx:
mx = s
if s < mn:
mn = s
if m - mx + mn + 1 < 0:
print(0)
else:
print(m - mx + mn +1)
``` | 3 | |
909 | E | Coprocessor | PROGRAMMING | 1,900 | [
"dfs and similar",
"dp",
"graphs",
"greedy"
] | null | null | You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depen... | The first line contains two space-separated integers *N* (1<=≤<=*N*<=≤<=105) — the total number of tasks given, and *M* (0<=≤<=*M*<=≤<=105) — the total number of dependencies between tasks.
The next line contains *N* space-separated integers . If *E**i*<==<=0, task *i* can only be executed on the main processor, other... | Output one line containing an integer — the minimal number of coprocessor calls necessary to execute the program. | [
"4 3\n0 1 0 1\n0 1\n1 2\n2 3\n",
"4 3\n1 1 1 0\n0 1\n0 2\n3 0\n"
] | [
"2\n",
"1\n"
] | In the first test, tasks 1 and 3 can only be executed on the coprocessor. The dependency graph is linear, so the tasks must be executed in order 3 -> 2 -> 1 -> 0. You have to call coprocessor twice: first you call it for task 3, then you execute task 2 on the main processor, then you call it for for task 1, an... | 2,000 | [
{
"input": "4 3\n0 1 0 1\n0 1\n1 2\n2 3",
"output": "2"
},
{
"input": "4 3\n1 1 1 0\n0 1\n0 2\n3 0",
"output": "1"
},
{
"input": "10 39\n0 1 0 1 0 1 1 0 1 1\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n3 4\n3 6\n3 7\n3 8\n3 9\n... | 1,667,318,123 | 6,323 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 108 | 8,294,400 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m = map(int, input().split())
e = list(map(int, input().split()))
s = [0] * n
for _ in range(m):
t1, t2 = map(int, input().split())
if not e[t1] and e[t2]:
s[t2] = 1
ans = sum(s)
print(ans) | Title: Coprocessor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are n... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n, m = map(int, input().split())
e = list(map(int, input().split()))
s = [0] * n
for _ in range(m):
t1, t2 = map(int, input().split())
if not e[t1] and e[t2]:
s[t2] = 1
ans = sum(s)
print(ans)
``` | 0 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,694,534,947 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 46 | 0 | from sys import stdin
input = stdin.readline
if __name__ == "__main__":
s = input().strip()
aux = "hello_"
i = 0
for c in s:
if i == 5:
break
elif c == aux[i]:
i += 1
print(["NO", "YES"][i==5])
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
from sys import stdin
input = stdin.readline
if __name__ == "__main__":
s = input().strip()
aux = "hello_"
i = 0
for c in s:
if i == 5:
break
elif c == aux[i]:
i += 1
print(["NO", "YES"][i==5])
``` | 3.977 |
0 | none | none | none | 0 | [
"none"
] | null | null | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*... | The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed th... | If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answe... | [
"4 4\n1 3 5 7\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"3 1\n2 5 10\n"
] | [
"0.5\n",
"0.875\n",
"-1\n"
] | In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 a... | 0 | [
{
"input": "4 4\n1 3 5 7",
"output": "0.5"
},
{
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875"
},
{
"input": "3 1\n2 5 10",
"output": "-1"
},
{
"input": "5 3\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 128\n110 121 140 158 174 188 251 271 27... | 1,521,912,075 | 6,375 | Python 3 | WRONG_ANSWER | PRETESTS | 8 | 93 | 7,065,600 | n, U = list(map(int , input().split()))
E = list(map(int , input().split()))
E.append(10**20)
E.append(10**20)
E.append(10**20)
start = 0
finish = 1
res = -1
while start < n:
while (E[finish] - E[start] >U) and start <n:
start += 1
while (E[finish+1] - E[start] <=U) and (finish<n):
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the sche... | ```python
n, U = list(map(int , input().split()))
E = list(map(int , input().split()))
E.append(10**20)
E.append(10**20)
E.append(10**20)
start = 0
finish = 1
res = -1
while start < n:
while (E[finish] - E[start] >U) and start <n:
start += 1
while (E[finish+1] - E[start] <=U) and (finish<... | 0 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,591,690,082 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 140 | 0 | n = int(input())
a = [int(s) for s in input().split()]
a.sort()
count = 1
max = 1
for i in range(len(a) - 1):
if a[i] == a[i + 1]:
count += 1
else:
if count > max:
max = count
count = 1
if count > max:
print(count)
else:
print(max) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n = int(input())
a = [int(s) for s in input().split()]
a.sort()
count = 1
max = 1
for i in range(len(a) - 1):
if a[i] == a[i + 1]:
count += 1
else:
if count > max:
max = count
count = 1
if count > max:
print(count)
else:
print(max)
``` | 3 | |
792 | B | Counting-out Rhyme | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T... | The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1).
The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109). | Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. | [
"7 5\n10 4 11 4 1\n",
"3 2\n2 5\n"
] | [
"4 2 5 6 1 \n",
"3 2 \n"
] | Let's consider first example:
- In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader... | 0 | [
{
"input": "7 5\n10 4 11 4 1",
"output": "4 2 5 6 1 "
},
{
"input": "3 2\n2 5",
"output": "3 2 "
},
{
"input": "2 1\n1",
"output": "2 "
},
{
"input": "2 1\n2",
"output": "1 "
},
{
"input": "2 1\n3",
"output": "2 "
},
{
"input": "10 7\n5 10 4 3 8 10 6",... | 1,598,181,360 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 109 | 6,656,000 | siz,qu = map(int,input().split())
ar,ind = [x for x in range(1,siz+1)],0
for k in map(int,input().split()):
nx = (ind + k) % siz
print(ar[nx])
siz -= 1; ar.pop(nx); ind = nx | Title: Counting-out Rhyme
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ... | ```python
siz,qu = map(int,input().split())
ar,ind = [x for x in range(1,siz+1)],0
for k in map(int,input().split()):
nx = (ind + k) % siz
print(ar[nx])
siz -= 1; ar.pop(nx); ind = nx
``` | 3 | |
389 | B | Fox and Cross | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.
Ciel wants to draw several... | The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board.
Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. | Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". | [
"5\n.#...\n####.\n.####\n...#.\n.....\n",
"4\n####\n####\n####\n####\n",
"6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n",
"6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n",
"3\n...\n...\n...\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In example 1, you can draw two crosses. The picture below shows what they look like.
In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all. | 1,000 | [
{
"input": "4\n####\n####\n####\n####",
"output": "NO"
},
{
"input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.",
"output": "YES"
},
{
"input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.",
"output": "NO"
},
{
"input": "5\n.....\n.#...\n####.\n.####\n...#.",
... | 1,616,862,414 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 93 | 1,843,200 | def check():
for i in range(n):
for j in range(n):
if board[i][j] == '#':
return False
return True
n = int(input())
board = []
for i in range(n):
board.append([char for char in input()])
for i in range(1,n-1):
for j in range(1,n-1):
if board[i][j] == '#' and... | Title: Fox and Cross
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of t... | ```python
def check():
for i in range(n):
for j in range(n):
if board[i][j] == '#':
return False
return True
n = int(input())
board = []
for i in range(n):
board.append([char for char in input()])
for i in range(1,n-1):
for j in range(1,n-1):
if board[i][j] ... | 3 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,681,288,725 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | # Read the input value n from the user
n = int(input())
# Check if n is odd. If it is, we cannot construct a perfect permutation.
if n % 2 == 1:
print("-1")
else:
# Create a list to store the permutation
permutation = list(range(1, n+1))
# Swap every two adjacent elements in the permutation
... | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
# Read the input value n from the user
n = int(input())
# Check if n is odd. If it is, we cannot construct a perfect permutation.
if n % 2 == 1:
print("-1")
else:
# Create a list to store the permutation
permutation = list(range(1, n+1))
# Swap every two adjacent elements in the pe... | 3 | |
426 | A | Sereja and Mugs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume th... | The first line contains integers *n* and *s* (2<=≤<=*n*<=≤<=100; 1<=≤<=*s*<=≤<=1000) — the number of mugs and the volume of the cup. The next line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10). Number *a**i* means the volume of the *i*-th mug. | In a single line, print "YES" (without the quotes) if his friends can play in the described manner, and "NO" (without the quotes) otherwise. | [
"3 4\n1 1 1\n",
"3 4\n3 1 3\n",
"3 4\n4 4 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3 4\n1 1 1",
"output": "YES"
},
{
"input": "3 4\n3 1 3",
"output": "YES"
},
{
"input": "3 4\n4 4 4",
"output": "NO"
},
{
"input": "2 1\n1 10",
"output": "YES"
},
{
"input": "3 12\n5 6 6",
"output": "YES"
},
{
"input": "4 10\n6 3 8 7",
"... | 1,560,281,787 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 109 | 0 | n,s1 = map(int,input().split())
l = list(map(int,input().split()))
if sum(l)-max(l)<=s1:
print("YES")
else:
print("NO") | Title: Sereja and Mugs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and *n* water mugs on it. Then all players take turns to move. During a move, a player takes a non... | ```python
n,s1 = map(int,input().split())
l = list(map(int,input().split()))
if sum(l)-max(l)<=s1:
print("YES")
else:
print("NO")
``` | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,697,722,333 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | # https://codeforces.com/problemset/problem/379/A
a, b = [int(x) for x in input().split()]
h = 0
while a > 0:
h += a
a //= b
print(h)
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
# https://codeforces.com/problemset/problem/379/A
a, b = [int(x) for x in input().split()]
h = 0
while a > 0:
h += a
a //= b
print(h)
``` | 0 | |
681 | B | Economy Game | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.
Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — Kolya's initial game-coin score. | Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes). | [
"1359257\n",
"17851817\n"
] | [
"YES",
"NO"
] | In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total. | 1,000 | [
{
"input": "1359257",
"output": "YES"
},
{
"input": "17851817",
"output": "NO"
},
{
"input": "1000000000",
"output": "YES"
},
{
"input": "17851818",
"output": "YES"
},
{
"input": "438734347",
"output": "YES"
},
{
"input": "43873430",
"output": "YES... | 1,691,621,778 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | n = int(input())
for i in range((n//1234567)+1):
for j in range((((n-(i*1234567))//123456) + 1)):
if (n-(i*1234567 + j*123456)) % 1234 == 0:
print("YES"); exit()
else:
print("NO") | Title: Economy Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0.... | ```python
n = int(input())
for i in range((n//1234567)+1):
for j in range((((n-(i*1234567))//123456) + 1)):
if (n-(i*1234567 + j*123456)) % 1234 == 0:
print("YES"); exit()
else:
print("NO")
``` | 3 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,582,900,617 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 512,000 | import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sy... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(i... | 3 | |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,668,161,839 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
def separate(x):
return int(x / 2)
if n % 2 == 0:
print(separate(n), end=' ')
print(separate(n))
else:
print(separate(n), end=' ')
print(separate(n + 1)) | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
n = int(input())
def separate(x):
return int(x / 2)
if n % 2 == 0:
print(separate(n), end=' ')
print(separate(n))
else:
print(separate(n), end=' ')
print(separate(n + 1))
``` | 0 | |
534 | A | Exam | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other... | A single line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of students at an exam. | In the first line print integer *k* — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other.
In the second line print *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*), where *a**i* is the number of the student on the *i*-th position... | [
"6",
"3\n"
] | [
"6\n1 5 3 6 2 4",
"2\n1 3"
] | none | 500 | [
{
"input": "6",
"output": "6\n5 3 1 6 4 2 "
},
{
"input": "3",
"output": "2\n1 3"
},
{
"input": "1",
"output": "1\n1 "
},
{
"input": "2",
"output": "1\n1"
},
{
"input": "4",
"output": "4\n3 1 4 2 "
},
{
"input": "5",
"output": "5\n5 3 1 4 2 "
},
... | 1,590,398,585 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n = int(input())
if n==1 or n==2: print('1\n1'); exit()
if n==3: print('2\n1 3'); exit()
print(n)
t2 = [[], []]
for i in range(1, n+1, 2):
t2[0].append(i)
if i+1<=n: t2[1].append(i+1)
print(*t2[0], *t2[1])
| Title: Exam
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An exam for *n* students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (*i* and *i*<=+<=1) always studied side by side and bec... | ```python
n = int(input())
if n==1 or n==2: print('1\n1'); exit()
if n==3: print('2\n1 3'); exit()
print(n)
t2 = [[], []]
for i in range(1, n+1, 2):
t2[0].append(i)
if i+1<=n: t2[1].append(i+1)
print(*t2[0], *t2[1])
``` | 0 | |
400 | A | Inna and Choose Options | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"... | The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line.
The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ... | For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b... | [
"4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n"
] | [
"3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n"
] | none | 500 | [
{
"input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO",
"output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0"
},
{
"input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX",
"output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1"
},
{
"input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n... | 1,617,723,126 | 2,147,483,647 | PyPy 3 | OK | TESTS | 44 | 155 | 2,048,000 | def ok(s , a , b):
mat = []
for i in range(0 , len(s) , b):
mat.append(s[i:i+b])
for j in range(b):
c = 0
for i in range(a):
if mat[i][j] == 'O': c+=1
if not c: return True
return False
t = int(input())
for _ in range(t):
s = input()
... | Title: Inna and Choose Options
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below:
There is one person playing the game.... | ```python
def ok(s , a , b):
mat = []
for i in range(0 , len(s) , b):
mat.append(s[i:i+b])
for j in range(b):
c = 0
for i in range(a):
if mat[i][j] == 'O': c+=1
if not c: return True
return False
t = int(input())
for _ in range(t):
s ... | 3 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,492,967,202 | 1,302 | Python 3 | OK | TESTS | 88 | 202 | 14,336,000 | n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
ans = 0
for i in range(1, n):
if (a[i] - a[0]) % k:
print(-1)
break
else:
ans += (a[i] - a[0]) // k
else:
print(ans) | Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
ans = 0
for i in range(1, n):
if (a[i] - a[0]) % k:
print(-1)
break
else:
ans += (a[i] - a[0]) // k
else:
print(ans)
``` | 3 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | 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,694,197,765 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 34 | 92 | 0 | n=int(input())
x=input().split()
z=[int(i) for i in x]
sf,sl=max(z),min(z)
check1,check2=[],[]
lswap,rswap=z.index(sf),(len(z)-(z.index(sl)+1))
lcount,rcount=z.count(sf),z.count(sl)
for i in range(len(z)):
if z[i]==sl:
check2.append(i)
rswap=(len(z)-(max(check2)+1))
elif z[i]==sf:
... | 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
n=int(input())
x=input().split()
z=[int(i) for i in x]
sf,sl=max(z),min(z)
check1,check2=[],[]
lswap,rswap=z.index(sf),(len(z)-(z.index(sl)+1))
lcount,rcount=z.count(sf),z.count(sl)
for i in range(len(z)):
if z[i]==sl:
check2.append(i)
rswap=(len(z)-(max(check2)+1))
elif z[i... | -1 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,673,118,410 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 78 | 13,516,800 | n,b,d=map(int,input().split())
oranges=list(map(int,input().split()))
c=0
total=0
for orange in oranges:
if orange>b:
continue
else:
total+=orange
if total>d:
total=0
c+=1
print(c)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n,b,d=map(int,input().split())
oranges=list(map(int,input().split()))
c=0
total=0
for orange in oranges:
if orange>b:
continue
else:
total+=orange
if total>d:
total=0
c+=1
print(c)
``` | 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,607,246,328 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 280 | 0 | y,w = map(int, input().split())
x = 6 - max(y,w) + 1
n = 6
if 6 % x == 0:
n = 6 // x
x = 1
print(x,'/',n, sep= '' ) | 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
y,w = map(int, input().split())
x = 6 - max(y,w) + 1
n = 6
if 6 % x == 0:
n = 6 // x
x = 1
print(x,'/',n, sep= '' )
``` | 0 |
527 | A | Playing with Paper | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle... | The first line of the input contains two integers *a*, *b* (1<=≤<=*b*<=<<=*a*<=≤<=1012) — the sizes of the original sheet of paper. | Print a single integer — the number of ships that Vasya will make. | [
"2 1\n",
"10 7\n",
"1000000000000 1\n"
] | [
"2\n",
"6\n",
"1000000000000\n"
] | Pictures to the first and second sample test. | 500 | [
{
"input": "2 1",
"output": "2"
},
{
"input": "10 7",
"output": "6"
},
{
"input": "1000000000000 1",
"output": "1000000000000"
},
{
"input": "3 1",
"output": "3"
},
{
"input": "4 1",
"output": "4"
},
{
"input": "3 2",
"output": "3"
},
{
"in... | 1,429,549,320 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 2,000 | 4,608,000 | dan = list(map(int, input().split()))
a,b = dan[0], dan[1]
ans = 0
while a >0 and b >0:
if a >b:
a -=b
else:
b-=a
ans +=1
print(ans) | Title: Playing with Paper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=×<= *b* mm sheet of paper (*a*<=><=*b*). Usually the first step in making an origami is making a squ... | ```python
dan = list(map(int, input().split()))
a,b = dan[0], dan[1]
ans = 0
while a >0 and b >0:
if a >b:
a -=b
else:
b-=a
ans +=1
print(ans)
``` | 0 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,666,369,344 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 92 | 0 | import os,sys,io,math
from array import array
from math import *
I=lambda:[*map(int,sys.stdin.readline().split())]
IS=lambda:input()
IN=lambda:int(input())
IF=lambda:float(input())
n=IN()
x,y=0,n-2
for i in range(2,n):
b=n
while b:
x+=b%i
b//=i
g=math.gcd(x,y)
x,y=x//g,y//g
pri... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
import os,sys,io,math
from array import array
from math import *
I=lambda:[*map(int,sys.stdin.readline().split())]
IS=lambda:input()
IN=lambda:int(input())
IF=lambda:float(input())
n=IN()
x,y=0,n-2
for i in range(2,n):
b=n
while b:
x+=b%i
b//=i
g=math.gcd(x,y)
x,y=x//g... | 3.954 |
357 | A | Group of Students | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ... | The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. | If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. | [
"5\n3 4 3 2 1\n6 8\n",
"5\n0 3 3 4 2\n3 10\n",
"2\n2 5\n3 6\n"
] | [
"3\n",
"4\n",
"0\n"
] | In the first sample the beginner group has 7 students, the intermediate group has 6 of them.
In the second sample another correct answer is 3. | 500 | [
{
"input": "5\n3 4 3 2 1\n6 8",
"output": "3"
},
{
"input": "5\n0 3 3 4 2\n3 10",
"output": "4"
},
{
"input": "2\n2 5\n3 6",
"output": "0"
},
{
"input": "3\n0 1 0\n2 10",
"output": "0"
},
{
"input": "5\n2 2 2 2 2\n5 5",
"output": "0"
},
{
"input": "10\... | 1,381,840,249 | 1,849 | Python 3 | OK | TESTS | 58 | 62 | 307,200 | m = int(input())
c = list(map(int,input().split()))
x, y = map(int,input().split())
for i in range(m):
sb = sum(c[:-i-1])
si = sum(c[-i-1:])
if x <= sb <= y:
if x <= si <= y:
print(m-i)
break
else:
print(0)
| Title: Group of Students
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According ... | ```python
m = int(input())
c = list(map(int,input().split()))
x, y = map(int,input().split())
for i in range(m):
sb = sum(c[:-i-1])
si = sum(c[-i-1:])
if x <= sb <= y:
if x <= si <= y:
print(m-i)
break
else:
print(0)
``` | 3 | |
841 | B | Godsend | PROGRAMMING | 1,100 | [
"games",
"math"
] | null | null | Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts... | First line of input data contains single integer *n* (1<=≤<=*n*<=≤<=106) — length of the array.
Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes). | [
"4\n1 3 2 3\n",
"2\n2 2\n"
] | [
"First\n",
"Second\n"
] | In first sample first player remove whole array in one move and win.
In second sample first player can't make a move and lose. | 1,000 | [
{
"input": "4\n1 3 2 3",
"output": "First"
},
{
"input": "2\n2 2",
"output": "Second"
},
{
"input": "4\n2 4 6 8",
"output": "Second"
},
{
"input": "5\n1 1 1 1 1",
"output": "First"
},
{
"input": "4\n720074544 345031254 849487632 80870826",
"output": "Second"
... | 1,700,224,862 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | from sys import stdin, stdout
def main():
n=int(stdin.readline().strip())
arr=[int(x) for x in stdin.readline().strip().split(' ')]
even,odd = 0,0
for x in arr:
if x%2==1: odd+=1
else: even+=1
return 'First' if odd%2==1 else 'Second'
stdout.write(str(main()))
| Title: Godsend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l... | ```python
from sys import stdin, stdout
def main():
n=int(stdin.readline().strip())
arr=[int(x) for x in stdin.readline().strip().split(' ')]
even,odd = 0,0
for x in arr:
if x%2==1: odd+=1
else: even+=1
return 'First' if odd%2==1 else 'Second'
stdout.write(str(main()))
``` | 0 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,699,211,717 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 79,360,000 | from enum import IntEnum, unique
from typing import List, Optional
@unique
class Activity(IntEnum):
CONTEST = 0
GYM = 1
REST = 2
def get_possible_activities(value: int, prev_activity: Optional[Activity]):
if value == 0:
return [Activity.REST]
elif value == 1:
if prev_activity is No... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
from enum import IntEnum, unique
from typing import List, Optional
@unique
class Activity(IntEnum):
CONTEST = 0
GYM = 1
REST = 2
def get_possible_activities(value: int, prev_activity: Optional[Activity]):
if value == 0:
return [Activity.REST]
elif value == 1:
if prev_acti... | 0 | |
567 | D | One-Dimensional Battle Ships | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"greedy",
"sortings"
] | null | null | Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of *n* square cells (that is, on a 1<=×<=*n* table).
At the beginning of the game Alice puts *k* ships on the field without telling their positions to Bob. Each ship looks as a 1<=×<=*a* rectangle (that is,... | The first line of the input contains three integers: *n*, *k* and *a* (1<=≤<=*n*,<=*k*,<=*a*<=≤<=2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the *n*, *k* and *a* are such that you can put *k* ships of size *a* on the field, so that no two ships intersect or t... | Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to *m* in the order the were made. If the sought move doesn't exist, then print "-1". | [
"11 3 3\n5\n4 8 6 1 11\n",
"5 1 3\n2\n1 5\n",
"5 1 3\n1\n3\n"
] | [
"3\n",
"-1\n",
"1\n"
] | none | 2,000 | [
{
"input": "11 3 3\n5\n4 8 6 1 11",
"output": "3"
},
{
"input": "5 1 3\n2\n1 5",
"output": "-1"
},
{
"input": "5 1 3\n1\n3",
"output": "1"
},
{
"input": "1 1 1\n1\n1",
"output": "1"
},
{
"input": "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 120... | 1,678,971,618 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 873 | 19,353,600 | n,k,a=map(int,input().split())
m=int(input())+1
x=list(map(int,input().split()))+[0]
l,r=0,m
while r-l>1:
d=(l+r)//2
y=sorted(x[:d])
if sum((q-p)//(a+1) for p,q in zip([0]+y,y+[n+1]))>=k:l=d
else:r=d
print(r%m-(r==m))
| Title: One-Dimensional Battle Ships
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of *n* square cells (that is, on a 1<=×<=*n* table).
At the beginning of the game Alice puts... | ```python
n,k,a=map(int,input().split())
m=int(input())+1
x=list(map(int,input().split()))+[0]
l,r=0,m
while r-l>1:
d=(l+r)//2
y=sorted(x[:d])
if sum((q-p)//(a+1) for p,q in zip([0]+y,y+[n+1]))>=k:l=d
else:r=d
print(r%m-(r==m))
``` | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=100). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer — the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,677,491,558 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | N=int(input())
if 1<=N<=100:
z=1
a=1
for i in range(N):
a+=z
z+=1
print(a-1) | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
N=int(input())
if 1<=N<=100:
z=1
a=1
for i in range(N):
a+=z
z+=1
print(a-1)
``` | -1 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,588,849,318 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 156 | 20,172,800 | import math
a,b=map(int,input().split())
aw=0
bw=0
dr=0
for i in range(1,7):
if abs(a-i)<abs(b-i):
aw+=1
elif abs(a-i)==abs(b-i):
dr+=1
else:
bw+=1
print(aw,dr,bw) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
import math
a,b=map(int,input().split())
aw=0
bw=0
dr=0
for i in range(1,7):
if abs(a-i)<abs(b-i):
aw+=1
elif abs(a-i)==abs(b-i):
dr+=1
else:
bw+=1
print(aw,dr,bw)
``` | 3 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,671,490,931 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 3 | 124 | 2,867,200 | n , t = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
budget = 0
idx = 0
#print(a)
while budget<t and idx<n:
if a[idx]+budget <= t:
idx+=1
budget+=a[idx]
else:
break
print(idx) | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n , t = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
budget = 0
idx = 0
#print(a)
while budget<t and idx<n:
if a[idx]+budget <= t:
idx+=1
budget+=a[idx]
else:
break
print(idx)
``` | -1 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,599,973,622 | 122 | PyPy 3 | OK | TESTS | 37 | 155 | 0 | import sys
n, k = map(int, input().split())
print((n + k) // k * k)
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
import sys
n, k = map(int, input().split())
print((n + k) // k * k)
``` | 3 | |
847 | G | University Classes | PROGRAMMING | 900 | [
"implementation"
] | null | null | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones — the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot... | Print minimum number of rooms needed to hold all groups classes on Monday. | [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] | [
"1\n",
"3\n"
] | In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | 0 | [
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n... | 1,599,955,114 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 156 | 1,536,000 | n=int(input())
arr=[]
for i in range(n):
arr.append(input())
s=[0,0,0,0,0,0,0]
for i in range(7):
for item in arr:
s[i]+=int(item[i])
print(max(s))
| Title: University Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known ... | ```python
n=int(input())
arr=[]
for i in range(n):
arr.append(input())
s=[0,0,0,0,0,0,0]
for i in range(7):
for item in arr:
s[i]+=int(item[i])
print(max(s))
``` | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=≤<=*n*<=≤<=100) — the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) — the number of cookies in the *i*-th bag. | Print in the only line the only number — the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,605,697,534 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 218 | 0 | n = int(input())
arr = list(map(int, input().split()))
s,ans = sum(arr),0
for i,item in enumerate(arr):
if (s - item) % 2 == 0:
ans += 1
print(ans) | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n = int(input())
arr = list(map(int, input().split()))
s,ans = sum(arr),0
for i,item in enumerate(arr):
if (s - item) % 2 == 0:
ans += 1
print(ans)
``` | 3 | |
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,671,098,456 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 296 | 51,200,000 | n = int(input())
dical,dicfi,dicse = {},{},{}
for i in input().split():
if i not in dical:dical[i]=1
else:dical[i]+=1
for i in input().split():
if i not in dicfi:dicfi[i]=1
else:dicfi[i]+=1
for i in input().split():
if i not in dicse:dicse[i]=1
else:dicse[i]+=1
for key,item in dical.items():
... | 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
n = int(input())
dical,dicfi,dicse = {},{},{}
for i in input().split():
if i not in dical:dical[i]=1
else:dical[i]+=1
for i in input().split():
if i not in dicfi:dicfi[i]=1
else:dicfi[i]+=1
for i in input().split():
if i not in dicse:dicse[i]=1
else:dicse[i]+=1
for key,item in dical.i... | 3 | |
522 | A | Reposts | PROGRAMMING | 1,200 | [
"*special",
"dfs and similar",
"dp",
"graphs",
"trees"
] | null | null | One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1 reposted name2", where name1 is the n... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and ... | Print a single integer — the maximum length of a repost chain. | [
"5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya\n",
"6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforces reposted Polycarp\n",
"1\nSoMeStRaNgEgUe repos... | [
"6\n",
"2\n",
"2\n"
] | none | 500 | [
{
"input": "5\ntourist reposted Polycarp\nPetr reposted Tourist\nWJMZBMR reposted Petr\nsdya reposted wjmzbmr\nvepifanov reposted sdya",
"output": "6"
},
{
"input": "6\nMike reposted Polycarp\nMax reposted Polycarp\nEveryOne reposted Polycarp\n111 reposted Polycarp\nVkCup reposted Polycarp\nCodeforc... | 1,519,468,453 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 5,734,400 | n=int(input())
name='polycarp'
link={'polycarp':1}
ans=1
h=0
sd=[]
for i in range(n):
m=input().split()
m.remove('reposted')
for j in m:
sd.append(j.lower())
if h==(n*2-1):
break
link[sd[h]]=link[sd[h+1]]+1
ans=max(ans,link[sd[h]])
h+=2
print(ans)
... | Title: Reposts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
... | ```python
n=int(input())
name='polycarp'
link={'polycarp':1}
ans=1
h=0
sd=[]
for i in range(n):
m=input().split()
m.remove('reposted')
for j in m:
sd.append(j.lower())
if h==(n*2-1):
break
link[sd[h]]=link[sd[h+1]]+1
ans=max(ans,link[sd[h]])
h+=2
print(ans) ... | 3 | |
166 | A | Rank List | PROGRAMMING | 1,100 | [
"binary search",
"implementation",
"sortings"
] | null | null | Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
You know the rules of comparing the results of two give... | The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1<=≤<=*p**i*,<=*t**i*<=≤<=50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All num... | In the only line print the sought number of teams that got the *k*-th place in the final results' table. | [
"7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10\n",
"5 4\n3 1\n3 1\n5 3\n3 1\n3 1\n"
] | [
"3\n",
"4\n"
] | The final results' table for the first sample is:
- 1-3 places — 4 solved problems, the penalty time equals 10 - 4 place — 3 solved problems, the penalty time equals 20 - 5-6 places — 2 solved problems, the penalty time equals 1 - 7 place — 1 solved problem, the penalty time equals 10
The table shows that the se... | 500 | [
{
"input": "7 2\n4 10\n4 10\n4 10\n3 20\n2 1\n2 1\n1 10",
"output": "3"
},
{
"input": "5 4\n3 1\n3 1\n5 3\n3 1\n3 1",
"output": "4"
},
{
"input": "5 1\n2 2\n1 1\n1 1\n1 1\n2 2",
"output": "2"
},
{
"input": "6 3\n2 2\n3 1\n2 2\n4 5\n2 2\n4 5",
"output": "1"
},
{
"i... | 1,614,435,077 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 124 | 307,200 | n,k=map(int,input().split())
arr=[list(map(int,input().split())) for i in range(n)]
arr.sort(key=lambda x:x[0], reverse=True)
kth=arr[k-1]
count=0
for i in range(n):
if kth[0]==arr[i][0] and kth[1]==arr[i][1]:
count+=1
print(count)
| Title: Rank List
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for... | ```python
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for i in range(n)]
arr.sort(key=lambda x:x[0], reverse=True)
kth=arr[k-1]
count=0
for i in range(n):
if kth[0]==arr[i][0] and kth[1]==arr[i][1]:
count+=1
print(count)
``` | 0 | |
780 | B | The Meeting Place Cannot Be Changed | PROGRAMMING | 1,600 | [
"binary search"
] | 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. | 1,000 | [
{
"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,590,270,068 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 5,000 | 2,252,800 | n = int(input())
x = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
l = 0
r = 500000000
# print(1/2.0)
# print((1/2.0)/2.0)
while l<r:
mid = (l+r)/2.0
L = x[0]-v[0]*mid
R = x[0]+v[0]*mid
for i in range(1, n):
if x[i]-v[i]*mid > L:
L = x[i]-v[i]*mid
if... | Title: The Meeting Place Cannot Be Changed
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... | ```python
n = int(input())
x = [int(i) for i in input().split()]
v = [int(i) for i in input().split()]
l = 0
r = 500000000
# print(1/2.0)
# print((1/2.0)/2.0)
while l<r:
mid = (l+r)/2.0
L = x[0]-v[0]*mid
R = x[0]+v[0]*mid
for i in range(1, n):
if x[i]-v[i]*mid > L:
L = x[i]-v[i]*mid
... | 0 | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,566,746,229 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 0 | ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,m=kk()
ps,bs=ll(),ll()
b=c=0
for a in range(n):
while b<m and bs[b]<ps[a]: b+=1
if b==m:c+=1
print(c) | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
ii=lambda:int(input())
kk=lambda:map(int, input().split())
ll=lambda:list(kk())
n,m=kk()
ps,bs=ll(),ll()
b=c=0
for a in range(n):
while b<m and bs[b]<ps[a]: b+=1
if b==m:c+=1
print(c)
``` | 0 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,678,533,368 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 102,400 | from collections import deque
n, m = map(int, input().split())
a = list(map(int, input().split()))
line = deque(range(n))
candies = [0] * n
home = []
while line:
child = line.popleft()
candies[child] += m
if candies[child] < a[child]:
line.append(child)
else:
home.appen... | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
from collections import deque
n, m = map(int, input().split())
a = list(map(int, input().split()))
line = deque(range(n))
candies = [0] * n
home = []
while line:
child = line.popleft()
candies[child] += m
if candies[child] < a[child]:
line.append(child)
else:
... | 3 | |
879 | B | Table Tennis | PROGRAMMING | 1,200 | [
"data structures",
"implementation"
] | null | null | *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner.
For each of t... | The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ... | Output a single integer — power of the winner. | [
"2 2\n1 2\n",
"4 2\n3 1 2 4\n",
"6 2\n6 5 3 1 2 4\n",
"2 10000000000\n2 1\n"
] | [
"2 ",
"3 ",
"6 ",
"2\n"
] | Games in the second sample:
3 plays with 1. 3 wins. 1 goes to the end of the line.
3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner. | 1,000 | [
{
"input": "2 2\n1 2",
"output": "2 "
},
{
"input": "4 2\n3 1 2 4",
"output": "3 "
},
{
"input": "6 2\n6 5 3 1 2 4",
"output": "6 "
},
{
"input": "2 10000000000\n2 1",
"output": "2"
},
{
"input": "4 4\n1 3 4 2",
"output": "4 "
},
{
"input": "2 21474836... | 1,674,226,320 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 46 | 0 | def f(n, x):
q = 0
if x == 1:
return 1
for i in range(1, n + 1):
if i == 1 and n >= x:
q +=1
elif x % i == 0 and i != 1 and x <= n * i:
q += 1
return q
def main():
a = []
j = 0
v = 0
variables = input().split()
n, k = int... | Title: Table Tennis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o... | ```python
def f(n, x):
q = 0
if x == 1:
return 1
for i in range(1, n + 1):
if i == 1 and n >= x:
q +=1
elif x % i == 0 and i != 1 and x <= n * i:
q += 1
return q
def main():
a = []
j = 0
v = 0
variables = input().split()
... | 3 | |
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,507,094,854 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | s=[ ord(i)-ord('a') for i in input()]
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in s:
ans+=a[i]*(i+1)
max_here=max(a)
tt=len(s)
count=0
while count!=n:
ans+=max_here*(tt+count+1)
count+=1
print(ans)
| 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=[ ord(i)-ord('a') for i in input()]
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in s:
ans+=a[i]*(i+1)
max_here=max(a)
tt=len(s)
count=0
while count!=n:
ans+=max_here*(tt+count+1)
count+=1
print(ans)
``` | 0 | |
697 | A | Pineapple Incident | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times *t*, *t*<=+<=*s*, *t*<=+<=*s*<=+<=1, *t*<=+<=2*s*, *t*<=+<=2*s*<=+<=1, etc.
Barney woke up in the morn... | The first and only line of input contains three integers *t*, *s* and *x* (0<=≤<=*t*,<=*x*<=≤<=109, 2<=≤<=*s*<=≤<=109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. | Print a single "YES" (without quotes) if the pineapple will bark at time *x* or a single "NO" (without quotes) otherwise in the only line of output. | [
"3 10 4\n",
"3 10 3\n",
"3 8 51\n",
"3 8 52\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and ... | 500 | [
{
"input": "3 10 4",
"output": "NO"
},
{
"input": "3 10 3",
"output": "YES"
},
{
"input": "3 8 51",
"output": "YES"
},
{
"input": "3 8 52",
"output": "YES"
},
{
"input": "456947336 740144 45",
"output": "NO"
},
{
"input": "33 232603 599417964",
"ou... | 1,515,835,018 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 62 | 5,632,000 | yo=list(map(int,input().split()))
t=yo[0]
s=yo[1]
x=yo[2]
if x<t+s:
if (x-t)%s==0 :
print("YES")
else:
print("NO")
else:
if (x-t)%s==0 or (x-t-1)%s==0:
print("YES")
else:
print("NO") | Title: Pineapple Incident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time *t* (in seconds) it barks for the first time. Then every *s* seconds after it, it barks twice with 1 second interval. Thus it barks at times... | ```python
yo=list(map(int,input().split()))
t=yo[0]
s=yo[1]
x=yo[2]
if x<t+s:
if (x-t)%s==0 :
print("YES")
else:
print("NO")
else:
if (x-t)%s==0 or (x-t-1)%s==0:
print("YES")
else:
print("NO")
``` | 0 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,685,724,449 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 249 | 61,337,600 | N=int(input())
A=list(map(int,input().split()))
S=[0]
for a in A:
S.append(S[-1]+a)
SUM=S[-1]
if SUM%3!=0:
print(0)
exit()
ANS=0
now=0
for i in range(N-1,0,-1):
if S[i]==SUM//3:
ANS+=now
if S[i]==SUM//3*2:
now+=1
print(ANS)
| Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
N=int(input())
A=list(map(int,input().split()))
S=[0]
for a in A:
S.append(S[-1]+a)
SUM=S[-1]
if SUM%3!=0:
print(0)
exit()
ANS=0
now=0
for i in range(N-1,0,-1):
if S[i]==SUM//3:
ANS+=now
if S[i]==SUM//3*2:
now+=1
print(ANS)
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,521,138,869 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 5,632,000 | import itertools
a = sorted(list(map(int, input().split())))
p = ([sorted(t) for t in itertools.permutations(a, 3)])
p = max([t[0]+t[1]-t[2] for t in p])
print(("TRIANGLE" if p>0 else "SEGMENT") if p>=0 else "IMPOSSIBLE") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
import itertools
a = sorted(list(map(int, input().split())))
p = ([sorted(t) for t in itertools.permutations(a, 3)])
p = max([t[0]+t[1]-t[2] for t in p])
print(("TRIANGLE" if p>0 else "SEGMENT") if p>=0 else "IMPOSSIBLE")
``` | 3.927038 |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,668,498,226 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | candels, scale = map(int, input().split())
cand = candels
hours = cand/1
remain = 0
while cand >= scale:
cand += remain
cand= cand // scale
hours += cand
remain = cand % scale
print(int(hours)) | Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
candels, scale = map(int, input().split())
cand = candels
hours = cand/1
remain = 0
while cand >= scale:
cand += remain
cand= cand // scale
hours += cand
remain = cand % scale
print(int(hours))
``` | 0 | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,659,376,205 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 62 | 0 | I = lambda: map(int, input().split(':'))
h, m = I()
dh, dm = I()
h, m = h-dh, m-dm
h, m = (h+m//60)%24, m%60
print(f'{h:02}:{m:02}') | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
I = lambda: map(int, input().split(':'))
h, m = I()
dh, dm = I()
h, m = h-dh, m-dm
h, m = (h+m//60)%24, m%60
print(f'{h:02}:{m:02}')
``` | 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,616,413,879 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 124 | 0 | n, m = map(int, input().split())
n = 6 - (max(n, m) - 1)
d = 6
if d % n == 0:
d /= n
n = 1
elif n % 2 == 0:
n /= 2
d /= 2
print(f"{int(n)}/{int(d)}") | 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
n, m = map(int, input().split())
n = 6 - (max(n, m) - 1)
d = 6
if d % n == 0:
d /= n
n = 1
elif n % 2 == 0:
n /= 2
d /= 2
print(f"{int(n)}/{int(d)}")
``` | 3.938 |
621 | B | Wet Shark and Bishops | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation"
] | null | null | Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o... | The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops.
Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ... | Output one integer — the number of pairs of bishops which attack each other. | [
"5\n1 1\n1 5\n3 3\n5 1\n5 5\n",
"3\n1 1\n2 3\n3 5\n"
] | [
"6\n",
"0\n"
] | In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal. | 1,000 | [
{
"input": "5\n1 1\n1 5\n3 3\n5 1\n5 5",
"output": "6"
},
{
"input": "3\n1 1\n2 3\n3 5",
"output": "0"
},
{
"input": "3\n859 96\n634 248\n808 72",
"output": "0"
},
{
"input": "3\n987 237\n891 429\n358 145",
"output": "0"
},
{
"input": "3\n411 81\n149 907\n611 114"... | 1,613,696,396 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 1,544 | 9,625,600 | d = {}
d1 = {}
ans = 0
for _ in range(int(input())):
x,y = map(int, input().split())
sum = x+y
diff = x-y
d[sum] = d.get(sum, 0) + 1
d1[diff] = d1.get(diff, 0) + 1
for k in d:
if d[k] > 1:
ans += (d[k]*(d[k]-1))//2
for z in d1:
if d1[z] > 1:
ans += (d1... | Title: Wet Shark and Bishops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
We... | ```python
d = {}
d1 = {}
ans = 0
for _ in range(int(input())):
x,y = map(int, input().split())
sum = x+y
diff = x-y
d[sum] = d.get(sum, 0) + 1
d1[diff] = d1.get(diff, 0) + 1
for k in d:
if d[k] > 1:
ans += (d[k]*(d[k]-1))//2
for z in d1:
if d1[z] > 1:
... | 3 | |
821 | E | Okabe and El Psy Kongroo | PROGRAMMING | 2,100 | [
"dp",
"matrices"
] | null | null | Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as all points (*x*,<=*y*) such that *x* and *y* are non-negative. Okabe starts at the origin (point (0,<=0)), and n... | The first line of input contains the integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1018) — the number of segments and the destination *x* coordinate.
The next *n* lines contain three space-separated integers *a**i*, *b**i*, and *c**i* (0<=≤<=*a**i*<=<<=*b**i*<=≤<=1018, 0<=≤<=*c**i*<=≤<=15) — the left and r... | Print the number of walks satisfying the conditions, modulo 1000000007 (109<=+<=7). | [
"1 3\n0 3 3\n",
"2 6\n0 3 0\n3 10 2\n"
] | [
"4\n",
"4\n"
] | The graph above corresponds to sample 1. The possible walks are:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7fcce410dbd2cf4e427a6b50e0f159b7ce538901.png" style="max-width: 100.0%;max-height: 100.0%;"/> - <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/... | 2,500 | [
{
"input": "1 3\n0 3 3",
"output": "4"
},
{
"input": "2 6\n0 3 0\n3 10 2",
"output": "4"
},
{
"input": "2 3\n0 2 13\n2 3 11",
"output": "4"
},
{
"input": "2 9\n0 8 0\n8 10 10",
"output": "1"
},
{
"input": "1 1\n0 3 9",
"output": "1"
},
{
"input": "3 8\... | 1,692,108,414 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | print("_RANDOM_GUESS_1692108414.6137848")# 1692108414.6138015 | Title: Okabe and El Psy Kongroo
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe likes to take walks but knows that spies from the Organization could be anywhere; that's why he wants to know how many different walks he can take in his city safely. Okabe's city can be represented as al... | ```python
print("_RANDOM_GUESS_1692108414.6137848")# 1692108414.6138015
``` | 0 | |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,636,992,953 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 512,000 |
cell = []
def valid(i,j,n):
if i<0 or j<0 or i>=n or j>=n or cell[i][j] == 'L':
return False
a = (i+1>=n or cell[i+1][j] == 'S')
b = (i-1<0 or cell[i-1][j] == 'S')
c = (j+1>=n or cell[i][j+1] == 'S')
d = (j-1<0 or cell[i][j-1] == 'S')
return a==b==c==d==1
... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
cell = []
def valid(i,j,n):
if i<0 or j<0 or i>=n or j>=n or cell[i][j] == 'L':
return False
a = (i+1>=n or cell[i+1][j] == 'S')
b = (i-1<0 or cell[i-1][j] == 'S')
c = (j+1>=n or cell[i][j+1] == 'S')
d = (j-1<0 or cell[i][j-1] == 'S')
return a==b==c==d==1
... | 0 | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,597,432,244 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 0 | matrix=[[],[],[],[]]
for i in range(1,4):
x=list(input())
x.insert(0,'')
matrix[i]=x
if(matrix[1][1] == matrix[3][3] and matrix[1][3] == matrix[3][1] and matrix[1][2] == matrix[3][2] and matrix[2][1] == matrix[2][3]):
print("YES")
else:
print("NO") | Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
matrix=[[],[],[],[]]
for i in range(1,4):
x=list(input())
x.insert(0,'')
matrix[i]=x
if(matrix[1][1] == matrix[3][3] and matrix[1][3] == matrix[3][1] and matrix[1][2] == matrix[3][2] and matrix[2][1] == matrix[2][3]):
print("YES")
else:
print("NO")
``` | 3.93 |
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,693,301,911 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | def binarysearch(a, b, c):
left = a
right = b
res = -1
while left <= right:
mid = (left + right) // 2
if arraya[mid] <= c:
res = mid
left = mid + 1
else:
right = mid - 1
return res+1
n, m = map(int,input().spli... | 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 binarysearch(a, b, c):
left = a
right = b
res = -1
while left <= right:
mid = (left + right) // 2
if arraya[mid] <= c:
res = mid
left = mid + 1
else:
right = mid - 1
return res+1
n, m = map(int,in... | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,697,909,217 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | word = input()
if ord(word[0]) >= 97 and ord(word[0]) <= 122:
word = chr(ord(word[0]) - 32) + word[1:]
print(word) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
word = input()
if ord(word[0]) >= 97 and ord(word[0]) <= 122:
word = chr(ord(word[0]) - 32) + word[1:]
print(word)
``` | 3 | |
246 | D | Colorful Graph | PROGRAMMING | 1,600 | [
"brute force",
"dfs and similar",
"graphs"
] | null | null | You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex is an integer *c**i*.
Let's consider all vertices of the graph, that are painted some color *k*. Let... | The first line contains two space-separated integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of vertices end edges of the graph, correspondingly. The second line contains a sequence of integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105) — the colors of the graph vertices. The numbers on the line are sep... | Print the number of the color which has the set of neighbours with the maximum cardinality. It there are multiple optimal colors, print the color with the minimum number. Please note, that you want to find such color, that the graph has at least one vertex with such color. | [
"6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6\n",
"5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4\n"
] | [
"3\n",
"2\n"
] | none | 2,000 | [
{
"input": "6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6",
"output": "3"
},
{
"input": "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4",
"output": "2"
},
{
"input": "3 1\n13 13 4\n1 2",
"output": "4"
},
{
"input": "2 1\n500 300\n1 2",
"output": "300"
},
{
"input":... | 1,570,534,493 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 12 | 2,000 | 16,384,000 | n,e=list(map(int,input().split()))
color=list(map(int,input().split()))
d={}
for itr in color:
if itr not in d: d[itr]=set()
for itr in range(e):
a1,a2=list(map(int,input().split()))
if color[a1-1]==color[a2-1]: continue
d[color[a1-1]].add(color[a2-1])
d[color[a2-1]].add(color[a1-1])
#prin... | Title: Colorful Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an undirected graph, consisting of *n* vertices and *m* edges. We will consider the graph's vertices numbered with integers from 1 to *n*. Each vertex of the graph has a color. The color of the *i*-th vertex i... | ```python
n,e=list(map(int,input().split()))
color=list(map(int,input().split()))
d={}
for itr in color:
if itr not in d: d[itr]=set()
for itr in range(e):
a1,a2=list(map(int,input().split()))
if color[a1-1]==color[a2-1]: continue
d[color[a1-1]].add(color[a2-1])
d[color[a2-1]].add(color[a1-... | 0 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,587,057,863 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 186 | 1,433,600 | a,b=map(int,input().split())
k=int(0)
for _ in range(a):
c=input().split(" ")
if c[0]=="+":
b=b+int(c[1])
else:
if b-int(c[1])>=0:
b=b-int(c[1])
else:
k=k+1
print(b,k) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
a,b=map(int,input().split())
k=int(0)
for _ in range(a):
c=input().split(" ")
if c[0]=="+":
b=b+int(c[1])
else:
if b-int(c[1])>=0:
b=b-int(c[1])
else:
k=k+1
print(b,k)
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | 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,649,548,189 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | a = int(input())
b = int(input())
c = int(input())
if (a / c) != 0 and (b / c) != 0:
r = ((a / c) + 1) * ((b / c) + 1)
print(r)
else:
x = (a / c) * (b / c)
print(x) | 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
a = int(input())
b = int(input())
c = int(input())
if (a / c) != 0 and (b / c) != 0:
r = ((a / c) + 1) * ((b / c) + 1)
print(r)
else:
x = (a / c) * (b / c)
print(x)
``` | -1 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,594,058,631 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 6,758,400 | m=str(input())
n=str(input())
s=list(m)
d=list(n)
z=0
for i in range(len(s)):
for j in range(len(d)):
if s[i]==d[j]:
z+=1
if z==len(s) and s!=d:
print('YES')
else:
print('NO')
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
m=str(input())
n=str(input())
s=list(m)
d=list(n)
z=0
for i in range(len(s)):
for j in range(len(d)):
if s[i]==d[j]:
z+=1
if z==len(s) and s!=d:
print('YES')
else:
print('NO')
``` | 0 |
246 | E | Blood Cousins Return | PROGRAMMING | 2,400 | [
"binary search",
"data structures",
"dfs and similar",
"dp",
"sortings"
] | null | null | Polycarpus got hold of a family tree. The found tree describes the family relations of *n* people, numbered from 1 to *n*. Every person in this tree has at most one direct ancestor. Also, each person in the tree has a name, the names are not necessarily unique.
We call the man with a number *a* a 1-ancestor of the man... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the tree. Next *n* lines contain the description of people in the tree. The *i*-th line contains space-separated string *s**i* and integer *r**i* (0<=≤<=*r**i*<=≤<=*n*), where *s**i* is the name of the man with a num... | Print *m* whitespace-separated integers — the answers to Polycarpus's records. Print the answers to the records in the order, in which the records occur in the input. | [
"6\npasha 0\ngerald 1\ngerald 1\nvalera 2\nigor 3\nolesya 1\n5\n1 1\n1 2\n1 3\n3 1\n6 1\n",
"6\nvalera 0\nvalera 1\nvalera 1\ngerald 0\nvalera 4\nkolya 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1\n"
] | [
"2\n2\n0\n1\n0\n",
"1\n0\n0\n0\n2\n0\n0\n"
] | none | 2,500 | [
{
"input": "6\npasha 0\ngerald 1\ngerald 1\nvalera 2\nigor 3\nolesya 1\n5\n1 1\n1 2\n1 3\n3 1\n6 1",
"output": "2\n2\n0\n1\n0"
},
{
"input": "6\nvalera 0\nvalera 1\nvalera 1\ngerald 0\nvalera 4\nkolya 4\n7\n1 1\n1 2\n2 1\n2 2\n4 1\n5 1\n6 1",
"output": "1\n0\n0\n0\n2\n0\n0"
},
{
"input":... | 1,698,835,785 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 72 | 1,652 | 89,702,400 | import os,sys,random,threading
from random import randint
from copy import deepcopy
from io import BytesIO, IOBase
from types import GeneratorType
from functools import lru_cache, reduce
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from itertools import accumu... | Title: Blood Cousins Return
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus got hold of a family tree. The found tree describes the family relations of *n* people, numbered from 1 to *n*. Every person in this tree has at most one direct ancestor. Also, each person in the tree ha... | ```python
import os,sys,random,threading
from random import randint
from copy import deepcopy
from io import BytesIO, IOBase
from types import GeneratorType
from functools import lru_cache, reduce
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from itertools imp... | 3 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,686,493,424 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | a = ''
b = int(input())
for i in range(1, b + 1):
a += str(i)
print(a[b - 1])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
a = ''
b = int(input())
for i in range(1, b + 1):
a += str(i)
print(a[b - 1])
``` | 3 | |
641 | A | Little Artem and Grasshopper | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Gr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip.
Next line contains a string of length *n* which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d*... | Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). | [
"2\n><\n1 2\n",
"3\n>><\n2 1 1\n"
] | [
"FINITE\n",
"INFINITE"
] | In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.
Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. | 500 | [
{
"input": "2\n><\n1 2",
"output": "FINITE"
},
{
"input": "3\n>><\n2 1 1",
"output": "INFINITE"
},
{
"input": "1\n>\n1000000000",
"output": "FINITE"
},
{
"input": "1\n<\n1000000000",
"output": "FINITE"
},
{
"input": "2\n>>\n1 1",
"output": "FINITE"
},
{
... | 1,653,122,155 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 77 | 307,200 | #I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
# mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collections import... | Title: Little Artem and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.
The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and t... | ```python
#I = lambda: [int(i) for i in input().split()]
#import io, os, sys
#input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
# n = int(input())
# l1 = list(map(int,input().split()))
# n,x = map(int,input().split())
# s = input()
# mod = 1000000007
# print("Case #"+str(_+1)+":",)
from collecti... | 0 | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,573,562,913 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 140 | 0 | import sys
if __name__ == '__main__':
n = int(input())
statements = [input() for _ in range(n)]
if statements[-1] == 'f':
print(0)
sys.exist(0)
# Join f
cs = ['s'] if statements[0] == 's' else []
for i in range(1, n):
if statements[i] == 's' and statements[i - 1] == 'f... | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
import sys
if __name__ == '__main__':
n = int(input())
statements = [input() for _ in range(n)]
if statements[-1] == 'f':
print(0)
sys.exist(0)
# Join f
cs = ['s'] if statements[0] == 's' else []
for i in range(1, n):
if statements[i] == 's' and statements[i ... | 0 | |
459 | B | Pashmak and Flowers | PROGRAMMING | 1,300 | [
"combinatorics",
"implementation",
"sortings"
] | null | null | Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty diff... | The first line of the input contains *n* (2<=≤<=*n*<=≤<=2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1<=≤<=*b**i*<=≤<=109). | The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively. | [
"2\n1 2\n",
"3\n1 4 5\n",
"5\n3 1 2 3 1\n"
] | [
"1 1",
"4 1",
"2 4"
] | In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
1. choosing the first and the second flowers; 1. choosing the first and the fifth flowers; 1. choosing the fourth and the second flowers; 1. choosing the fourth and the fifth flowers. | 500 | [
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "3\n1 4 5",
"output": "4 1"
},
{
"input": "5\n3 1 2 3 1",
"output": "2 4"
},
{
"input": "2\n1 1",
"output": "0 1"
},
{
"input": "3\n1 1 1",
"output": "0 3"
},
{
"input": "4\n1 1 1 1",
"output": "0 ... | 1,662,867,413 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 218 | 18,329,600 | n = int(input())
a = list(map(int,input().split()))
a.sort()
if a[0]==a[-1]:
if n%2==0:
print(0,(n//2)*(n-1))
else:
print(0,((n-1)//2)*n)
exit()
l = 0
r = -1
while a[l]==a[0]:
l+=1
while a[r]==a[-1]:
r-=1
print(a[-1]-a[0],l*(-r-1))
| Title: Pashmak and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have th... | ```python
n = int(input())
a = list(map(int,input().split()))
a.sort()
if a[0]==a[-1]:
if n%2==0:
print(0,(n//2)*(n-1))
else:
print(0,((n-1)//2)*n)
exit()
l = 0
r = -1
while a[l]==a[0]:
l+=1
while a[r]==a[-1]:
r-=1
print(a[-1]-a[0],l*(-r-1))
``` | 3 |
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.