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
512
D
Fox And Travelling
PROGRAMMING
2,900
[ "dp", "trees" ]
null
null
Fox Ciel is going to travel to New Foxland during this summer. New Foxland has *n* attractions that are linked by *m* undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has *k* days to visit this city and each day she will visit exactly one attraction. There is one important ...
First line contains two integers: *n*, *m* (1<=≤<=*n*<=≤<=100, ), the number of attractions and number of undirected roads. Then next *m* lines each contain two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n* and *a**i*<=≠<=*b**i*), describing a road. There is no more than one road connecting each pair of at...
Output *n*<=+<=1 integer: the number of possible travelling plans modulo 109<=+<=9 for all *k* from 0 to *n*.
[ "3 2\n1 2\n2 3\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9\n", "13 0\n" ]
[ "1\n2\n4\n4\n", "1\n0\n0\n0\n0\n", "1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0\n", "1\n13\n156\n1716\n17160\n154440\n1235520\n8648640\n51891840\n259459200\n37836791\n113510373\n227020746\n227020746\n" ]
In the first sample test for *k* = 3 there are 4 travelling plans: {1, 2, 3}, {1, 3, 2}, {3, 1, 2}, {3, 2, 1}. In the second sample test Ciel can't visit any attraction in the first day, so for *k* &gt; 0 the answer is 0. In the third sample test Foxlands look like this:
2,250
[ { "input": "3 2\n1 2\n2 3", "output": "1\n2\n4\n4" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "1\n0\n0\n0\n0" }, { "input": "12 11\n2 3\n4 7\n4 5\n5 6\n4 6\n6 12\n5 12\n5 8\n8 9\n10 8\n11 9", "output": "1\n6\n31\n135\n483\n1380\n3060\n5040\n5040\n0\n0\n0\n0" }, { "inp...
1,690,490,271
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
15
0
print("_RANDOM_GUESS_1690490271.61528")# 1690490271.6152992
Title: Fox And Travelling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel is going to travel to New Foxland during this summer. New Foxland has *n* attractions that are linked by *m* undirected roads. Two attractions are called adjacent if they are linked by a road. Fox Ciel has ...
```python print("_RANDOM_GUESS_1690490271.61528")# 1690490271.6152992 ```
0
624
B
Making a String
PROGRAMMING
1,100
[ "greedy", "sortings" ]
null
null
You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the ...
The first line of the input contains a single integer *n* (2<=<=≤<=<=*n*<=<=≤<=<=26) — the number of letters in the alphabet. The next line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string.
Print a single integer — the maximum length of the string that meets all the requirements.
[ "3\n2 5 5\n", "3\n1 1 2\n" ]
[ "11\n", "3\n" ]
For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".
1,000
[ { "input": "3\n2 5 5", "output": "11" }, { "input": "3\n1 1 2", "output": "3" }, { "input": "2\n1 1", "output": "1" }, { "input": "3\n1 1000000000 2", "output": "1000000003" }, { "input": "26\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10000...
1,454,609,648
4,148
Python 3
CHALLENGED
CHALLENGES
8
46
0
n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) tot = l[0] cur = l[0] for i in range(1, n): new = min([cur-1, l[i]]) tot += new cur = new print(tot)
Title: Making a String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than ...
```python n = int(input()) l = list(map(int, input().split())) l.sort(reverse=True) tot = l[0] cur = l[0] for i in range(1, n): new = min([cur-1, l[i]]) tot += new cur = new print(tot) ```
-1
525
C
Ilya and Sticks
PROGRAMMING
1,600
[ "greedy", "math", "sortings" ]
null
null
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way tha...
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of the available sticks. The second line of the input contains *n* positive integers *l**i* (2<=≤<=*l**i*<=≤<=106) — the lengths of the sticks.
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
[ "4\n2 4 4 2\n", "4\n2 2 3 5\n", "4\n100003 100004 100005 100006\n" ]
[ "8\n", "0\n", "10000800015\n" ]
none
1,000
[ { "input": "4\n2 4 4 2", "output": "8" }, { "input": "4\n2 2 3 5", "output": "0" }, { "input": "4\n100003 100004 100005 100006", "output": "10000800015" }, { "input": "8\n5 3 3 3 3 4 4 4", "output": "25" }, { "input": "10\n123 124 123 124 2 2 2 2 9 9", "output...
1,427,432,849
2,147,483,647
Python 3
OK
TESTS
96
171
7,680,000
def main(): n = int(input()) l = [int(i) for i in input().split()] l.sort() l.reverse() candidate = [] i = 1 while (i < n): if (l[i - 1] - l[i] <= 1): candidate.append(min(l[i - 1], l[i])) i += 2 else: i += 1 area = 0 ...
Title: Ilya and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of *n* sticks and an instrument. Each stick is characterized by its length *l**i*. Ilya decided to m...
```python def main(): n = int(input()) l = [int(i) for i in input().split()] l.sort() l.reverse() candidate = [] i = 1 while (i < n): if (l[i - 1] - l[i] <= 1): candidate.append(min(l[i - 1], l[i])) i += 2 else: i += 1 ar...
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,699,267,540
2,147,483,647
Python 3
OK
TESTS
48
46
0
a=[int(i) for i in input().split()] print(min(abs(a[0]-a[1])+abs(a[0]-a[2]),abs(a[1]-a[0])+abs(a[1]-a[2]),abs(a[2]-a[0])+abs(a[2]-a[1])))
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python a=[int(i) for i in input().split()] print(min(abs(a[0]-a[1])+abs(a[0]-a[2]),abs(a[1]-a[0])+abs(a[1]-a[2]),abs(a[2]-a[0])+abs(a[2]-a[1]))) ```
3
676
C
Vasya and String
PROGRAMMING
1,500
[ "binary search", "dp", "strings", "two pointers" ]
null
null
High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original strin...
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters.
[ "4 2\nabba\n", "8 1\naabaabaa\n" ]
[ "4\n", "5\n" ]
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
1,500
[ { "input": "4 2\nabba", "output": "4" }, { "input": "8 1\naabaabaa", "output": "5" }, { "input": "1 0\na", "output": "1" }, { "input": "1 1\nb", "output": "1" }, { "input": "1 0\nb", "output": "1" }, { "input": "1 1\na", "output": "1" }, { ...
1,595,398,124
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
140
20,172,800
import os from math import* n,k=map(int,input().split()) arr=input() fp=0 fp1=0 ans=0 ans1=0 count=0 count1=0 for i in range(n): if arr[i]=="a": count+=1 if count>k: count=1 if ans<i-fp: ans=i-fp fp=i if arr[i]=="b": count1+=1 if count1>k: count1=1 if ans1<i-fp1: ans=i-f...
Title: Vasya and String Time Limit: None seconds Memory Limit: None megabytes Problem Description: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequ...
```python import os from math import* n,k=map(int,input().split()) arr=input() fp=0 fp1=0 ans=0 ans1=0 count=0 count1=0 for i in range(n): if arr[i]=="a": count+=1 if count>k: count=1 if ans<i-fp: ans=i-fp fp=i if arr[i]=="b": count1+=1 if count1>k: count1=1 if ans1<i-fp1: ...
0
733
B
Parade
PROGRAMMING
1,100
[ "math" ]
null
null
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits beg...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of columns. The next *n* lines contain the pairs of integers *l**i* and *r**i* (1<=≤<=*l**i*,<=*r**i*<=≤<=500) — the number of soldiers in the *i*-th column which start to march from the left or the right leg respectively.
Print single integer *k* — the number of the column in which soldiers need to change the leg from which they start to march, or 0 if the maximum beauty is already reached. Consider that columns are numbered from 1 to *n* in the order they are given in the input data. If there are several answers, print any of them.
[ "3\n5 6\n8 9\n10 3\n", "2\n6 5\n5 6\n", "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n" ]
[ "3\n", "1\n", "0\n" ]
In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal 5 + 8 + 10 = 23, and from the right leg — 6 + 9 + 3 = 18. In this case the beauty of the parade will equal |23 - 18| = 5. If you give the order to change the leg to the third co...
1,000
[ { "input": "3\n5 6\n8 9\n10 3", "output": "3" }, { "input": "2\n6 5\n5 6", "output": "1" }, { "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32", "output": "0" }, { "input": "2\n500 499\n500 500", "output": "0" }, { "input": "1\n139 252", "output": "0" }, { ...
1,640,458,187
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
93
0
a=int(input()) x=0 y=0 o=0 p=0 l=0 u=0 for i in range(a): d,c=map(int,input().split()) o+=d p+=c if x>d-c: x=d-c l=i if y<d-c: y=d-c u=i e=o-p e1=e+l e2=e+u w=abs(e) q=0 if w<abs(e1): w=abs(e1) q=l if w<abs(e2) : w=abs(e2) q=...
Title: Parade Time Limit: None seconds Memory Limit: None megabytes Problem Description: Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should...
```python a=int(input()) x=0 y=0 o=0 p=0 l=0 u=0 for i in range(a): d,c=map(int,input().split()) o+=d p+=c if x>d-c: x=d-c l=i if y<d-c: y=d-c u=i e=o-p e1=e+l e2=e+u w=abs(e) q=0 if w<abs(e1): w=abs(e1) q=l if w<abs(e2) : w=abs(e...
0
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr...
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO...
1,604,167,921
2,147,483,647
Python 3
OK
TESTS
71
248
0
a=[] for i in range(1,32): a.append(i*(i+1)/2) b=int(input()) print("YES" if b in a else "NO")
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t...
```python a=[] for i in range(1,32): a.append(i*(i+1)/2) b=int(input()) print("YES" if b in a else "NO") ```
3.938
630
A
Again Twenty Five!
PROGRAMMING
800
[ "number theory" ]
null
null
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power us...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output the last two digits of 5*n* without spaces between them.
[ "2\n" ]
[ "25" ]
none
0
[ { "input": "2", "output": "25" }, { "input": "7", "output": "25" }, { "input": "1000000000000000000", "output": "25" }, { "input": "2000000000000000000", "output": "25" }, { "input": "987654321012345678", "output": "25" } ]
1,695,456,044
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
500
614,400
a = int(input()) s = 1 d = 5 while s != a: d = d * 5 s += 1 print(d%100) # Sat Sep 23 2023 11:00:43 GMT+0300 (Moscow Standard Time)
Title: Again Twenty Five! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and ge...
```python a = int(input()) s = 1 d = 5 while s != a: d = d * 5 s += 1 print(d%100) # Sat Sep 23 2023 11:00:43 GMT+0300 (Moscow Standard Time) ```
0
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the inp...
Print a single integer — the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n...
1,541,343,256
2,147,483,647
Python 3
OK
TESTS
19
109
0
n, m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) Pc, Pa, ans = 0, 0, 0 while Pc < n and Pa < m : if a[Pa] >= c[Pc] : ans += 1 Pa += 1 Pc += 1 else: Pc += 1 print(ans)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ...
```python n, m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) Pc, Pa, ans = 0, 0, 0 while Pc < n and Pa < m : if a[Pa] >= c[Pc] : ans += 1 Pa += 1 Pc += 1 else: Pc += 1 print(ans) ```
3
475
B
Strongly Connected City
PROGRAMMING
1,400
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to wes...
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character...
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
[ "3 3\n&gt;&lt;&gt;\nv^v\n", "4 6\n&lt;&gt;&lt;&gt;\nv^v^v^\n" ]
[ "NO\n", "YES\n" ]
The figure above shows street directions in the second sample test case.
1,000
[ { "input": "3 3\n><>\nv^v", "output": "NO" }, { "input": "4 6\n<><>\nv^v^v^", "output": "YES" }, { "input": "2 2\n<>\nv^", "output": "YES" }, { "input": "2 2\n>>\n^v", "output": "NO" }, { "input": "3 3\n>><\n^^v", "output": "YES" }, { "input": "3 4\n>>...
1,680,788,480
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
def dfs(horizontal, vertical, node_x, node_y, visited, n, m, lens, name): if node_x != 0 and horizontal[node_y] == "<" and not visited.get((node_x, node_y), 0): visited[(node_x, node_y)] = 1 lens[name] += 1 dfs(horizontal, vertical, node_x - 1, node_y, visited, n, m, lens, name) ...
Title: Strongly Connected City Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one...
```python def dfs(horizontal, vertical, node_x, node_y, visited, n, m, lens, name): if node_x != 0 and horizontal[node_y] == "<" and not visited.get((node_x, node_y), 0): visited[(node_x, node_y)] = 1 lens[name] += 1 dfs(horizontal, vertical, node_x - 1, node_y, visited, n, m, lens, na...
0
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "i...
1,595,027,530
2,147,483,647
Python 3
OK
TESTS
18
93
6,656,000
n = int(input()) count = 0 res = [] if n >1000000: # if it is a big number, check from the last few numbers instead from beginning limit = 100 else: limit = n for i in range(n-limit, n): if n - i == sum(map(int,(str(i)))): res.append(i) if res: print(len(res)) for i in res: pr...
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe...
```python n = int(input()) count = 0 res = [] if n >1000000: # if it is a big number, check from the last few numbers instead from beginning limit = 100 else: limit = n for i in range(n-limit, n): if n - i == sum(map(int,(str(i)))): res.append(i) if res: print(len(res)) for i in re...
3
160
A
Twins
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces.
In the single line print the single number — the minimum needed number of coins.
[ "2\n3 3\n", "3\n2 1 2\n" ]
[ "2\n", "2\n" ]
In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum. In the second sample one coin isn't e...
500
[ { "input": "2\n3 3", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "5\n4 2 2 2 2", "output": "3" }, { "input": "7\n1 10 1 2 1 1 1", "output": "1" }, { "input": "5\n3 2 3 3 1", "output": "3" ...
1,696,336,388
2,147,483,647
PyPy 3-64
OK
TESTS
29
124
1,638,400
n=int(input()) c=0 k=0 l=list(map(int,input().split())) for i in range(n): c+=max(l) k+=1 l.remove(max(l)) if c>sum(l): print(k) break
Title: Twins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w...
```python n=int(input()) c=0 k=0 l=list(map(int,input().split())) for i in range(n): c+=max(l) k+=1 l.remove(max(l)) if c>sum(l): print(k) break ```
3
248
B
Chilly Willy
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneous...
A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
[ "1\n", "5\n" ]
[ "-1\n", "10080" ]
none
1,000
[ { "input": "1", "output": "-1" }, { "input": "5", "output": "10080" }, { "input": "6", "output": "100170" }, { "input": "4", "output": "1050" }, { "input": "15", "output": "100000000000110" }, { "input": "16", "output": "1000000000000050" }, { ...
1,611,405,846
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
122
0
n = int(input()) if (n < 2): print(-1) else: ans = 1 for i in range(n-1): ans *= 10 print ((ans // 210 + 1) * 210)
Title: Chilly Willy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected wit...
```python n = int(input()) if (n < 2): print(-1) else: ans = 1 for i in range(n-1): ans *= 10 print ((ans // 210 + 1) * 210) ```
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,589,812,657
2,147,483,647
PyPy 3
OK
TESTS
40
155
20,172,800
a = str(input()) b =0 word="hello" for i in range(len(a)): if(a[i]==word[b]): b+=1 if(b==5): break if(b==5): print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python a = str(input()) b =0 word="hello" for i in range(len(a)): if(a[i]==word[b]): b+=1 if(b==5): break if(b==5): print("YES") else: print("NO") ```
3.884925
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,549,024,918
2,147,483,647
Python 3
OK
TESTS
31
218
0
input() Wires = list(map(int, input().split())) N = int(input()) Shot = list() for i in range(N): Shot.append(list(map(int, input().split()))) Shot[i][0] -= 1 for i in range(len(Shot)): if Shot[i][0] != 0: Wires[Shot[i][0] - 1] += Shot[i][1] - 1 if Shot[i][0] != len(Wires) - 1: ...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python input() Wires = list(map(int, input().split())) N = int(input()) Shot = list() for i in range(N): Shot.append(list(map(int, input().split()))) Shot[i][0] -= 1 for i in range(len(Shot)): if Shot[i][0] != 0: Wires[Shot[i][0] - 1] += Shot[i][1] - 1 if Shot[i][0] != len(Wires) ...
3
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be...
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ...
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000...
1,624,324,963
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
from sys import exit info = input().split() list = [] for i in range(int(info[1])): list.append(input()) for j in range(int(info[1])): if list[0] == list[1] or list[0] == list[2] or list[1] == list[2]: print("NO") exit(0) for k in range(int(info[1])): x = 1 for l...
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of...
```python from sys import exit info = input().split() list = [] for i in range(int(info[1])): list.append(input()) for j in range(int(info[1])): if list[0] == list[1] or list[0] == list[2] or list[1] == list[2]: print("NO") exit(0) for k in range(int(info[1])): x = 1 ...
0
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,503,581,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
0
import sys n=int(input()) num=list(map(int,input().split())) s=sum(num) if(s%2==1): print("First") else: print("Second")
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 import sys n=int(input()) num=list(map(int,input().split())) s=sum(num) if(s%2==1): print("First") else: print("Second") ```
0
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,688,037,100
2,147,483,647
Python 3
OK
TESTS
34
46
0
""" Problema: Gioco di Sereja e Dima Descrizione del problema: Sereja e Dima stanno giocando a un gioco con delle carte numerate. Durante il gioco, i giocatori si alternano a prendere una carta dalla fila, scegliendo la carta più a sinistra o più a destra. Alla fine del gioco, i punti dei giocatori sono determinat...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python """ Problema: Gioco di Sereja e Dima Descrizione del problema: Sereja e Dima stanno giocando a un gioco con delle carte numerate. Durante il gioco, i giocatori si alternano a prendere una carta dalla fila, scegliendo la carta più a sinistra o più a destra. Alla fine del gioco, i punti dei giocatori sono ...
3
446
C
DZY Loves Fibonacci Numbers
PROGRAMMING
2,400
[ "data structures", "math", "number theory" ]
null
null
In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Moreover, there are *m* queries, each query has one of the two types: 1. Format of the que...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=300000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — initial array *a*. Then, *m* lines follow. A single line describes a single query in the format given in the statement. It is guaranteed ...
For each query of the second type, print the value of the sum on a single line.
[ "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3\n" ]
[ "17\n12\n" ]
After the first query, *a* = [2, 3, 5, 7]. For the second query, *sum* = 2 + 3 + 5 + 7 = 17. After the third query, *a* = [2, 4, 6, 9]. For the fourth query, *sum* = 2 + 4 + 6 = 12.
1,500
[ { "input": "4 4\n1 2 3 4\n1 1 4\n2 1 4\n1 2 4\n2 1 3", "output": "17\n12" }, { "input": "2 2\n1 2\n2 1 2\n2 1 2", "output": "3\n3" }, { "input": "10 20\n56 12 68 23 41 29 97 69 79 76\n1 3 5\n1 8 9\n2 3 10\n1 7 10\n2 1 10\n1 5 10\n2 2 4\n1 2 4\n1 5 6\n2 1 2\n2 4 5\n1 1 5\n1 8 9\n2 5 8\n2 ...
1,699,697,007
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
#罗景轩2300012610 n = int(input()) l = list(map(int, input().split())) Sum = sum(l) First_Pointer = 0 Second_Pointer = 0 Partial_Sum = 0 for i in l[:n]: Partial_Sum += i if Partial_Sum == Sum * 2 / 3: Second_Pointer += First_Pointer if Partial_Sum == Sum / 3: First_Pointer += 1 ...
Title: DZY Loves Fibonacci Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematical terms, the sequence *F**n* of Fibonacci numbers is defined by the recurrence relation DZY loves Fibonacci numbers very much. Today DZY gives you an array consisting of *n* integers: *a*1,<=...
```python #罗景轩2300012610 n = int(input()) l = list(map(int, input().split())) Sum = sum(l) First_Pointer = 0 Second_Pointer = 0 Partial_Sum = 0 for i in l[:n]: Partial_Sum += i if Partial_Sum == Sum * 2 / 3: Second_Pointer += First_Pointer if Partial_Sum == Sum / 3: First_Point...
-1
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equival...
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { ...
1,580,645,201
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
307,200
# s1="baaa" # s2="abaa" s1=input() s2=input() def eq(a,b,c,d): if ((b-a)!=(d-c))|((b-a)%2!=0&(d-a)%2!=0): return 1 else: if s1[a:b]==s2[c:d]: return 0 else: if (eq(a,(b+a)//2,(c+d)//2,d)==0&eq((a+b)//2+1,b,c,(c+d)//2-1)==0)|(eq(a,(b+a)//2,c,(c+d)//2-1)=...
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split str...
```python # s1="baaa" # s2="abaa" s1=input() s2=input() def eq(a,b,c,d): if ((b-a)!=(d-c))|((b-a)%2!=0&(d-a)%2!=0): return 1 else: if s1[a:b]==s2[c:d]: return 0 else: if (eq(a,(b+a)//2,(c+d)//2,d)==0&eq((a+b)//2+1,b,c,(c+d)//2-1)==0)|(eq(a,(b+a)//2,c,(c...
0
264
A
Escape from Stones
PROGRAMMING
1,200
[ "constructive algorithms", "data structures", "implementation", "two pointers" ]
null
null
Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's ...
The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r".
Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left.
[ "llrlr\n", "rrlll\n", "lrlrr\n" ]
[ "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n", "2\n4\n5\n3\n1\n" ]
In the first example, the positions of stones 1, 2, 3, 4, 5 will be <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/58fdb5684df807bfcb705a9da9ce175613362b7d.png" style="max-width: 100.0%;max-height: 100.0%;"/>, respectively. So you should print the sequence: 3, 5, 4, 2, 1.
500
[ { "input": "llrlr", "output": "3\n5\n4\n2\n1" }, { "input": "rrlll", "output": "1\n2\n5\n4\n3" }, { "input": "lrlrr", "output": "2\n4\n5\n3\n1" }, { "input": "lllrlrllrl", "output": "4\n6\n9\n10\n8\n7\n5\n3\n2\n1" }, { "input": "llrlrrrlrr", "output": "3\n5\n6...
1,694,617,100
2,147,483,647
Python 3
OK
TESTS
57
1,575
3,276,800
s = input() for a in range(len(s)): if s[a] == 'r': print(a +1) for a in range(len(s), 0 , -1): # print(a) if s[a - 1] == 'l': print(a)
Title: Escape from Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the ...
```python s = input() for a in range(len(s)): if s[a] == 'r': print(a +1) for a in range(len(s), 0 , -1): # print(a) if s[a - 1] == 'l': print(a) ```
3
656
C
Without Text
PROGRAMMING
2,000
[ "*special" ]
null
null
You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png)
The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character or a full stop ".".
Output the required answer.
[ "Codeforces\n", "APRIL.1st\n" ]
[ "-87\n", "17\n" ]
none
0
[ { "input": "Codeforces", "output": "-87" }, { "input": "APRIL.1st", "output": "17" }, { "input": ".0.1.2.", "output": "0" }, { "input": "CODEcode", "output": "0" }, { "input": "A", "output": "1" }, { "input": "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ...
1,576,512,247
2,147,483,647
PyPy 3
OK
TESTS
39
156
0
s = input() ans = 0 for x in s: if x.isupper(): ans += ord(x) - ord('A') + 1 if x.islower(): ans -= ord(x) - ord('a') + 1 print(ans)
Title: Without Text Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input Specification: The only line of the input is a s...
```python s = input() ans = 0 for x in s: if x.isupper(): ans += ord(x) - ord('A') + 1 if x.islower(): ans -= ord(x) - ord('a') + 1 print(ans) ```
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,695,478,969
2,147,483,647
PyPy 3-64
OK
TESTS
43
62
0
n = list(map(int, list(input()))) for i in range(len(n)): n[i] = min(n[i], 9 - n[i]) if n[0] == 0: n[0] = 9 print("".join(map(str, n)))
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python n = list(map(int, list(input()))) for i in range(len(n)): n[i] = min(n[i], 9 - n[i]) if n[0] == 0: n[0] = 9 print("".join(map(str, n))) ```
3
618
A
Slime Combining
PROGRAMMING
800
[ "implementation" ]
null
null
Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of...
The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000).
Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left.
[ "1\n", "2\n", "3\n", "8\n" ]
[ "1\n", "2\n", "2 1\n", "4\n" ]
In the first sample, we only have a single slime with value 1. The final state of the board is just a single slime with value 1. In the second sample, we perform the following steps: Initially we place a single slime in a row by itself. Thus, row is initially 1. Then, we will add another slime. The row is now 1 1. S...
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "3", "output": "2 1" }, { "input": "8", "output": "4" }, { "input": "100000", "output": "17 16 11 10 8 6" }, { "input": "12345", "output": "14 13 6 5 4 1" }, { "in...
1,683,656,830
2,147,483,647
Python 3
OK
TESTS
27
1,060
614,400
n = int(input()) slimes = [1] * n i = 0 while i < len(slimes)-1: if slimes[i] == slimes[i+1]: slimes[i] += 1 del slimes[i+1] i = max(i-1, 0) # Go back one position if necessary else: i += 1 print(*slimes)
Title: Slime Combining Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, y...
```python n = int(input()) slimes = [1] * n i = 0 while i < len(slimes)-1: if slimes[i] == slimes[i+1]: slimes[i] += 1 del slimes[i+1] i = max(i-1, 0) # Go back one position if necessary else: i += 1 print(*slimes) ```
3
171
D
Broken checker
PROGRAMMING
1,300
[ "*special", "brute force" ]
null
null
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem was alright, that's a mercy.
The only line of the input contains an integer between 1 and 5, inclusive. All tests for this problem are different. The contents of the test case doesn't need to be equal to its index.
The only line of the output contains an integer between 1 and 3, inclusive.
[]
[]
This problem has no samples, since there so few test cases.
0
[ { "input": "3", "output": "1" }, { "input": "1", "output": "2" }, { "input": "4", "output": "2" }, { "input": "2", "output": "3" }, { "input": "5", "output": "1" } ]
1,557,978,620
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
218
0
print([1,2,3,1,2,3][int(input())]) # # # # # # # # # ##############################
Title: Broken checker Time Limit: None seconds Memory Limit: None megabytes Problem Description: "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No,...
```python print([1,2,3,1,2,3][int(input())]) # # # # # # # # # ############################## ```
0
468
B
Two Sets
PROGRAMMING
2,000
[ "2-sat", "dfs and similar", "dsu", "graph matchings", "greedy" ]
null
null
Little X has *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n*. He wants to divide all of them into two sets *A* and *B*. The following two conditions must be satisfied: - If number *x* belongs to set *A*, then number *a*<=-<=*x* must also belong to set *A*. - If number *x* belongs to set *B*, then number *b*<=-<=*x...
The first line contains three space-separated integers *n*,<=*a*,<=*b* (1<=≤<=*n*<=≤<=105; 1<=≤<=*a*,<=*b*<=≤<=109). The next line contains *n* space-separated distinct integers *p*1,<=*p*2,<=...,<=*p**n* (1<=≤<=*p**i*<=≤<=109).
If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print *n* integers: *b*1,<=*b*2,<=...,<=*b**n* (*b**i* equals either 0, or 1), describing the division. If *b**i* equals to 0, then *p**i* belongs to set *A*, otherwise it belongs to set *B*. If it's impossible, print "NO" ...
[ "4 5 9\n2 3 4 5\n", "3 3 4\n1 2 4\n" ]
[ "YES\n0 0 1 1\n", "NO\n" ]
It's OK if all the numbers are in the same set, and the other one is empty.
1,000
[ { "input": "4 5 9\n2 3 4 5", "output": "YES\n0 0 1 1" }, { "input": "3 3 4\n1 2 4", "output": "NO" }, { "input": "100 8883 915\n1599 4666 663 3646 754 2113 2200 3884 4082 1640 3795 2564 2711 2766 1122 4525 1779 2678 2816 2182 1028 2337 4918 1273 4141 217 2682 1756 309 4744 915 1351 3302 ...
1,598,533,058
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
140
409,600
import itertools as it import collections as cc import heapq as hp import sys import collections as cc I=lambda : list(map(int,input().split())) aa=cc.defaultdict(list) bb=cc.defaultdict(list) for i in range(1): n,a,b=I() tf=1 l=I() ch=cc.defaultdict(int) for i in range(n): ch[l[i]]=i ans=[0]*n...
Title: Two Sets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X has *n* distinct integers: *p*1,<=*p*2,<=...,<=*p**n*. He wants to divide all of them into two sets *A* and *B*. The following two conditions must be satisfied: - If number *x* belongs to set *A*, then number *a*<=-...
```python import itertools as it import collections as cc import heapq as hp import sys import collections as cc I=lambda : list(map(int,input().split())) aa=cc.defaultdict(list) bb=cc.defaultdict(list) for i in range(1): n,a,b=I() tf=1 l=I() ch=cc.defaultdict(int) for i in range(n): ch[l[i]]=i ...
0
25
E
Test
PROGRAMMING
2,200
[ "hashing", "strings" ]
E. Test
2
256
Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input data contains the substring *s*1, the second enters an infinite loop...
There are exactly 3 lines in the input data. The *i*-th line contains string *s**i*. All the strings are non-empty, consists of lowercase Latin letters, the length of each string doesn't exceed 105.
Output one number — what is minimal length of the string, containing *s*1, *s*2 and *s*3 as substrings.
[ "ab\nbc\ncd\n", "abacaba\nabaaba\nx\n" ]
[ "4\n", "11\n" ]
none
0
[ { "input": "ab\nbc\ncd", "output": "4" }, { "input": "abacaba\nabaaba\nx", "output": "11" }, { "input": "syvncqmfhautvxudqdhggz\nhrpxzeghsocjpicuixskfuzupytsgjsdiyb\nybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehls", "output": "100" }, { "input": "jwdezvgfm\nmdoqvylpuvyk\nqylld...
1,646,921,802
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
30
0
t=3 s=["l"] while t: t-=1 s.append(input()) res="" if s[1] in s[2]: res+=s[2] elif s[2] in s[1]: res+=s[1] else: i=len(s[1])-1 j=0 while i>=0 and j<len(s[2]) and s[1][i]==s[2][j]: i-=1 j+=1 res+=s[1]+s[2][j:] if s[3] in res: print(len...
Title: Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong an...
```python t=3 s=["l"] while t: t-=1 s.append(input()) res="" if s[1] in s[2]: res+=s[2] elif s[2] in s[1]: res+=s[1] else: i=len(s[1])-1 j=0 while i>=0 and j<len(s[2]) and s[1][i]==s[2][j]: i-=1 j+=1 res+=s[1]+s[2][j:] if s[3] in res: ...
0
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, ...
1,650,907,723
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n = int(input()) a = sorted(list(map(int, input().split()))) for i in range(n): if a[i]-a[i-1]>1: print(a[i-1]+1) break if a[0]>1: print(1)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the...
```python n = int(input()) a = sorted(list(map(int, input().split()))) for i in range(n): if a[i]-a[i-1]>1: print(a[i-1]+1) break if a[0]>1: print(1) ```
0
852
G
Bathroom terminal
PROGRAMMING
1,700
[ "implementation" ]
null
null
Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in the tape-player, he sees a key hanging from a ceiling, chained to some kind of a machine, which is conn...
The first line of input contains two integers *N* and *M* (1<=≤<=*N*<=≤<= 100 000, 1<=≤<=*M*<=≤<= 5000), representing the number of words and patterns respectively. The next *N* lines represent each word, and after those *N* lines, following *M* lines represent each pattern. Each word and each pattern has a maximum le...
Output contains *M* lines and each line consists of one integer, representing the number of words that match the corresponding pattern.
[ "3 1\nabc\naec\nac\na?c\n" ]
[ "3\n" ]
If we switch '?' with 'b', 'e' and with empty character, we get 'abc', 'aec' and 'ac' respectively.
0
[ { "input": "3 1\nabc\naec\nac\na?c", "output": "3" }, { "input": "22 2\naaaab\naaabb\naabab\naabbb\nabaab\nababb\nabbab\nabbbb\naaab\naabb\nabab\nabbb\naab\nabb\nab\ncccd\nccdd\ncdcd\ncddd\nccd\ncdd\ncd\na???b\nc??d", "output": "15\n7" }, { "input": "15 6\naaa\naaabbb\naaabb\naaaaa\naaaa...
1,585,709,494
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
307,200
from bisect import * n,m,k=[int(i) for i in input().split()] pln=[] for i in range(m): pln.append([int(i) for i in input().split()]) pln.sort() grp=[[pln[0]]];gt=0; for i in range(1,m): if pln[i][0]!=pln[i-1][0]: gt=gt+1 grp.append([]) grp[gt].append(pln[i]) xx=[] for i in ran...
Title: Bathroom terminal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Smith wakes up at the side of a dirty, disused bathroom, his ankle chained to pipes. Next to him is tape-player with a hand-written message "Play Me". He finds a tape in his own back pocket. After putting the tape in ...
```python from bisect import * n,m,k=[int(i) for i in input().split()] pln=[] for i in range(m): pln.append([int(i) for i in input().split()]) pln.sort() grp=[[pln[0]]];gt=0; for i in range(1,m): if pln[i][0]!=pln[i-1][0]: gt=gt+1 grp.append([]) grp[gt].append(pln[i]) xx=[] fo...
-1
239
A
Two Bags of Potatoes
PROGRAMMING
1,200
[ "greedy", "implementation", "math" ]
null
null
Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, first...
The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105).
Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1.
[ "10 1 10\n", "10 6 40\n" ]
[ "-1\n", "2 8 14 20 26 \n" ]
none
500
[ { "input": "10 1 10", "output": "-1" }, { "input": "10 6 40", "output": "2 8 14 20 26 " }, { "input": "10 1 20", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "1 10000 1000000000", "output": "9999 19999 29999 39999 49999 59999 69999 79999 89999 99999 109999 119999 12999...
1,688,982,704
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
29
310
5,632,000
# your code goes here y,k,n=map(int,input().split()) if y+k>n: print(-1) if y+k==n: print(k) else: arr=[] mul=k i=1 while mul<=n: mul=k*i if mul>y: arr.append(mul-y) i+=1 if len(arr)!=0: arr.pop() print(*arr)
Title: Two Bags of Potatoes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* pota...
```python # your code goes here y,k,n=map(int,input().split()) if y+k>n: print(-1) if y+k==n: print(k) else: arr=[] mul=k i=1 while mul<=n: mul=k*i if mul>y: arr.append(mul-y) i+=1 if len(arr)!=0: arr.pop() print(*arr) ```
0
745
B
Hongcow Solves A Puzzle
PROGRAMMING
1,400
[ "implementation" ]
null
null
Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed tha...
The first line of input will contain two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500), the dimensions of the puzzle piece. The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty ...
Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise.
[ "2 3\nXXX\nXXX\n", "2 2\n.X\nXX\n", "5 5\n.....\n..X..\n.....\n.....\n.....\n" ]
[ "YES\n", "NO\n", "YES\n" ]
For the first sample, one example of a rectangle we can form is as follows For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle. In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle:
1,000
[ { "input": "2 3\nXXX\nXXX", "output": "YES" }, { "input": "2 2\n.X\nXX", "output": "NO" }, { "input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
1,482,012,156
2,147,483,647
Python 3
OK
TESTS
77
420
614,400
import sys n, m = map(int, input().split()) a = [input() for _ in range(n)] min_i, min_j = n, m max_i, max_j = 0, 0 for i in range(n): for j in range(m): if a[i][j] == 'X': min_i, min_j = min(min_i, i), min(min_j, j) max_i, max_j = max(max_i, i), max(max_j, j) for i in range(min_...
Title: Hongcow Solves A Puzzle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow likes solving puzzles. One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where t...
```python import sys n, m = map(int, input().split()) a = [input() for _ in range(n)] min_i, min_j = n, m max_i, max_j = 0, 0 for i in range(n): for j in range(m): if a[i][j] == 'X': min_i, min_j = min(min_i, i), min(min_j, j) max_i, max_j = max(max_i, i), max(max_j, j) for i in ...
3
607
A
Chain Reaction
PROGRAMMING
1,600
[ "binary search", "dp" ]
null
null
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however....
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beac...
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
[ "4\n1 9\n3 1\n6 1\n7 4\n", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n" ]
[ "1\n", "3\n" ]
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
500
[ { "input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3" }, { "input": "1\n0 1", "output": "0" }, { "input": "1\n0 1000000", "output": "0" }, { "input": "1\n1000000 1000000", "output": "0" }, { ...
1,588,202,781
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
155
307,200
from sys import stdin from collections import defaultdict def solve(energy, maxval): maxalive = -1 arr = [0] * (maxval + 1) for i in range(1, maxval + 1): if i not in energy: arr[i] = arr[i - 1] continue idx = max(0, i - energy[i] - 1) tmp = arr[idx] + 1 ...
Title: Chain Reaction Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of d...
```python from sys import stdin from collections import defaultdict def solve(energy, maxval): maxalive = -1 arr = [0] * (maxval + 1) for i in range(1, maxval + 1): if i not in energy: arr[i] = arr[i - 1] continue idx = max(0, i - energy[i] - 1) tmp = arr[i...
0
584
D
Dima and Lisa
PROGRAMMING
1,800
[ "brute force", "math", "number theory" ]
null
null
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≤<=*i*<=≤<=*k*), such that 1. 1<=...
The single line contains an odd number *n* (3<=≤<=*n*<=&lt;<=109).
In the first line print *k* (1<=≤<=*k*<=≤<=3), showing how many numbers are in the representation you found. In the second line print numbers *p**i* in any order. If there are multiple possible solutions, you can print any of them.
[ "27\n" ]
[ "3\n5 11 11\n" ]
A prime is an integer strictly larger than one that is divisible only by one and by itself.
2,000
[ { "input": "27", "output": "3\n2 2 23" }, { "input": "3", "output": "1\n3" }, { "input": "25", "output": "2\n2 23" }, { "input": "9", "output": "2\n2 7" }, { "input": "91", "output": "2\n2 89" }, { "input": "57", "output": "3\n2 2 53" }, { ...
1,695,722,689
2,147,483,647
PyPy 3-64
OK
TESTS
109
124
4,096,000
import sys import random input = sys.stdin.readline rd = random.randint(10 ** 9, 2 * 10 ** 9) n = int(input()) def isPrime(x: int) -> bool: if x < 3: return x == 2 if x % 2 != 1: return False A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] d = x - 1 r = 0 ...
Title: Dima and Lisa Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, ...
```python import sys import random input = sys.stdin.readline rd = random.randint(10 ** 9, 2 * 10 ** 9) n = int(input()) def isPrime(x: int) -> bool: if x < 3: return x == 2 if x % 2 != 1: return False A = [2, 325, 9375, 28178, 450775, 9780504, 1795265022] d = x - 1 ...
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,662,784,170
2,147,483,647
Python 3
OK
TESTS
58
46
0
n=input() a="heidi" j=0 for i in n: if i==a[j] : j+=1 if j==5: break if(j==5): print('YES') else: print('NO')
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 n=input() a="heidi" j=0 for i in n: if i==a[j] : j+=1 if j==5: break if(j==5): print('YES') else: print('NO') ```
3
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,697,537,907
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
s=input() if(s==s.upper()): print(s.capitalize()) else: w=s[0] w1=s[1] if(w==w.lower()): if(w1==w1.upper()): print(s.capitalize())
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python s=input() if(s==s.upper()): print(s.capitalize()) else: w=s[0] w1=s[1] if(w==w.lower()): if(w1==w1.upper()): print(s.capitalize()) ```
0
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether thi...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXY...
1,692,822,759
2,147,483,647
Python 3
OK
TESTS
59
46
0
alpha="abcdefghijklmnopqrstuvwxyz" n=int(input("")) s=input().lower() for x in alpha: if x not in s: print("no") quit() print("yes")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. ...
```python alpha="abcdefghijklmnopqrstuvwxyz" n=int(input("")) s=input().lower() for x in alpha: if x not in s: print("no") quit() print("yes") ```
3
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,687,268,614
2,147,483,647
Python 3
OK
TESTS
40
92
0
s = input() t = input() t1 = s[::-1] if(t==t1): 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 s = input() t = input() t1 = s[::-1] if(t==t1): print("YES") else: print("NO") ```
3.977
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,625,087,900
2,147,483,647
Python 3
OK
TESTS
83
124
0
s = input().split(' ') s = [int(i) for i in s] s.sort() def sticks(s): if (s[0] + s[1] > s[2]) or (s[1] + s[2] > s[3]) or (s[0] + s[2] > s[3]): return 'TRIANGLE' elif (s[0] + s[1] == s[2]) or (s[1] + s[2] == s[3]) or (s[0] + s[2] == s[3]): return 'SEGMENT' else: return 'IM...
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 s = input().split(' ') s = [int(i) for i in s] s.sort() def sticks(s): if (s[0] + s[1] > s[2]) or (s[1] + s[2] > s[3]) or (s[0] + s[2] > s[3]): return 'TRIANGLE' elif (s[0] + s[1] == s[2]) or (s[1] + s[2] == s[3]) or (s[0] + s[2] == s[3]): return 'SEGMENT' else: ...
3.969
90
B
African Crossword
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. African Crossword
2
256
An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
[ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n" ]
[ "abcd", "codeforces" ]
none
1,000
[ { "input": "3 3\ncba\nbcd\ncbc", "output": "abcd" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "output": "codeforces" }, { "input": "4 4\nusah\nusha\nhasu\nsuha", "output": "ahhasusu" }, { "input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "output...
1,673,460,157
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
n, m = map(int, input().split()) grid = [] for _ in range(n): grid.append(list(input())) for i in range(n): for j in range(m): if grid[i][j] == '*': continue for k in range(j+1, m): if grid[i][j] == grid[i][k]: grid[i][k] = '*' for j in rang...
Title: African Crossword Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: An African crossword is a rectangular table *n*<=×<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To s...
```python n, m = map(int, input().split()) grid = [] for _ in range(n): grid.append(list(input())) for i in range(n): for j in range(m): if grid[i][j] == '*': continue for k in range(j+1, m): if grid[i][j] == grid[i][k]: grid[i][k] = '*' for...
0
916
A
Jamie and Alarm Snooze
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ...
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59).
Print the minimum number of times he needs to press the button.
[ "3\n11 23\n", "5\n01 07\n" ]
[ "2\n", "0\n" ]
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20. In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
500
[ { "input": "3\n11 23", "output": "2" }, { "input": "5\n01 07", "output": "0" }, { "input": "34\n09 24", "output": "3" }, { "input": "2\n14 37", "output": "0" }, { "input": "14\n19 54", "output": "9" }, { "input": "42\n15 44", "output": "12" }, ...
1,624,329,125
2,147,483,647
Python 3
OK
TESTS
254
77
0
n=int(input()) h,m=map(int,input().split()) c=h*60+m ans=0 while "7" not in str(c//60)+str(c%60): c-=n ans+=1 if c==0: c=1440 print(ans)
Title: Jamie and Alarm Snooze Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the...
```python n=int(input()) h,m=map(int,input().split()) c=h*60+m ans=0 while "7" not in str(c//60)+str(c%60): c-=n ans+=1 if c==0: c=1440 print(ans) ```
3
678
B
The Same Calendar
PROGRAMMING
1,600
[ "implementation" ]
null
null
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ...
The only line contains integer *y* (1000<=≤<=*y*<=&lt;<=100'000) — the year of the calendar.
Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar.
[ "2016\n", "2000\n", "50501\n" ]
[ "2044\n", "2028\n", "50507\n" ]
Today is Monday, the 13th of June, 2016.
0
[ { "input": "2016", "output": "2044" }, { "input": "2000", "output": "2028" }, { "input": "50501", "output": "50507" }, { "input": "1000", "output": "1006" }, { "input": "1900", "output": "1906" }, { "input": "1899", "output": "1905" }, { "i...
1,586,385,820
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
109
0
import math n = int(input()) if n % 4 == 2 or n % 4 == 3: print(n + 11) elif n % 4 == 0: print(n + 28) elif n % 4 == 1: print(n + 6)
Title: The Same Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful t...
```python import math n = int(input()) if n % 4 == 2 or n % 4 == 3: print(n + 11) elif n % 4 == 0: print(n + 28) elif n % 4 == 1: print(n + 6) ```
0
975
B
Mancala
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next ...
The only line contains 14 integers $a_1, a_2, \ldots, a_{14}$ ($0 \leq a_i \leq 10^9$) — the number of stones in each hole. It is guaranteed that for any $i$ ($1\leq i \leq 14$) $a_i$ is either zero or odd, and there is at least one stone in the board.
Output one integer, the maximum possible score after one move.
[ "0 1 1 0 0 0 0 0 0 7 0 0 0 0\n", "5 1 1 1 1 0 0 0 0 0 0 0 0 0\n" ]
[ "4\n", "8\n" ]
In the first test case the board after the move from the hole with $7$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $4$.
1,000
[ { "input": "0 1 1 0 0 0 0 0 0 7 0 0 0 0", "output": "4" }, { "input": "5 1 1 1 1 0 0 0 0 0 0 0 0 0", "output": "8" }, { "input": "10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1", "output": "54294" }, { "input": "0 0 0 0 0 0 0 0 0 0 0 0 0 15", ...
1,684,334,354
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
a=list(map(int,input().split())) l=[] sum=0 for i in range(14): s=0 b=a[:] for x in b: x+=b[i]//14 for j in range(b[i]%14): if i+j+1<14: b[i+j+1]+=1 else: b[13-i-j]+=1 b[i]=0 for q in b: if q%2==0: s+=q if s...
Title: Mancala Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. ...
```python a=list(map(int,input().split())) l=[] sum=0 for i in range(14): s=0 b=a[:] for x in b: x+=b[i]//14 for j in range(b[i]%14): if i+j+1<14: b[i+j+1]+=1 else: b[13-i-j]+=1 b[i]=0 for q in b: if q%2==0: s+=q...
0
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { ...
1,594,387,279
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
108
20,172,800
class Solution: def __init__(self): self.n = int(input()) self.a = int(input()) def solve_and_print(self): a = [int(ai) for ai in str(self.a) if int(ai) > 1] ans = [2 for _ in range(a.count(2))] + [3 for _ in range(a.count(3))] + \ [5 for _ in range(a.cou...
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that cont...
```python class Solution: def __init__(self): self.n = int(input()) self.a = int(input()) def solve_and_print(self): a = [int(ai) for ai in str(self.a) if int(ai) > 1] ans = [2 for _ in range(a.count(2))] + [3 for _ in range(a.count(3))] + \ [5 for _ in r...
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,653,406,979
2,147,483,647
Python 3
OK
TESTS
30
92
0
basic = input() upper = [] lower = [] for item in basic: if (item.isupper() == True ): upper.append(item) elif (item.islower() == True ): lower.append(item) if len(upper) <= len(lower) : print(basic.lower()) elif len(upper) > len(lower) : print(basic.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python basic = input() upper = [] lower = [] for item in basic: if (item.isupper() == True ): upper.append(item) elif (item.islower() == True ): lower.append(item) if len(upper) <= len(lower) : print(basic.lower()) elif len(upper) > len(lower) : print(basic.upper()) ```
3.977
735
D
Taxes
PROGRAMMING
1,600
[ "math", "number theory" ]
null
null
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not equal to *n*, of course). For example, if *n*<==<=6 then Funt has to pay 3 burles, while fo...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·109) — the total year income of mr. Funt.
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
[ "4\n", "27\n" ]
[ "2\n", "3\n" ]
none
1,750
[ { "input": "4", "output": "2" }, { "input": "27", "output": "3" }, { "input": "3", "output": "1" }, { "input": "5", "output": "1" }, { "input": "10", "output": "2" }, { "input": "2000000000", "output": "2" }, { "input": "26", "output": ...
1,565,522,896
2,147,483,647
PyPy 3
OK
TESTS
85
140
1,228,800
n = int(input()) def isPrime(n): if (n==0 or n==1): return False i = 2 while (i*i<=n): if (n%i==0): return False i += 1 return True if (n%2==0): if (n==2): print(1) else: print(2) else: if (isPrime(n)): print(1) elif (isPrime(...
Title: Taxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to *n* (*n*<=≥<=2) burles and the amount of tax he has to pay is calculated as the maximum divisor of *n* (not ...
```python n = int(input()) def isPrime(n): if (n==0 or n==1): return False i = 2 while (i*i<=n): if (n%i==0): return False i += 1 return True if (n%2==0): if (n==2): print(1) else: print(2) else: if (isPrime(n)): print(1) elif...
3
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*|  &gt;  |...
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,593,946,618
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
186
22,220,800
n = int(inpu()) a = [] b = [] scoreA = 0 scoreB = 0 for i in range(n): e = int(input()) if e > 0: scoreA+=e a.append(e) else: scoreB+=abs(e) b.append(abs(e)) if i==n-1: last = e if scoreA > scoreB or a < b: print("first") elif scoreA < score...
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(inpu()) a = [] b = [] scoreA = 0 scoreB = 0 for i in range(n): e = int(input()) if e > 0: scoreA+=e a.append(e) else: scoreB+=abs(e) b.append(abs(e)) if i==n-1: last = e if scoreA > scoreB or a < b: print("first") elif scor...
-1
369
A
Valera and Plates
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can...
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
500
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\...
1,647,867,455
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
a=int(input()) n,g,p=map(int,input().split()) b=list(map(int,input().split())) g1=b.count(1) p1=b.count(2) ot=0 ostg=0 if g>g1: ostg=g-g1 else: ot=g1-g p=p+ostg if p<p1: ot=ot+(p1-p) print(ot)
Title: Valera and Plates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ...
```python a=int(input()) n,g,p=map(int,input().split()) b=list(map(int,input().split())) g1=b.count(1) p1=b.count(2) ot=0 ostg=0 if g>g1: ostg=g-g1 else: ot=g1-g p=p+ostg if p<p1: ot=ot+(p1-p) print(ot) ```
-1
0
none
none
none
0
[ "none" ]
null
null
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in *n* ho...
The first line of the input contains two integers, given in the decimal notation, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the number of hours in one day and the number of minutes in one hour, respectively.
Print one integer in decimal notation — the number of different pairs of hour and minute, such that all digits displayed on the watches are distinct.
[ "2 3\n", "8 2\n" ]
[ "4\n", "5\n" ]
In the first sample, possible pairs are: (0: 1), (0: 2), (1: 0), (1: 2). In the second sample, possible pairs are: (02: 1), (03: 1), (04: 1), (05: 1), (06: 1).
0
[ { "input": "2 3", "output": "4" }, { "input": "8 2", "output": "5" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "8 8", "output": "0" }, { "input": "50 50", "output": "0" }, { "input": "344 344", "o...
1,623,245,120
2,300
PyPy 3
WRONG_ANSWER
TESTS
10
202
2,457,600
from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i*i > x: ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, ro...
```python from collections import defaultdict, deque, Counter from sys import stdin, stdout from heapq import heappush, heappop import math import io import os import math import bisect #?############################################################ def isPrime(x): for i in range(2, x): if i...
0
818
B
Permutation Game
PROGRAMMING
1,600
[ "implementation" ]
null
null
*n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n* appears exactly once in it. The game consists of *m* steps. On each step the current leader with in...
The first line contains two integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *m* integer numbers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*) — indices of leaders in the beginning of each step.
Print such permutation of *n* numbers *a*1,<=*a*2,<=...,<=*a**n* that leaders in the game will be exactly *l*1,<=*l*2,<=...,<=*l**m* if all the rules are followed. If there are multiple solutions print any of them. If there is no permutation which satisfies all described conditions print -1.
[ "4 5\n2 3 1 4 4\n", "3 3\n3 1 2\n" ]
[ "3 1 2 4 \n", "-1\n" ]
Let's follow leadership in the first example: - Child 2 starts. - Leadership goes from 2 to 2 + *a*<sub class="lower-index">2</sub> = 3. - Leadership goes from 3 to 3 + *a*<sub class="lower-index">3</sub> = 5. As it's greater than 4, it's going in a circle to 1. - Leadership goes from 1 to 1 + *a*<sub class="lowe...
0
[ { "input": "4 5\n2 3 1 4 4", "output": "3 1 2 4 " }, { "input": "3 3\n3 1 2", "output": "-1" }, { "input": "1 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
1,498,789,013
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
93
23,142,400
n, m = [int(item) for item in input().split()] l = [int(item) for item in input().split()] l = [0] + l a = [0] * (n + 1) for i in range(1, m): a[l[i]] = (l[i + 1] - l[i] - 1) % n + 1 #print(a) cnt = [0] * (n + 1) for i in range(1, n + 1): cnt[a[i]] += 1 if a[i] != 0 and cnt[a[i]] > 1: ...
Title: Permutation Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation *a*1,<=*a*2,<=...,<=*a**n* of length *n*. It is an integer sequence such that each integer from 1 to *n...
```python n, m = [int(item) for item in input().split()] l = [int(item) for item in input().split()] l = [0] + l a = [0] * (n + 1) for i in range(1, m): a[l[i]] = (l[i + 1] - l[i] - 1) % n + 1 #print(a) cnt = [0] * (n + 1) for i in range(1, n + 1): cnt[a[i]] += 1 if a[i] != 0 and cnt[a[i]]...
0
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider t...
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling t...
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { ...
1,665,632,560
2,147,483,647
Python 3
OK
TESTS
45
154
8,396,800
n = int(input()) l = list(map(int, input().split())) m = min(l) if l.count(m) > 1: print("Still Rozdil" ) else: print((l.index(m) + 1))
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha...
```python n = int(input()) l = list(map(int, input().split())) m = min(l) if l.count(m) > 1: print("Still Rozdil" ) else: print((l.index(m) + 1)) ```
3
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,671,302,035
2,147,483,647
Python 3
OK
TESTS
40
92
0
x=str(input()) y=str(input()) x_rev=x[::-1] if x_rev==y: 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 x=str(input()) y=str(input()) x_rev=x[::-1] if x_rev==y: print("YES") else: print("NO") ```
3.977
152
B
Steps
PROGRAMMING
1,300
[ "binary search", "implementation" ]
null
null
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple. Vasya noticed that the yard is a rectangu...
The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*). The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. ...
Print the single number — the number of steps Vasya had made. Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "4 5\n1 1\n3\n1 1\n1 1\n0 -2\n", "10 10\n1 2\n1\n-1 0\n" ]
[ "4\n", "0\n" ]
In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0,  - 2) and he ends up in square (4, 2). Overall,...
1,000
[ { "input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2", "output": "4" }, { "input": "10 10\n1 2\n1\n-1 0", "output": "0" }, { "input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5", "output": "13" }, { "input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n2...
1,648,430,101
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
122
0
r,c=list(map(int,input().split())) xc,yc=list(map(int,input().split())) count=0 for i in range(int(input())): x,y=list(map(int,input().split())) if ((x+xc)<=r): xc+=x if((y+yc)<=c): yc+=y count+=1 print(count+1)
Title: Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ...
```python r,c=list(map(int,input().split())) xc,yc=list(map(int,input().split())) count=0 for i in range(int(input())): x,y=list(map(int,input().split())) if ((x+xc)<=r): xc+=x if((y+yc)<=c): yc+=y count+=1 print(count+1) ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,658,231,127
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
inputList = list(map(int, input().split())) n = inputList[0] m = inputList[1] a = inputList[2] if(n>=a): dimension1 = n//a else: dimension1 = 1 if(m>=a): dimension2 = m//a else: dimension2 = 1 elif (n%a==0 and m%a!=0): dimension2 += 1 elif (n%a!=0 and m%a==0): dimension1 += 1 ...
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python inputList = list(map(int, input().split())) n = inputList[0] m = inputList[1] a = inputList[2] if(n>=a): dimension1 = n//a else: dimension1 = 1 if(m>=a): dimension2 = m//a else: dimension2 = 1 elif (n%a==0 and m%a!=0): dimension2 += 1 elif (n%a!=0 and m%a==0): dimensi...
-1
169
B
Replacing Digits
PROGRAMMING
1,100
[ "greedy" ]
null
null
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. ...
The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain lead...
Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes.
[ "1024\n010\n", "987\n1234567\n" ]
[ "1124\n", "987\n" ]
none
1,000
[ { "input": "1024\n010", "output": "1124" }, { "input": "987\n1234567", "output": "987" }, { "input": "10\n1", "output": "11" }, { "input": "11\n1", "output": "11" }, { "input": "12\n2", "output": "22" }, { "input": "1\n0", "output": "1" }, { ...
1,649,771,869
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
4
216
3,481,600
from decimal import * import math import sys rasp_final="" def transformare_baza(numar,baza): transformare="" while numar>=baza: rest=numar%baza numar=numar//baza transformare+=str(rest) transformare+=str(numar) noua_baza=transformare[::-1] return noua_baza #c=int(input()) for z in ran...
Title: Replacing Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary ...
```python from decimal import * import math import sys rasp_final="" def transformare_baza(numar,baza): transformare="" while numar>=baza: rest=numar%baza numar=numar//baza transformare+=str(rest) transformare+=str(numar) noua_baza=transformare[::-1] return noua_baza #c=int(input()) fo...
-1
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ...
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd...
1,700,028,153
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
s = input() t = input() if len(t) < len(s): s, t = t, s a = set() for i in s: a.add(i) tmp = '' ans = -1 for i in t: if i not in a: tmp += i else: ans = max(ans, len(tmp)) tmp = '' print(ans)
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two ...
```python s = input() t = input() if len(t) < len(s): s, t = t, s a = set() for i in s: a.add(i) tmp = '' ans = -1 for i in t: if i not in a: tmp += i else: ans = max(ans, len(tmp)) tmp = '' print(ans) ```
0
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,669,984,810
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using namespace std; int main() { int a,b,d,sum,n,cnt; scanf("%d%d%d",&n,&b,&d); int arr[n]; sum=0; cnt=0; for(int i=0; i<n; i++) { scanf("%d",&arr[i]); } for(int i=0; i<n; i++) { if(arr[i]>b) { ...
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 #include <bits/stdc++.h> using namespace std; int main() { int a,b,d,sum,n,cnt; scanf("%d%d%d",&n,&b,&d); int arr[n]; sum=0; cnt=0; for(int i=0; i<n; i++) { scanf("%d",&arr[i]); } for(int i=0; i<n; i++) { if(arr[i]>b) { ...
-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,693,332,138
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
13,619,200
n, b, d = list(map(int, input().split())) oranges = list(map(int, input().split())) oranges = list(filter(lambda x: x <= b, oranges)) answer = 0 if len(oranges) == 0 or sum(oranges) - d == 0 else sum(oranges) // d print(answer)
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 = list(map(int, input().split())) oranges = list(map(int, input().split())) oranges = list(filter(lambda x: x <= b, oranges)) answer = 0 if len(oranges) == 0 or sum(oranges) - d == 0 else sum(oranges) // d print(answer) ```
0
346
B
Lucky Common Subsequence
PROGRAMMING
2,000
[ "dp", "strings" ]
null
null
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri...
The input contains three strings in three separate lines: *s*1, *s*2 and *virus* (1<=≤<=|*s*1|,<=|*s*2|,<=|*virus*|<=≤<=100). Each string consists only of uppercase English letters.
Output the longest common subsequence of *s*1 and *s*2 without *virus* as a substring. If there are multiple answers, any of them will be accepted. If there is no valid common subsequence, output 0.
[ "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ\n", "AA\nA\nA\n" ]
[ "ORZ\n", "0\n" ]
none
1,000
[ { "input": "AJKEQSLOBSROFGZ\nOVGURWZLWVLUXTH\nOZ", "output": "ORZ" }, { "input": "AA\nA\nA", "output": "0" }, { "input": "PWBJTZPQHA\nZJMKLWSROQ\nUQ", "output": "WQ" }, { "input": "QNHRPFYMAAPJDUHBAEXNEEZSTMYHVGQPYKNMVKMBVSVLIYGUVMJHEFLJEPIWFHSLISTGOKRXNMSCXYKMAXBPKCOCNTIRPCU...
1,524,179,504
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
156
7,577,600
x= input() y= input() virus= input() dicc = {} n= len(x) m= len(y) c = [] for i in range(n): column = [] for j in range(m): column.append(0) dicc[i,j]="" c.append(column) for i in range(n): for j in range(m): if x[i] == y[j]:...
Title: Lucky Common Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequen...
```python x= input() y= input() virus= input() dicc = {} n= len(x) m= len(y) c = [] for i in range(n): column = [] for j in range(m): column.append(0) dicc[i,j]="" c.append(column) for i in range(n): for j in range(m): if x[i...
0
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of...
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb...
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "...
1,580,303,716
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
109
307,200
a,b,c,d=[int(i) for i in input().split()] if(a==c and b==d): print("0 0 0") else: if(a==c or b==d): print(1,end=" ") else: print(2,end=" ") if(((a+b)%2)!=((c+d)%2)): print(0,end=" ") elif(a+b==c+d): print(1,end=" ") else: print(2,end=" ") ...
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=...
```python a,b,c,d=[int(i) for i in input().split()] if(a==c and b==d): print("0 0 0") else: if(a==c or b==d): print(1,end=" ") else: print(2,end=" ") if(((a+b)%2)!=((c+d)%2)): print(0,end=" ") elif(a+b==c+d): print(1,end=" ") else: print(2,end...
0
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,683,881,748
2,147,483,647
Python 3
OK
TESTS
101
92
0
a = eval(input()) s = (input()) s = s.split() arr = [0] * a for i in range(a): b = int(s[i]) arr[b-1] = int(i+1) res = ' '.join([str(elem) for elem in arr]) print(res)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python a = eval(input()) s = (input()) s = s.split() arr = [0] * a for i in range(a): b = int(s[i]) arr[b-1] = int(i+1) res = ' '.join([str(elem) for elem in arr]) print(res) ```
3
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the ...
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooo...
1,530,184,455
2,147,483,647
Python 3
OK
TESTS
18
93
0
n=int(input()) def f(n): if n==1 or n==2: return 1 return f(n-1)+f(n-2) i=2 p=[] while f(i)<=n: p.append(f(i)) i+=1 x='' for i in range(n): if i+1 in p: x+='O' else: x+='o' print(x)
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should o...
```python n=int(input()) def f(n): if n==1 or n==2: return 1 return f(n-1)+f(n-2) i=2 p=[] while f(i)<=n: p.append(f(i)) i+=1 x='' for i in range(n): if i+1 in p: x+='O' else: x+='o' print(x) ```
3
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n...
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7...
1,691,089,064
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> #define endl '\n' #define ll long long int #define loop(i,a,b) for(ll i=a;i<=b;++i) #define pb push_back #define f first #define s second #define mp make_pair #define MOD 1000000007 ...
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ...
```python #include<bits/stdc++.h> #define endl '\n' #define ll long long int #define loop(i,a,b) for(ll i=a;i<=b;++i) #define pb push_back #define f first #define s second #define mp make_pair #define MOD 1...
-1
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,685,679,607
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
124
2,764,800
n=int(input()) p=list(map(int,input().split())) gift=[0]*n for i in range(1,n+1): gift[p[i]-1]=i+1 print(*gift)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n=int(input()) p=list(map(int,input().split())) gift=[0]*n for i in range(1,n+1): gift[p[i]-1]=i+1 print(*gift) ```
-1
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The pre...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ...
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "...
1,634,201,527
2,147,483,647
Python 3
OK
TESTS
25
92
0
n,m = map(int,input().split()) m%=(n*(n+1)/2) for i in range(1,n): if m<i: break m-=i print(int(m))
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu...
```python n,m = map(int,input().split()) m%=(n*(n+1)/2) for i in range(1,n): if m<i: break m-=i print(int(m)) ```
3.977
978
B
File Name
PROGRAMMING
800
[ "greedy", "strings" ]
null
null
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia...
The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name. The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name.
Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0.
[ "6\nxxxiii\n", "5\nxxoxx\n", "10\nxxxxxxxxxx\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters.
0
[ { "input": "6\nxxxiii", "output": "1" }, { "input": "5\nxxoxx", "output": "0" }, { "input": "10\nxxxxxxxxxx", "output": "8" }, { "input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "output": "98" }, { ...
1,656,237,013
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
4,505,600
n = int(input()) s = input() c = 0 d = 0 for i in range(len(s)): if s[i] == 'x': d += 1 else: if d > c: c = d d = 0 if i == len(s) - 1: if d > c: c = d if c >= 3: print(c - 2) else: print(0)
Title: File Name Time Limit: None seconds Memory Limit: None megabytes Problem Description: You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let...
```python n = int(input()) s = input() c = 0 d = 0 for i in range(len(s)): if s[i] == 'x': d += 1 else: if d > c: c = d d = 0 if i == len(s) - 1: if d > c: c = d if c >= 3: print(c - 2) else: print(0) ```
0
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i...
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0...
1,660,423,962
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n, m = map(int, input().split()) num_list = list(int(num) for num in input().strip().split())[:n] r = sum(num_list[:m]) l =sum(num_list[m-1:]) print(r , l ) if(r > l ): print (r) else: print(l)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city...
```python n, m = map(int, input().split()) num_list = list(int(num) for num in input().strip().split())[:n] r = sum(num_list[:m]) l =sum(num_list[m-1:]) print(r , l ) if(r > l ): print (r) else: print(l) ```
0
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'...
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one spac...
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n...
1,605,528,452
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
218
0
l=[] l1=[] a=int(input()) total=0 for i in a*[0]: l.append(list(map(int,input().split()))) print(l) for i in range(a): cx,cy,cyu,cyd,cxu,cxd=0,0,0,0,0,0 for x in range(a): if l[i][0]==l[x][0] and (cyu<1 or cyd<1): if l[i][1]<l[x][1]: cyu+=1 elif l...
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the give...
```python l=[] l1=[] a=int(input()) total=0 for i in a*[0]: l.append(list(map(int,input().split()))) print(l) for i in range(a): cx,cy,cyu,cyd,cxu,cxd=0,0,0,0,0,0 for x in range(a): if l[i][0]==l[x][0] and (cyu<1 or cyd<1): if l[i][1]<l[x][1]: cyu+=1 ...
0
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,617,897,447
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
56
748
2,457,600
n = int(input()) list1 = [] list2 = [] cas = 1 answer =[] for i in range(n): h , m = map(int, input().split()) list1.append(m) list2.append(h) for j in range(1,len(list1)): if list2[j] == list2[j-1] and list1[j] == list1[j-1]: cas += 1 if list2[j] != list2[j-1] or list1[j] != lis...
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python n = int(input()) list1 = [] list2 = [] cas = 1 answer =[] for i in range(n): h , m = map(int, input().split()) list1.append(m) list2.append(h) for j in range(1,len(list1)): if list2[j] == list2[j-1] and list1[j] == list1[j-1]: cas += 1 if list2[j] != list2[j-1] or list1...
-1
814
A
An abandoned sentiment from past
PROGRAMMING
900
[ "constructive algorithms", "greedy", "implementation", "sortings" ]
null
null
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ...
Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise.
[ "4 2\n11 0 0 14\n5 4\n", "6 1\n2 3 0 8 9 10\n5\n", "4 1\n8 94 0 4\n89\n", "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n" ]
[ "Yes\n", "No\n", "Yes\n", "Yes\n" ]
In the first sample: - Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulti...
500
[ { "input": "4 2\n11 0 0 14\n5 4", "output": "Yes" }, { "input": "6 1\n2 3 0 8 9 10\n5", "output": "No" }, { "input": "4 1\n8 94 0 4\n89", "output": "Yes" }, { "input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7", "output": "Yes" }, { "input": "40 1\n23 26 27 28 31 35 38 4...
1,496,838,775
1,075
Python 3
WRONG_ANSWER
PRETESTS
3
61
0
n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) b = sorted(b) ib = 0 for i in range(len(a)): if a[i] == 0: a[i] = b[ib] ib += 1 last = -1 increasing = True for i in range(len(a) - 1): if a[i] <= last: increasing = False last = a[i] if increasing: print(...
Title: An abandoned sentiment from past Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of t...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) b = sorted(b) ib = 0 for i in range(len(a)): if a[i] == 0: a[i] = b[ib] ib += 1 last = -1 increasing = True for i in range(len(a) - 1): if a[i] <= last: increasing = False last = a[i] if increasin...
0
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ...
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are...
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, M...
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1...
1,677,656,767
2,147,483,647
PyPy 3-64
OK
TESTS
48
77
0
n, k = map(int, input().split()) a = list(map(int, input().split())) res = 0 for _ in range(n): if a[0] <= k: a = a[1:] res += 1 elif a[-1] <= k: a = a[:-1] res += 1 print(res)
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) res = 0 for _ in range(n): if a[0] <= k: a = a[1:] res += 1 elif a[-1] <= k: a = a[:-1] res += 1 print(res) ```
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,683,939,627
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
124
0
n, t = map(int, input().split()) a = list(map(int, input().split())) pref_a = [0] for i in range(n): pref_a.append(pref_a[i] + a[i]) r = n l = 0 ans = 0 while True: if pref_a[r] - pref_a[l] <= t: r += (n - r) // 2 elif pref_a[r] - pref_a[l] > t: r = r // 2 il = l ir = r...
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 = map(int, input().split()) a = list(map(int, input().split())) pref_a = [0] for i in range(n): pref_a.append(pref_a[i] + a[i]) r = n l = 0 ans = 0 while True: if pref_a[r] - pref_a[l] <= t: r += (n - r) // 2 elif pref_a[r] - pref_a[l] > t: r = r // 2 il = l ...
0
178
A1
Educational Game
PROGRAMMING
1,000
[]
null
null
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* numbered from 1 to *n*. The goal of the game is to make numbers *a*1,<=*a*2,<=...,<=*a**k* (i.e. some pr...
The first input line contains a single integer *n*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=104), separated by single spaces. The input limitations for getting 20 points are: - 1<=≤<=*n*<=≤<=300 The input limitations for getting 50 points are: - 1<=≤<=*n*<=≤<=2000 The input limitations f...
Print exactly *n*<=-<=1 lines: the *k*-th output line must contain the minimum number of moves needed to make the first *k* elements of the original sequence *a**i* equal to zero. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams, or the %I64d sp...
[ "4\n1 0 1 2\n", "8\n1 2 3 4 5 6 7 8\n" ]
[ "1\n1\n3\n", "1\n3\n6\n10\n16\n24\n40\n" ]
none
20
[ { "input": "4\n1 0 1 2", "output": "1\n1\n3" }, { "input": "8\n1 2 3 4 5 6 7 8", "output": "1\n3\n6\n10\n16\n24\n40" }, { "input": "5\n4 1 4 7 6", "output": "4\n5\n9\n17" }, { "input": "9\n13 13 7 11 3 9 3 5 5", "output": "13\n26\n33\n44\n47\n69\n79\n117" }, { "in...
1,691,996,717
2,147,483,647
PyPy 3-64
OK
TESTS1
12
122
1,536,000
def find(a): n=0 while pow(2,n)<=a: n+=1 return pow(2,n-1) m = int(input()) l = [int(x) for x in input().split()] ans=0 n=0 c=0 for i in range(m): ans+=l[i] if c<m-1: c+=1 print(ans) n=int(find(m-(i+1))) l[i+n]+=l[i] ...
Title: Educational Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of *n* non-negative integers *a**i* nu...
```python def find(a): n=0 while pow(2,n)<=a: n+=1 return pow(2,n-1) m = int(input()) l = [int(x) for x in input().split()] ans=0 n=0 c=0 for i in range(m): ans+=l[i] if c<m-1: c+=1 print(ans) n=int(find(m-(i+1))) l[i+n]+=l[i] ...
3
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" ...
1,599,933,825
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
217
69,324,800
import sys import threading sys.setrecursionlimit(10**5) threading.stack_size(1 << 27) input=sys.stdin.readline thread = threading.Thread(target=main) thread.start() thread.join() n, k = [int(i) for i in input().split()] dp = [[-1]*(2005) for i in range(2005)] MOD=10**9+7 def solve(x,k): if(k==0): ...
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join h...
```python import sys import threading sys.setrecursionlimit(10**5) threading.stack_size(1 << 27) input=sys.stdin.readline thread = threading.Thread(target=main) thread.start() thread.join() n, k = [int(i) for i in input().split()] dp = [[-1]*(2005) for i in range(2005)] MOD=10**9+7 def solve(x,k): if(k=...
-1
701
A
Cards
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one player. Find the way to distribute cards such that the sum of values written of the cards ...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100) — the number of cards in the deck. It is guaranteed that *n* is even. The second line contains the sequence of *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100), where *a**i* is equal to the number written on the *i*-th card.
Print *n*<=/<=2 pairs of integers, the *i*-th pair denote the cards that should be given to the *i*-th player. Each card should be given to exactly one player. Cards are numbered in the order they appear in the input. It is guaranteed that solution exists. If there are several correct answers, you are allowed to print...
[ "6\n1 5 7 4 4 3\n", "4\n10 10 10 10\n" ]
[ "1 3\n6 2\n4 5\n", "1 2\n3 4\n" ]
In the first sample, cards are distributed in such a way that each player has the sum of numbers written on his cards equal to 8. In the second sample, all values *a*<sub class="lower-index">*i*</sub> are equal. Thus, any distribution is acceptable.
500
[ { "input": "6\n1 5 7 4 4 3", "output": "1 3\n6 2\n4 5" }, { "input": "4\n10 10 10 10", "output": "1 4\n2 3" }, { "input": "100\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,681,590,885
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n = int(input()) allCards = list(map(int,input().split())) sumOneHand = sum(allCards)/(n/2) used = [] allHands = [] for i in range(n): if i in used: continue for j in range(i+1, n): if j in used: continue if allCards[i] + allCards[j] == sumOneHand: allHands.appe...
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cards (*n* is even) in the deck. Each card has a positive integer written on it. *n*<=/<=2 people will play new card game. At the beginning of the game each player gets two cards, each card is given to exactly one p...
```python n = int(input()) allCards = list(map(int,input().split())) sumOneHand = sum(allCards)/(n/2) used = [] allHands = [] for i in range(n): if i in used: continue for j in range(i+1, n): if j in used: continue if allCards[i] + allCards[j] == sumOneHand: all...
0
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*...
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": ...
1,698,996,040
2,147,483,647
PyPy 3-64
OK
TESTS
25
46
0
n = int(input()) s = str(input()) k1 = s.count("A") k2 = s.count("D") if k1 > k2: print("Anton") elif k1 < k2: print("Danik") else: print("Friendship")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, w...
```python n = int(input()) s = str(input()) k1 = s.count("A") k2 = s.count("D") if k1 > k2: print("Anton") elif k1 < k2: print("Danik") else: print("Friendship") ```
3
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of...
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numb...
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "...
1,666,164,734
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
y1, x1, y2, x2 = map(int, input().split()) res = '' if x1 == x2 or y1 == y2: # ладья res += '1 ' else: res += '2 ' if (x1 + y1) % 2 == (x2 + y2) % 2: # офицер if abs(x1 - x2) == abs(y1 - y2): res += '1 ' else: res += '2 ' else: res += '0 ' res += str(round((((x2 - x1...
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=...
```python y1, x1, y2, x2 = map(int, input().split()) res = '' if x1 == x2 or y1 == y2: # ладья res += '1 ' else: res += '2 ' if (x1 + y1) % 2 == (x2 + y2) % 2: # офицер if abs(x1 - x2) == abs(y1 - y2): res += '1 ' else: res += '2 ' else: res += '0 ' res += str(round(...
0
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ...
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*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,689,764,326
2,147,483,647
PyPy 3-64
OK
TESTS
33
62
0
n=int(input()) if n%2 == 0: print(f"4 {n-4}") else: print(f"9 {n-9}")
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()) if n%2 == 0: print(f"4 {n-4}") else: print(f"9 {n-9}") ```
3
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other table...
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0...
1,612,221,531
2,147,483,647
Python 3
OK
TESTS
22
77
307,200
a,b=map(int,input().split()) j=0 while j<a: for i in range(0,a): if i==j:print(b,end=" ") else: print(0,end=" ") j+=1 print()
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortun...
```python a,b=map(int,input().split()) j=0 while j<a: for i in range(0,a): if i==j:print(b,end=" ") else: print(0,end=" ") j+=1 print() ```
3
54
A
Presents
PROGRAMMING
1,300
[ "implementation" ]
A. Presents
2
256
The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he c...
The first line contains integers *N* and *K* (1<=≤<=*N*<=≤<=365, 1<=≤<=*K*<=≤<=*N*). The second line contains a number *C* which represents the number of holidays (0<=≤<=*C*<=≤<=*N*). Then in the same line follow *C* numbers ranging from 1 to *N* which are the numbers of holiday days. The numbers are given in the incr...
Print a single number — the minimal number of presents the Hedgehog will receive over the following *N* days.
[ "5 2\n1 3\n", "10 1\n3 6 7 8\n" ]
[ "3", "10" ]
none
500
[ { "input": "5 2\n1 3", "output": "3" }, { "input": "10 1\n3 6 7 8", "output": "10" }, { "input": "5 5\n1 3", "output": "1" }, { "input": "10 3\n3 3 6 9", "output": "3" }, { "input": "5 2\n0", "output": "2" }, { "input": "1 1\n0", "output": "1" },...
1,533,484,224
2,147,483,647
Python 3
OK
TESTS
65
248
0
n, k = list(map(int,input().strip().split(' '))) holidays = list(map(int,input().strip().split(' ')))[1:] prev = 0 i = 0 inc = 0 pres = 0 while i < n: i += 1 inc += 1 if inc == k or i in holidays: prev = i inc = 0 pres += 1 print(pres)
Title: Presents Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Hedgehog likes to give presents to his friend, but no less he likes to receive them. Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the spec...
```python n, k = list(map(int,input().strip().split(' '))) holidays = list(map(int,input().strip().split(' ')))[1:] prev = 0 i = 0 inc = 0 pres = 0 while i < n: i += 1 inc += 1 if inc == k or i in holidays: prev = i inc = 0 pres += 1 print(pres) ```
3.938
985
A
Chess Placing
PROGRAMMING
1,100
[ "implementation" ]
null
null
You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to . In one step you can move...
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100, *n* is even) — the size of the chessboard. The second line of the input contains integer numbers (1<=≤<=*p**i*<=≤<=*n*) — initial positions of the pieces. It is guaranteed that all the positions are distinct.
Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.
[ "6\n1 2 6\n", "10\n1 2 3 4 5\n" ]
[ "2\n", "10\n" ]
In the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3. In the second example the possible strategy is to move...
0
[ { "input": "6\n1 2 6", "output": "2" }, { "input": "10\n1 2 3 4 5", "output": "10" }, { "input": "2\n2", "output": "0" }, { "input": "100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 ...
1,582,209,048
348
Python 3
WRONG_ANSWER
TESTS
4
109
0
n = int(input()) fig = list(map(int, input().split())) mp = [0] * n turn1 = 0 turn2 = 0 for i in range(n // 2): turn1 += abs(fig[i] - (i * 2 + 1)) turn2 += abs(fig[i] - (i * 2 + 2)) print(min(turn1, turn2))
Title: Chess Placing Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a chessboard of size 1<=×<=*n*. It is guaranteed that *n* is even. The chessboard is painted like this: "BWBW...BW". Some cells of the board are occupied by the chess pieces. Each cell contains no more than...
```python n = int(input()) fig = list(map(int, input().split())) mp = [0] * n turn1 = 0 turn2 = 0 for i in range(n // 2): turn1 += abs(fig[i] - (i * 2 + 1)) turn2 += abs(fig[i] - (i * 2 + 2)) print(min(turn1, turn2)) ```
0
6
C
Alice, Bob and Chocolate
PROGRAMMING
1,200
[ "greedy", "two pointers" ]
C. Alice, Bob and Chocolate
2
64
Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them wi...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=105) — the amount of bars on the table. The second line contains a sequence *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000), where *t**i* is the time (in seconds) needed to consume the *i*-th bar (in the order from left to right).
Print two numbers *a* and *b*, where *a* is the amount of bars consumed by Alice, and *b* is the amount of bars consumed by Bob.
[ "5\n2 9 8 2 7\n" ]
[ "2 3\n" ]
none
0
[ { "input": "5\n2 9 8 2 7", "output": "2 3" }, { "input": "1\n1", "output": "1 0" }, { "input": "2\n1 1", "output": "1 1" }, { "input": "3\n1 1 1", "output": "2 1" }, { "input": "4\n1 1 1 1", "output": "2 2" }, { "input": "1\n6", "output": "1 0" }...
1,585,135,748
2,147,483,647
PyPy 3
OK
TESTS
40
372
8,089,600
n = int(input()) a = [int(x) for x in input().split()] b = 0 c = 0 d = 0 e = n-1 while d <= e: if b <= c: b += a[d] d += 1 else: c += a[e] e -= 1 print(d, n - d)
Title: Alice, Bob and Chocolate Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Alice and Bob like games. And now they are ready to start a new game. They have placed *n* chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. Fo...
```python n = int(input()) a = [int(x) for x in input().split()] b = 0 c = 0 d = 0 e = n-1 while d <= e: if b <= c: b += a[d] d += 1 else: c += a[e] e -= 1 print(d, n - d) ```
3.846728
55
A
Flea travel
PROGRAMMING
1,200
[ "implementation", "math" ]
A. Flea travel
1
256
A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: will the flea visit all the hassocks or not. We assume that ...
The only line contains single integer: 1<=≤<=*n*<=≤<=1000 — number of hassocks.
Output "YES" if all the hassocks will be visited and "NO" otherwise.
[ "1\n", "3\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "YES" }, { "input": "4", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "NO" }, { "input": "7", "output": "NO...
1,691,394,607
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=input() print 'YNEOS'[n&(n-1)>0::2]
Title: Flea travel Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A flea is sitting at one of the *n* hassocks, arranged in a circle, at the moment. After minute number *k* the flea jumps through *k*<=-<=1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighbo...
```python n=input() print 'YNEOS'[n&(n-1)>0::2] ```
-1
967
A
Mind the Gap
PROGRAMMING
1,100
[ "implementation" ]
null
null
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut...
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i...
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
[ "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "3 17\n0 30\n1 0\n12 0\n" ]
[ "6 1\n", "24 50\n", "0 0\n" ]
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th...
500
[ { "input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50" }, { "input": "3 17\n0 30\n1 0\n12 0", "output": "0 0" }, { ...
1,627,655,554
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
| In English По-русски _failure_coder |
Title: Mind the Gap Time Limit: None seconds Memory Limit: None megabytes Problem Description: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ...
```python | In English По-русски _failure_coder | ```
-1
454
A
Little Pony and Crystal Mine
PROGRAMMING
800
[ "implementation" ]
null
null
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot...
The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd).
Output a crystal of size *n*.
[ "3\n", "5\n", "7\n" ]
[ "*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n" ]
none
500
[ { "input": "3", "output": "*D*\nDDD\n*D*" }, { "input": "5", "output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**" }, { "input": "7", "output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***" }, { "input": "11", "output": "*****D*****\n****DDD****\n***DDDDD***\n**...
1,616,639,981
2,147,483,647
PyPy 3
OK
TESTS
12
93
0
n = int(input()) for i in range(1+(n)//2): num_D = 1 + ((i)*2) num_ast = (n-num_D)//2 str_d = ''.join(['*']*(num_ast)+['D']*(num_D)+['*']*(num_ast)) print(str_d) for i in range((n)//2): num_D = n - ((i+1)*2) num_ast = (n-num_D)//2 str_d = ''.join(['*']*(num_ast)+['D']*(num_D)+['*']*(num_ast)) print(st...
Title: Little Pony and Crystal Mine Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You ...
```python n = int(input()) for i in range(1+(n)//2): num_D = 1 + ((i)*2) num_ast = (n-num_D)//2 str_d = ''.join(['*']*(num_ast)+['D']*(num_D)+['*']*(num_ast)) print(str_d) for i in range((n)//2): num_D = n - ((i+1)*2) num_ast = (n-num_D)//2 str_d = ''.join(['*']*(num_ast)+['D']*(num_D)+['*']*(num_ast)) ...
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,688,033,038
2,147,483,647
Python 3
OK
TESTS
31
92
0
T = int(input()) a = input() a = a.split() a = [int(x) for x in a] l = 0 for i in a: l += i l = l/T print(l)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python T = int(input()) a = input() a = a.split() a = [int(x) for x in a] l = 0 for i in a: l += i l = l/T print(l) ```
3
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all...
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3...
1,688,066,911
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
def II(): return(int(input())) def LMI(): return(list(map(int,input().split()))) def I(): return(input()) def MII(): return(map(int,input().split())) # import sys # input=sys.stdin.readline # import io,os # input = io.BytesIO(os.read(0,os.fstat(0).st_size)). # from collections import Counte...
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down fro...
```python def II(): return(int(input())) def LMI(): return(list(map(int,input().split()))) def I(): return(input()) def MII(): return(map(int,input().split())) # import sys # input=sys.stdin.readline # import io,os # input = io.BytesIO(os.read(0,os.fstat(0).st_size)). # from collections imp...
0
706
D
Vasiliy's Multiset
PROGRAMMING
1,800
[ "binary search", "bitmasks", "data structures", "trees" ]
null
null
Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given *q* queries and a multiset *A*, initially containing only integer 0. There are three types of queries: 1. "+ x" — add integer *x* to multiset *A*.1. "- x" — erase one occurrence of integer *x* from multiset *A...
The first line of the input contains a single integer *q* (1<=≤<=*q*<=≤<=200<=000) — the number of queries Vasiliy has to perform. Each of the following *q* lines of the input contains one of three characters '+', '-' or '?' and an integer *x**i* (1<=≤<=*x**i*<=≤<=109). It's guaranteed that there is at least one query...
For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer *x**i* and some integer from the multiset *A*.
[ "10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11\n" ]
[ "11\n10\n14\n13\n" ]
After first five operations multiset *A* contains integers 0, 8, 9, 11, 6 and 1. The answer for the sixth query is integer <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9e2f3d4f1a7c134a5695ba1d548df2b4f9292206.png" style="max-width: 100.0%;max-height: 100.0%;"/> — maximum among integers ...
2,000
[ { "input": "10\n+ 8\n+ 9\n+ 11\n+ 6\n+ 1\n? 3\n- 8\n? 3\n? 8\n? 11", "output": "11\n10\n14\n13" }, { "input": "12\n+ 4\n+ 4\n+ 5\n? 3\n- 4\n? 3\n- 4\n? 3\n? 3\n- 5\n+ 10\n? 1", "output": "7\n7\n6\n6\n11" }, { "input": "10\n? 1\n+ 1\n+ 8\n- 1\n+ 2\n+ 7\n+ 4\n+ 7\n+ 3\n? 7", "output": ...
1,689,346,016
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689346016.331094")# 1689346016.33111
Title: Vasiliy's Multiset Time Limit: None seconds Memory Limit: None megabytes Problem Description: Author has gone out of the stories about Vasiliy, so here is just a formal task description. You are given *q* queries and a multiset *A*, initially containing only integer 0. There are three types of queries: 1. ...
```python print("_RANDOM_GUESS_1689346016.331094")# 1689346016.33111 ```
0
71
B
Progress Bar
PROGRAMMING
1,300
[ "implementation", "math" ]
B. Progress Bar
1
256
A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squares, located in line. To add clarity, let's number them with positive integers from 1 to *n* fr...
We are given 3 space-separated integers *n*, *k*, *t* (1<=≤<=*n*,<=*k*<=≤<=100, 0<=≤<=*t*<=≤<=100).
Print *n* numbers. The *i*-th of them should be equal to *a**i*.
[ "10 10 54\n", "11 13 37\n" ]
[ "10 10 10 10 10 4 0 0 0 0 ", "13 13 13 13 0 0 0 0 0 0 0 " ]
none
1,000
[ { "input": "10 10 54", "output": "10 10 10 10 10 4 0 0 0 0 " }, { "input": "11 13 37", "output": "13 13 13 13 0 0 0 0 0 0 0 " }, { "input": "9 25 50", "output": "25 25 25 25 12 0 0 0 0 " }, { "input": "43 47 77", "output": "47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 47 ...
1,669,115,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, k, t = map(int, input().split()) z = n * k * t // 100 ans = [k] * (z//k) ans += [z%k] ans += [0] * (n-z//k-1) print(ans)
Title: Progress Bar Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar. A bar is represented as *n* squar...
```python n, k, t = map(int, input().split()) z = n * k * t // 100 ans = [k] * (z//k) ans += [z%k] ans += [0] * (n-z//k-1) print(ans) ```
0
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,627,555,537
2,147,483,647
Python 3
OK
TESTS
42
77
6,758,400
k = int(input().split()[1]) if sum(sorted(list(map(int,input().split())))[:-1]) > k: print('NO') else: print('YES')
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 k = int(input().split()[1]) if sum(sorted(list(map(int,input().split())))[:-1]) > k: print('NO') else: print('YES') ```
3
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,688,652,245
2,147,483,647
Python 3
OK
TESTS
21
46
0
n=int(input()) f=[] for i in range(1,n+1): if i%2==1: f.append("I hate") else: f.append("I love") if i!=n: f.append("that") f.append("it") x=' '.join(f) print(x)
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and...
```python n=int(input()) f=[] for i in range(1,n+1): if i%2==1: f.append("I hate") else: f.append("I love") if i!=n: f.append("that") f.append("it") x=' '.join(f) print(x) ```
3
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams...
The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line...
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7...
1,689,889,342
2,147,483,647
PyPy 3
OK
TESTS
32
77
0
n,a,b, = map(int,input().split()) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) for i in range(1,n+1): if i in l1: print(1,end = ' ') else: print(2,end = ' ') print()
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between...
```python n,a,b, = map(int,input().split()) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) for i in range(1,n+1): if i in l1: print(1,end = ' ') else: print(2,end = ' ') print() ```
3
361
B
Levko and Permutation
PROGRAMMING
1,200
[ "constructive algorithms", "math", "number theory" ]
null
null
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g...
The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*).
In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them.
[ "4 2\n", "1 1\n" ]
[ "2 4 3 1", "-1\n" ]
In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 &gt; 1 and *gcd*(3, 3) = 3 &gt; 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful. The second sample has no beautiful permutations.
1,000
[ { "input": "4 2", "output": "2 1 3 4 " }, { "input": "1 1", "output": "-1" }, { "input": "7 4", "output": "3 1 2 4 5 6 7 " }, { "input": "10 9", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10000 5000", "output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1...
1,610,441,116
2,147,483,647
PyPy 3
OK
TESTS
47
218
8,908,800
import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline n, k = list(map(int, input().split())) if k == n: print(-1) exit() ans = list(range(n-k+1, n+1)) new_n = n-k for i in range(1, new_n+1): print(i%new_n + 1, end=" ") print(*an...
Title: Levko and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb...
```python import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') input = sys.stdin.readline n, k = list(map(int, input().split())) if k == n: print(-1) exit() ans = list(range(n-k+1, n+1)) new_n = n-k for i in range(1, new_n+1): print(i%new_n + 1, end=" ") ...
3
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "...
1,687,031,771
2,147,483,647
Python 3
OK
TESTS
85
46
102,400
s = input() if 'AB' in s and 'BA' in s: # Find the first occurrence of "AB" and the first occurrence of "BA" after the "AB" ab_index = s.find('AB') ba_index = s.find('BA', ab_index + 2) # Check if the substrings are non-overlapping if ba_index != -1 and ba_index != ab_index + 1: p...
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contain...
```python s = input() if 'AB' in s and 'BA' in s: # Find the first occurrence of "AB" and the first occurrence of "BA" after the "AB" ab_index = s.find('AB') ba_index = s.find('BA', ab_index + 2) # Check if the substrings are non-overlapping if ba_index != -1 and ba_index != ab_index + 1: ...
3
62
A
A Student's Dream
PROGRAMMING
1,300
[ "greedy", "math" ]
A. A Student's Dream
2
256
Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable profess...
The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.
Print YES or NO, that is, the answer to Petr Palych's question.
[ "5 1\n10 5\n", "4 5\n3 3\n", "1 2\n11 6\n" ]
[ "YES", "YES", "NO" ]
The boy and the girl don't really care who goes to the left.
500
[ { "input": "5 1\n10 5", "output": "YES" }, { "input": "4 5\n3 3", "output": "YES" }, { "input": "1 2\n11 6", "output": "NO" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "2 2\n1 1", "output": "YES" }, { "input": "3 3\n1 1", "output": "NO"...
1,667,660,525
2,147,483,647
PyPy 3
OK
TESTS
60
156
0
A1,A2=map(int,input().split()) B1,B2=map(int,input().split()) print("YES" if A2-1<=B1<=(A2-1)*2+4 or A1-1<=B2<=(A1-1)*2+4 else "NO")
Title: A Student's Dream Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming t...
```python A1,A2=map(int,input().split()) B1,B2=map(int,input().split()) print("YES" if A2-1<=B1<=(A2-1)*2+4 or A1-1<=B2<=(A1-1)*2+4 else "NO") ```
3.961
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,587,637,002
2,147,483,647
Python 3
OK
TESTS
36
218
0
def main(): y,w=[int(x) for x in input().split()] temp=max(y,w) ans=7-temp if ans==1: print('1/6') elif ans==2: print('1/3') elif ans==3: print('1/2') elif ans==4: print('2/3') elif ans==5: print('5/6') elif ans==6: prin...
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 def main(): y,w=[int(x) for x in input().split()] temp=max(y,w) ans=7-temp if ans==1: print('1/6') elif ans==2: print('1/3') elif ans==3: print('1/2') elif ans==4: print('2/3') elif ans==5: print('5/6') elif ans==6: ...
3.891
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,673,034,077
2,147,483,647
Python 3
OK
TESTS
40
92
0
t=input() s=input() if s==t[-1::-1]: 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 t=input() s=input() if s==t[-1::-1]: print("YES") else: print("NO") ```
3.977
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — ...
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has...
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }...
1,659,787,704
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
a = int(input()) b = int(input()) c = int(input()) ratio = [1, 2, 4] loop = [a*i for i in ratio] sum = 0 bool = False for loop, ratio in zip(loop, ratio): if (loop-ratio) == 0: bool = True print(0) else: sum += (loop-ratio) if bool == False: print(sum)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa...
```python a = int(input()) b = int(input()) c = int(input()) ratio = [1, 2, 4] loop = [a*i for i in ratio] sum = 0 bool = False for loop, ratio in zip(loop, ratio): if (loop-ratio) == 0: bool = True print(0) else: sum += (loop-ratio) if bool == False: print(sum) ```
0
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels...
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output":...
1,691,865,584
2,147,483,647
Python 3
OK
TESTS
29
62
0
def can_pass_all_levels(n, p_levels, q_levels): levels = [False] * n for level in p_levels: levels[level - 1] = True for level in q_levels: levels[level - 1] = True for level in levels: if not level: return False return True n = int...
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the g...
```python def can_pass_all_levels(n, p_levels, q_levels): levels = [False] * n for level in p_levels: levels[level - 1] = True for level in q_levels: levels[level - 1] = True for level in levels: if not level: return False return True ...
3
276
B
Little Girl and Game
PROGRAMMING
1,300
[ "games", "greedy" ]
null
null
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The players move in turns; In one move the player can remove an arbitrary letter from string *s*. - If the p...
The input contains a single line, containing string *s* (1<=≤<=|*s*|<=<=≤<=<=103). String *s* consists of lowercase English letters.
In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.
[ "aba\n", "abca\n" ]
[ "First\n", "Second\n" ]
none
1,000
[ { "input": "aba", "output": "First" }, { "input": "abca", "output": "Second" }, { "input": "aabb", "output": "First" }, { "input": "ctjxzuimsxnarlciuynqeoqmmbqtagszuo", "output": "Second" }, { "input": "gevqgtaorjixsxnbcoybr", "output": "First" }, { "i...
1,641,374,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
from collections import Counter def isPalindrome(s): return s==s[::-1] s = input() player = 'Second' if isPalindrome(s): player = 'First' else: cnt = Counter(s) x = [i for i in cnt.items() if i[1]==1] if len(x)%2!=0: player = 'First' print(player)
Title: Little Girl and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Girl loves problems on games very much. Here's one of them. Two players have got a string *s*, consisting of lowercase English letters. They play a game that is described by the following rules: - The...
```python from collections import Counter def isPalindrome(s): return s==s[::-1] s = input() player = 'Second' if isPalindrome(s): player = 'First' else: cnt = Counter(s) x = [i for i in cnt.items() if i[1]==1] if len(x)%2!=0: player = 'First' print(player) ```
0
120
C
Winnie-the-Pooh and honey
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=≤<=*a**i*<=≤<=100).
Print a single number — how many kilos of honey gets Piglet.
[ "3 3\n15 8 10\n" ]
[ "9\n" ]
none
0
[ { "input": "3 3\n15 8 10", "output": "9" }, { "input": "1 3\n3", "output": "0" }, { "input": "3 4\n3 8 2", "output": "5" }, { "input": "3 2\n95 25 49", "output": "151" }, { "input": "3 1\n8 3 2", "output": "5" }, { "input": "5 1\n4 7 9 5 7", "outpu...
1,647,664,176
2,147,483,647
PyPy 3-64
OK
TESTS
20
122
0
fin = open('input.txt', 'r') fout = open('output.txt', 'w') n, k = list(map(int, fin.readline().split())) arr = list(map(int, fin.readline().split())) sum = 0 for e in arr: if (e//k) > 3: sum += e - 3*k else: sum += e%k fout.write(str(sum)) fout.close() fin.close()
Title: Winnie-the-Pooh and honey Time Limit: None seconds Memory Limit: None megabytes Problem Description: As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie an...
```python fin = open('input.txt', 'r') fout = open('output.txt', 'w') n, k = list(map(int, fin.readline().split())) arr = list(map(int, fin.readline().split())) sum = 0 for e in arr: if (e//k) > 3: sum += e - 3*k else: sum += e%k fout.write(str(sum)) fout.close() fin.close() ```
3