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
0
none
none
none
0
[ "none" ]
null
null
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodo...
First line of input contains two integer numbers: *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100<=000) — amount of segments of Teodor's picture and maximal coordinate of point that Sasha can ask about. *i*th of next *n* lines contains two integer numbers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*m*) — left and right ends ...
Single line of output should contain one integer number *k* – size of largest set (*x**i*,<=*cnt*(*x**i*)) where all *x**i* are different, 1<=≤<=*x**i*<=≤<=*m*, and *cnt*(*x**i*) is amount of segments, containing point with coordinate *x**i*, such that one can't be sure that there doesn't exist point, belonging to all ...
[ "2 4\n1 2\n3 4\n", "4 6\n1 3\n2 3\n4 6\n5 6\n" ]
[ "4\n", "5\n" ]
First example shows situation where Sasha can never be sure that Teodor isn't lying to him, because even if one knows *cnt*(*x*<sub class="lower-index">*i*</sub>) for each point in segment [1;4], he can't distinguish this case from situation Teodor has drawn whole [1;4] segment. In second example Sasha can ask about 5...
0
[]
1,520,155,811
3,011
Python 3
WRONG_ANSWER
PRETESTS
2
62
5,632,000
n, m = map(int, input().split()) events1 = [0] * (m + 1) events2 = [0] * (m + 1) for i in range(n): a, b = map(int, input().split()) events1[a] += 1 events2[b] += 1 counts = [0] * (n - 1) cur = 0 mx = 0 mx_i = -1 for i in range(1, m + 1): cur += events1[i] if cur > 0: counts[...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;*m*] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integ...
```python n, m = map(int, input().split()) events1 = [0] * (m + 1) events2 = [0] * (m + 1) for i in range(n): a, b = map(int, input().split()) events1[a] += 1 events2[b] += 1 counts = [0] * (n - 1) cur = 0 mx = 0 mx_i = -1 for i in range(1, m + 1): cur += events1[i] if cur > 0: ...
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,466,665
2,147,483,647
Python 3
OK
TESTS
30
92
0
s=input() c=0;d=0 for i in s: if i.isupper(): c=c+1 else: d=d+1 if c>d: print(s.upper()) else: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() c=0;d=0 for i in s: if i.isupper(): c=c+1 else: d=d+1 if c>d: print(s.upper()) else: print(s.lower()) ```
3.977
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" ...
1,515,597,196
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,632,000
n=int(input()) k=int(input()) i=0 while((n>>i)>0): i+=1 i-=1 if(k==1): print(n) else: print((2<<i)-1)
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co...
```python n=int(input()) k=int(input()) i=0 while((n>>i)>0): i+=1 i-=1 if(k==1): print(n) else: print((2<<i)-1) ```
-1
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,623,928,244
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
154
7,577,600
n = int(input()) a = list(map(int,input().split())) if n==len(set(a)): print(n) else: print("Still Rozdil")
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()) a = list(map(int,input().split())) if n==len(set(a)): print(n) else: print("Still Rozdil") ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ...
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, o...
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4...
1,630,692,021
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
16,486,400
n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) tem1=0 tem2=0 stack1={} stack2={} for i in range(m): target = q[i] if(target in stack1): tem1 += stack1[target] else: x=0 for j in range(n): x+=1 ...
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c...
```python n = int(input()) a = list(map(int,input().split())) m = int(input()) q = list(map(int,input().split())) tem1=0 tem2=0 stack1={} stack2={} for i in range(m): target = q[i] if(target in stack1): tem1 += stack1[target] else: x=0 for j in range(n): x+...
0
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,683,633,606
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
def canMove(i,j): return i > -1 and i<n and j > -1 and j < m; def dfsMaze(i,j): visited[i][j]=True neighbors=[] verticalNeighj=j if dj[i]=='v': verticalNeighi=i+1 else: verticalNeighi=i-1 horizontalNeighi=i if di[j]=='>': horizontalNeighj=j+1...
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 canMove(i,j): return i > -1 and i<n and j > -1 and j < m; def dfsMaze(i,j): visited[i][j]=True neighbors=[] verticalNeighj=j if dj[i]=='v': verticalNeighi=i+1 else: verticalNeighi=i-1 horizontalNeighi=i if di[j]=='>': horizontal...
0
44
C
Holidays
PROGRAMMING
1,300
[ "implementation" ]
C. Holidays
2
256
School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people a...
The first input line contains two numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next *m* lines contain the description of the duty schedule. Each line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=*...
Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day.
[ "10 5\n1 2\n3 3\n4 6\n7 7\n8 10\n", "10 5\n1 2\n2 3\n4 5\n7 8\n9 10\n", "10 5\n1 2\n3 3\n5 7\n7 7\n7 10\n" ]
[ "OK\n", "2 2\n", "4 0\n" ]
Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number.
0
[ { "input": "10 5\n1 2\n3 3\n4 6\n7 7\n8 10", "output": "OK" }, { "input": "10 5\n1 2\n2 3\n4 5\n7 8\n9 10", "output": "2 2" }, { "input": "10 5\n1 2\n3 3\n5 7\n7 7\n7 10", "output": "4 0" }, { "input": "5 4\n1 1\n2 2\n3 3\n4 5", "output": "OK" }, { "input": "100 5...
1,695,445,612
2,147,483,647
PyPy 3
OK
TESTS
35
186
0
n, m = map(int, input().split()) a = [0]*105 while m: l, r = map(int, input().split()) a[l] += 1 a[r+1] -= 1 m -= 1 for i in range(1, n+1): a[i] += a[i-1] flag = 1 for i in range(1, n+1): if a[i] == 0 or a[i] > 1: flag = 0 print(i, '', end = '') print(...
Title: Holidays Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: School holidays come in Berland. The holidays are going to continue for *n* days. The students of school №*N* are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the ...
```python n, m = map(int, input().split()) a = [0]*105 while m: l, r = map(int, input().split()) a[l] += 1 a[r+1] -= 1 m -= 1 for i in range(1, n+1): a[i] += a[i-1] flag = 1 for i in range(1, n+1): if a[i] == 0 or a[i] > 1: flag = 0 print(i, '', end = '') ...
3.9535
448
A
Rewards
PROGRAMMING
800
[ "implementation" ]
null
null
Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c...
The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100). The numbers in the lines are separated by single spaces.
Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes).
[ "1 1 1\n1 1 1\n4\n", "1 1 3\n2 3 4\n2\n", "1 0 0\n1 0 0\n1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "1 1 1\n1 1 1\n4", "output": "YES" }, { "input": "1 1 3\n2 3 4\n2", "output": "YES" }, { "input": "1 0 0\n1 0 0\n1", "output": "NO" }, { "input": "0 0 0\n0 0 0\n1", "output": "YES" }, { "input": "100 100 100\n100 100 100\n100", "output": "YES" }, ...
1,643,799,366
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
62
0
a,a1,a2=map(int,input().split()) b,b1,b2=map(int,input().split()) n=int(input()) bob=b+b1+b2 aob=a+a1+a2 if aob<=5: aob=1 else: aob=(aob//5)+1 if bob<=10: bob=1 else: bob=(bob//10)+1 if aob+bob<=n: print("YES") else: print("NO")
Title: Rewards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ...
```python a,a1,a2=map(int,input().split()) b,b1,b2=map(int,input().split()) n=int(input()) bob=b+b1+b2 aob=a+a1+a2 if aob<=5: aob=1 else: aob=(aob//5)+1 if bob<=10: bob=1 else: bob=(bob//10)+1 if aob+bob<=n: print("YES") else: print("NO") ```
0
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,633,292,375
2,147,483,647
Python 3
OK
TESTS
34
62
6,963,200
inpt1 = [int(x) for x in input().split(" ")] queue, icecreams = inpt1 distressed_kids = 0 for people in range(queue): inpt2 = input().split(" ") if inpt2[0] == "+": icecreams += int(inpt2[1]) else: if int(inpt2[1]) > icecreams: distressed_kids += 1 else: ...
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python inpt1 = [int(x) for x in input().split(" ")] queue, icecreams = inpt1 distressed_kids = 0 for people in range(queue): inpt2 = input().split(" ") if inpt2[0] == "+": icecreams += int(inpt2[1]) else: if int(inpt2[1]) > icecreams: distressed_kids += 1 els...
3
797
A
k-Factorization
PROGRAMMING
1,100
[ "implementation", "math", "number theory" ]
null
null
Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*.
The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=20).
If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them.
[ "100000 2\n", "100000 20\n", "1024 5\n" ]
[ "2 50000 \n", "-1\n", "2 64 2 2 2 \n" ]
none
0
[ { "input": "100000 2", "output": "2 50000 " }, { "input": "100000 20", "output": "-1" }, { "input": "1024 5", "output": "2 64 2 2 2 " }, { "input": "100000 10", "output": "2 2 2 2 2 5 5 5 5 5 " }, { "input": "99999 3", "output": "3 813 41 " }, { "input...
1,635,698,442
2,147,483,647
Python 3
OK
TESTS
166
77
5,017,600
from math import sqrt def eratosfen(x): arr = [True] * (x + 1) result = [] for i in range(2, x + 1): if arr[i]: result.append(i) for j in range(2 * i, x + 1, i): arr[j] = False return result n, k = map(int, input().split()) simples = erato...
Title: k-Factorization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. Input Specification: The first line contains two int...
```python from math import sqrt def eratosfen(x): arr = [True] * (x + 1) result = [] for i in range(2, x + 1): if arr[i]: result.append(i) for j in range(2 * i, x + 1, i): arr[j] = False return result n, k = map(int, input().split()) simpl...
3
940
D
Alena And The Heater
PROGRAMMING
1,600
[ "binary search", "implementation" ]
null
null
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following proced...
The first line of input contains a single integer *n* (5<=≤<=*n*<=≤<=105) — the length of *a* and *b*'. The second line of input contains *n* space separated integers *a*1,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of *a*. The third line of input contains a string of *n* characters, consisting of 0 a...
Output two integers *l* and *r* (<=-<=109<=≤<=*l*<=≤<=*r*<=≤<=109), conforming to the requirements described above. If there are multiple solutions, output any of them. It's guaranteed that the answer exists.
[ "5\n1 2 3 4 5\n00001\n", "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n" ]
[ "6 15\n", "-5 5\n" ]
In the first test case any pair of *l* and *r* pair is valid, if 6 ≤ *l* ≤ *r* ≤ 10<sup class="upper-index">9</sup>, in that case *b*<sub class="lower-index">5</sub> = 1, because *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">5</sub> &lt; *l*.
1,500
[ { "input": "5\n1 2 3 4 5\n00001", "output": "6 1000000000" }, { "input": "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110", "output": "-5 5" }, { "input": "10\n-8 -9 -9 -7 -10 -10 -8 -8 -9 -10\n0000000011", "output": "-7 1000000000" }, { "input": "11\n226 226 226 226 226 227 10000...
1,519,964,711
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
62
19,865,600
l = [-int(1e9), int(1e9)] r = [-int(1e9), int(1e9)] n = int(input()) a = [int(x) for x in input().split(' ')] b = [int(x) for x in input()] sumb = sum(b[:3]) for i in range(4, n): maxa = max(a[i-4:i+1]) mina = min(a[i-4:i+1]) sumb = sumb + b[i-1] - (b[i-5] if i-5>=0 else 0) if b[i] == 1: if s...
Title: Alena And The Heater Time Limit: None seconds Memory Limit: None megabytes Problem Description: "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtai...
```python l = [-int(1e9), int(1e9)] r = [-int(1e9), int(1e9)] n = int(input()) a = [int(x) for x in input().split(' ')] b = [int(x) for x in input()] sumb = sum(b[:3]) for i in range(4, n): maxa = max(a[i-4:i+1]) mina = min(a[i-4:i+1]) sumb = sumb + b[i-1] - (b[i-5] if i-5>=0 else 0) if b[i] == 1: ...
0
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she...
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
1,603,179,245
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
108
0
if __name__=='__main__': n=int(input()) t=int(input()) ai=[ int(input()) for _ in range(n)] days=0 for i in ai: if t >0: t=t-(86400-i) days+=1 print(days)
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of ...
```python if __name__=='__main__': n=int(input()) t=int(input()) ai=[ int(input()) for _ in range(n)] days=0 for i in ai: if t >0: t=t-(86400-i) days+=1 print(days) ```
-1
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=2·105) — the sizes of arrays *a* and *b*. The second line contains *n* integers — the elements of array *a* (<=-<=109<=≤<=*a**i*<=≤<=109). The third line contains *m* integers — the elements of array *b* (<=-<=109<=≤<=*b**j*<=≤<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,697,903,436
2,147,483,647
Python 3
OK
TESTS
60
1,028
36,454,400
n, m = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() result = [] def bb(A, num): ini = 0 final = len(A) - 1 while ini <= final: mid = (ini + final) // 2 if A[mid] <= num: ini = mid + 1 else: ...
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python n, m = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() result = [] def bb(A, num): ini = 0 final = len(A) - 1 while ini <= final: mid = (ini + final) // 2 if A[mid] <= num: ini = mid + 1 else: ...
3
588
A
Duff and Meat
PROGRAMMING
900
[ "greedy" ]
null
null
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Print the minimum money needed to keep Duff happy for *n* days, in one line.
[ "3\n1 3\n2 2\n3 1\n", "3\n1 3\n2 1\n3 2\n" ]
[ "10\n", "8\n" ]
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
750
[ { "input": "3\n1 3\n2 2\n3 1", "output": "10" }, { "input": "3\n1 3\n2 1\n3 2", "output": "8" }, { "input": "1\n39 52", "output": "2028" }, { "input": "2\n25 56\n94 17", "output": "2998" }, { "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321" }...
1,626,880,538
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
109
20,172,800
n = int(input()) x = [] for _ in range(n): a, p = map(int, input().split()) x.append([a, p]) ind = 0 ans = 0 while ind < n: ans += x[ind][0] * x[ind][1] price = x[ind][1] ind += 1 while ind < n and x[ind][1] > x[ind - 1][1]: ans += x[ind][0] * price ind += 1 print(a...
Title: Duff and Meat Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her ...
```python n = int(input()) x = [] for _ in range(n): a, p = map(int, input().split()) x.append([a, p]) ind = 0 ans = 0 while ind < n: ans += x[ind][0] * x[ind][1] price = x[ind][1] ind += 1 while ind < n and x[ind][1] > x[ind - 1][1]: ans += x[ind][0] * price ind += ...
0
0
none
none
none
0
[ "none" ]
null
null
Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is possible that Polycarp begins to sleep in one day, and wakes u...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of alarms. Each of the next *n* lines contains a description of one alarm. Each description has a format "hh:mm", where *hh* is the hour when the alarm rings, and *mm* is the minute of that hour when the alarm rings. The number of hours is b...
Print a line in format "hh:mm", denoting the maximum time Polycarp can sleep continuously. *hh* denotes the number of hours, and *mm* denotes the number of minutes. The number of minutes should be between 0 and 59. Look through examples to understand the format better.
[ "1\n05:43\n", "4\n22:00\n03:21\n16:03\n09:59\n" ]
[ "23:59\n", "06:37\n" ]
In the first example there is only one alarm which rings during one minute of a day, and then rings again on the next day, 23 hours and 59 minutes later. Polycarp can sleep all this time.
0
[ { "input": "1\n05:43", "output": "23:59" }, { "input": "4\n22:00\n03:21\n16:03\n09:59", "output": "06:37" }, { "input": "20\n23:59\n00:00\n00:01\n00:02\n00:03\n00:04\n00:05\n00:06\n00:07\n00:08\n00:09\n00:10\n00:11\n00:12\n00:13\n00:14\n00:15\n00:16\n00:17\n00:18", "output": "23:40" ...
1,521,336,514
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
7,065,600
print("heheda")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has a strict daily schedule. He has *n* alarms set for each day, and the *i*-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm ...
```python print("heheda") ```
0
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t...
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas...
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output":...
1,621,439,758
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n,k = map(int,input().split()) sahsa=lena=0 while(n>k): sahsa+=1 n-=k if(n<k): break else: lena+=1 if(sahsa>lena): print("NO") else: print("YES")
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with ...
```python n,k = map(int,input().split()) sahsa=lena=0 while(n>k): sahsa+=1 n-=k if(n<k): break else: lena+=1 if(sahsa>lena): print("NO") else: print("YES") ```
0
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,695,035,165
2,147,483,647
Python 3
OK
TESTS
102
46
0
s=input() s1=input() n="" for i in range(len(s)): if s[i]=="1" and s1[i]=="1": n=n+"0" elif s[i]=="0" and s1[i]=="0": n=n+"0" else: n=n+"1" print(n)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python s=input() s1=input() n="" for i in range(len(s)): if s[i]=="1" and s1[i]=="1": n=n+"0" elif s[i]=="0" and s1[i]=="0": n=n+"0" else: n=n+"1" print(n) ```
3.9885
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,694,332,414
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
62
0
n=int(input()) c=0 r=0 while n>0: r=int(n%10) n=int(n/10) #print(r,n) if r==4 or r==7: c=1+c if c==4 or c==7 or c==47 or c==74 or c==44: print("YES") else: print("NO")
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n=int(input()) c=0 r=0 while n>0: r=int(n%10) n=int(n/10) #print(r,n) if r==4 or r==7: c=1+c if c==4 or c==7 or c==47 or c==74 or c==44: print("YES") else: print("NO") ```
0
306
A
Candies
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *...
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
[ "12 3\n", "15 4\n", "18 7\n" ]
[ "4 4 4 ", "3 4 4 4 ", "2 2 2 3 3 3 3 " ]
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
500
[ { "input": "12 4", "output": "3 3 3 3 " }, { "input": "15 6", "output": "2 2 2 3 3 3 " }, { "input": "18 8", "output": "2 2 2 2 2 2 3 3 " }, { "input": "1 1", "output": "1 " }, { "input": "2 1", "output": "2 " }, { "input": "100 1", "output": "100 ...
1,554,268,141
2,147,483,647
PyPy 3
OK
TESTS
20
278
0
n,m=map(int,input().split()) a=[n//m]*m n=n%m for i in range(m-n,m): a[i]+=1 print(*a)
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ...
```python n,m=map(int,input().split()) a=[n//m]*m n=n%m for i in range(m-n,m): a[i]+=1 print(*a) ```
3
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon...
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output"...
1,620,028,233
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
248
2,150,400
import math n = int(input()) radi = list(map(int,input().split())) a = 0 if n%2 == 1 : for i in range(n): if (i+1)%2==1: a += pi*radi[i]**2 else: a -= pi*radi[i]**2 print(a)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in...
```python import math n = int(input()) radi = list(map(int,input().split())) a = 0 if n%2 == 1 : for i in range(n): if (i+1)%2==1: a += pi*radi[i]**2 else: a -= pi*radi[i]**2 print(a) ```
-1
454
B
Little Pony and Sort by Shift
PROGRAMMING
1,200
[ "implementation" ]
null
null
One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence to its beginning: Help Twilight Sparkle to calculate: what ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105).
If it's impossible to sort the sequence output -1. Otherwise output the minimum number of operations Twilight Sparkle needs to sort it.
[ "2\n2 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "1\n", "-1\n", "0\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 3 2", "output": "-1" }, { "input": "2\n1 2", "output": "0" }, { "input": "6\n3 4 5 6 3 2", "output": "-1" }, { "input": "3\n1 2 1", "output": "1" }, { "input": "5\n1 1 2 1 1", "output": "2" }...
1,580,053,264
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
23
218
10,752,000
n = int(input()) a = list(map(int, input().rstrip().split())) maxm = max(a) ind_min = n ind_max = 0 # minm_ind = a.index(min(a)) test = 0 for i in range(n): if a[i] == maxm: ind_min = min(i, ind_min) ind_max = max(i, ind_max) flag1 = 0 flag2 = 0 flag3 = 0 flag4 = 0 flag = 0 # CHeck first half is sor...
Title: Little Pony and Sort by Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, Twilight Sparkle is interested in how to sort a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. ...
```python n = int(input()) a = list(map(int, input().rstrip().split())) maxm = max(a) ind_min = n ind_max = 0 # minm_ind = a.index(min(a)) test = 0 for i in range(n): if a[i] == maxm: ind_min = min(i, ind_min) ind_max = max(i, ind_max) flag1 = 0 flag2 = 0 flag3 = 0 flag4 = 0 flag = 0 # CHeck first h...
0
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. Th...
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0...
1,696,399,060
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n, k = map(int, input().split()) participation_counts = list(map(int, input().split())) # Count students who have not reached their maximum participation limit remaining_counts = [0] * 6 for count in participation_counts: if count < 5: remaining_counts[count] += 1 max_teams = 0 # Calculate the...
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi...
```python n, k = map(int, input().split()) participation_counts = list(map(int, input().split())) # Count students who have not reached their maximum participation limit remaining_counts = [0] * 6 for count in participation_counts: if count < 5: remaining_counts[count] += 1 max_teams = 0 # Cal...
0
242
B
Big Segment
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all oth...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109) — the borders of the *i*-th segment. It is guaranteed that no two segments c...
Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.
[ "3\n1 1\n2 2\n3 3\n", "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10\n" ]
[ "-1\n", "3\n" ]
none
1,000
[ { "input": "3\n1 1\n2 2\n3 3", "output": "-1" }, { "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3" }, { "input": "4\n1 5\n2 2\n2 4\n2 5", "output": "1" }, { "input": "5\n3 3\n1 3\n2 2\n2 3\n1 2", "output": "2" }, { "input": "7\n7 7\n8 8\n3 7\n1 6\n1 ...
1,540,533,968
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
n = input() n = int(n) position = -1 maximum = [] segments = [] for i in range(1, n+1): seg = list(map(int, input().split())) if not maximum: maximum = seg if seg[0] <= maximum[0] and seg[1] >= maximum[1]: maximum = seg position = i segments.append(seg) if i != -...
Title: Big Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments ...
```python n = input() n = int(n) position = -1 maximum = [] segments = [] for i in range(1, n+1): seg = list(map(int, input().split())) if not maximum: maximum = seg if seg[0] <= maximum[0] and seg[1] >= maximum[1]: maximum = seg position = i segments.append(seg) ...
0
259
B
Little Elephant and Magic Square
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ...
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented...
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditio...
[ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n" ]
[ "1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n" ]
none
1,000
[ { "input": "0 1 1\n1 0 1\n1 1 0", "output": "1 1 1\n1 1 1\n1 1 1" }, { "input": "0 3 6\n5 0 5\n4 7 0", "output": "6 3 6\n5 5 5\n4 7 4" }, { "input": "0 4 4\n4 0 4\n4 4 0", "output": "4 4 4\n4 4 4\n4 4 4" }, { "input": "0 54 48\n36 0 78\n66 60 0", "output": "69 54 48\n36 5...
1,620,970,722
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
6,963,200
l=[] for i in range(3): l.append(list(map(int,input().split()))) for i in range(3): for j in range(3): if(l[i][j]==0 and i==0): l[i][j] = l[i][-1] elif(l[i][j]==0 and i==1): l[i][j] = ((l[i][0]+l[i][-1])//2) elif(l[i][j]==0 and i==2): l[i][j]...
Title: Little Elephant and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ...
```python l=[] for i in range(3): l.append(list(map(int,input().split()))) for i in range(3): for j in range(3): if(l[i][j]==0 and i==0): l[i][j] = l[i][-1] elif(l[i][j]==0 and i==1): l[i][j] = ((l[i][0]+l[i][-1])//2) elif(l[i][j]==0 and i==2): ...
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,695,881,058
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
x =int(input()) p =[] while x >0: j = str(input()) p.append(j) x = x-1 for element in p: if len(element)<=4: print(element) else: print(element[0]+str((len(element)-2))+element[-1])
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python x =int(input()) p =[] while x >0: j = str(input()) p.append(j) x = x-1 for element in p: if len(element)<=4: print(element) else: print(element[0]+str((len(element)-2))+element[-1]) ```
0
451
A
Game With Sticks
PROGRAMMING
900
[ "implementation" ]
null
null
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid show...
The first line of input contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100).
Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game.
[ "2 2\n", "2 3\n", "3 3\n" ]
[ "Malvika\n", "Malvika\n", "Akshat\n" ]
Explanation of the first sample: The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1 - 2 and 1 - 3). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov...
500
[ { "input": "2 2", "output": "Malvika" }, { "input": "2 3", "output": "Malvika" }, { "input": "3 3", "output": "Akshat" }, { "input": "20 68", "output": "Malvika" }, { "input": "1 1", "output": "Akshat" }, { "input": "1 2", "output": "Akshat" }, ...
1,677,036,753
2,147,483,647
Python 3
OK
TESTS
28
46
0
line = list(map(int, input().strip().split())) if(min(line)%2 == 0): print("Malvika") else: print("Akshat")
Title: Game With Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid...
```python line = list(map(int, input().strip().split())) if(min(line)%2 == 0): print("Malvika") else: print("Akshat") ```
3
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,602,611,011
2,147,483,647
Python 3
OK
TESTS
20
218
0
f=open('input.txt','r') g=open('output.txt','w') n,k=map(int,f.readline().split()) a=list(map(int,f.readline().split())) s,res=sum(a),0 for val in a: res+=int(k*min(3,val//k)) print(s-res,file=g)
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 f=open('input.txt','r') g=open('output.txt','w') n,k=map(int,f.readline().split()) a=list(map(int,f.readline().split())) s,res=sum(a),0 for val in a: res+=int(k*min(3,val//k)) print(s-res,file=g) ```
3
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n...
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the...
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,547,532,487
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
216
0
a=open('input.txt','r') b=open('output.txt','w') l1=a.readline() l2=a.readline() o='' if l1=='front': if l2==1: o=('L') else: o=('R') else: if l2==1: o=('R') else: o=('L') b.write(o) a.close() b.close()
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through...
```python a=open('input.txt','r') b=open('output.txt','w') l1=a.readline() l2=a.readline() o='' if l1=='front': if l2==1: o=('L') else: o=('R') else: if l2==1: o=('R') else: o=('L') b.write(o) a.close() b.close() ```
0
903
B
The Modcrab
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has *h*2 health points and an attack power of *a*2. Knowing that, Vova...
The first line contains three integers *h*1, *a*1, *c*1 (1<=≤<=*h*1,<=*a*1<=≤<=100, 2<=≤<=*c*1<=≤<=100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers *h*2, *a*2 (1<=≤<=*h*2<=≤<=100, 1<=≤<=*a*2<=&lt;<=*c*1) — the Modcrab's health and his attack power.
In the first line print one integer *n* denoting the minimum number of phases required to win the battle. Then print *n* lines. *i*-th line must be equal to HEAL if Vova drinks a potion in *i*-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slayi...
[ "10 6 100\n17 5\n", "11 6 100\n12 5\n" ]
[ "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE\n" ]
In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win. In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.
0
[ { "input": "10 6 100\n17 5", "output": "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE" }, { "input": "11 6 100\n12 5", "output": "2\nSTRIKE\nSTRIKE" }, { "input": "25 27 91\n10 87", "output": "1\nSTRIKE" }, { "input": "79 4 68\n9 65", "output": "21\nSTRIKE\nHEAL\nHEAL\nHEAL\nHEAL\nHEAL...
1,564,366,732
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
import bisect def list_output(s): print(' '.join(map(str, s))) def list_input(s='int'): if s == 'int': return list(map(int, input().split())) elif s == 'float': return list(map(float, input().split())) return list(map(str, input().split())) [h1, a1, c1] = list(...
Title: The Modcrab Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyze...
```python import bisect def list_output(s): print(' '.join(map(str, s))) def list_input(s='int'): if s == 'int': return list(map(int, input().split())) elif s == 'float': return list(map(float, input().split())) return list(map(str, input().split())) [h1, a1, c...
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,615,755,597
2,147,483,647
Python 3
OK
TESTS
35
124
0
m,n = input().split(' ') num = int(m)*int(n) print(int(num/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python m,n = input().split(' ') num = int(m)*int(n) print(int(num/2)) ```
3.969
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,656,008,422
2,147,483,647
Python 3
OK
TESTS
54
499
8,601,600
n=int(input()) a=list(map(int, input().split())) for i in range(n): if i==0: print(abs(a[i+1]-a[i]),end=" ") elif i==n-1: print(abs(a[n-1]-a[n-2]),end=" ") else: print(min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])),end=" ") print(max(abs(a[i]-a[0]),abs(a[n-1]-a[i])))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love...
```python n=int(input()) a=list(map(int, input().split())) for i in range(n): if i==0: print(abs(a[i+1]-a[i]),end=" ") elif i==n-1: print(abs(a[n-1]-a[n-2]),end=" ") else: print(min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])),end=" ") print(max(abs(a[i]-a[0]),abs(a[n-1]-a[i]))) `...
3
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ...
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=...
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a...
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "outpu...
1,499,934,940
2,147,483,647
Python 3
OK
TESTS
58
62
5,529,600
n,k,d=map(int,input().split()) k-=1 z=list(map(int,input().split())) table=[] i=0 while(i<n): if(z[i]!=0 and z[i]<=d): table.append(abs(k-i)*10) i+=1 print(min(table))
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li...
```python n,k,d=map(int,input().split()) k-=1 z=list(map(int,input().split())) table=[] i=0 while(i<n): if(z[i]!=0 and z[i]<=d): table.append(abs(k-i)*10) i+=1 print(min(table)) ```
3
159
C
String Manipulation 1.0
PROGRAMMING
1,400
[ "*special", "binary search", "brute force", "data structures", "strings" ]
null
null
One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can...
The first line contains an integer *k* (1<=≤<=*k*<=≤<=2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0<=≤<=*n*<=≤<=20000) — the number of username changes. Each of the next *n* lines contains the actual ...
Print a single string — the user's final name after all changes are applied to it.
[ "2\nbac\n3\n2 a\n1 b\n2 c\n", "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n" ]
[ "acb\n", "baa\n" ]
Let's consider the first sample. Initially we have name "bacbac"; the first operation transforms it into "bacbc", the second one — to "acbc", and finally, the third one transforms it into "acb".
1,500
[ { "input": "2\nbac\n3\n2 a\n1 b\n2 c", "output": "acb" }, { "input": "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b", "output": "baa" }, { "input": "1\naabbabbb\n7\n2 a\n1 a\n1 a\n2 b\n1 b\n3 b\n1 b", "output": "b" }, { "input": "1\na\n0", "output": "a" }, { "input": "4\ndb\n...
1,624,030,300
2,147,483,647
PyPy 3
OK
TESTS
31
2,806
12,800,000
from collections import defaultdict k = int(input()) s = input() d = defaultdict(list) word = list(s*k) for i in range(len(word)): d[word[i]].append(i) n = int(input()) for _ in range(n): a,b = input().split() a = int(a) change = d[b].pop(a-1) word[change] = '' print(''.join(word))
Title: String Manipulation 1.0 Time Limit: None seconds Memory Limit: None megabytes Problem Description: One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character...
```python from collections import defaultdict k = int(input()) s = input() d = defaultdict(list) word = list(s*k) for i in range(len(word)): d[word[i]].append(i) n = int(input()) for _ in range(n): a,b = input().split() a = int(a) change = d[b].pop(a-1) word[change] = '' print(''.join(w...
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,576,819,876
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
280
0
n = int(input()) ss = [int(i) for i in input().split()] d = [] if (ss[0] + ss[1])% 2 == 0: if ss[0] % 2 == 0: for i in range(ss[0],n*(ss[1]-ss[0])+1,ss[1]-ss[0]): d.append(i) diff_list = list(set(d)-set(ss)) print(d.index(int(diff_list[0]))+1) else: for i in ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) ss = [int(i) for i in input().split()] d = [] if (ss[0] + ss[1])% 2 == 0: if ss[0] % 2 == 0: for i in range(ss[0],n*(ss[1]-ss[0])+1,ss[1]-ss[0]): d.append(i) diff_list = list(set(d)-set(ss)) print(d.index(int(diff_list[0]))+1) else: ...
0
0
none
none
none
0
[ "none" ]
null
null
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of...
The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors. Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000). The total number of balls doesn't exceed 1000.
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007.
[ "3\n2\n2\n1\n", "4\n1\n2\n3\n4\n" ]
[ "3\n", "1680\n" ]
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
0
[ { "input": "3\n2\n2\n1", "output": "3" }, { "input": "4\n1\n2\n3\n4", "output": "1680" }, { "input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "12520708" }, { "input": "5\n10\n10\n10\n10\n10", "output": "425711769" }, { "input": "11\n291\n3...
1,435,168,717
5,317
Python 3
RUNTIME_ERROR
PRETESTS
2
202
2,662,400
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import time MAX = 1000000007 def test(m, c, C, k, z): global MAX if m == 0: return 1 if c < 0: c = 0 ans = 0 for i in range(c, k): if C[i] != 0: C[i] -= 1 ans += test(m-1, min(i-1, c), C, k, z+[i]) ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- import time MAX = 1000000007 def test(m, c, C, k, z): global MAX if m == 0: return 1 if c < 0: c = 0 ans = 0 for i in range(c, k): if C[i] != 0: C[i] -= 1 ans += test(m-1, min(i-1, c), C, k, ...
-1
588
A
Duff and Meat
PROGRAMMING
900
[ "greedy" ]
null
null
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Print the minimum money needed to keep Duff happy for *n* days, in one line.
[ "3\n1 3\n2 2\n3 1\n", "3\n1 3\n2 1\n3 2\n" ]
[ "10\n", "8\n" ]
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
750
[ { "input": "3\n1 3\n2 2\n3 1", "output": "10" }, { "input": "3\n1 3\n2 1\n3 2", "output": "8" }, { "input": "1\n39 52", "output": "2028" }, { "input": "2\n25 56\n94 17", "output": "2998" }, { "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321" }...
1,496,663,518
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
#list(map(int,input().split())) n = int(input()) anse = 0 mn = 0 for i in range(n): a,p = map(int,input().split(" ")) mn = min(mn,p) anse += a * p print(anse)
Title: Duff and Meat Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her ...
```python #list(map(int,input().split())) n = int(input()) anse = 0 mn = 0 for i in range(n): a,p = map(int,input().split(" ")) mn = min(mn,p) anse += a * p print(anse) ```
0
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's gu...
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,505,930,002
2,147,483,647
Python 3
OK
TESTS
23
154
0
input(); a = input() l=a.count('L') r=a.count('R') if (r==0): print(a.rindex('L')+1,a.index('L')) elif (l==0): print( a.index('R')+1,a.rindex('R')+2,) else : print(a.index('R')+1,a.index('L'))
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *...
```python input(); a = input() l=a.count('L') r=a.count('R') if (r==0): print(a.rindex('L')+1,a.index('L')) elif (l==0): print( a.index('R')+1,a.rindex('R')+2,) else : print(a.index('R')+1,a.index('L')) ```
3
988
E
Divisibility by 25
PROGRAMMING
2,100
[ "brute force", "greedy" ]
null
null
You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes. What is the mi...
The first line contains an integer $n$ ($1 \le n \le 10^{18}$). It is guaranteed that the first (left) digit of the number $n$ is not a zero.
If it is impossible to obtain a number that is divisible by $25$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.
[ "5071\n", "705\n", "1241367\n" ]
[ "4\n", "1\n", "-1\n" ]
In the first example one of the possible sequences of moves is 5071 $\rightarrow$ 5701 $\rightarrow$ 7501 $\rightarrow$ 7510 $\rightarrow$ 7150.
0
[ { "input": "5071", "output": "4" }, { "input": "705", "output": "1" }, { "input": "1241367", "output": "-1" }, { "input": "7501", "output": "2" }, { "input": "507", "output": "2" }, { "input": "17010", "output": "1" }, { "input": "52231", ...
1,659,752,951
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
7
62
2,764,800
from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline cases = [[2, 5], [5, 0], [7, 5], [0, 0]] def calc_moves(num, locs, x, y): # cost to make num -> ......xy...
Title: Divisibility by 25 Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer $n$ from $1$ to $10^{18}$ without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes...
```python from collections import * from heapq import * from bisect import * from itertools import * from functools import * from math import * from string import * import sys input = sys.stdin.readline cases = [[2, 5], [5, 0], [7, 5], [0, 0]] def calc_moves(num, locs, x, y): # cost to make num -...
0
622
A
Infinite Sequence
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ...
The only line contains integer *n* (1<=≤<=*n*<=≤<=1014) — the position of the number to find. Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
Print the element in the *n*-th position of the sequence (the elements are numerated from one).
[ "3\n", "5\n", "10\n", "55\n", "56\n" ]
[ "2\n", "2\n", "4\n", "10\n", "1\n" ]
none
0
[ { "input": "3", "output": "2" }, { "input": "5", "output": "2" }, { "input": "10", "output": "4" }, { "input": "55", "output": "10" }, { "input": "56", "output": "1" }, { "input": "1000000000000", "output": "88209" }, { "input": "8471941278...
1,685,610,584
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> using namespace std; int main() { long long a; cin>> a; long long i= 1; while (a>i){ a=a-i; i++;} cout<<a; return 0; }
Title: Infinite Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,...
```python #include <iostream> using namespace std; int main() { long long a; cin>> a; long long i= 1; while (a>i){ a=a-i; i++;} cout<<a; return 0; } ```
-1
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least...
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, ...
1,427,901,211
2,147,483,647
Python 3
OK
TESTS
25
124
0
n, d = map(int, input().split()) p, v = 0, 0 for b in map(int, input().split()): if b <= p: c = (p + d - b) // d v += c b += c * d p = b print(v)
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*...
```python n, d = map(int, input().split()) p, v = 0, 0 for b in map(int, input().split()): if b <= p: c = (p + d - b) // d v += c b += c * d p = b print(v) ```
3.938
873
D
Merge Sort
PROGRAMMING
1,800
[ "constructive algorithms", "divide and conquer" ]
null
null
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≤<=*i*<=&lt;<=*r*<=-<=1 *a*[*i*]<=≤<=*a*[*i*<=+...
The first line contains two numbers *n* and *k* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*k*<=≤<=200000) — the size of a desired permutation and the number of *mergesort* calls required to sort it.
If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] — the elements of a permutation that would meet the required conditions. If there are multiple answers, print a...
[ "3 3\n", "4 1\n", "5 6\n" ]
[ "2 1 3 ", "1 2 3 4 ", "-1\n" ]
none
0
[ { "input": "3 3", "output": "2 1 3 " }, { "input": "4 1", "output": "1 2 3 4 " }, { "input": "5 6", "output": "-1" }, { "input": "100 100", "output": "-1" }, { "input": "10000 10001", "output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27...
1,646,608,753
2,147,483,647
Python 3
OK
TESTS
36
77
7,168,000
n, m = list(map(int, input().split())) solucao = [] def merge(inicio, fim, rem): if rem < 2: solucao.extend(range(inicio, fim)) return rem if fim - inicio == 1: solucao.append(inicio) return rem rem -= 2 mid = (inicio + fim + 1)//2 rem = merge(mid, fim, rem) rem = merge(inicio, mid, rem) return rem ...
Title: Merge Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-desce...
```python n, m = list(map(int, input().split())) solucao = [] def merge(inicio, fim, rem): if rem < 2: solucao.extend(range(inicio, fim)) return rem if fim - inicio == 1: solucao.append(inicio) return rem rem -= 2 mid = (inicio + fim + 1)//2 rem = merge(mid, fim, rem) rem = merge(inicio, mid, rem) re...
3
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive co...
In the only line of input there is an integer *n* (3<=≤<=*n*<=≤<=1000), the sum of numerator and denominator of the fraction.
Output two space-separated positive integers *a* and *b*, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
[ "3\n", "4\n", "12\n" ]
[ "1 2\n", "1 3\n", "5 7\n" ]
none
500
[ { "input": "3", "output": "1 2" }, { "input": "4", "output": "1 3" }, { "input": "12", "output": "5 7" }, { "input": "34", "output": "15 19" }, { "input": "13", "output": "6 7" }, { "input": "11", "output": "5 6" }, { "input": "24", "ou...
1,549,382,459
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
0
n=int(input()) [print(n//2,n//2+1) if n%2 else print(n//2-1,n//2+1)]
Title: Fraction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&lt;<=*b*) and that the fraction is cal...
```python n=int(input()) [print(n//2,n//2+1) if n%2 else print(n//2-1,n//2+1)] ```
0
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ...
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" ...
1,618,685,008
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
61
0
s=input() y =s.count('Danil')==1 or s.count('Olya')==1 or s.count('Slava')==1 or s.count('Ann')==1 or s.count('Nikita')==1 print(['NO','YES'][y])
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems,...
```python s=input() y =s.count('Danil')==1 or s.count('Olya')==1 or s.count('Slava')==1 or s.count('Ann')==1 or s.count('Nikita')==1 print(['NO','YES'][y]) ```
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,457,707,156
2,147,483,647
PyPy 3
OK
TESTS
57
124
0
#!/usr/bin/env python3 if __name__ == '__main__': N = int(input()) a = list(map(int, input().split())) res = 0 used = set() for c in sorted(a, reverse=True): while c and c in used: c -= 1 if c: used.add(c) res += c print(res)
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 #!/usr/bin/env python3 if __name__ == '__main__': N = int(input()) a = list(map(int, input().split())) res = 0 used = set() for c in sorted(a, reverse=True): while c and c in used: c -= 1 if c: used.add(c) res += c print(res) ```
3
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 ...
1,571,711,044
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
9
202
10,035,200
n = int(input()) a = list(map(int,input().split())) m = 1 st = a[0] pv = -1 cur = 0 ct = 1 for i in range(1,n): #print(pv,cur) if(a[i] == a[cur]): cur = i ct += 1 continue if(a[i] == a[pv] or pv == -1): ct += 1 pv = cur cur = i else: ...
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo...
```python n = int(input()) a = list(map(int,input().split())) m = 1 st = a[0] pv = -1 cur = 0 ct = 1 for i in range(1,n): #print(pv,cur) if(a[i] == a[cur]): cur = i ct += 1 continue if(a[i] == a[pv] or pv == -1): ct += 1 pv = cur cur = i e...
0
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000...
1,698,115,383
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
import math n,m =map(int,input().split() print(math.gcd(n,m))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre...
```python import math n,m =map(int,input().split() print(math.gcd(n,m)) ```
-1
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9",...
1,675,894,353
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
92
0
s = input() def func(s): cnt = 0 for i in range(len(s)): if cnt >= 2: return "NO" if s[i] == '4': cnt += 1 elif s[i] == '1': cnt = 0 elif s[i] != '4' and s[i] != '1': return "NO" return "YES" print(func(s))
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're ...
```python s = input() def func(s): cnt = 0 for i in range(len(s)): if cnt >= 2: return "NO" if s[i] == '4': cnt += 1 elif s[i] == '1': cnt = 0 elif s[i] != '4' and s[i] != '1': return "NO" return "YES" print(func(s)) ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,600,095,993
2,147,483,647
PyPy 3
OK
TESTS
32
280
0
n = int(input()) listnum = [int(a) for a in input().split()] even = [] odd = [] index = 0 for elem in listnum: if elem%2 == 0: even.append(elem) else: odd.append(elem) if len(even) == 1: index = listnum.index(even[0]) else: index = listnum.index(odd[0]) print(index+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) listnum = [int(a) for a in input().split()] even = [] odd = [] index = 0 for elem in listnum: if elem%2 == 0: even.append(elem) else: odd.append(elem) if len(even) == 1: index = listnum.index(even[0]) else: index = listnum.index(odd[0]) print(index+1) ...
3.93
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it la...
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on...
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "outp...
1,644,666,913
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
0
n,m=map(int,input().split()) if n<m: print(n) elif n==m: print(n+1) else: k=n s=0 while n//m!=1: s+=n//m n=n//m s+=1 if (k+s)%m==0: print(k+s+1) else: print(k+s)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th...
```python n,m=map(int,input().split()) if n<m: print(n) elif n==m: print(n+1) else: k=n s=0 while n//m!=1: s+=n//m n=n//m s+=1 if (k+s)%m==0: print(k+s+1) else: print(k+s) ```
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,676,907,055
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
x=int(input()) c=int(input()) for t in range(c): if len(x) >= (10): print(x[0]+ len(x)-2 + x[-1] else: print(x)
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python x=int(input()) c=int(input()) for t in range(c): if len(x) >= (10): print(x[0]+ len(x)-2 + x[-1] else: print(x) ```
-1
1,006
B
Polycarp's Practice
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cann...
The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are p...
In the first line of the output print the maximum possible total profit. In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible ...
[ "8 3\n5 4 2 6 5 1 9 2\n", "5 1\n1 1 1 1 1\n", "4 2\n1 2000 2000 2\n" ]
[ "20\n3 2 3", "1\n5\n", "4000\n2 2\n" ]
The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$.
0
[ { "input": "8 3\n5 4 2 6 5 1 9 2", "output": "20\n4 1 3" }, { "input": "5 1\n1 1 1 1 1", "output": "1\n5" }, { "input": "4 2\n1 2000 2000 2", "output": "4000\n2 2" }, { "input": "1 1\n2000", "output": "2000\n1" }, { "input": "1 1\n1234", "output": "1234\n1" ...
1,603,911,628
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
307,200
import sys,math n,k = map(int,input().split(' ')) arr = list(map(int,input().split(' '))) arr.sort() s = sum(arr[n-k:]) sepe = arr[n-k:-1] x = 0 print(s) ans = [] for i in range(1,n): if arr[i] in sepe: ans.append(len(arr[x:i])) sepe[sepe.index(arr[i])] = None x = i if len(arr[x:])>0: an...
Title: Polycarp's Practice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least...
```python import sys,math n,k = map(int,input().split(' ')) arr = list(map(int,input().split(' '))) arr.sort() s = sum(arr[n-k:]) sepe = arr[n-k:-1] x = 0 print(s) ans = [] for i in range(1,n): if arr[i] in sepe: ans.append(len(arr[x:i])) sepe[sepe.index(arr[i])] = None x = i if len(arr[x:])...
0
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { ...
1,698,287,460
2,147,483,647
Python 3
OK
TESTS
34
92
0
x = str(input()) def isnearlucky(x): count = 0 for char in x: if char == "4" or char == "7": count += 1 continue count = str(count) count = count.replace("4","") count = count.replace("7","") if len(count) == 0: print("YES") else: ...
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python x = str(input()) def isnearlucky(x): count = 0 for char in x: if char == "4" or char == "7": count += 1 continue count = str(count) count = count.replace("4","") count = count.replace("7","") if len(count) == 0: print("YES") else:...
3.977
347
A
Difference Row
PROGRAMMING
1,300
[ "constructive algorithms", "implementation", "sortings" ]
null
null
You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permu...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000).
Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value.
[ "5\n100 -100 50 0 -50\n" ]
[ "100 -50 0 50 -100 \n" ]
In the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one. Sequence *x*<sub class="lower-inde...
500
[ { "input": "5\n100 -100 50 0 -50", "output": "100 -50 0 50 -100 " }, { "input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "output": "963 -795 -367 -282 -49 -26 0 764 948 -939 " }, { "input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 ...
1,595,177,013
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
6,860,800
def solve(n, nums): nums.sort() ret = [] print(nums) if nums[0] < 0: ret.append(nums[-1]) for i in range(1,n-1): ret.append(nums[i]) ret.append(nums[0]) else: for i in range(n): ret.append(nums[-i-1]) return ret n = int(inp...
Title: Difference Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote ...
```python def solve(n, nums): nums.sort() ret = [] print(nums) if nums[0] < 0: ret.append(nums[-1]) for i in range(1,n-1): ret.append(nums[i]) ret.append(nums[0]) else: for i in range(n): ret.append(nums[-i-1]) return ret n...
0
299
A
Ksusha and Array
PROGRAMMING
1,000
[ "brute force", "number theory", "sortings" ]
null
null
Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the array has. The next line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the array elements.
Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n" ]
[ "2\n", "1\n", "-1\n" ]
none
500
[ { "input": "3\n2 2 4", "output": "2" }, { "input": "5\n2 1 3 1 6", "output": "1" }, { "input": "3\n2 3 5", "output": "-1" }, { "input": "1\n331358794", "output": "331358794" }, { "input": "5\n506904227 214303304 136194869 838256937 183952885", "output": "-1" ...
1,554,290,008
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
156
0
n=int(input()) l=list(map(int, input().split())) k=min(a) for i in range(n): if l[i]%k!=0: print(-1) exit() print(k)
Title: Ksusha and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ksusha is a beginner coder. Today she starts studying arrays. She has array *a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* positive integers. Her university teacher gave her a task. Find such number in the array, that ...
```python n=int(input()) l=list(map(int, input().split())) k=min(a) for i in range(n): if l[i]%k!=0: print(-1) exit() print(k) ```
-1
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
The first input line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 — those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and...
Print a single number — the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second...
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1...
1,594,226,762
2,147,483,647
PyPy 3
OK
TESTS
49
280
21,401,600
pages = int(input()) days = list(map(int, input().split())) current = -1 while pages > 0: current += 1 if current == 7: current = 0 pages -= days[current] print(current + 1)
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s...
```python pages = int(input()) days = list(map(int, input().split())) current = -1 while pages > 0: current += 1 if current == 7: current = 0 pages -= days[current] print(current + 1) ```
3
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,643,635,411
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
77
7,065,600
q=[int(w)for w in input().split()] e=[int(w)for w in input().split()] r=0 y=0 for t in e: if t<=q[1]: y+=t if y>q[2]: y-=q[2] r+=1 print(r)
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 q=[int(w)for w in input().split()] e=[int(w)for w in input().split()] r=0 y=0 for t in e: if t<=q[1]: y+=t if y>q[2]: y-=q[2] r+=1 print(r) ```
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,633,503,477
2,147,483,647
PyPy 3
OK
TESTS
58
156
30,720,000
cont = 0 c = 0 n,b,d = [int(i) for i in input().split()] lis = [int(i) for i in input().split()] for x in range(len(lis)): if lis[x] <= b: cont += lis[x] if cont > d: cont = 0 c+=1 print(c)
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b...
```python cont = 0 c = 0 n,b,d = [int(i) for i in input().split()] lis = [int(i) for i in input().split()] for x in range(len(lis)): if lis[x] <= b: cont += lis[x] if cont > d: cont = 0 c+=1 print(c) ```
3
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { ...
1,651,066,697
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
n,k=map(int,input().split()) rj=0 for i in range(n): a=input() da=True for j in a: if int(j)>k: da=False break if da: rj+=1 print(rj)
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve...
```python n,k=map(int,input().split()) rj=0 for i in range(n): a=input() da=True for j in a: if int(j)>k: da=False break if da: rj+=1 print(rj) ```
0
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis...
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla...
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,622,893,326
2,147,483,647
PyPy 3
OK
TESTS
37
1,434
9,113,600
s=str(int(input())) flag=False for i in range(0,len(s)): if(s[i]=='0' and flag==False): flag=True elif(flag==False and i==len(s)-1): flag=True else: print(s[i],end='')
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought...
```python s=str(int(input())) flag=False for i in range(0,len(s)): if(s[i]=='0' and flag==False): flag=True elif(flag==False and i==len(s)-1): flag=True else: print(s[i],end='') ```
3
725
A
Jumping Ball
PROGRAMMING
1,000
[ "implementation" ]
null
null
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at pos...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
[ "4\n&lt;&lt;&gt;&lt;\n", "5\n&gt;&gt;&gt;&gt;&gt;\n", "4\n&gt;&gt;&lt;&lt;\n" ]
[ "2", "5", "0" ]
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
500
[ { "input": "4\n<<><", "output": "2" }, { "input": "5\n>>>>>", "output": "5" }, { "input": "4\n>><<", "output": "0" }, { "input": "3\n<<>", "output": "3" }, { "input": "3\n<<<", "output": "3" }, { "input": "3\n><<", "output": "0" }, { "input...
1,611,937,313
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
5
108
7,168,000
if __name__ == "__main__": nr_of_bumpers = int(input()) bumper_types = list(input()) fall_bumpers = 0 bumper_index = 0 while bumper_types[bumper_index] == '<' and bumper_index < nr_of_bumpers: fall_bumpers += 1 bumper_index += 1 bumper_index = nr_of_bumpers - 1 while...
Title: Jumping Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b...
```python if __name__ == "__main__": nr_of_bumpers = int(input()) bumper_types = list(input()) fall_bumpers = 0 bumper_index = 0 while bumper_types[bumper_index] == '<' and bumper_index < nr_of_bumpers: fall_bumpers += 1 bumper_index += 1 bumper_index = nr_of_bumpers - 1 ...
-1
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,691,430,732
2,147,483,647
Python 3
OK
TESTS
30
92
0
s=input() u=0 l=0 ss="ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in s: if i in ss: u+=1 else: l+=1 if l>=u: print(s.lower()) else: print(s.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 s=input() u=0 l=0 ss="ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i in s: if i in ss: u+=1 else: l+=1 if l>=u: print(s.lower()) else: print(s.upper()) ```
3.977
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,691,725,478
2,147,483,647
Python 3
OK
TESTS
27
31
0
n = int(input()) counter=0 for x in range(n): p ,q = map(int ,input().split()) if (q-p)-2>=0: counter +=1 print(counter)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python n = int(input()) counter=0 for x in range(n): p ,q = map(int ,input().split()) if (q-p)-2>=0: counter +=1 print(counter) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,665,839,410
2,147,483,647
Python 3
OK
TESTS
35
92
0
M, N = map(int, input().split()) fair_valid = int(M / 2) * N sides = (M % 2) * int(N / 2) print(fair_valid + sides)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python M, N = map(int, input().split()) fair_valid = int(M / 2) * N sides = (M % 2) * int(N / 2) print(fair_valid + sides) ```
3.977
463
B
Caisa and Pylons
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0 has zero height, the pylon with number *i* (*i*<=&gt;<=0) has height *h**i*. The goal of the game is ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *h*1, *h*2,<=..., *h**n* (1<=<=≤<=<=*h**i*<=<=≤<=<=105) representing the heights of the pylons.
Print a single number representing the minimum number of dollars paid by Caisa.
[ "5\n3 4 3 2 4\n", "3\n4 4 4\n" ]
[ "4\n", "4\n" ]
In the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.
1,000
[ { "input": "5\n3 4 3 2 4", "output": "4" }, { "input": "3\n4 4 4", "output": "4" }, { "input": "99\n1401 2019 1748 3785 3236 3177 3443 3772 2138 1049 353 908 310 2388 1322 88 2160 2783 435 2248 1471 706 2468 2319 3156 3506 2794 1999 1983 2519 2597 3735 537 344 3519 3772 3872 2961 3895 20...
1,675,096,121
2,147,483,647
PyPy 3-64
OK
TESTS
49
93
10,956,800
# DO NOT EDIT THIS import math import sys input = sys.stdin.readline from collections import deque, defaultdict import heapq def counter(a): c = defaultdict(lambda : 0) # way faster than Counter for el in a: c[el] += 1 return c def inp(): return [int(k) for k in input().split()] # DO...
Title: Caisa and Pylons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (*n*<=+<=1) pylons numbered from 0 to *n* in this game. The pylon with number 0...
```python # DO NOT EDIT THIS import math import sys input = sys.stdin.readline from collections import deque, defaultdict import heapq def counter(a): c = defaultdict(lambda : 0) # way faster than Counter for el in a: c[el] += 1 return c def inp(): return [int(k) for k in input().split(...
3
588
A
Duff and Meat
PROGRAMMING
900
[ "greedy" ]
null
null
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Print the minimum money needed to keep Duff happy for *n* days, in one line.
[ "3\n1 3\n2 2\n3 1\n", "3\n1 3\n2 1\n3 2\n" ]
[ "10\n", "8\n" ]
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
750
[ { "input": "3\n1 3\n2 2\n3 1", "output": "10" }, { "input": "3\n1 3\n2 1\n3 2", "output": "8" }, { "input": "1\n39 52", "output": "2028" }, { "input": "2\n25 56\n94 17", "output": "2998" }, { "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321" }...
1,618,617,238
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
109
0
preco = 101 result = 0 for i in range(int(input())): x,y = input().split(" ") x = int(x) y = int(y) if(preco>y): preco = y result += preco * x print(result)
Title: Duff and Meat Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her ...
```python preco = 101 result = 0 for i in range(int(input())): x,y = input().split(" ") x = int(x) y = int(y) if(preco>y): preco = y result += preco * x print(result) ```
0
358
A
Dima and Continuous Line
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
[ "4\n0 10 5 15\n", "4\n0 15 5 10\n" ]
[ "yes\n", "no\n" ]
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
500
[ { "input": "4\n0 10 5 15", "output": "yes" }, { "input": "4\n0 15 5 10", "output": "no" }, { "input": "5\n0 1000 2000 3000 1500", "output": "yes" }, { "input": "5\n-724093 710736 -383722 -359011 439613", "output": "no" }, { "input": "50\n384672 661179 -775591 -989...
1,618,055,663
2,147,483,647
PyPy 3
OK
TESTS
37
155
2,867,200
n = int(input()) x = False A = [int(i) for i in input().split()] for i in range(n-2): x1 , x2= min(A[i],A[i+1]),max(A[i],A[i+1]) for j in range(i+1,n-1): X1,X2 = min(A[j],A[j+1]),max(A[j],A[j+1]) if(x1<X1 and X1<x2 and x2<X2): x = True elif(X1<x1 and X2>x1 and X2<x2): x = True if(x): print("y...
Title: Dima and Continuous Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher g...
```python n = int(input()) x = False A = [int(i) for i in input().split()] for i in range(n-2): x1 , x2= min(A[i],A[i+1]),max(A[i],A[i+1]) for j in range(i+1,n-1): X1,X2 = min(A[j],A[j+1]),max(A[j],A[j+1]) if(x1<X1 and X1<x2 and x2<X2): x = True elif(X1<x1 and X2>x1 and X2<x2): x = True if(x): ...
3
742
B
Arpa’s obvious problem and Mehrdad’s terrible solution
PROGRAMMING
1,500
[ "brute force", "math", "number theory" ]
null
null
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad di...
First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer: the answer to the problem.
[ "2 3\n1 2\n", "6 1\n5 1 2 3 4 1\n" ]
[ "1", "2" ]
In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1. In the second sample the only two pairs are *i* = 3, *j* = 4 ...
1,000
[ { "input": "2 3\n1 2", "output": "1" }, { "input": "6 1\n5 1 2 3 4 1", "output": "2" }, { "input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "output": "0" }, { "i...
1,699,285,104
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
77
4,505,600
l=[0 for j in range(10**5+1)] n, k = ([int(x) for x in input().split()]) l1=list(map(int,input().split())) for j in l1: l[j]+=1 ans=0 for j in l1: a=j^k ans+=l[a]*l[j] print(ans//2)
Title: Arpa’s obvious problem and Mehrdad’s terrible solution Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indice...
```python l=[0 for j in range(10**5+1)] n, k = ([int(x) for x in input().split()]) l1=list(map(int,input().split())) for j in l1: l[j]+=1 ans=0 for j in l1: a=j^k ans+=l[a]*l[j] print(ans//2) ```
0
703
A
Mishka and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined....
The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ...
If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line.
[ "3\n3 5\n2 1\n4 2\n", "2\n6 1\n1 6\n", "3\n1 5\n3 3\n2 2\n" ]
[ "Mishka", "Friendship is magic!^^", "Chris" ]
In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game. In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1. In the third sample case Chris wins the first round, but there...
500
[ { "input": "3\n3 5\n2 1\n4 2", "output": "Mishka" }, { "input": "2\n6 1\n1 6", "output": "Friendship is magic!^^" }, { "input": "3\n1 5\n3 3\n2 2", "output": "Chris" }, { "input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1", "output": "Mishka" }, { "input": "8\n2 4\n1 4\n1 ...
1,689,822,119
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
15
31
0
m=0 c=0 n=int(input()) for i in range(n): a=list(map(int,input().split())) if a[0]>a[1]: m+=1 else: c+=1 if m>c: print("Mishka") elif m==c: print("Friendship is magic!^^") else: print("Chris")
Title: Mishka and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st...
```python m=0 c=0 n=int(input()) for i in range(n): a=list(map(int,input().split())) if a[0]>a[1]: m+=1 else: c+=1 if m>c: print("Mishka") elif m==c: print("Friendship is magic!^^") else: print("Chris") ```
0
0
none
none
none
0
[ "none" ]
null
null
Let's define the sum of two permutations *p* and *q* of numbers 0,<=1,<=...,<=(*n*<=-<=1) as permutation , where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0,<=1,<=...,<=(*n*<=-<=1) (counting from zero), and *Ord*(*p*) is the number of permutation *p* in the lexicographical order. For example, ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000). The second line contains *n* distinct integers from 0 to *n*<=-<=1, separated by a space, forming permutation *p*. The third line contains *n* distinct integers from 0 to *n*<=-<=1, separated by spaces, forming permutation *q*.
Print *n* distinct integers from 0 to *n*<=-<=1, forming the sum of the given permutations. Separate the numbers by spaces.
[ "2\n0 1\n0 1\n", "2\n0 1\n1 0\n", "3\n1 2 0\n2 1 0\n" ]
[ "0 1\n", "1 0\n", "1 0 2\n" ]
Permutations of numbers from 0 to 1 in the lexicographical order: (0, 1), (1, 0). In the first sample *Ord*(*p*) = 0 and *Ord*(*q*) = 0, so the answer is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8ce4cd76db7c3f712f9101b410c36891976581b8.png" style="max-width: 100.0%;max-height: 100.0...
0
[]
1,421,057,859
4,659
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
7
2,000
85,811,200
#!/usr/bin/python3 import sys class Tree: def __init__(self, a, b): self.range = (a, b) if a == b: self.active = 1 self.left = None self.rigt = None return else: mid = (a + b) // 2 self.left = Tree(a, mid) ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define the sum of two permutations *p* and *q* of numbers 0,<=1,<=...,<=(*n*<=-<=1) as permutation , where *Perm*(*x*) is the *x*-th lexicographically permutation of numbers 0,<=1,<=...,<=(*n*<=-<=1) (counting from zero), an...
```python #!/usr/bin/python3 import sys class Tree: def __init__(self, a, b): self.range = (a, b) if a == b: self.active = 1 self.left = None self.rigt = None return else: mid = (a + b) // 2 self.left = Tree(a, mi...
0
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,694,965,562
2,147,483,647
Python 3
OK
TESTS
15
31
0
k,n,w=map(int,input().split()) total = k*(w*(w+1) // 2) borrow=max(0,total - n) print(borrow)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He h...
```python k,n,w=map(int,input().split()) total = k*(w*(w+1) // 2) borrow=max(0,total - n) print(borrow) ```
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di...
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", ...
1,690,345,125
2,147,483,647
PyPy 3-64
OK
TESTS
34
92
0
a = int(input()) count = 0 count2 = 0 index = 0 lis = [] for i in range(a): b = input() lis.append(b) for j in range(len(lis)): if lis[0] == lis[j]: count += 1 else: count2 += 1 index = j if count > count2: print(lis[0]) else: print(lis[index]) ...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process...
```python a = int(input()) count = 0 count2 = 0 index = 0 lis = [] for i in range(a): b = input() lis.append(b) for j in range(len(lis)): if lis[0] == lis[j]: count += 1 else: count2 += 1 index = j if count > count2: print(lis[0]) else: print(li...
3.977
493
D
Vasya and Chess
PROGRAMMING
1,700
[ "constructive algorithms", "games", "math" ]
null
null
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell cont...
The input contains a single number *n* (2<=≤<=*n*<=≤<=109) — the size of the board.
On the first line print the answer to problem — string "white" or string "black", depending on who wins if the both players play optimally. If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If ther...
[ "2\n", "3\n" ]
[ "white\n1 2\n", "black\n" ]
In the first sample test the white queen can capture the black queen at the first move, so the white player wins. In the second test from the statement if the white queen captures the green pawn located on the central vertical line, then it will be captured by the black queen during the next move. So the only move for...
1,500
[ { "input": "2", "output": "white\n1 2" }, { "input": "3", "output": "black" }, { "input": "4", "output": "white\n1 2" }, { "input": "6", "output": "white\n1 2" }, { "input": "10", "output": "white\n1 2" }, { "input": "16", "output": "white\n1 2" ...
1,548,322,556
2,147,483,647
PyPy 3
OK
TESTS
26
140
0
from sys import stdin # main starts n = int(stdin.readline().strip()) if n% 2 == 0: print("white") print(1, 2) else: print("black")
Title: Vasya and Chess Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. I...
```python from sys import stdin # main starts n = int(stdin.readline().strip()) if n% 2 == 0: print("white") print(1, 2) else: print("black") ```
3
729
D
Sea Battle
PROGRAMMING
1,700
[ "constructive algorithms", "greedy", "math" ]
null
null
Galya is playing one-dimensional Sea Battle on a 1<=×<=*n* grid. In this game *a* ships are placed on the grid. Each of the ships consists of *b* consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after ea...
The first line contains four positive integers *n*, *a*, *b*, *k* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=*n*, 0<=≤<=*k*<=≤<=*n*<=-<=1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length *n*, c...
In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to *n*, starting f...
[ "5 1 2 1\n00100\n", "13 3 2 3\n1000000010001\n" ]
[ "2\n4 2\n", "2\n7 11\n" ]
There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.
1,750
[ { "input": "5 1 2 1\n00100", "output": "2\n2 5 " }, { "input": "13 3 2 3\n1000000010001", "output": "2\n3 5 " }, { "input": "1 1 1 0\n0", "output": "1\n1 " }, { "input": "2 2 1 0\n00", "output": "1\n1 " }, { "input": "5 4 1 0\n00000", "output": "2\n1 2 " }, ...
1,592,462,645
2,147,483,647
PyPy 3
OK
TESTS
21
296
18,841,600
# Why do we fall ? So we can learn to pick ourselves up. from itertools import groupby n,a,b,k = map(int,input().split()) s = input() sg = [list(g) for s,g in groupby(s)] ll = 0 hits = [] for i in range(0,len(sg)): if sg[i][0] == '0' and len(sg[i]) >= b: for hit in range(b-1,len(sg[i]),b): ...
Title: Sea Battle Time Limit: None seconds Memory Limit: None megabytes Problem Description: Galya is playing one-dimensional Sea Battle on a 1<=×<=*n* grid. In this game *a* ships are placed on the grid. Each of the ships consists of *b* consecutive cells. No cell can be part of two ships, however, the ships can to...
```python # Why do we fall ? So we can learn to pick ourselves up. from itertools import groupby n,a,b,k = map(int,input().split()) s = input() sg = [list(g) for s,g in groupby(s)] ll = 0 hits = [] for i in range(0,len(sg)): if sg[i][0] == '0' and len(sg[i]) >= b: for hit in range(b-1,len(sg[i]...
3
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co...
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya ca...
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,632,745,920
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
109
20,172,800
""" 0 -> -1 -1 1 -> -1 1 2 -> 1 -1 3 -> 1 1 """ n = int(input()) day_info = list(map(int, input().split())) minimum_rest_days = 0 prev = -1 i = 0 while i < n: if day_info[i] == 0: prev = -1 minimum_rest_days += 1 elif day_info[i] == 1: if prev in [-1, "gym"]: prev = "contest"...
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int...
```python """ 0 -> -1 -1 1 -> -1 1 2 -> 1 -1 3 -> 1 1 """ n = int(input()) day_info = list(map(int, input().split())) minimum_rest_days = 0 prev = -1 i = 0 while i < n: if day_info[i] == 0: prev = -1 minimum_rest_days += 1 elif day_info[i] == 1: if prev in [-1, "gym"]: prev =...
0
369
B
Valera and Contest
PROGRAMMING
1,400
[ "constructive algorithms", "implementation", "math" ]
null
null
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual competition, so each student in the team solved problems individually. After the contest was over, Valer...
The first line of the input contains exactly six integers *n*,<=*k*,<=*l*,<=*r*,<=*s**all*,<=*s**k* (1<=≤<=*n*,<=*k*,<=*l*,<=*r*<=≤<=1000; *l*<=≤<=*r*; *k*<=≤<=*n*; 1<=≤<=*s**k*<=≤<=*s**all*<=≤<=106). It's guaranteed that the input is such that the answer exists.
Print exactly *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the number of points each student scored. If there are multiple solutions, you can print any of them. You can print the distribution of points in any order.
[ "5 3 1 3 13 9\n", "5 3 1 3 15 9\n" ]
[ "2 3 2 3 3 ", "3 3 3 3 3 " ]
none
1,000
[ { "input": "5 3 1 3 13 9", "output": "2 3 2 3 3 " }, { "input": "5 3 1 3 15 9", "output": "3 3 3 3 3 " }, { "input": "50 25 1 1 50 25", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 " }, { "input": "1000 700 782...
1,639,288,486
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
93
1,536,000
def work(arr, start, end, least, most, tot, csum): for i in range(start, end+1): if csum + most - least < tot: csum += (most-least) arr[i] = most else: arr[i] += tot - csum return n, k, l, r, sall, sk = map(int, input().split()) arr = [l]*(n...
Title: Valera and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of *n* students (including Valera). This contest was an individual c...
```python def work(arr, start, end, least, most, tot, csum): for i in range(start, end+1): if csum + most - least < tot: csum += (most-least) arr[i] = most else: arr[i] += tot - csum return n, k, l, r, sall, sk = map(int, input().split()) ar...
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,553,868,690
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
218
0
n, k = input().split() k = int(k) l = [int(x) for x in input().split() if int(x) !=0] l.sort() # print(l) # print(k) def chama(l, k): for s in range(k): minimum = l[0] print(minimum) l = [x-minimum for x in l if x-minimum > 0 ] if not l: return k-s # print(l) return 0 # print(l) # print('minimum ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n, k = input().split() k = int(k) l = [int(x) for x in input().split() if int(x) !=0] l.sort() # print(l) # print(k) def chama(l, k): for s in range(k): minimum = l[0] print(minimum) l = [x-minimum for x in l if x-minimum > 0 ] if not l: return k-s # print(l) return 0 # print(l) # print...
-1
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" ...
1,544,134,132
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
6
109
0
n = int(input()) L = "" for i in range(1,370): L += str(i) print(L[n-1])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python n = int(input()) L = "" for i in range(1,370): L += str(i) print(L[n-1]) ```
-1
0
none
none
none
0
[ "none" ]
null
null
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,...
In the first line print single integer — the maximum possible minimum mex. In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109. It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109. If there are multiple solutio...
[ "5 3\n1 3\n2 5\n4 5\n", "4 2\n1 4\n2 4\n" ]
[ "2\n1 0 2 1 0\n", "3\n5 2 0 1" ]
The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2.
0
[ { "input": "5 3\n1 3\n2 5\n4 5", "output": "2\n0 1 0 1 0" }, { "input": "4 2\n1 4\n2 4", "output": "3\n0 1 2 0" }, { "input": "1 1\n1 1", "output": "1\n0" }, { "input": "2 1\n2 2", "output": "1\n0 0" }, { "input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3", "output":...
1,610,987,772
2,147,483,647
Python 3
OK
TESTS
69
483
8,601,600
def mex(arr,n): mini=float("inf") for l,r in arr: mini=min(mini,r-l+1) print(mini) for i in range(n): print(i%mini,end=" ") return "" a,b=map(int,input().strip().split()) blanck=[] for i in range(b): x,y=map(int,input().strip().split()) blanck.append([x,y]) pri...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special. Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some...
```python def mex(arr,n): mini=float("inf") for l,r in arr: mini=min(mini,r-l+1) print(mini) for i in range(n): print(i%mini,end=" ") return "" a,b=map(int,input().strip().split()) blanck=[] for i in range(b): x,y=map(int,input().strip().split()) blanck.append([...
3
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,654,910,892
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
x = int(input()) y = int(input()) given = 0 output = 0 code = True while code: if given < y: for i in range(1, x + 1): if given < y: given += i if given > y: given -= i output = y - given ...
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 x = int(input()) y = int(input()) given = 0 output = 0 code = True while code: if given < y: for i in range(1, x + 1): if given < y: given += i if given > y: given -= i output = y - given ...
-1
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", ...
1,700,149,158
2,147,483,647
Python 3
OK
TESTS
47
202
15,872,000
n = int(input()) read = list(map(int, input().split())) read.sort() count = {} exist = set() points = [[0] * 100001 for i in range(0, 2)] for i in range(0, n): if not read[i] in count: count[read[i]] = 1 exist.add(read[i]) else: count[read[i]] += 1 for i in range(0, read[n-1]...
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make ...
```python n = int(input()) read = list(map(int, input().split())) read.sort() count = {} exist = set() points = [[0] * 100001 for i in range(0, 2)] for i in range(0, n): if not read[i] in count: count[read[i]] = 1 exist.add(read[i]) else: count[read[i]] += 1 for i in range(0,...
3
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,501,065,435
2,147,483,647
Python 3
OK
TESTS
30
124
4,608,000
a=input() cup=0 for i in a: if i.isupper(): cup+=1 if cup>len(a)-cup: print(a.upper()) else: print(a.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a=input() cup=0 for i in a: if i.isupper(): cup+=1 if cup>len(a)-cup: print(a.upper()) else: print(a.lower()) ```
3.960417
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,695,666,507
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n,h = map(int,input().spilt()) input().split() width = 0 n = int(input()) arr = list(map(int,input().split()) for i in range (0,n) if arr[i] > h: width += 2 else: width += 1
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python n,h = map(int,input().spilt()) input().split() width = 0 n = int(input()) arr = list(map(int,input().split()) for i in range (0,n) if arr[i] > h: width += 2 else: width += 1 ```
-1
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,698,329,321
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = list(map(int,input().split())) n_set = set(n) print(len(n)-len(n_set))
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python n = list(map(int,input().split())) n_set = set(n) print(len(n)-len(n_set)) ```
3
819
A
Mister B and Boring Game
PROGRAMMING
2,200
[ "games", "greedy" ]
null
null
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his competitor. Initially the players have a string *s* consisting of t...
First and only line contains four space-separated integers: *a*, *b*, *l* and *r* (1<=≤<=*a*,<=*b*<=≤<=12, 1<=≤<=*l*<=≤<=*r*<=≤<=109) — the numbers of letters each player appends and the bounds of the segment.
Print one integer — the minimum possible number of different letters in the segment from position *l* to position *r*, inclusive, in string *s*.
[ "1 1 1 8\n", "4 2 2 6\n", "3 7 4 6\n" ]
[ "2", "3", "1" ]
In the first sample test one of optimal strategies generate string *s* = "abababab...", that's why answer is 2. In the second sample test string *s* = "abcdbcaefg..." can be obtained, chosen segment will look like "bcdbc", that's why answer is 3. In the third sample test string *s* = "abczzzacad..." can be obtained, ...
500
[ { "input": "1 1 1 8", "output": "2" }, { "input": "4 2 2 6", "output": "3" }, { "input": "3 7 4 6", "output": "1" }, { "input": "4 5 1 1", "output": "1" }, { "input": "12 12 1 1000", "output": "13" }, { "input": "12 1 1000 1000", "output": "1" },...
1,691,943,500
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1691943492.7095313")# 1691943492.7095478
Title: Mister B and Boring Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters...
```python print("_RANDOM_GUESS_1691943492.7095313")# 1691943492.7095478 ```
0
937
B
Vile Grasshoppers
PROGRAMMING
1,400
[ "brute force", "math", "number theory" ]
null
null
The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (more precise, from 2 to *p*) are occupied by tiny vile grasshoppers which you're at war with. These grassh...
The only line contains two integers *p* and *y* (2<=≤<=*p*<=≤<=*y*<=≤<=109).
Output the number of the highest suitable branch. If there are none, print -1 instead.
[ "3 6\n", "3 4\n" ]
[ "5\n", "-1\n" ]
In the first sample case grasshopper from branch 2 reaches branches 2, 4 and 6 while branch 3 is initially settled by another grasshopper. Therefore the answer is 5. It immediately follows that there are no valid branches in second sample case.
1,000
[ { "input": "3 6", "output": "5" }, { "input": "3 4", "output": "-1" }, { "input": "2 2", "output": "-1" }, { "input": "5 50", "output": "49" }, { "input": "944192806 944193066", "output": "944192807" }, { "input": "1000000000 1000000000", "output":...
1,521,967,216
2,147,483,647
Python 3
OK
TESTS
58
93
7,065,600
from math import sqrt p,y = map(int,input().split()) def is_prime(n, p): if n % 2 == 0 and n > 2: return False if p == 2: return True for x in range(3, min(p, int(sqrt(n))) + 1, 2): if n % x == 0: return False return True for i in range(y, p,-1): if is_prime(i, p): ...
Title: Vile Grasshoppers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The weather is fine today and hence it's high time to climb the nearby pine and enjoy the landscape. The pine's trunk includes several branches, located one above another and numbered from 2 to *y*. Some of them (mor...
```python from math import sqrt p,y = map(int,input().split()) def is_prime(n, p): if n % 2 == 0 and n > 2: return False if p == 2: return True for x in range(3, min(p, int(sqrt(n))) + 1, 2): if n % x == 0: return False return True for i in range(y, p,-1): if is_prime(i...
3
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le...
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago...
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" ...
1,623,551,345
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
14
186
2,764,800
import sys import math from math import factorial, inf, gcd, sqrt from heapq import * from functools import * from itertools import * from collections import * from typing import * from bisect import * import random from sys import stdin, stdout sys.setrecursionlimit(10**5) def inp(): return stdin....
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ...
```python import sys import math from math import factorial, inf, gcd, sqrt from heapq import * from functools import * from itertools import * from collections import * from typing import * from bisect import * import random from sys import stdin, stdout sys.setrecursionlimit(10**5) def inp(): ret...
0
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,697,685,482
2,147,483,647
PyPy 3-64
OK
TESTS
21
124
0
from math import floor inp = list(input()) inp1 = [] out = "" for i in inp: if i != "+": inp1.append(i) inp = sorted(inp1) for item in inp: out = out + item + "+" print(out[:-1])
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python from math import floor inp = list(input()) inp1 = [] out = "" for i in inp: if i != "+": inp1.append(i) inp = sorted(inp1) for item in inp: out = out + item + "+" print(out[:-1]) ```
3
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,584,987,566
2,147,483,647
PyPy 3
OK
TESTS
80
342
0
n = int(input()) heights = [int(x) for x in input().split()] leftCounter = [0] * n rightCounter = [0] * n for i in range(1,n): if heights[i-1] <= heights[i]: leftCounter[i] = leftCounter[i-1] + 1 if heights[n-i-1] >= heights[n-i]: rightCounter[n-i-1] = rightCounter[n-i] + 1 maxSections ...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n = int(input()) heights = [int(x) for x in input().split()] leftCounter = [0] * n rightCounter = [0] * n for i in range(1,n): if heights[i-1] <= heights[i]: leftCounter[i] = leftCounter[i-1] + 1 if heights[n-i-1] >= heights[n-i]: rightCounter[n-i-1] = rightCounter[n-i] + 1 ma...
3.9145
7
A
Kalevitch and Chess
PROGRAMMING
1,100
[ "brute force", "constructive algorithms" ]
A. Kalevitch and Chess
2
64
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, th...
The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/c...
Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.
[ "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n", "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n" ]
[ "3\n", "1\n" ]
none
0
[ { "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3" }, { "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1" }, { "input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWW...
1,451,273,285
2,147,483,647
Python 3
OK
TESTS
30
124
0
d=0 c=0 for i in range (0,8): a=input() if a!='BBBBBBBB' and d==0: d=1 for j in range (0,8): if a[j]=='B': c+=1 if a=='BBBBBBBB': c+=1 print(c)
Title: Kalevitch and Chess Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de...
```python d=0 c=0 for i in range (0,8): a=input() if a!='BBBBBBBB' and d==0: d=1 for j in range (0,8): if a[j]=='B': c+=1 if a=='BBBBBBBB': c+=1 print(c) ```
3.969
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ...
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihn...
1,562,177,124
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
171
2,560,000
def printMatrix(matrix): for matrixrow in matrix: row = '' for value in matrixrow: row += str(value) + ' ' print(row) n = int(input()) w = [[0 for i in range(n)] for i in range(n)] a = [[0 for i in range(n)] for i in range(n)] b = [[0 for i in range(n)] for i in rang...
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiinetee...
```python def printMatrix(matrix): for matrixrow in matrix: row = '' for value in matrixrow: row += str(value) + ' ' print(row) n = int(input()) w = [[0 for i in range(n)] for i in range(n)] a = [[0 for i in range(n)] for i in range(n)] b = [[0 for i in range(n)] for...
-1
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 ...
1,597,929,147
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
a,b,c = map(int, input().split()) print(b+c-1%a+1)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e...
```python a,b,c = map(int, input().split()) print(b+c-1%a+1) ```
0
747
A
Display Size
PROGRAMMING
800
[ "brute force", "math" ]
null
null
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels o...
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Print two integers — the number of rows and columns on the display.
[ "8\n", "64\n", "5\n", "999999\n" ]
[ "2 4\n", "8 8\n", "1 5\n", "999 1001\n" ]
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 ro...
500
[ { "input": "8", "output": "2 4" }, { "input": "64", "output": "8 8" }, { "input": "5", "output": "1 5" }, { "input": "999999", "output": "999 1001" }, { "input": "716539", "output": "97 7387" }, { "input": "1", "output": "1 1" }, { "input":...
1,621,762,612
2,147,483,647
PyPy 3
OK
TESTS
43
93
0
a = int(input()) b = int(a**0.5) while a%b: b -= 1 print(b, a//b)
Title: Display Size Time Limit: None seconds Memory Limit: None megabytes Problem Description: A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) ...
```python a = int(input()) b = int(a**0.5) while a%b: b -= 1 print(b, a//b) ```
3
0
none
none
none
0
[ "none" ]
null
null
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert...
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*...
Print a single integer number, the maximum number of letters that Nastya can remove.
[ "ababcba\nabb\n5 3 4 1 7 6 2\n", "bbbabb\nbb\n1 6 3 4 2 5\n" ]
[ "3", "4" ]
In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https...
0
[ { "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3" }, { "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4" }, { "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9" }, { "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1...
1,700,242,518
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
20
2,000
47,820,800
def check(lst, sub): s = len(sub) r = len(lst) k = 0 for i in range(r): if k < s and lst[i] == sub[k]: k += 1 return k // s def q(w, t, p, a): c = [] for i in range(w): c.append(a[i] - 1) c.sort() s = [] j = 0 for...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nas...
```python def check(lst, sub): s = len(sub) r = len(lst) k = 0 for i in range(r): if k < s and lst[i] == sub[k]: k += 1 return k // s def q(w, t, p, a): c = [] for i in range(w): c.append(a[i] - 1) c.sort() s = [] j = ...
0
260
A
Adding Digits
PROGRAMMING
1,400
[ "implementation", "math" ]
null
null
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di...
The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105).
In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them.
[ "5 4 5\n", "12 11 1\n", "260 150 10\n" ]
[ "524848\n", "121\n", "-1\n" ]
none
500
[ { "input": "5 4 5", "output": "524848" }, { "input": "12 11 1", "output": "121" }, { "input": "260 150 10", "output": "-1" }, { "input": "78843 5684 42717", "output": "-1" }, { "input": "93248 91435 1133", "output": "-1" }, { "input": "100000 10 64479"...
1,609,698,517
2,147,483,647
Python 3
OK
TESTS
25
764
409,600
a,b,n = map(int,input().split()) check = 1 if a%b==0: print(a*(10**n)) else: check = 0 for y in range(10): if (a*10+y)%b==0: a = a*10+y check = 1 break else: pass if check==0: print(-1) else: print(a*(10*...
Title: Adding Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one ...
```python a,b,n = map(int,input().split()) check = 1 if a%b==0: print(a*(10**n)) else: check = 0 for y in range(10): if (a*10+y)%b==0: a = a*10+y check = 1 break else: pass if check==0: print(-1) else: pr...
3
450
A
Jzzhu and Children
PROGRAMMING
1,000
[ "implementation" ]
null
null
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of...
The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100).
Output a single integer, representing the number of the last child.
[ "5 2\n1 3 1 4 2\n", "6 4\n1 1 2 2 3 3\n" ]
[ "4\n", "6\n" ]
Let's consider the first sample. Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en...
500
[ { "input": "5 2\n1 3 1 4 2", "output": "4" }, { "input": "6 4\n1 1 2 2 3 3", "output": "6" }, { "input": "7 3\n6 1 5 4 2 3 1", "output": "4" }, { "input": "10 5\n2 7 3 6 2 5 1 3 4 5", "output": "4" }, { "input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18...
1,641,226,991
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
0
n,m=map(int, input().split()) a=list(map(int, input().split())) x=max(a) if a.count(x)==1: print(a.index(x)+1) else: a1=a[::-1] print(a1.index(x)+len(a))
Title: Jzzhu and Children Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line ...
```python n,m=map(int, input().split()) a=list(map(int, input().split())) x=max(a) if a.count(x)==1: print(a.index(x)+1) else: a1=a[::-1] print(a1.index(x)+len(a)) ```
0
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin...
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &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,417,738,144
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
sum1 = 0 sum2 = 0 list1 = [] list2 = [] last = 0 n = int(input()) for i in range(n): val = int(input()) if val > 0: sum1 += val list1.append(val) last = 1 else: sum2 += -val list2.append(-val) last = -1 if sum1 > sum2: print("first")...
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 sum1 = 0 sum2 = 0 list1 = [] list2 = [] last = 0 n = int(input()) for i in range(n): val = int(input()) if val > 0: sum1 += val list1.append(val) last = 1 else: sum2 += -val list2.append(-val) last = -1 if sum1 > sum2: prin...
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV set...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,585,465,787
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
280
0
n, m = map(int,input().split()) res = 0 a = [int(a) for a in input().split()] sorted(a) for i in a: if m == 0: break if i < 0 and m > 0: res += i print(res*-1)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n, m = map(int,input().split()) res = 0 a = [int(a) for a in input().split()] sorted(a) for i in a: if m == 0: break if i < 0 and m > 0: res += i print(res*-1) ```
0
998
B
Cutting
PROGRAMMING
1,200
[ "dp", "greedy", "sortings" ]
null
null
There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulti...
First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal...
Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins.
[ "6 4\n1 2 5 10 15 20\n", "4 10\n1 3 2 4\n", "6 100\n1 2 3 4 5 6\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins. In the second sample it is not possible to make even one cut even with unlimited number of bitcoins. In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$....
1,000
[ { "input": "6 4\n1 2 5 10 15 20", "output": "1" }, { "input": "4 10\n1 3 2 4", "output": "0" }, { "input": "6 100\n1 2 3 4 5 6", "output": "2" }, { "input": "2 100\n13 78", "output": "0" }, { "input": "10 1\n56 56 98 2 11 64 97 41 95 53", "output": "0" }, ...
1,685,464,979
2,147,483,647
PyPy 3-64
OK
TESTS
34
62
0
e,c=map(int,input().split()) arr = list(map(int,input().split())) lst = [] n = 0 nodds = 0 nevens = 0 for b in arr: if b%2==0: nevens+=1 else: nodds+=1 for i in range(e): if arr[i]%2==0: n+=1 else: n-=1 if n==0 and i!=0: nodds-=1 neve...
Title: Cutting Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Gi...
```python e,c=map(int,input().split()) arr = list(map(int,input().split())) lst = [] n = 0 nodds = 0 nevens = 0 for b in arr: if b%2==0: nevens+=1 else: nodds+=1 for i in range(e): if arr[i]%2==0: n+=1 else: n-=1 if n==0 and i!=0: nodds-=1 ...
3
246
B
Increase and Decrease
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
[ "2\n2 1\n", "3\n1 4 1\n" ]
[ "1\n", "3\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 4 1", "output": "3" }, { "input": "4\n2 -7 -2 -6", "output": "3" }, { "input": "4\n2 0 -2 -1", "output": "3" }, { "input": "6\n-1 1 0 0 -1 -1", "output": "5" }, { "input": "5\n0 0 0 0 0", "outp...
1,576,396,080
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
from itertools import combinations n1=int(input()) a=list(map(int,input())) n=n1 while(n): b=list(combinations(list,n) for i in range length(b): sum=sum(b[i]) if(sum%n==0): break n-- print(n)
Title: Increase and Decrease Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that...
```python from itertools import combinations n1=int(input()) a=list(map(int,input())) n=n1 while(n): b=list(combinations(list,n) for i in range length(b): sum=sum(b[i]) if(sum%n==0): break n-- print(n) ```
-1
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki...
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt...
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", ...
1,665,580,681
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
s = str(input()) if s[len(s) - 1] == '9': print("GOTO Vasilisa.") else: i = 0 while i < len(s): if s[i] == '.': break i += 1 if int(s[i + 1]) >= 5: print(int(s[: i]) + 1) else: print(int(s[: i]))
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those stran...
```python s = str(input()) if s[len(s) - 1] == '9': print("GOTO Vasilisa.") else: i = 0 while i < len(s): if s[i] == '.': break i += 1 if int(s[i + 1]) >= 5: print(int(s[: i]) + 1) else: print(int(s[: i])) ```
0