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
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,632,219,315
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
124
6,758,400
friends = int(input()) fingers = sum(list(map(int, input().split()))) # so fingers % friends+1 != 0 def how_many(friends, fingers): for i in range(1,6): if (fingers + i) % (friends + 1) != 1: return i print(how_many(friends, fingers))
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python friends = int(input()) fingers = sum(list(map(int, input().split()))) # so fingers % friends+1 != 0 def how_many(friends, fingers): for i in range(1,6): if (fingers + i) % (friends + 1) != 1: return i print(how_many(friends, fingers)) ```
0
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single s...
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "...
1,579,976,006
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
n = int(input()) n = n+1 fingers = list(map(int, input().split())) s = sum(fingers) print((n) - (s%n))
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the...
```python n = int(input()) n = n+1 fingers = list(map(int, input().split())) s = sum(fingers) print((n) - (s%n)) ```
0
120
B
Quiz League
PROGRAMMING
1,100
[ "implementation" ]
null
null
A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que...
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=1000 and 1<=≤<=*k*<=≤<=*n*) — the numbers of sectors on the table and the number of the sector where the arrow is pointing. The second line contains *n* numbers: *a**i*<==<=0 if the question from sector *i* has already been asked and *a**i*<==<=1 ...
Print the single number — the number of the sector containing the question the experts will be asked. It is guaranteed that the answer exists, that is that not all the questions have already been asked.
[ "5 5\n0 1 0 1 0\n", "2 1\n1 1\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "5 5\n0 1 0 1 0", "output": "2" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "3 2\n1 0 0", "output": "1" }, { "input": "3 3\n0 1 0", "output": "2" }, { "input": "1 1\n1", "output": "1" }, { "input": "6 3\n0 0 1 1 0 1", "output":...
1,582,366,299
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
R = lambda f: f.readline().split() with open('input.txt') as f1: with open('output.txt', 'w') as f2: n, k = map(int, R(f1)) k -= 1 A = R(f1) while A[k]=='0': k = (k+1) % n f2.write(k+1)
Title: Quiz League Time Limit: None seconds Memory Limit: None megabytes Problem Description: A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a quest...
```python R = lambda f: f.readline().split() with open('input.txt') as f1: with open('output.txt', 'w') as f2: n, k = map(int, R(f1)) k -= 1 A = R(f1) while A[k]=='0': k = (k+1) % n f2.write(k+1) ```
-1
234
A
Lefthanders and Righthanders
PROGRAMMING
1,200
[ "implementation" ]
null
null
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the chi...
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space...
[ "6\nLLRLLL\n", "4\nRRLL\n" ]
[ "1 4\n2 5\n6 3\n", "3 1\n4 2\n" ]
none
0
[ { "input": "6\nLLRLLL", "output": "1 4\n2 5\n6 3" }, { "input": "4\nRRLL", "output": "3 1\n4 2" }, { "input": "4\nLLRR", "output": "1 3\n2 4" }, { "input": "6\nRLLRRL", "output": "1 4\n2 5\n3 6" }, { "input": "8\nLRLRLLLR", "output": "1 5\n6 2\n3 7\n4 8" }, ...
1,620,681,926
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
6,963,200
def flip(O): if O[i] == 'R' and O[i+2] == 'L': print((i+3),(i+1)) else: print((i+1),(i+3)) if O[i+1] == 'R' and O[i+3] == 'L': print((i+4),(i+2)) else: print((i+2),(i+4)) def flop(O): if O[f] == 'R' and O[f+3] == 'L': print((f+4),(f+1)) else: print((f+1),(f+4)) if O[f+1] == 'R' and...
Title: Lefthanders and Righthanders Time Limit: None seconds Memory Limit: None megabytes Problem Description: One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t...
```python def flip(O): if O[i] == 'R' and O[i+2] == 'L': print((i+3),(i+1)) else: print((i+1),(i+3)) if O[i+1] == 'R' and O[i+3] == 'L': print((i+4),(i+2)) else: print((i+2),(i+4)) def flop(O): if O[f] == 'R' and O[f+3] == 'L': print((f+4),(f+1)) else: print((f+1),(f+4)) if O[f+1] ...
-1
540
D
Bad Luck Island
PROGRAMMING
1,900
[ "dp", "probabilities" ]
null
null
The Bad Luck Island is inhabited by three kinds of species: *r* rocks, *s* scissors and *p* papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill...
The single line contains three integers *r*, *s* and *p* (1<=≤<=*r*,<=*s*,<=*p*<=≤<=100) — the original number of individuals in the species of rock, scissors and paper, respectively.
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10<=-<=9.
[ "2 2 2\n", "2 1 2\n", "1 1 3\n" ]
[ "0.333333333333 0.333333333333 0.333333333333\n", "0.150000000000 0.300000000000 0.550000000000\n", "0.057142857143 0.657142857143 0.285714285714\n" ]
none
2,000
[ { "input": "2 2 2", "output": "0.333333333333 0.333333333333 0.333333333333" }, { "input": "2 1 2", "output": "0.150000000000 0.300000000000 0.550000000000" }, { "input": "1 1 3", "output": "0.057142857143 0.657142857143 0.285714285714" }, { "input": "3 2 1", "output": "0...
1,653,508,018
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
def dfs(veretex): global pr, a, b, n if veretex == n: pos = veretex else: pos = veretex + b[veretex] if pos - a[pos] <= 0: if dist[0] > dist[veretex] + 1: dist[0] = dist[veretex] + 1 pr[0] = veretex else: for i in range(a[pos]+1): if dist[pos-i] > dist[veretex] + 1: dist[pos-i] = ...
Title: Bad Luck Island Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Bad Luck Island is inhabited by three kinds of species: *r* rocks, *s* scissors and *p* papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belon...
```python def dfs(veretex): global pr, a, b, n if veretex == n: pos = veretex else: pos = veretex + b[veretex] if pos - a[pos] <= 0: if dist[0] > dist[veretex] + 1: dist[0] = dist[veretex] + 1 pr[0] = veretex else: for i in range(a[pos]+1): if dist[pos-i] > dist[veretex] + 1: dist...
-1
203
A
Two Problems
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the c...
The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first an...
If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes).
[ "30 5 20 20 3 5\n", "10 4 100 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
500
[ { "input": "30 5 20 20 3 5", "output": "YES" }, { "input": "10 4 100 5 5 1", "output": "NO" }, { "input": "0 7 30 50 3 4", "output": "YES" }, { "input": "50 10 30 20 1 2", "output": "YES" }, { "input": "40 1 40 5 11 2", "output": "YES" }, { "input": "3...
1,645,723,318
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
l=list(input().split()) x=int(l[0]) t=int(l[1]) a=int(l[2]) b=int(l[3]) da=int(l[4]) db=int(l[5]) if(a-da+b-db)>=x: print('YES') else: print('NO')
Title: Two Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his frien...
```python l=list(input().split()) x=int(l[0]) t=int(l[1]) a=int(l[2]) b=int(l[3]) da=int(l[4]) db=int(l[5]) if(a-da+b-db)>=x: print('YES') else: print('NO') ```
0
141
A
Amusing Joke
PROGRAMMING
800
[ "implementation", "sortings", "strings" ]
null
null
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O...
The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do...
Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.
[ "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n", "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n", "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left. In the second sample letter "P" is missing from the pile and there's an extra letter "L". In the third sample there's an extra letter "L".
500
[ { "input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS", "output": "YES" }, { "input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI", "output": "NO" }, { "input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER", "output": "NO" }, { "input": "B\nA\nAB", "output": ...
1,686,235,333
2,147,483,647
Python 3
OK
TESTS
54
92
307,200
from collections import Counter # Read the input strings guest_name = input().strip() host_name = input().strip() scrambled_letters = input().strip() # Concatenate the guest's name and host's name concatenated_name = guest_name + host_name # Check if the letters in the pile can form the names if Counter(c...
Title: Amusing Joke Time Limit: None seconds Memory Limit: None megabytes Problem Description: So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam...
```python from collections import Counter # Read the input strings guest_name = input().strip() host_name = input().strip() scrambled_letters = input().strip() # Concatenate the guest's name and host's name concatenated_name = guest_name + host_name # Check if the letters in the pile can form the names if...
3
946
C
String Transformation
PROGRAMMING
1,300
[ "greedy", "strings" ]
null
null
You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace letter z with any other letter. Your target is to make some number...
The only one line of the input consisting of the string *s* consisting of |*s*| (1<=≤<=|*s*|<=≤<=105) small english letters.
If you can get a string that can be obtained from the given string and will contain english alphabet as a subsequence, print it. Otherwise print «-1» (without quotes).
[ "aacceeggiikkmmooqqssuuwwyy\n", "thereisnoanswer\n" ]
[ "abcdefghijklmnopqrstuvwxyz\n", "-1\n" ]
none
0
[ { "input": "aacceeggiikkmmooqqssuuwwyy", "output": "abcdefghijklmnopqrstuvwxyz" }, { "input": "thereisnoanswer", "output": "-1" }, { "input": "jqcfvsaveaixhioaaeephbmsmfcgdyawscpyioybkgxlcrhaxs", "output": "-1" }, { "input": "rtdacjpsjjmjdhcoprjhaenlwuvpfqzurnrswngmpnkdnunaen...
1,578,374,568
1,368
Python 3
WRONG_ANSWER
TESTS
3
108
307,200
s = input() def aln(c): return ord(c) - ord('A') -31 def nal(n): return chr(n+96) a = [] for i in range(len(s)): a.append(aln(s[i])) tar = 1 for i in range(len(s)): if a[i] != tar and a[i] < tar: a[i] = tar tar = tar + 1 if tar == 27: ans = '' for i in range(len(s)): ...
Title: String Transformation Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* consisting of |*s*| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be rep...
```python s = input() def aln(c): return ord(c) - ord('A') -31 def nal(n): return chr(n+96) a = [] for i in range(len(s)): a.append(aln(s[i])) tar = 1 for i in range(len(s)): if a[i] != tar and a[i] < tar: a[i] = tar tar = tar + 1 if tar == 27: ans = '' for i in range(len(s))...
0
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
The first line of input contains two integer numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≤<=*a**i*<=≤<=100) — the length of the segment that can be watered by the *i*-th bucket in one ...
Print one integer number — the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5...
1,525,941,988
2,147,483,647
Python 3
OK
TESTS
83
78
7,065,600
n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() for i in a: if m % i==0:s=m/i print(int(s))
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ...
```python n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() for i in a: if m % i==0:s=m/i print(int(s)) ```
3
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, al...
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": ...
1,676,035,341
2,147,483,647
PyPy 3-64
OK
TESTS
30
62
0
n = int(input()) l = [6,8,4,2] if n == 0: print(1) else: print(l[(n%4)])
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one ques...
```python n = int(input()) l = [6,8,4,2] if n == 0: print(1) else: print(l[(n%4)]) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,650,350,803
2,147,483,647
PyPy 3-64
OK
TESTS
30
92
0
s="" l=list(input()) i=0 while(i<len(l)): if(l[i]=="."): s+="0" i+=1 elif l[i]=='-' and l[i+1]=='.': s+="1" i+=2 elif l[i]=='-' and l[i+1]=='-': s+="2" i+=2 print(s)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ...
```python s="" l=list(input()) i=0 while(i<len(l)): if(l[i]=="."): s+="0" i+=1 elif l[i]=='-' and l[i+1]=='.': s+="1" i+=2 elif l[i]=='-' and l[i+1]=='-': s+="2" i+=2 print(s) ```
3.977
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,669,131,669
2,147,483,647
Python 3
OK
TESTS
47
218
7,065,600
input() a = [int(x) for x in input().split()] b = [0]*100001 for i in a: b[i] += 1 for i in range(2, 100001): b[i] = max(b[i-1], b[i-2]+i*b[i]) print(b[100000])
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 input() a = [int(x) for x in input().split()] b = [0]*100001 for i in a: b[i] += 1 for i in range(2, 100001): b[i] = max(b[i-1], b[i-2]+i*b[i]) print(b[100000]) ```
3
827
E
Rusty String
PROGRAMMING
2,700
[ "fft", "math", "strings" ]
null
null
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length *n* and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was written. Grigory couldn't understand for a long time what these letters remind hi...
There are several (at least one) test cases in the input. The first line contains single integer — the number of test cases. There is an empty line before each test case. Each test case is described in two lines: the first line contains single integer *n* (1<=≤<=*n*<=≤<=5·105) — the length of the string, the second li...
For each test case print two lines. In the first line print the number of possible periods after we replace each unreadable letter with "V" or "K". In the next line print all these values in increasing order.
[ "3\n \n5\nV??VK\n \n6\n??????\n \n4\n?VK?\n" ]
[ "2\n3 5\n6\n1 2 3 4 5 6\n3\n2 3 4\n" ]
In the first test case from example we can obtain, for example, "VKKVK", which has periods 3 and 5. In the second test case we can obtain "VVVVVV" which has all periods from 1 to 6. In the third test case string "KVKV" has periods 2 and 4, and string "KVKK" has periods 3 and 4.
1,750
[]
1,665,605,572
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
MAX = 10000 ans = [-1 for _ in range(MAX)] t = int(input()) for _ in range(t): cnt = 0 # Obtiene n y a desde standard input n = int(input()) # Largo n de palabra s = " " + list(map(str, input().split()))[0] for x in range(1, n+1): # print(s[x...
Title: Rusty String Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigory loves strings. Recently he found a metal strip on a loft. The strip had length *n* and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand w...
```python MAX = 10000 ans = [-1 for _ in range(MAX)] t = int(input()) for _ in range(t): cnt = 0 # Obtiene n y a desde standard input n = int(input()) # Largo n de palabra s = " " + list(map(str, input().split()))[0] for x in range(1, n+1): #...
-1
408
B
Garland
PROGRAMMING
1,200
[ "implementation" ]
null
null
Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each pie...
The first line contains a non-empty sequence of *n* (1<=≤<=*n*<=≤<=1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of *m* (1<=≤<=*m*<=≤<=1000) small English letters that correspond to the colors of the ...
Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
[ "aaabbac\naabbccac\n", "a\nz\n" ]
[ "6\n", "-1" ]
In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot mak...
1,000
[ { "input": "aaabbac\naabbccac", "output": "6" }, { "input": "a\nz", "output": "-1" }, { "input": "r\nr", "output": "1" }, { "input": "stnsdn\nndnndsn", "output": "4" }, { "input": "yqfqfp\ntttwtqq", "output": "-1" }, { "input": "zzbbrrtrtzr\ntbbtrrrzr"...
1,630,064,990
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
77
7,065,600
import collections have=input() want=input() h=collections.Counter(have) w=collections.Counter(want) needed=0 for i in w: if h[i]==0: print(-1) exit() if h[i]>=w[i]: needed+=w[i] elif h[i]<w[i]: needed+=1 print(needed)
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter....
```python import collections have=input() want=input() h=collections.Counter(have) w=collections.Counter(want) needed=0 for i in w: if h[i]==0: print(-1) exit() if h[i]>=w[i]: needed+=w[i] elif h[i]<w[i]: needed+=1 print(needed) ```
0
854
A
Fraction
PROGRAMMING
800
[ "brute force", "constructive algorithms", "math" ]
null
null
Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (*a*<=&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,577,568,258
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
307,200
import math as m def divisors(n): r=int(m.sqrt(n)) h1=[] h2=[n] for i in range(2, r+1): if n%i==0: h1.append(i) h2.append(n//i) h2.reverse() h1=h1+h2 return h1 def coprime(h1, h2): t=True for i in h1: if i in h2: t...
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 import math as m def divisors(n): r=int(m.sqrt(n)) h1=[] h2=[n] for i in range(2, r+1): if n%i==0: h1.append(i) h2.append(n//i) h2.reverse() h1=h1+h2 return h1 def coprime(h1, h2): t=True for i in h1: if i in h2: ...
-1
682
B
Alyona and Mex
PROGRAMMING
1,200
[ "sortings" ]
null
null
Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular,...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the array.
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
[ "5\n1 3 3 3 6\n", "2\n2 1\n" ]
[ "5\n", "3\n" ]
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements.
1,000
[ { "input": "5\n1 3 3 3 6", "output": "5" }, { "input": "2\n2 1", "output": "3" }, { "input": "1\n1", "output": "2" }, { "input": "1\n1000000000", "output": "2" }, { "input": "1\n2", "output": "2" }, { "input": "2\n1 1", "output": "2" }, { "...
1,469,342,496
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
n = int(input()) mx = 1 a = list(map(int, input().split())) a.sort() for i in a: if l >= mx: mx += 1 print(mx)
Title: Alyona and Mex Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is small...
```python n = int(input()) mx = 1 a = list(map(int, input().split())) a.sort() for i in a: if l >= mx: mx += 1 print(mx) ```
-1
538
B
Quasi Binary
PROGRAMMING
1,400
[ "constructive algorithms", "dp", "greedy", "implementation" ]
null
null
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106).
In the first line print a single integer *k* — the minimum number of numbers in the representation of number *n* as a sum of quasibinary numbers. In the second line print *k* numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal *n*. Do not...
[ "9\n", "32\n" ]
[ "9\n1 1 1 1 1 1 1 1 1 \n", "3\n10 11 11 \n" ]
none
1,000
[ { "input": "9", "output": "9\n1 1 1 1 1 1 1 1 1 " }, { "input": "32", "output": "3\n10 11 11 " }, { "input": "1", "output": "1\n1 " }, { "input": "415", "output": "5\n1 101 101 101 111 " }, { "input": "10011", "output": "1\n10011 " }, { "input": "10201...
1,619,282,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
0
# MC521 - Desafios de Programacao I - 1s2021 # Contest: 23/04/2021 # Problema H - Quasi Binary # le o numero inteiro a ser analisado n = int(input()) # inializa variavel auxilair num = [0] * 7 # separa a ordem dos numeros for i in range(7): num[i] = n//(10**(6-i)) n = n%(10**(6-i)) # destrincha o numero while(n...
Title: Quasi Binary Time Limit: None seconds Memory Limit: None megabytes Problem Description: A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not. You are given a positive integer *n*. Repr...
```python # MC521 - Desafios de Programacao I - 1s2021 # Contest: 23/04/2021 # Problema H - Quasi Binary # le o numero inteiro a ser analisado n = int(input()) # inializa variavel auxilair num = [0] * 7 # separa a ordem dos numeros for i in range(7): num[i] = n//(10**(6-i)) n = n%(10**(6-i)) # destrincha o nume...
0
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,684,995,581
2,147,483,647
PyPy 3-64
OK
TESTS
32
62
11,673,600
n = int(input()) a = [int(x) for x in input().split()] ans = 1 cur = 1 for i in range(1,n): if a[i] > a[i-1]: cur += 1 ans = max(cur,ans) else: cur = 1 print(ans)
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python n = int(input()) a = [int(x) for x in input().split()] ans = 1 cur = 1 for i in range(1,n): if a[i] > a[i-1]: cur += 1 ans = max(cur,ans) else: cur = 1 print(ans) ```
3
592
C
The Big Race
PROGRAMMING
1,800
[ "math" ]
null
null
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While ...
The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=&gt;<=0 holds) is called irreducible, if there is no such integer *d*<=&gt;<=1, that both *p* and *q* are divisible by *d*.
[ "10 3 2\n", "7 1 2\n" ]
[ "3/10\n", "3/7\n" ]
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
1,500
[ { "input": "10 3 2", "output": "3/10" }, { "input": "7 1 2", "output": "3/7" }, { "input": "1 1 1", "output": "1/1" }, { "input": "5814 31 7", "output": "94/2907" }, { "input": "94268 813 766", "output": "765/94268" }, { "input": "262610 5583 4717", ...
1,446,313,253
4,253
Python 3
COMPILATION_ERROR
PRETESTS
0
0
0
from fractions import gcd import sys numbers = raw_input() t,w,b = [long(n) for n in numbers.split()] lcm=(w*b)/gcd(w,b) mini=min(w,b) cnt=t/lcm ans=0 ans+=cnt*mini last=lcm*cnt ans += min(mini,(t+1-last)) ans -= 1 gcd=gcd(ans,t) ans = ans/gcd t = t/gcd print ans, sys.stdout.write("/") ...
Title: The Big Race Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today. Willman and Bolt have exactly the same speed, so when they compete the...
```python from fractions import gcd import sys numbers = raw_input() t,w,b = [long(n) for n in numbers.split()] lcm=(w*b)/gcd(w,b) mini=min(w,b) cnt=t/lcm ans=0 ans+=cnt*mini last=lcm*cnt ans += min(mini,(t+1-last)) ans -= 1 gcd=gcd(ans,t) ans = ans/gcd t = t/gcd print ans, sys.stdout.wr...
-1
587
A
Duff and Weight Lifting
PROGRAMMING
1,500
[ "greedy" ]
null
null
Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of the remaining weights and throw them away. She does this until there's no more weight left. Malek asked her to ...
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=106), the number of weights. The second line contains *n* integers *w*1,<=...,<=*w**n* separated by spaces (0<=≤<=*w**i*<=≤<=106 for each 1<=≤<=*i*<=≤<=*n*), the powers of two forming the weights values.
Print the minimum number of steps in a single line.
[ "5\n1 1 2 3 3\n", "4\n0 1 2 3\n" ]
[ "2\n", "4\n" ]
In the first sample case: One optimal way would be to throw away the first three in the first step and the rest in the second step. Also, it's not possible to do it in one step because their sum is not a power of two. In the second sample case: The only optimal way is to throw away one weight in each step. It's not po...
500
[ { "input": "5\n1 1 2 3 3", "output": "2" }, { "input": "4\n0 1 2 3", "output": "4" }, { "input": "1\n120287", "output": "1" }, { "input": "2\n28288 0", "output": "2" }, { "input": "2\n95745 95745", "output": "1" }, { "input": "13\n92 194 580495 0 10855...
1,509,617,961
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
62
0
# cook your dish here n=int(input()) a=list(map(int,input().split())) a.sort() x=a[0] ans=1 for i in range(1,n): if(a[i]==x): x+=1 else: x=a[i] ans+=1 print(ans)
Title: Duff and Weight Lifting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of *i*-th of them is 2*w**i* pounds. In each step, Duff can lift some of th...
```python # cook your dish here n=int(input()) a=list(map(int,input().split())) a.sort() x=a[0] ans=1 for i in range(1,n): if(a[i]==x): x+=1 else: x=a[i] ans+=1 print(ans) ```
0
802
G
Fake News (easy)
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi assess whether the given piece is true, but please be discreet about it...
The first and only line of input contains a single nonempty string *s* of length at most 1000 composed of lowercase letters (a-z).
Output YES if the string *s* contains heidi as a subsequence and NO otherwise.
[ "abcheaibcdi\n", "hiedi\n" ]
[ "YES", "NO" ]
A string *s* contains another string *p* as a subsequence if it is possible to delete some characters from *s* and obtain *p*.
0
[ { "input": "abcheaibcdi", "output": "YES" }, { "input": "hiedi", "output": "NO" }, { "input": "ihied", "output": "NO" }, { "input": "diehi", "output": "NO" }, { "input": "deiih", "output": "NO" }, { "input": "iheid", "output": "NO" }, { "in...
1,598,193,330
2,147,483,647
Python 3
OK
TESTS
58
109
6,656,000
s=input() t="heidi" ps=0 for e in s: if(e==t[ps]): ps+=1 if(ps==len(t)): print("YES") quit() print("NO")
Title: Fake News (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a ...
```python s=input() t="heidi" ps=0 for e in s: if(e==t[ps]): ps+=1 if(ps==len(t)): print("YES") quit() print("NO") ```
3
501
A
Contest
PROGRAMMING
900
[ "implementation" ]
null
null
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ...
The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180). It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round).
Output on a single line: "Misha" (without the quotes), if Misha got more points than Vasya. "Vasya" (without the quotes), if Vasya got more points than Misha. "Tie" (without the quotes), if both of them got the same number of points.
[ "500 1000 20 30\n", "1000 1000 1 1\n", "1500 1000 176 177\n" ]
[ "Vasya\n", "Tie\n", "Misha\n" ]
none
500
[ { "input": "500 1000 20 30", "output": "Vasya" }, { "input": "1000 1000 1 1", "output": "Tie" }, { "input": "1500 1000 176 177", "output": "Misha" }, { "input": "1500 1000 74 177", "output": "Misha" }, { "input": "750 2500 175 178", "output": "Vasya" }, { ...
1,579,187,521
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
109
0
a,b,c,d=map(int,input().split()) x=0 y=0 c=0 if(a%250==0 and b%250==0): if(a>b): print("Misha") elif(b>a): print("Vasya") elif(a==b): print("Tie")
Title: Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t...
```python a,b,c,d=map(int,input().split()) x=0 y=0 c=0 if(a%250==0 and b%250==0): if(a>b): print("Misha") elif(b>a): print("Vasya") elif(a==b): print("Tie") ```
0
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,692,555,433
2,147,483,647
Python 3
OK
TESTS
30
234
17,203,200
import sys count = 0 tetrahedron = 4 cube = 6 octahedron = 8 dodecahedron = 12 icosahedron = 20 lst = [] number = int(input()) for i in range(number): lst.append(input()) for i in lst: if i == 'Tetrahedron': count += 4 elif i == 'Cube': count += 6 elif i == 'Octahedron': count += 8 el...
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python import sys count = 0 tetrahedron = 4 cube = 6 octahedron = 8 dodecahedron = 12 icosahedron = 20 lst = [] number = int(input()) for i in range(number): lst.append(input()) for i in lst: if i == 'Tetrahedron': count += 4 elif i == 'Cube': count += 6 elif i == 'Octahedron': count +=...
3
572
B
Order Book
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i*, direction *d**i* — buy or sell, and integer *q**i*. This means that the participant is ready ...
The input starts with two positive integers *n* and *s* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*s*<=≤<=50), the number of orders and the book depth. Next *n* lines contains a letter *d**i* (either 'B' or 'S'), an integer *p**i* (0<=≤<=*p**i*<=≤<=105) and an integer *q**i* (1<=≤<=*q**i*<=≤<=104) — direction, price and volume resp...
Print no more than 2*s* lines with aggregated orders from order book of depth *s*. The output format for orders should be the same as in input.
[ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n" ]
[ "S 50 8\nS 40 1\nB 25 10\nB 20 4\n" ]
Denote (x, y) an order with price *x* and volume *y*. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample. You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.
1,000
[ { "input": "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10", "output": "S 50 8\nS 40 1\nB 25 10\nB 20 4" }, { "input": "2 1\nB 7523 5589\nS 69799 1711", "output": "S 69799 1711\nB 7523 5589" }, { "input": "1 1\nB 48259 991", "output": "B 48259 991" }, { "input": "1 50\n...
1,554,900,446
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
108
409,600
from collections import defaultdict n, s = map(int, input().split(' ')) B = defaultdict(lambda: 0) S = defaultdict(lambda: 0) for _ in range(n): d, p, q = input().split(' ') if d == 'B': B[int(p)] += int(q) else: S[int(p)] += int(q) b_keys = sorted(B.keys(), reverse=True)...
Title: Order Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number *i* has price *p**i...
```python from collections import defaultdict n, s = map(int, input().split(' ')) B = defaultdict(lambda: 0) S = defaultdict(lambda: 0) for _ in range(n): d, p, q = input().split(' ') if d == 'B': B[int(p)] += int(q) else: S[int(p)] += int(q) b_keys = sorted(B.keys(), rev...
-1
810
B
Summer sell-off
PROGRAMMING
1,300
[ "greedy", "sortings" ]
null
null
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag...
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin...
Print a single integer denoting the maximal number of products that shop can sell.
[ "4 2\n2 1\n3 5\n2 3\n1 5\n", "4 1\n0 2\n0 3\n3 5\n0 6\n" ]
[ "10", "5" ]
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the s...
1,000
[ { "input": "4 2\n2 1\n3 5\n2 3\n1 5", "output": "10" }, { "input": "4 1\n0 2\n0 3\n3 5\n0 6", "output": "5" }, { "input": "1 1\n5 8", "output": "8" }, { "input": "2 1\n8 12\n6 11", "output": "19" }, { "input": "2 1\n6 7\n5 7", "output": "13" }, { "inpu...
1,673,440,723
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
11
1,000
11,776,000
def sort_(l, x): n = len(l) for i in range(n-1): index_min = i for j in range(i+1, n): if l[j]>=l[index_min]: index_min = j if index_min!=i: l[i], l[index_min] = l[index_min], l[i] if i==x: break n, f = map(int, i...
Title: Summer sell-off Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass...
```python def sort_(l, x): n = len(l) for i in range(n-1): index_min = i for j in range(i+1, n): if l[j]>=l[index_min]: index_min = j if index_min!=i: l[i], l[index_min] = l[index_min], l[i] if i==x: break n, f = ...
0
157
A
Game Outcome
PROGRAMMING
800
[ "brute force" ]
null
null
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100.
Print the single number — the number of the winning squares.
[ "1\n1\n", "2\n1 2\n3 4\n", "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n" ]
[ "0\n", "2\n", "6\n" ]
In the first example two upper squares are winning. In the third example three left squares in the both middle rows are winning:
500
[ { "input": "1\n1", "output": "0" }, { "input": "2\n1 2\n3 4", "output": "2" }, { "input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3", "output": "6" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "4" }, { "inpu...
1,417,168,272
2,147,483,647
Python 3
OK
TESTS
49
124
0
n = int(input()) a = [] h = [] v = [] for i in range(n): a.append([int(x) for x in input().split()]) for l in a: h.append(sum(l)) for l in zip(*a): v.append(sum(l)) ans = 0 for x in h: for y in v: if y > x: ans += 1 print(ans)
Title: Game Outcome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s...
```python n = int(input()) a = [] h = [] v = [] for i in range(n): a.append([int(x) for x in input().split()]) for l in a: h.append(sum(l)) for l in zip(*a): v.append(sum(l)) ans = 0 for x in h: for y in v: if y > x: ans += 1 print(ans) ```
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,666,431,619
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
a,b=map(int,input().split()) c=0 d=0 e=0 c=a+b d=c//2 e=d+1 print(e)
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 a,b=map(int,input().split()) c=0 d=0 e=0 c=a+b d=c//2 e=d+1 print(e) ```
0
268
A
Games
PROGRAMMING
800
[ "brute force" ]
null
null
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ...
The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively.
In a single line print the number of games where the host team is going to play in the guest uniform.
[ "3\n1 2\n2 4\n3 4\n", "4\n100 42\n42 100\n5 42\n100 5\n", "2\n1 2\n1 2\n" ]
[ "1\n", "5\n", "0\n" ]
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea...
500
[ { "input": "3\n1 2\n2 4\n3 4", "output": "1" }, { "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5" }, { "input": "2\n1 2\n1 2", "output": "0" }, { "input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52", "output": "6" }, { "input": "10\n68 42\n1 35\n25 70\n...
1,696,847,401
2,147,483,647
Python 3
OK
TESTS
31
92
0
# -*- coding: utf-8 -*- """ Created on Mon Oct 9 17:19:01 2023 @author: 25419 """ n=int(input()) home=[] guest=[] sum=0 for i in range(n): temp=input().split() home.append(temp[0]) guest.append(temp[1]) for i in range(n): if home[i] in guest: temp=guest.count(home[i]) ...
Title: Games Time Limit: None seconds Memory Limit: None megabytes Problem Description: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W...
```python # -*- coding: utf-8 -*- """ Created on Mon Oct 9 17:19:01 2023 @author: 25419 """ n=int(input()) home=[] guest=[] sum=0 for i in range(n): temp=input().split() home.append(temp[0]) guest.append(temp[1]) for i in range(n): if home[i] in guest: temp=guest.count(home[i...
3
933
A
A Twisty Movement
PROGRAMMING
1,800
[ "dp" ]
null
null
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000), denoting the length of the original sequence. The second line contains *n* space-separated integers, describing the original sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2,<=*i*<==<=1,<=2,<=...,<=*n*).
Print a single integer, which means the maximum possible length of the longest non-decreasing subsequence of the new sequence.
[ "4\n1 2 1 2\n", "10\n1 1 2 2 2 1 1 2 2 1\n" ]
[ "4\n", "9\n" ]
In the first example, after reversing [2, 3], the array will become [1, 1, 2, 2], where the length of the longest non-decreasing subsequence is 4. In the second example, after reversing [3, 7], the array will become [1, 1, 1, 1, 2, 2, 2, 2, 2, 1], where the length of the longest non-decreasing subsequence is 9.
500
[ { "input": "4\n1 2 1 2", "output": "4" }, { "input": "10\n1 1 2 2 2 1 1 2 2 1", "output": "9" }, { "input": "200\n2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 1 1 1 2 1 1 2 2 2 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 2 2 2 1 2 2 2 1 2 1 2 1 2 1 1 1 1 2 2 2 1 1 2 ...
1,528,569,701
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
0
n=int(input()) a=list(map(int,input().split())) le=0;b=[];now=a[0] for i in range(n): if a[i]>=now: le+=1;now=max(now,a[i]) else: now=a[i];b.append(le);le=1 b.append(le) ma=0 for i in range(len(b)-1): ma=max(b[i]+b[i+1],ma) print(ma)
Title: A Twisty Movement Time Limit: None seconds Memory Limit: None megabytes Problem Description: A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A perform...
```python n=int(input()) a=list(map(int,input().split())) le=0;b=[];now=a[0] for i in range(n): if a[i]>=now: le+=1;now=max(now,a[i]) else: now=a[i];b.append(le);le=1 b.append(le) ma=0 for i in range(len(b)-1): ma=max(b[i]+b[i+1],ma) print(ma) ```
0
910
A
The Way to Home
PROGRAMMING
800
[ "dfs and similar", "dp", "greedy", "implementation" ]
null
null
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* ...
The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ...
If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1.
[ "8 4\n10010101\n", "4 2\n1001\n", "8 4\n11100101\n", "12 3\n101111100101\n" ]
[ "2\n", "-1\n", "3\n", "4\n" ]
In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four). In the second example the frog can not reach home, because to make it she need to jump on a ...
500
[ { "input": "8 4\n10010101", "output": "2" }, { "input": "4 2\n1001", "output": "-1" }, { "input": "8 4\n11100101", "output": "3" }, { "input": "12 3\n101111100101", "output": "4" }, { "input": "5 4\n11011", "output": "1" }, { "input": "5 4\n10001", ...
1,644,320,475
2,147,483,647
Python 3
OK
TESTS
63
46
0
def main(): n, d = list(map(int, input().split())) string = input() current_pos = 0 counter = 0 while True: decided_pos = -1 for i in range(current_pos + 1, min(n, current_pos + d + 1)): if string[i] == "1": decided_pos = i if decided...
Title: The Way to Home Time Limit: None seconds Memory Limit: None megabytes Problem Description: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c...
```python def main(): n, d = list(map(int, input().split())) string = input() current_pos = 0 counter = 0 while True: decided_pos = -1 for i in range(current_pos + 1, min(n, current_pos + d + 1)): if string[i] == "1": decided_pos = i ...
3
805
B
3-palindrome
PROGRAMMING
1,000
[ "constructive algorithms" ]
null
null
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a su...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the length of the string.
Print the string that satisfies all the constraints. If there are multiple answers, print any of them.
[ "2\n", "3\n" ]
[ "aa\n", "bba\n" ]
A palindrome is a sequence of characters which reads the same backward and forward.
1,000
[ { "input": "2", "output": "aa" }, { "input": "3", "output": "aab" }, { "input": "38", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaa" }, { "input": "47", "output": "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaab" }, { "input": "59", "output": "aabbaabbaabb...
1,585,576,980
2,147,483,647
PyPy 3
OK
TESTS
42
140
1,024,000
n = int(input()) if n == 1: print('b') elif n == 2: print('bb') else: res = 'a' n -= 1 q = n//4 r = n%4 res += 'bbaa'*q if r == 1: res += 'b' elif r == 2: res += 'bb' elif r == 3: res += 'bba' print(res)
Title: 3-palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each o...
```python n = int(input()) if n == 1: print('b') elif n == 2: print('bb') else: res = 'a' n -= 1 q = n//4 r = n%4 res += 'bbaa'*q if r == 1: res += 'b' elif r == 2: res += 'bb' elif r == 3: res += 'bba' print(res) ```
3
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — mo...
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDL...
1,585,404,411
2,147,483,647
PyPy 3
OK
TESTS
25
140
0
n = int(input()) s = input() l = s.count('L') r = s.count('R') u = s.count('U') d = s.count('D') l_r = min(l,r) u_d = min(u,d) print(2*l_r + 2*u_d)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the ce...
```python n = int(input()) s = input() l = s.count('L') r = s.count('R') u = s.count('U') d = s.count('D') l_r = min(l,r) u_d = min(u,d) print(2*l_r + 2*u_d) ```
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104).
Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,697,657,834
2,147,483,647
PyPy 3-64
OK
TESTS
32
62
1,638,400
n, m, z = [int(i) for i in input().split()] c = 0 for i in range(1, z//m+1): if (m*i) % n == 0: c += 1 print(c)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python n, m, z = [int(i) for i in input().split()] c = 0 for i in range(1, z//m+1): if (m*i) % n == 0: c += 1 print(c) ```
3
558
A
Lala Land and Apple Trees
PROGRAMMING
1,100
[ "brute force", "implementation", "sortings" ]
null
null
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t...
The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land. The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it. It's guarant...
Output the maximum number of apples Amr can collect.
[ "2\n-1 5\n1 5\n", "3\n-2 2\n1 4\n-1 3\n", "3\n1 9\n3 5\n7 10\n" ]
[ "10", "9", "9" ]
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to *x* =  - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ...
500
[ { "input": "2\n-1 5\n1 5", "output": "10" }, { "input": "3\n-2 2\n1 4\n-1 3", "output": "9" }, { "input": "3\n1 9\n3 5\n7 10", "output": "9" }, { "input": "1\n1 1", "output": "1" }, { "input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "output": "3...
1,511,604,876
876
PyPy 3
OK
TESTS
43
124
23,142,400
n = int(input()) li = [] p,ne =0,0 for _ in range(n): a,b = map(int,input().split()) li.append([a,b]) if a>0: p+=1 else: ne+=1 li.sort() ans = 0 if ne>p: li=li[::-1] for i in range(min(2*p+1,n)): ans+=li[i][1] else: for i in range(min(2*ne+1,n)): ans+=li[i][1] print(ans)
Title: Lala Land and Apple Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree num...
```python n = int(input()) li = [] p,ne =0,0 for _ in range(n): a,b = map(int,input().split()) li.append([a,b]) if a>0: p+=1 else: ne+=1 li.sort() ans = 0 if ne>p: li=li[::-1] for i in range(min(2*p+1,n)): ans+=li[i][1] else: for i in range(min(2*ne+1,n)): ans+=li[i][1] print(ans) ```
3
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,662,132,968
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
372
0
def solve(): n = int(input()) h1 = -1 m1 = -1 c = 1 ans = 0 for i in range(n): h, m = map(int, input().split()) #print(h1,h,m1,m,c) if h1 == h and m1 == m: c += 1 else: h1 = h m1 = m ans = max(ans, c) ...
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python def solve(): n = int(input()) h1 = -1 m1 = -1 c = 1 ans = 0 for i in range(n): h, m = map(int, input().split()) #print(h1,h,m1,m,c) if h1 == h and m1 == m: c += 1 else: h1 = h m1 = m ans = max...
0
911
A
Nearest Minimums
PROGRAMMING
1,100
[ "implementation" ]
null
null
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Print the only number — distance between two nearest minimums in the array.
[ "2\n3 3\n", "3\n5 6 5\n", "9\n2 1 3 5 4 1 2 3 1\n" ]
[ "1\n", "2\n", "3\n" ]
none
0
[ { "input": "2\n3 3", "output": "1" }, { "input": "3\n5 6 5", "output": "2" }, { "input": "9\n2 1 3 5 4 1 2 3 1", "output": "3" }, { "input": "6\n4 6 7 8 6 4", "output": "5" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "42\n1 1 ...
1,583,426,411
2,147,483,647
Python 3
OK
TESTS
140
187
9,523,200
n=int(input()) s=list(map(int,input().split())) mn=min(s) l1=[] for i in range(n): if s[i]==mn: l1.append(i) l2=[] for i in range(1,len(l1)): l2.append(l1[i]-l1[i-1]) print(min(l2))
Title: Nearest Minimums Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. I...
```python n=int(input()) s=list(map(int,input().split())) mn=min(s) l1=[] for i in range(n): if s[i]==mn: l1.append(i) l2=[] for i in range(1,len(l1)): l2.append(l1[i]-l1[i-1]) print(min(l2)) ```
3
7
E
Defining Macros
PROGRAMMING
2,600
[ "dp", "expression parsing", "implementation" ]
E. Defining Macros
3
256
Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the following model of #define constructions (also called macros). Each macro has its name and value. T...
The first line contains the only number *n* (0<=≤<=*n*<=≤<=100) — the amount of #define constructions in the given program. Then there follow *n* lines, each of them contains just one #define construction. Each construction has the following syntax: #define name expression where - name — the macro name, - express...
Output "OK", if the expression is correct according to the above given criterion, otherwise output "Suspicious".
[ "1\n#define sum x + y\n1 * sum\n", "1\n#define sum (x + y)\nsum - sum\n", "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr\n", "3\n#define SumSafe (a+b)\n#define DivUnsafe a/b\n#define DenominatorUnsafe a*b\n((SumSafe) + DivUnsafe/DivUnsafe + x/Deno...
[ "Suspicious\n", "OK\n", "OK\n", "Suspicious\n" ]
none
0
[ { "input": "1\n#define sum x + y\n1 * sum", "output": "Suspicious" }, { "input": "1\n#define sum (x + y)\nsum - sum", "output": "OK" }, { "input": "4\n#define sum x + y\n#define mul a * b\n#define div a / b\n#define expr sum + mul * div * mul\nexpr", "output": "OK" }, { "...
1,585,310,202
2,147,483,647
PyPy 3
OK
TESTS
139
342
2,355,200
P, A, S, M, D = 1, 2, 4, 8, 16 ADD = A | S ANY = A | S | M | D OP_BIT = {"+": A, "-": S, "*": M, "/": D, ")": 0} UNSAFE_BEFORE = {P: 0, A: 0, S: ADD, M: ADD, D: ANY} UNSAFE_AFTER = {P: 0, A: 0, S: 0, M: ADD, D: ADD} macro = dict() def expr(chars, pseudo=P, expand=macro.get, op_bit=O...
Title: Defining Macros Time Limit: 3 seconds Memory Limit: 256 megabytes Problem Description: Most C/C++ programmers know about excellent opportunities that preprocessor #define directives give; but many know as well about the problems that can arise because of their careless use. In this problem we consider the fo...
```python P, A, S, M, D = 1, 2, 4, 8, 16 ADD = A | S ANY = A | S | M | D OP_BIT = {"+": A, "-": S, "*": M, "/": D, ")": 0} UNSAFE_BEFORE = {P: 0, A: 0, S: ADD, M: ADD, D: ANY} UNSAFE_AFTER = {P: 0, A: 0, S: 0, M: ADD, D: ADD} macro = dict() def expr(chars, pseudo=P, expand=macro.get, ...
3.938613
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,688,749,144
2,147,483,647
PyPy 3-64
OK
TESTS
31
216
0
n = int(input()) wires = list(map(int, input().split())) shots = int(input()) shots_list = list() for i in range(shots): a,b = map(int, input().split()) a -= 1 if a != 0: wires[a-1] += b-1 if a != n-1: wires[a+1] += wires[a] - b wires[a] = 0 for i in range(len(wir...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python n = int(input()) wires = list(map(int, input().split())) shots = int(input()) shots_list = list() for i in range(shots): a,b = map(int, input().split()) a -= 1 if a != 0: wires[a-1] += b-1 if a != n-1: wires[a+1] += wires[a] - b wires[a] = 0 for i in ran...
3
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,654,986,637
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
from math import ceil # 799A data = list(map(int, input().split())) n = data[0]; t = data[1]; k = data[2]; d = data[3] # no of batches needed: batches1 = ceil(n / k) t1 = batches1 * t t2 = d baked = k while baked < n: baked += k t2 += t if baked >= n: break baked += k; t2 += t-d ...
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python from math import ceil # 799A data = list(map(int, input().split())) n = data[0]; t = data[1]; k = data[2]; d = data[3] # no of batches needed: batches1 = ceil(n / k) t1 = batches1 * t t2 = d baked = k while baked < n: baked += k t2 += t if baked >= n: break baked += k; t2 ...
0
911
A
Nearest Minimums
PROGRAMMING
1,100
[ "implementation" ]
null
null
You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
The first line contains positive integer *n* (2<=≤<=*n*<=≤<=105) — size of the given array. The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=109) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
Print the only number — distance between two nearest minimums in the array.
[ "2\n3 3\n", "3\n5 6 5\n", "9\n2 1 3 5 4 1 2 3 1\n" ]
[ "1\n", "2\n", "3\n" ]
none
0
[ { "input": "2\n3 3", "output": "1" }, { "input": "3\n5 6 5", "output": "2" }, { "input": "9\n2 1 3 5 4 1 2 3 1", "output": "3" }, { "input": "6\n4 6 7 8 6 4", "output": "5" }, { "input": "2\n1000000000 1000000000", "output": "1" }, { "input": "42\n1 1 ...
1,514,655,269
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,529,600
n = int(input()) a = list(map(int, input())) ans = 10000000000 for i in range(n - 1): for j in range(i + 1, n): if a[i] == min(a) and a[j] == min(a): ans = min(ans, j - i) print(ans)
Title: Nearest Minimums Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of *n* integer numbers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. I...
```python n = int(input()) a = list(map(int, input())) ans = 10000000000 for i in range(n - 1): for j in range(i + 1, n): if a[i] == min(a) and a[j] == min(a): ans = min(ans, j - i) print(ans) ```
-1
590
A
Median Smoothing
PROGRAMMING
1,700
[ "implementation" ]
null
null
A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya liked the idea of the method very much, and he decided to try it in practi...
The first input line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=500<=000) — the length of the initial sequence. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=0 or *a**i*<==<=1), giving the initial sequence itself.
If the sequence will never become stable, print a single number <=-<=1. Otherwise, first print a single integer — the minimum number of times one needs to apply the median smoothing algorithm to the initial sequence before it becomes is stable. In the second line print *n* numbers separated by a space  — the resulting...
[ "4\n0 0 1 1\n", "5\n0 1 0 1 0\n" ]
[ "0\n0 0 1 1\n", "2\n0 0 0 0 0\n" ]
In the second sample the stabilization occurs in two steps: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5a983e7baab048cbe43812cb997c15e9d7100231.png" style="max-width: 100.0%;max-height: 100.0%;"/>, and the sequence 00000 is obviously stable.
750
[ { "input": "4\n0 0 1 1", "output": "0\n0 0 1 1" }, { "input": "5\n0 1 0 1 0", "output": "2\n0 0 0 0 0" }, { "input": "3\n1 0 0", "output": "0\n1 0 0" }, { "input": "4\n1 0 0 1", "output": "0\n1 0 0 1" }, { "input": "7\n1 0 1 1 1 0 1", "output": "1\n1 1 1 1 1 1...
1,516,994,840
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
5,632,000
n=int(input());a=list(map(int,input().split()));b=[a[0]];k=0 for i in range(1,n-1): b.append(sorted(a[i-1:i+2])[1]) k=k+1 if b[i]!=a[i] else k b.append(a[-1]) print(k) print(''.join((str(x)+' ') for x in b))
Title: Median Smoothing Time Limit: None seconds Memory Limit: None megabytes Problem Description: A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in sci...
```python n=int(input());a=list(map(int,input().split()));b=[a[0]];k=0 for i in range(1,n-1): b.append(sorted(a[i-1:i+2])[1]) k=k+1 if b[i]!=a[i] else k b.append(a[-1]) print(k) print(''.join((str(x)+' ') for x in b)) ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,679,166,938
2,147,483,647
Python 3
OK
TESTS
40
46
0
a=input() c=0 p=0 x='hello' for i in range(len(a)): if x[c]==a[i]: c+=1 p+=1 if p==5: break if p==5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python a=input() c=0 p=0 x='hello' for i in range(len(a)): if x[c]==a[i]: c+=1 p+=1 if p==5: break if p==5: print("YES") else: print("NO") ```
3.977
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,526,453,170
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
93
8,089,600
c=0 a= ["Danil", "Olya", "Slava", "Ann" , "Nikita"] b=input() for i in range(len(a)): if a[i] in b: c+=1 if(c==1):print("YES") else : print("NO")
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 c=0 a= ["Danil", "Olya", "Slava", "Ann" , "Nikita"] b=input() for i in range(len(a)): if a[i] in b: c+=1 if(c==1):print("YES") else : print("NO") ```
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,567,632,310
2,147,483,647
Python 3
OK
TESTS
25
218
0
n,k = map(int,input().split()) l = sorted(list(map(int,input().split()))) s = 0 for i in range(n): if l[i]>0: l[i]=0 for i in range(k): s += (0-l[i]) print(s)
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can...
```python n,k = map(int,input().split()) l = sorted(list(map(int,input().split()))) s = 0 for i in range(n): if l[i]>0: l[i]=0 for i in range(k): s += (0-l[i]) print(s) ```
3.9455
928
C
Dependency management
PROGRAMMING
1,900
[ "*special", "graphs", "implementation" ]
null
null
Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simplicity. A project in Vaja has its own uniqie non-empty name consisting of lowercase latin letters with lengt...
The first line contains an only integer *n* (1<=≤<=*n*<=≤<=1<=000) — the number of projects in Vaja. The following lines contain the project descriptions. Each project is described by a line consisting of its name and version separated by space. The next line gives the number of direct dependencies (from 0 to *n*<=-<=...
Output all Polycarp's project's dependencies in lexicographical order.
[ "4\na 3\n2\nb 1\nc 1\n \nb 2\n0\n \nb 1\n1\nb 2\n \nc 1\n1\nb 2\n", "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n \ncommons 2\n0\n \nmashadb 3\n0\n \nwebfrmk 6\n2\nmashadb 3\ncommons 2\n \nextra 4\n1\nextra 3\n \nextra 3\n0\n \nextra 1\n0\n \nmashadb 1\n1\nextra 3\n \nmashadb 2\n1\nextra 1\n", "3\nabc ...
[ "2\nb 1\nc 1\n", "4\ncommons 2\nextra 1\nmashadb 2\nwebfrmk 6\n", "1\ncba 2\n" ]
The first sample is given in the pic below. Arrow from *A* to *B* means that *B* directly depends on *A*. Projects that Polycarp's project «a» (version 3) depends on are painted black. The second sample is again given in the pic below. Arrow from *A* to *B* means that *B* directly depends on *A*. Projects that Polycar...
2,000
[ { "input": "4\na 3\n2\nb 1\nc 1\n\nb 2\n0\n\nb 1\n1\nb 2\n\nc 1\n1\nb 2", "output": "2\nb 1\nc 1" }, { "input": "9\ncodehorses 5\n3\nwebfrmk 6\nmashadb 1\nmashadb 2\n\ncommons 2\n0\n\nmashadb 3\n0\n\nwebfrmk 6\n2\nmashadb 3\ncommons 2\n\nextra 4\n1\nextra 3\n\nextra 3\n0\n\nextra 1\n0\n\nmashadb 1\n...
1,519,503,209
16,709
Python 3
WRONG_ANSWER
PRETESTS
1
61
5,632,000
count = int(input()) graph={} def get_new_elem(): name, version = input().split() node = (name, int(version)) elem = [] for i in range(int(input())): name, version = input().split() elem.append((name, int(version))) return node, elem main, melem = get_new_elem() graph={} ...
Title: Dependency management Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is currently developing a project in Vaja language and using a popular dependency management system called Vamen. From Vamen's point of view both Vaja project and libraries are treated projects for simpli...
```python count = int(input()) graph={} def get_new_elem(): name, version = input().split() node = (name, int(version)) elem = [] for i in range(int(input())): name, version = input().split() elem.append((name, int(version))) return node, elem main, melem = get_new_elem() ...
0
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,688,910,246
2,147,483,647
PyPy 3-64
OK
TESTS
65
62
0
def clc(): m,s = map(int,input().split()) if s == 0: if m == 1: print("0","0") else: print("-1","-1") else: maxi,mini = [None]*m,[None]*m tep = s for i in range(0,m): k = min(9,s) maxi[i] = str(k) ...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python def clc(): m,s = map(int,input().split()) if s == 0: if m == 1: print("0","0") else: print("-1","-1") else: maxi,mini = [None]*m,[None]*m tep = s for i in range(0,m): k = min(9,s) maxi[i] = str(k)...
3
746
B
Decoding
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, inf...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word. The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding.
Print the word that Polycarp encoded.
[ "5\nlogva\n", "2\nno\n", "4\nabba\n" ]
[ "volga\n", "no\n", "baba\n" ]
In the first example Polycarp encoded the word volga. At first, he wrote down the letter l from the position 3, after that his word looked like voga. After that Polycarp wrote down the letter o from the position 2, his word became vga. Then Polycarp wrote down the letter g which was at the second position, the word bec...
1,000
[ { "input": "5\nlogva", "output": "volga" }, { "input": "2\nno", "output": "no" }, { "input": "4\nabba", "output": "baba" }, { "input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv" }, { "...
1,652,721,692
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
4,505,600
n = int(input()) encoded = input() mid = (n // 2) - 1 + (n % 2) decoded = [''] * n decoded[mid] = encoded[0] l = mid - 1 h = mid + 1 for i in range(1, n): if i % 2 != 0: decoded[l] = encoded[i] l -= 1 else: decoded[h] = encoded[i] h += 1 print(decoded)
Title: Decoding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the...
```python n = int(input()) encoded = input() mid = (n // 2) - 1 + (n % 2) decoded = [''] * n decoded[mid] = encoded[0] l = mid - 1 h = mid + 1 for i in range(1, n): if i % 2 != 0: decoded[l] = encoded[i] l -= 1 else: decoded[h] = encoded[i] h += 1 print(de...
0
9
C
Hexadecimal's Numbers
PROGRAMMING
1,200
[ "brute force", "implementation", "math" ]
C. Hexadecimal's Numbers
1
64
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for th...
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
Output the only number — answer to the problem.
[ "10\n" ]
[ "2" ]
For *n* = 10 the answer includes numbers 1 and 10.
0
[ { "input": "10", "output": "2" }, { "input": "20", "output": "3" }, { "input": "72", "output": "3" }, { "input": "99", "output": "3" }, { "input": "100", "output": "4" }, { "input": "101", "output": "5" }, { "input": "102", "output": "5...
1,596,414,774
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
156
6,860,800
x=input("saisir un entier ") tab=list(x) entry=int(x) aid=str() if entry==0 : print("0"); elif entry<=9 : print("2") for i in range(len(tab)) : tab[i]=int(tab[i]) if 1<tab[0]: x=(2**len(tab))-1 elif tab[0]==1: if 1<tab[1]: x=(2**len(tab))-1 else: x=(2**(len(ta...
Title: Hexadecimal's Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ...
```python x=input("saisir un entier ") tab=list(x) entry=int(x) aid=str() if entry==0 : print("0"); elif entry<=9 : print("2") for i in range(len(tab)) : tab[i]=int(tab[i]) if 1<tab[0]: x=(2**len(tab))-1 elif tab[0]==1: if 1<tab[1]: x=(2**len(tab))-1 else: x=(...
0
404
A
Valera and X
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the...
The first line contains integer *n* (3<=≤<=*n*<=&lt;<=300; *n* is odd). Each of the next *n* lines contains *n* small English letters — the description of Valera's paper.
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
[ "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox\n", "3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
500
[ { "input": "5\nxooox\noxoxo\nsoxoo\noxoxo\nxooox", "output": "NO" }, { "input": "3\nwsw\nsws\nwsw", "output": "YES" }, { "input": "3\nxpx\npxp\nxpe", "output": "NO" }, { "input": "5\nliiil\nilili\niilii\nilili\nliiil", "output": "YES" }, { "input": "7\nbwccccb\nck...
1,636,261,875
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
4,198,400
#Valera and X x= [] n = int(input()) for i in range(n): k = input().split() x.append(k) # print(x) if x[::2] == x[0]: print("YES") else: print("NO") # print(x[0],x[n-1],x[::2])
Title: Valera and X Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a...
```python #Valera and X x= [] n = int(input()) for i in range(n): k = input().split() x.append(k) # print(x) if x[::2] == x[0]: print("YES") else: print("NO") # print(x[0],x[n-1],x[::2]) ```
0
0
none
none
none
0
[ "none" ]
null
null
Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок,...
В первой строке входных данных следует целое положительное число *n* (3<=≤<=*n*<=≤<=1000) — количество оценок, полученных Васей. Во второй строке входных данных следует последовательность из *n* чисел *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вас...
Выведите одно целое число — количество подарков, полученных Васей.
[ "6\n4 5 4 5 4 4\n", "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5\n" ]
[ "2\n", "3\n" ]
В первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно.
0
[ { "input": "6\n4 5 4 5 4 4", "output": "2" }, { "input": "14\n1 5 4 5 2 4 4 5 5 4 3 4 5 5", "output": "3" }, { "input": "3\n4 5 4", "output": "1" }, { "input": "3\n4 5 1", "output": "0" }, { "input": "4\n5 4 3 5", "output": "0" }, { "input": "10\n4 4 5...
1,458,848,297
41,896
Python 3
RUNTIME_ERROR
PRETESTS
0
31
4,608,000
n = int(input()) a = map(int, input.split()) ans = 0 for i in range(n - 2): if (a[i] >= 4 and a[i + 1] >= 4 and a[i + 2] >= 4): ans += 1 i += 2 print(ans)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи ...
```python n = int(input()) a = map(int, input.split()) ans = 0 for i in range(n - 2): if (a[i] >= 4 and a[i + 1] >= 4 and a[i + 2] >= 4): ans += 1 i += 2 print(ans) ```
-1
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,696,499,146
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
#Nhập số và nhâp số lệnh (X++ or ++X) và in ra giá trị của X '''X=0 n = int(input()) l = list() for i in range(n): l.append(input()) if (l[i] == "X++" or l[i] == "++X"): X +=1 elif (l[i] == "--X" or l[i]=="X--"): X -= 1 print(X)''' # cho ma trận 5x5, cho phân tử ở giữa làm chu...
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 #Nhập số và nhâp số lệnh (X++ or ++X) và in ra giá trị của X '''X=0 n = int(input()) l = list() for i in range(n): l.append(input()) if (l[i] == "X++" or l[i] == "++X"): X +=1 elif (l[i] == "--X" or l[i]=="X--"): X -= 1 print(X)''' # cho ma trận 5x5, cho phân tử ở gi...
0
645
F
Cowslip Collections
PROGRAMMING
2,500
[ "combinatorics", "math", "number theory" ]
null
null
In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, each garden they plant must have the exact same arrangement of flowers. Initially, Farmer John has *n* diffe...
The first line of the input contains three integers *n*, *k* and *q* (1<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*q*<=≤<=100<=000). The *i*-th (1<=≤<=*i*<=≤<=*n*) of the next *n* lines of the input contains an integer *a**i* (1<=≤<=*a**i*<=≤<=1<=000<=000), the number of flowers of species *i* Farmer John has initially. Th...
After each of the *q* days, output the sum of the maximum possible number of gardens, where the sum is taken over all possible choices of *k* species, modulo 109<=+<=7.
[ "3 3 2\n4\n6\n9\n8\n6\n", "4 1 2\n6\n5\n4\n3\n2\n1\n" ]
[ "5\n16\n", "20\n21\n" ]
In the first sample case, after the first day Farmer John has (4, 6, 9, 8) of each type of flower, and *k* = 3. Choosing (4, 6, 8) lets him make 2 gardens, each with (2, 3, 4) of each flower, respectively. Choosing (4, 6, 9), (4, 9, 8) and (6, 9, 8) each only let him make one garden, since there is no number of garden...
3,000
[ { "input": "3 3 2\n4\n6\n9\n8\n6", "output": "5\n16" }, { "input": "4 1 2\n6\n5\n4\n3\n2\n1", "output": "20\n21" }, { "input": "3 3 3\n6\n8\n10\n12\n14\n16", "output": "8\n20\n42" }, { "input": "1 1 1\n1\n1", "output": "2" }, { "input": "10 10 10\n10\n10\n10\n10\n...
1,689,646,144
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689646144.3984745")# 1689646144.3984945
Title: Cowslip Collections Time Limit: None seconds Memory Limit: None megabytes Problem Description: In an attempt to make peace with the Mischievious Mess Makers, Bessie and Farmer John are planning to plant some flower gardens to complement the lush, grassy fields of Bovinia. As any good horticulturist knows, eac...
```python print("_RANDOM_GUESS_1689646144.3984745")# 1689646144.3984945 ```
0
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr...
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi...
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a sin...
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.###...
1,485,481,040
2,147,483,647
Python 3
OK
TESTS
83
77
4,608,000
#!/usr/bin/env python3 # ------------------------------ # cs104c/assignment1/Grasshopper.py # Copyright (C) 2017 # Drew Romanyk # ------------------------------ # ------- # imports # ------- import sys # ------- # two_button_solve # ------- def grasshopper_solve(r, w): """ :param r: reader :param w: w...
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles....
```python #!/usr/bin/env python3 # ------------------------------ # cs104c/assignment1/Grasshopper.py # Copyright (C) 2017 # Drew Romanyk # ------------------------------ # ------- # imports # ------- import sys # ------- # two_button_solve # ------- def grasshopper_solve(r, w): """ :param r: reader :...
3
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,698,659,202
2,147,483,647
Python 3
OK
TESTS
25
92
0
s=input() res = s[0].upper() + s[1:] print(res)
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python s=input() res = s[0].upper() + s[1:] print(res) ```
3
485
A
Factory
PROGRAMMING
1,400
[ "implementation", "math", "matrices" ]
null
null
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu...
The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105).
Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".
[ "1 5\n", "3 6\n" ]
[ "No\n", "Yes\n" ]
none
1,000
[ { "input": "1 5", "output": "No" }, { "input": "3 6", "output": "Yes" }, { "input": "1 8", "output": "Yes" }, { "input": "2 3", "output": "No" }, { "input": "3 24", "output": "Yes" }, { "input": "1 1", "output": "Yes" }, { "input": "100000 ...
1,634,650,185
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
1,843,200
import sys from math import log2, ceil, floor inpu = sys.stdin.readline prin = sys.stdout.write def solve(a, m) : if m > a : x = log2(m) - log2(a) if ceil(x) == floor(x) : prin("Yes\n") return a *= pow(2, ceil(x)) val1 = a%m if val1 == 0: ...
Title: Factory Time Limit: None seconds Memory Limit: None megabytes Problem Description: One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac...
```python import sys from math import log2, ceil, floor inpu = sys.stdin.readline prin = sys.stdout.write def solve(a, m) : if m > a : x = log2(m) - log2(a) if ceil(x) == floor(x) : prin("Yes\n") return a *= pow(2, ceil(x)) val1 = a%m if val1 == 0:...
0
515
A
Drazil and Date
PROGRAMMING
1,000
[ "math" ]
null
null
Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (*x*,<=*y*) he can go to ...
You are given three integers *a*, *b*, and *s* (<=-<=109<=≤<=*a*,<=*b*<=≤<=109, 1<=≤<=*s*<=≤<=2·109) in a single line.
If you think Drazil made a mistake and it is impossible to take exactly *s* steps and get from his home to Varda's home, print "No" (without quotes). Otherwise, print "Yes".
[ "5 5 11\n", "10 15 25\n", "0 5 1\n", "0 0 2\n" ]
[ "No\n", "Yes\n", "No\n", "Yes\n" ]
In fourth sample case one possible route is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/0d30660ddf6eb6c64ffd071055a4e8ddd016cde5.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "5 5 11", "output": "No" }, { "input": "10 15 25", "output": "Yes" }, { "input": "0 5 1", "output": "No" }, { "input": "0 0 2", "output": "Yes" }, { "input": "999999999 999999999 2000000000", "output": "Yes" }, { "input": "-606037695 9983201...
1,585,813,943
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
109
0
I=lambda:list(map(int,input().split())) x,y,s=map(int,input().split()) if x+y<s: print('No') elif x+y==s: print('Yes') else: if (x+y)%2: print('No') else: print('Yes')
Title: Drazil and Date Time Limit: None seconds Memory Limit: None megabytes Problem Description: Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0,<=0) and Varda's home is located in point (*a*,<=*b*). In each step, he can move in a unit ...
```python I=lambda:list(map(int,input().split())) x,y,s=map(int,input().split()) if x+y<s: print('No') elif x+y==s: print('Yes') else: if (x+y)%2: print('No') else: print('Yes') ```
0
621
B
Wet Shark and Bishops
PROGRAMMING
1,300
[ "combinatorics", "implementation" ]
null
null
Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each other if they share the same diagonal. Note, that this is the o...
The first line of the input contains *n* (1<=≤<=*n*<=≤<=200<=000) — the number of bishops. Each of next *n* lines contains two space separated integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the number of row and the number of column where *i*-th bishop is positioned. It's guaranteed that no two bishops ...
Output one integer — the number of pairs of bishops which attack each other.
[ "5\n1 1\n1 5\n3 3\n5 1\n5 5\n", "3\n1 1\n2 3\n3 5\n" ]
[ "6\n", "0\n" ]
In the first sample following pairs of bishops attack each other: (1, 3), (1, 5), (2, 3), (2, 4), (3, 4) and (3, 5). Pairs (1, 2), (1, 4), (2, 5) and (4, 5) do not attack each other because they do not share the same diagonal.
1,000
[ { "input": "5\n1 1\n1 5\n3 3\n5 1\n5 5", "output": "6" }, { "input": "3\n1 1\n2 3\n3 5", "output": "0" }, { "input": "3\n859 96\n634 248\n808 72", "output": "0" }, { "input": "3\n987 237\n891 429\n358 145", "output": "0" }, { "input": "3\n411 81\n149 907\n611 114"...
1,694,341,315
2,147,483,647
PyPy 3-64
OK
TESTS
68
1,201
10,752,000
n = int(input()) # Number of bishops left_diagonal = {} # Dictionary to store bishops in the left diagonal (sum of row and column) right_diagonal = {} # Dictionary to store bishops in the right diagonal (difference of row and column) count = 0 # Initialize the count of attacking pairs for _ in range(n): ...
Title: Wet Shark and Bishops Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. We...
```python n = int(input()) # Number of bishops left_diagonal = {} # Dictionary to store bishops in the left diagonal (sum of row and column) right_diagonal = {} # Dictionary to store bishops in the right diagonal (difference of row and column) count = 0 # Initialize the count of attacking pairs for _ in range...
3
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old ...
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "i...
1,504,538,313
2,613
Python 3
OK
TESTS
46
77
0
from sys import exit from math import * ax, ay, bx, by, cx, cy = map(int, input().split()) l1 = (bx - ax)**2 + (by - ay)**2 l2 = (cx - bx)**2 + (cy - by)**2 dx = bx - ax dy = by - ay if l1 != l2: print('No') elif cx == bx + dx and cy == by + dy: print('No') else: print('Yes')
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle...
```python from sys import exit from math import * ax, ay, bx, by, cx, cy = map(int, input().split()) l1 = (bx - ax)**2 + (by - ay)**2 l2 = (cx - bx)**2 + (cy - by)**2 dx = bx - ax dy = by - ay if l1 != l2: print('No') elif cx == bx + dx and cy == by + dy: print('No') else: print('Yes') `...
3
14
A
Letter
PROGRAMMING
800
[ "implementation" ]
A. Letter
1
64
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w...
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ...
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
[ "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n", "3 3\n***\n*.*\n***\n" ]
[ "***\n*..\n***\n*..\n***\n", "***\n*.*\n***\n" ]
none
0
[ { "input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "output": "***\n*..\n***\n*..\n***" }, { "input": "3 3\n***\n*.*\n***", "output": "***\n*.*\n***" }, { "input": "1 1\n*", "output": "*" }, { "input": "2 1\n*\n*", "output": "*\n*" }, { "input"...
1,639,646,202
2,147,483,647
Python 3
OK
TESTS
30
92
0
n,m=[int(x) for x in input().split()] a,hmin,hmax,lmin,lmax=[],51,-1,51,-1 for i in range(n): s=input() a.append(s) if s.count('*')>0: hmin=min(i,hmin) hmax=max(i,hmax) for j in range(m): if s[j]=='*': lmin=min(j,lmin) lmax=max(j,lmax) for i in range(hmin,hma...
Title: Letter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe...
```python n,m=[int(x) for x in input().split()] a,hmin,hmax,lmin,lmax=[],51,-1,51,-1 for i in range(n): s=input() a.append(s) if s.count('*')>0: hmin=min(i,hmin) hmax=max(i,hmax) for j in range(m): if s[j]=='*': lmin=min(j,lmin) lmax=max(j,lmax) for i in rang...
3.954
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100). The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels...
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output":...
1,697,995,319
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=a+b c=set(c) if c*(c+1)//2==n*(n+1)//2: print("I become the guy.") else: print("Oh, my keyboard!" )
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the g...
```python n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=a+b c=set(c) if c*(c+1)//2==n*(n+1)//2: print("I become the guy.") else: print("Oh, my keyboard!" ) ```
-1
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,687,767,589
2,147,483,647
PyPy 3-64
OK
TESTS
101
124
0
def main() : print_Array(gived_Friend_Nums(input_Taked_Friend_Nums())) def gived_Friend_Nums(taked_friend_nums) : gived_friend_nums = [0] * len(taked_friend_nums) for friend_index in range(len(taked_friend_nums)) : gived_friend_nums[taked_friend_nums[friend_index] - 1] = friend_index + 1 return gi...
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python def main() : print_Array(gived_Friend_Nums(input_Taked_Friend_Nums())) def gived_Friend_Nums(taked_friend_nums) : gived_friend_nums = [0] * len(taked_friend_nums) for friend_index in range(len(taked_friend_nums)) : gived_friend_nums[taked_friend_nums[friend_index] - 1] = friend_index + 1 ...
3
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,567,748,198
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
0
n,d=map(int,input().split()) a=list(map(int,input().split())) s=sum(a)+(n-1)*10 if(s>d): print(-1) elif(s==d): print((n-1)*2) else: i=int(1) while(1): s=s+5 if(s==d): print((n-1)*2+i) break
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python n,d=map(int,input().split()) a=list(map(int,input().split())) s=sum(a)+(n-1)*10 if(s>d): print(-1) elif(s==d): print((n-1)*2) else: i=int(1) while(1): s=s+5 if(s==d): print((n-1)*2+i) break ```
0
361
B
Levko and Permutation
PROGRAMMING
1,200
[ "constructive algorithms", "math", "number theory" ]
null
null
Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numbers *a* and *b*. Levko assumes that element *p**i* of permutation *p*1,<=*p*2,<=... ,<=*p**n* is good if *g...
The single line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=*n*).
In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist. If there are multiple suitable permutations, you are allowed to print any of them.
[ "4 2\n", "1 1\n" ]
[ "2 4 3 1", "-1\n" ]
In the first sample elements 4 and 3 are good because *gcd*(2, 4) = 2 &gt; 1 and *gcd*(3, 3) = 3 &gt; 1. Elements 2 and 1 are not good because *gcd*(1, 2) = 1 and *gcd*(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful. The second sample has no beautiful permutations.
1,000
[ { "input": "4 2", "output": "2 1 3 4 " }, { "input": "1 1", "output": "-1" }, { "input": "7 4", "output": "3 1 2 4 5 6 7 " }, { "input": "10 9", "output": "1 2 3 4 5 6 7 8 9 10 " }, { "input": "10000 5000", "output": "5000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1...
1,601,419,173
2,147,483,647
Python 3
OK
TESTS
47
218
3,174,400
n, k = map(int, input().split()) res = [] if(n < k + 1): print(-1) else: for i in range(2, n - k + 1): res.append(i) res.append(1) for i in range(n - k + 1, n + 1): res.append(i) print(*res)
Title: Levko and Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves permutations very much. A permutation of length *n* is a sequence of distinct positive integers, each is at most *n*. Let’s assume that value *gcd*(*a*,<=*b*) shows the greatest common divisor of numb...
```python n, k = map(int, input().split()) res = [] if(n < k + 1): print(-1) else: for i in range(2, n - k + 1): res.append(i) res.append(1) for i in range(n - k + 1, n + 1): res.append(i) print(*res) ```
3
962
C
Make a Square
PROGRAMMING
1,400
[ "brute force", "implementation", "math" ]
null
null
You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive integer without leading zeros. Determine the minimum number of operations that you need to consistently ...
The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^{9}$). The number is given without leading zeroes.
If it is impossible to make the square of some positive integer from $n$, print -1. In the other case, print the minimal number of operations required to do it.
[ "8314\n", "625\n", "333\n" ]
[ "2\n", "0\n", "-1\n" ]
In the first example we should delete from $8314$ the digits $3$ and $4$. After that $8314$ become equals to $81$, which is the square of the integer $9$. In the second example the given $625$ is the square of the integer $25$, so you should not delete anything. In the third example it is impossible to make the squa...
0
[ { "input": "8314", "output": "2" }, { "input": "625", "output": "0" }, { "input": "333", "output": "-1" }, { "input": "1881388645", "output": "6" }, { "input": "1059472069", "output": "3" }, { "input": "1354124829", "output": "4" }, { "inpu...
1,598,588,419
3,739
PyPy 3
OK
TESTS
70
171
3,584,000
lis=[i*i for i in range(1,50000)] b = input() n=len(b) ans=10000000000 flag=0 for _ in lis: a = str(_) i=j=0 while i<n and j<len(a): if b[i]==a[j]: i+=1 j+=1 else: i+=1 if j==len(a): ans=min(ans,n-len(a)) flag=1 if flag...
Title: Make a Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a positive integer $n$, written without leading zeroes (for example, the number 04 is incorrect). In one operation you can delete any digit of the given integer so that the result remains a positive intege...
```python lis=[i*i for i in range(1,50000)] b = input() n=len(b) ans=10000000000 flag=0 for _ in lis: a = str(_) i=j=0 while i<n and j<len(a): if b[i]==a[j]: i+=1 j+=1 else: i+=1 if j==len(a): ans=min(ans,n-len(a)) flag=...
3
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, ...
1,528,729,679
5,579
Python 3
RUNTIME_ERROR
PRETESTS
0
77
0
np=list(map(int,input().split())) n=np[0] p=np[1] s=list(input()) counter=0 for i in range(n-p): if(s[i]==s[i+p]): if(s[i]=='.'): s[i]='0' s[i+p]='1' counter+=1 else: if(s[i]=='.')and(s[i+p]=='0'): s[i]='1' counter+=1 ...
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti...
```python np=list(map(int,input().split())) n=np[0] p=np[1] s=list(input()) counter=0 for i in range(n-p): if(s[i]==s[i+p]): if(s[i]=='.'): s[i]='0' s[i+p]='1' counter+=1 else: if(s[i]=='.')and(s[i+p]=='0'): s[i]='1' count...
-1
900
A
Find Extra One
PROGRAMMING
800
[ "geometry", "implementation" ]
null
null
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
[ "3\n1 1\n-1 -1\n2 -1\n", "4\n1 1\n2 2\n-1 1\n-2 2\n", "3\n1 2\n2 1\n4 60\n" ]
[ "Yes", "No", "Yes" ]
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
500
[ { "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes" }, { "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No" }, { "input": "3\n1 2\n2 1\n4 60", "output": "Yes" }, { "input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1", "output": "Yes" }, { "input": "2\n1...
1,563,715,005
2,147,483,647
Python 3
OK
TESTS
71
342
3,174,400
n = int(input()) l = len(list(filter(lambda x:x<0,[(lambda x: x[0])(list(map(int,input().split()))) for i in range(n)]))) print(['No','Yes'][min(l,n-l)<2])
Title: Find Extra One Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. Input Specification: The first li...
```python n = int(input()) l = len(list(filter(lambda x:x<0,[(lambda x: x[0])(list(map(int,input().split()))) for i in range(n)]))) print(['No','Yes'][min(l,n-l)<2]) ```
3
418
E
Tricky Password
PROGRAMMING
3,100
[ "data structures" ]
null
null
In order to ensure confidentiality, the access to the "Russian Code Cup" problems is password protected during the problem development process. To select a password, the jury can generate a special table that contains *n* columns and the infinite number of rows. To construct a table, the first row is fixed, and all th...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of columns. The second line contains the description of the first row of the table, that is, *n* integers, which are not less than 1 and do not exceed 109. The third line of the input contains an integer *m* (1<=≤<=*m*<=≤<=100000) — the number ...
Print an answer for each request of the second type in the order you receive them.
[ "6\n1 2 2 2 3 1\n3\n2 2 3\n1 3 3\n2 3 4\n" ]
[ "2\n1\n" ]
none
2,500
[]
1,692,704,362
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
# LUOGU_RID: 122278025 n = int(input()) first_row = list(map(int, input().split())) prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + first_row[i - 1] m = int(input()) for _ in range(m): query = list(map(int, input().split())) if query[0] == 1: v, p = q...
Title: Tricky Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: In order to ensure confidentiality, the access to the "Russian Code Cup" problems is password protected during the problem development process. To select a password, the jury can generate a special table that contains ...
```python # LUOGU_RID: 122278025 n = int(input()) first_row = list(map(int, input().split())) prefix_sum = [0] * (n + 1) for i in range(1, n + 1): prefix_sum[i] = prefix_sum[i - 1] + first_row[i - 1] m = int(input()) for _ in range(m): query = list(map(int, input().split())) if query[0] == 1: ...
0
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,692,361,113
2,147,483,647
Python 3
OK
TESTS
80
528
0
grid_size = int(input()) heights = input().split() heights = list(map(int, heights)) max = 0 for index in range(grid_size): temp = 0 left = index - 1 right = index + 1 while(left >= 0 and heights[left] <= heights[left+1]): temp += 1 left -= 1 while(right <grid_size a...
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 grid_size = int(input()) heights = input().split() heights = list(map(int, heights)) max = 0 for index in range(grid_size): temp = 0 left = index - 1 right = index + 1 while(left >= 0 and heights[left] <= heights[left+1]): temp += 1 left -= 1 while(right <g...
3.868
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" },...
1,699,008,709
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n=input() if len(n)%2==1:print("IGNORE HIM!") else:print("CHAT WITH HER!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though...
```python n=input() if len(n)%2==1:print("IGNORE HIM!") else:print("CHAT WITH HER!") ```
0
935
B
Fafa and the Gates
PROGRAMMING
900
[ "implementation" ]
null
null
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (...
The first line of the input contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of moves in the walking sequence. The second line contains a string *S* of length *n* consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence *S* in order from left to right.
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence *S*.
[ "1\nU\n", "6\nRURUUR\n", "7\nURRRUUU\n" ]
[ "0\n", "1\n", "2\n" ]
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
750
[ { "input": "1\nU", "output": "0" }, { "input": "6\nRURUUR", "output": "1" }, { "input": "7\nURRRUUU", "output": "2" }, { "input": "100\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR", "output": "3" }, { "input...
1,642,598,523
2,147,483,647
PyPy 3
OK
TESTS
24
108
2,048,000
n=int(input()) s=input() u,r,c=0,0,0 for i in range(len(s)-1): if s[i]=="U": u+=1 else: r+=1 if u==r and s[i]==s[i+1]: c+=1 print(c)
Title: Fafa and the Gates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The w...
```python n=int(input()) s=input() u,r,c=0,0,0 for i in range(len(s)-1): if s[i]=="U": u+=1 else: r+=1 if u==r and s[i]==s[i+1]: c+=1 print(c) ```
3
958
C1
Encryption (easy)
PROGRAMMING
1,200
[ "brute force" ]
null
null
Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo...
The first line of the input contains two space-separated integer *N* and *p* (2<=≤<=*N*<=≤<=100<=000, 2<=≤<=*p*<=≤<=10<=000) – the number of elements in *A*, and the modulo for computing scores, respectively. The second line contains *N* space-separated integers which are the elements of *A*. Each integer is from the ...
Output the number *S* as described in the problem statement.
[ "4 10\n3 4 7 2\n", "10 12\n16 3 24 13 9 8 7 5 12 12\n" ]
[ "16\n", "13\n" ]
In the first example, the score is maximized if the input sequence is split into two parts as (3, 4), (7, 2). It gives the total score of <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/fc1f9aecea625f3be9a56917d3ba448d669ff278.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the se...
0
[ { "input": "4 10\n3 4 7 2", "output": "16" }, { "input": "10 12\n16 3 24 13 9 8 7 5 12 12", "output": "13" }, { "input": "2 2\n9 9", "output": "2" }, { "input": "2 2\n8 8", "output": "0" }, { "input": "5 50\n1 1 1 1 1", "output": "5" }, { "input": "5 5...
1,596,145,414
2,147,483,647
PyPy 3
OK
TESTS
27
202
30,617,600
n , p = map(int , input().split()) data = list(map(int , input().split())) total = sum(data) cur = data[0] m = (cur % p) + (total - cur)%p for i in range(1,n-1): cur += data[i] m = max(m , (cur % p) + (total - cur)%p) print(m)
Title: Encryption (easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, ...
```python n , p = map(int , input().split()) data = list(map(int , input().split())) total = sum(data) cur = data[0] m = (cur % p) + (total - cur)%p for i in range(1,n-1): cur += data[i] m = max(m , (cur % p) + (total - cur)%p) print(m) ```
3
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million...
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "N...
1,594,460,984
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
248
20,172,800
n = int ( input ()) m = int ( input ()) c = 0 for i in range ( 1 , 31 ): if ( m == ( n ** i )): print ( "YES" ) print ( i - 1 ) break else : c = c + 1 if ( c > 0 ): print ( "NO" )
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa...
```python n = int ( input ()) m = int ( input ()) c = 0 for i in range ( 1 , 31 ): if ( m == ( n ** i )): print ( "YES" ) print ( i - 1 ) break else : c = c + 1 if ( c > 0 ): print ( "NO" ) ```
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,512,573,172
2,147,483,647
Python 3
OK
TESTS
102
77
5,529,600
a = list(input()) b = list(input()) n = len(a) c = [] for i in range(n): if a[i] == b[i]: c.append(0) else: c.append(1) for i in range(n): print(c[i],end = '')
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a = list(input()) b = list(input()) n = len(a) c = [] for i in range(n): if a[i] == b[i]: c.append(0) else: c.append(1) for i in range(n): print(c[i],end = '') ```
3.97045
32
A
Reconnaissance
PROGRAMMING
800
[ "brute force" ]
A. Reconnaissance
2
256
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som...
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1...
Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*.
[ "5 10\n10 20 50 60 65\n", "5 1\n55 30 29 31 55\n" ]
[ "6\n", "6\n" ]
none
500
[ { "input": "5 10\n10 20 50 60 65", "output": "6" }, { "input": "5 1\n55 30 29 31 55", "output": "6" }, { "input": "6 10\n4 6 4 1 9 3", "output": "30" }, { "input": "7 100\n19 1694 261 162 1 234 513", "output": "8" }, { "input": "8 42\n37 53 74 187 568 22 5 65", ...
1,579,637,699
2,147,483,647
Python 3
OK
TESTS
32
1,276
307,200
n,d = map(int,input().split()) lst = list(map(int,input().split())) count = 0 for i in range(n): for j in range(n): if i == j: continue else: if abs(lst[i] - lst[j]) <= d: count += 1 print(count)
Title: Reconnaissance Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h...
```python n,d = map(int,input().split()) lst = list(map(int,input().split())) count = 0 for i in range(n): for j in range(n): if i == j: continue else: if abs(lst[i] - lst[j]) <= d: count += 1 print(count) ```
3.680428
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,697,559,397
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
9
2,000
11,059,200
s = input() mapping = [] last = s[0] ald_found = {} for i in s[1:]: mapping.append(1 if last == i else 0) last = i mapping.append(1) # print(mapping) for _ in range(int(input())): l, r = map(int, input().split()) if ald_found.get((l, r)): print(ald_found[(l, r)]) else: ...
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = input() mapping = [] last = s[0] ald_found = {} for i in s[1:]: mapping.append(1 if last == i else 0) last = i mapping.append(1) # print(mapping) for _ in range(int(input())): l, r = map(int, input().split()) if ald_found.get((l, r)): print(ald_found[(l, r)]) els...
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,682,370,950
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
46
0
from math import floor a, b = (int(c) for c in input().strip().split()) if (floor((a*b)**0.5))%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 from math import floor a, b = (int(c) for c in input().strip().split()) if (floor((a*b)**0.5))%2==0: print("Malvika") else: print("Akshat") ```
0
385
B
Bear and Strings
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation", "math", "strings" ]
null
null
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string...
The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters.
Print a single number — the answer to the problem.
[ "bearbtear\n", "bearaabearc\n" ]
[ "6\n", "20\n" ]
In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9). In the second sample, the following pairs (*i*, *j*) match: (1,  4), (1,  5), (1,  6), (1,  7), (1,  8), (1,  9), (1,  10), (1,  11), (2,  10), (2,  11), (3,  10), (3,  11), (4,  10), (4,  11), (5,  10), (5,  11)...
1,000
[ { "input": "bearbtear", "output": "6" }, { "input": "bearaabearc", "output": "20" }, { "input": "pbearbearhbearzqbearjkterasjhy", "output": "291" }, { "input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb", "output"...
1,651,381,152
2,147,483,647
Python 3
OK
TESTS
43
46
0
import sys s = sys.stdin.readline().strip() b = 'bear' places = [] for i in range(len(s)-len(b)+1): if s[i] == b[0] and s[i+1] == b[1] and s[i+2] == b[2] and s[i+3] == b[3]: places.append(i) tot = 0 last = 0 for start in places: tot += (start - last + 1) * (len(s) - (start + 4) + 1) last = start +...
Title: Bear and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j...
```python import sys s = sys.stdin.readline().strip() b = 'bear' places = [] for i in range(len(s)-len(b)+1): if s[i] == b[0] and s[i+1] == b[1] and s[i+2] == b[2] and s[i+3] == b[3]: places.append(i) tot = 0 last = 0 for start in places: tot += (start - last + 1) * (len(s) - (start + 4) + 1) last...
3
712
C
Memory and De-Evolution
PROGRAMMING
1,600
[ "greedy", "math" ]
null
null
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*. In a single second, he can modify the length of a single side of the current triangle suc...
The first and only line contains two integers *x* and *y* (3<=≤<=*y*<=&lt;<=*x*<=≤<=100<=000) — the starting and ending equilateral triangle side lengths respectively.
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*.
[ "6 3\n", "8 5\n", "22 4\n" ]
[ "4\n", "3\n", "6\n" ]
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21...
1,500
[ { "input": "6 3", "output": "4" }, { "input": "8 5", "output": "3" }, { "input": "22 4", "output": "6" }, { "input": "4 3", "output": "3" }, { "input": "57 27", "output": "4" }, { "input": "61 3", "output": "9" }, { "input": "5 4", "out...
1,473,590,884
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
93
0
x = int(input()) y = int(input()) x_v = [y]*3 sum = 0 result = 0 while (x_v[0] != x) or (x != x_v[1] ) or (x != x_v[2]): x_v.sort() x_v[0] = min(x, x_v[1] + x_v[2] - 1) result += 1 print(x_v) print(result)
Title: Memory and De-Evolution Time Limit: None seconds Memory Limit: None megabytes Problem Description: Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle o...
```python x = int(input()) y = int(input()) x_v = [y]*3 sum = 0 result = 0 while (x_v[0] != x) or (x != x_v[1] ) or (x != x_v[2]): x_v.sort() x_v[0] = min(x, x_v[1] + x_v[2] - 1) result += 1 print(x_v) print(result) ```
-1
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,688,648,311
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
def count_damaged_vampires(k, l, m, n, d): damaged_vampires = 0 for vampire in range(1, d + 1): if vampire % k == 0 or vampire % l == 0 or vampire % m == 0 or vampire % n == 0: damaged_vampires += 1 return damaged_vampires k = int(input("every vampire getting getting punched")) ...
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python def count_damaged_vampires(k, l, m, n, d): damaged_vampires = 0 for vampire in range(1, d + 1): if vampire % k == 0 or vampire % l == 0 or vampire % m == 0 or vampire % n == 0: damaged_vampires += 1 return damaged_vampires k = int(input("every vampire getting getting punc...
0
245
E
Mishap in Club
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ...
The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive.
Print the sought minimum number of people
[ "+-+-+\n", "---" ]
[ "1\n", "3" ]
none
0
[ { "input": "+-+-+", "output": "1" }, { "input": "---", "output": "3" }, { "input": "-", "output": "1" }, { "input": "--", "output": "2" }, { "input": "---", "output": "3" }, { "input": "----", "output": "4" }, { "input": "---+", "output...
1,581,185,482
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
280
0
s=input() c=0 c2=0 for i in range(len(s)): if(s[i]=="-"): c+=1 elif(s[i]=="+"): for j in range(i,len(s)-1): if(s[j]=="-"): c2=1 break if(c2==0): c+=1 if(s[len(s)-1]=="+"): print(c-1) el...
Title: Mishap in Club Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitor...
```python s=input() c=0 c2=0 for i in range(len(s)): if(s[i]=="-"): c+=1 elif(s[i]=="+"): for j in range(i,len(s)-1): if(s[j]=="-"): c2=1 break if(c2==0): c+=1 if(s[len(s)-1]=="+"): prin...
0
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,547,539,573
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
216
0
dic={} ans="" answer=-10000 for _ in range(int(input())): name,score=input().split() score=int(score) dic[name]=dic.get(name,0)+score if(dic[name]>answer): ans=name answer=dic[name] print(ans)
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python dic={} ans="" answer=-10000 for _ in range(int(input())): name,score=input().split() score=int(score) dic[name]=dic.get(name,0)+score if(dic[name]>answer): ans=name answer=dic[name] print(ans) ```
0
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,621,287,989
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
j=int(input()) l=list(map(int,input().split(" "))) pos=0 v=0 for i in range(j-1): if l[i]>l[i+1]: pos=i v+=1 if a[j-1]>a[0]: v+=1 if v==0: print(0) else: if v>1: print(-1) else: print(j-1-v)
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 j=int(input()) l=list(map(int,input().split(" "))) pos=0 v=0 for i in range(j-1): if l[i]>l[i+1]: pos=i v+=1 if a[j-1]>a[0]: v+=1 if v==0: print(0) else: if v>1: print(-1) else: print(j-1-v) ```
-1
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX"...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, ...
1,618,500,592
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
n = int(input()) h = input() for i in range(n-1): z= input() l = input().split("->") if(l[1] == h): print("home") else: print("contest")
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei...
```python n = int(input()) h = input() for i in range(n-1): z= input() l = input().split("->") if(l[1] == h): print("home") else: print("contest") ```
0
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b...
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer — minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "...
1,661,939,298
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
77
0
r,x,y,a,b = list(map(int, input().split())) print((abs(a-x)+abs(b-y))//(2*r))
Title: Amr and Pins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can ...
```python r,x,y,a,b = list(map(int, input().split())) print((abs(a-x)+abs(b-y))//(2*r)) ```
0
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,677,095,543
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
m,n=map(int,input().split()) def max (m,n): if not 1<=n<=m*9: return -1 return ('9'*(n//9)+str(n%9)).ljust(m,'0') def min (m,n): if not 1<=n<=m*9: return -1 if n//9>=(m-1): return max(m,n)[::-1] return (('9'*(n//9)+str((n%9)-1)).ljust(m-1,'0')+'1')[::-1] if n%9!...
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python m,n=map(int,input().split()) def max (m,n): if not 1<=n<=m*9: return -1 return ('9'*(n//9)+str(n%9)).ljust(m,'0') def min (m,n): if not 1<=n<=m*9: return -1 if n//9>=(m-1): return max(m,n)[::-1] return (('9'*(n//9)+str((n%9)-1)).ljust(m-1,'0')+'1')[::-...
0
555
A
Case of Matryoshkas
PROGRAMMING
1,500
[ "implementation" ]
null
null
Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested one into another. The matryoshka dolls are numbered from 1 to *n*. A matryoshka with a smaller number can...
The first line contains integers *n* (1<=≤<=*n*<=≤<=105) and *k* (1<=≤<=*k*<=≤<=105) — the number of matryoshkas and matryoshka chains in the initial configuration. The next *k* lines contain the descriptions of the chains: the *i*-th line first contains number *m**i* (1<=≤<=*m**i*<=≤<=*n*), and then *m**i* numbers *a...
In the single line print the minimum number of seconds needed to assemble one large chain from the initial configuration.
[ "3 2\n2 1 2\n1 3\n", "7 3\n3 1 3 7\n2 2 5\n2 4 6\n" ]
[ "1\n", "10\n" ]
In the first sample test there are two chains: 1 → 2 and 3. In one second you can nest the first chain into the second one and get 1 → 2 → 3. In the second sample test you need to disassemble all the three chains into individual matryoshkas in 2 + 1 + 1 = 4 seconds and then assemble one big chain in 6 seconds.
250
[ { "input": "3 2\n2 1 2\n1 3", "output": "1" }, { "input": "7 3\n3 1 3 7\n2 2 5\n2 4 6", "output": "10" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "3 2\n1 2\n2 1 3", "output": "3" }, { "input": "5 3\n1 4\n3 1 2 3\n1 5", "output": "2" }, { "in...
1,609,499,198
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
140
0
n, k = map(int, input().split()) l = 1 for i in range(k): a = [int(i) for i in input().split()] if a[-1] == a[0]: l = a[0] print(2 * n - k - 2 * l + 1)
Title: Case of Matryoshkas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. He is now investigating the case of vandalism at the exhibition of contemporary art. The main exhibit is a construction of *n* matryoshka dolls that can be nested ...
```python n, k = map(int, input().split()) l = 1 for i in range(k): a = [int(i) for i in input().split()] if a[-1] == a[0]: l = a[0] print(2 * n - k - 2 * l + 1) ```
0
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "...
1,693,980,795
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
l = input() i = 0 a = [] while i < len(l) - 1: if l[i] + l[i + 1] == 'BA' or l[i] + l[i + 1] == 'AB': a.append(l[i] + l[i + 1]) i += 1 i += 1 if set(a) == {'AB', 'BA'}: print("YES") else: print("NO")
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contain...
```python l = input() i = 0 a = [] while i < len(l) - 1: if l[i] + l[i + 1] == 'BA' or l[i] + l[i + 1] == 'AB': a.append(l[i] + l[i + 1]) i += 1 i += 1 if set(a) == {'AB', 'BA'}: print("YES") else: print("NO") ```
0
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,636,946,454
2,147,483,647
Python 3
OK
TESTS
19
92
0
s = input() t = input() steps = 0 j = 0 for i in range(len(t)): if t[i] == s[j]: steps += 1 j += 1 print(steps + 1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s = input() t = input() steps = 0 j = 0 for i in range(len(t)): if t[i] == s[j]: steps += 1 j += 1 print(steps + 1) ```
3
215
B
Olympic Medal
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/...
The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta...
Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists.
[ "3 1 2 3\n1 2\n3 3 2 1\n1 2\n", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n" ]
[ "2.683281573000\n", "2.267786838055\n" ]
In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1.
500
[ { "input": "3 1 2 3\n1 2\n3 3 2 1\n1 2", "output": "2.683281573000" }, { "input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "output": "2.267786838055" }, { "input": "1 5\n1 3\n1 7\n515 892", "output": "3.263613058533" }, { "input": "2 3 2\n3 2 3 1\n2 2 1\n733 883", "output": "2....
1,532,115,264
2,147,483,647
Python 3
OK
TESTS
31
248
512,000
import math x = list(map(int, input().split())) y = list(map(int, input().split())) z = list(map(int, input().split())) A, B = map(int, input().split()) n = x.pop(0) m = y.pop(0) k = z.pop(0) x.sort() y.sort() z.sort() r1 = x[-1] p1 = y[-1] p2 = z[0] r2 = math.sqrt(r1**2 * p1 / (A/B*p2+p...
Title: Olympic Medal Time Limit: None seconds Memory Limit: None megabytes Problem Description: The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/...
```python import math x = list(map(int, input().split())) y = list(map(int, input().split())) z = list(map(int, input().split())) A, B = map(int, input().split()) n = x.pop(0) m = y.pop(0) k = z.pop(0) x.sort() y.sort() z.sort() r1 = x[-1] p1 = y[-1] p2 = z[0] r2 = math.sqrt(r1**2 * p1 /...
3
9
C
Hexadecimal's Numbers
PROGRAMMING
1,200
[ "brute force", "implementation", "math" ]
C. Hexadecimal's Numbers
1
64
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy. But his plan failed. The reason for th...
Input data contains the only number *n* (1<=≤<=*n*<=≤<=109).
Output the only number — answer to the problem.
[ "10\n" ]
[ "2" ]
For *n* = 10 the answer includes numbers 1 and 10.
0
[ { "input": "10", "output": "2" }, { "input": "20", "output": "3" }, { "input": "72", "output": "3" }, { "input": "99", "output": "3" }, { "input": "100", "output": "4" }, { "input": "101", "output": "5" }, { "input": "102", "output": "5...
1,622,487,292
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
13
1,000
1,843,200
n = int(input()) if '3' in str(n) or '4' in str(n) or '5' in str(n) or '6' in str(n) or '7' in str(n) or '8' in str(n) or '9' in str(n) or '2' in str(n): ver = 1 while ver != 0: n -= 1 if '3' in str(n) or '4' in str(n) or '5' in str(n) or '6' in str(n) or '7' in str(n) or '8' in str(n) or '...
Title: Hexadecimal's Numbers Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ...
```python n = int(input()) if '3' in str(n) or '4' in str(n) or '5' in str(n) or '6' in str(n) or '7' in str(n) or '8' in str(n) or '9' in str(n) or '2' in str(n): ver = 1 while ver != 0: n -= 1 if '3' in str(n) or '4' in str(n) or '5' in str(n) or '6' in str(n) or '7' in str(n) or '8' in s...
0
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal...
In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ...
1,620,223,023
2,147,483,647
Python 3
OK
TESTS
57
186
0
def fn(l): if l.count(0)>l.count(1): return l.count(1) else: return l.count(0) n=int(input()) l=[] r=[] for i in range(n): a,b=input().split() l.append(int(a)) r.append(int(b)) c=0 c+=fn(l) c+=fn(r) print(c)
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long...
```python def fn(l): if l.count(0)>l.count(1): return l.count(1) else: return l.count(0) n=int(input()) l=[] r=[] for i in range(n): a,b=input().split() l.append(int(a)) r.append(int(b)) c=0 c+=fn(l) c+=fn(r) print(c) ```
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,580,149,917
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
31
218
0
n=int(input()) l=list(map(int,input().split())) m=[] c=0 for i in range(n): if l[i]%2==0: m.append(i+1) c+=1 if c==1: print(m[0]) if c>1: for i in range(1,n): if i not in m: print(i)
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()) l=list(map(int,input().split())) m=[] c=0 for i in range(n): if l[i]%2==0: m.append(i+1) c+=1 if c==1: print(m[0]) if c>1: for i in range(1,n): if i not in m: print(i) ```
0
988
B
Substrings Sort
PROGRAMMING
1,100
[ "sortings", "strings" ]
null
null
You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if it is possible to choose several consecutive letters in $b$ in su...
The first line contains an integer $n$ ($1 \le n \le 100$) — the number of strings. The next $n$ lines contain the given strings. The number of letters in each string is from $1$ to $100$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $n$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $n$ given strings in required order.
[ "5\na\naba\nabacaba\nba\naba\n", "5\na\nabacaba\nba\naba\nabab\n", "3\nqwerty\nqwerty\nqwerty\n" ]
[ "YES\na\nba\naba\naba\nabacaba\n", "NO\n", "YES\nqwerty\nqwerty\nqwerty\n" ]
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
0
[ { "input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba" }, { "input": "5\na\nabacaba\nba\naba\nabab", "output": "NO" }, { "input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty" }, { "input": "1\nwronganswer", "output": "Y...
1,642,540,933
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
10
93
1,228,800
def insertion_sort(issam_elimrany): for i in range(1, len(issam_elimrany)): j = i while j > 0 and len(issam_elimrany[j - 1]) > len(issam_elimrany[j]): issam_elimrany[j - 1], issam_elimrany[j] = issam_elimrany[j], issam_elimrany[j - 1] j = j - 1 return issam_elimrany...
Title: Substrings Sort Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String ...
```python def insertion_sort(issam_elimrany): for i in range(1, len(issam_elimrany)): j = i while j > 0 and len(issam_elimrany[j - 1]) > len(issam_elimrany[j]): issam_elimrany[j - 1], issam_elimrany[j] = issam_elimrany[j], issam_elimrany[j - 1] j = j - 1 return issa...
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not ...
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20...
1,696,567,194
2,147,483,647
Python 3
OK
TESTS
32
46
0
t = int(input()) c = list(map(int,input().split())) c.sort() print(*c)
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the bo...
```python t = int(input()) c = list(map(int,input().split())) c.sort() print(*c) ```
3
879
B
Table Tennis
PROGRAMMING
1,200
[ "data structures", "implementation" ]
null
null
*n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins *k* games in a row. This player becomes the winner. For each of t...
The first line contains two integers: *n* and *k* (2<=≤<=*n*<=≤<=500, 2<=≤<=*k*<=≤<=1012) — the number of people and the number of wins. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — powers of the player. It's guaranteed that this line contains a valid permutation, i.e. all ...
Output a single integer — power of the winner.
[ "2 2\n1 2\n", "4 2\n3 1 2 4\n", "6 2\n6 5 3 1 2 4\n", "2 10000000000\n2 1\n" ]
[ "2 ", "3 ", "6 ", "2\n" ]
Games in the second sample: 3 plays with 1. 3 wins. 1 goes to the end of the line. 3 plays with 2. 3 wins. He wins twice in a row. He becomes the winner.
1,000
[ { "input": "2 2\n1 2", "output": "2 " }, { "input": "4 2\n3 1 2 4", "output": "3 " }, { "input": "6 2\n6 5 3 1 2 4", "output": "6 " }, { "input": "2 10000000000\n2 1", "output": "2" }, { "input": "4 4\n1 3 4 2", "output": "4 " }, { "input": "2 21474836...
1,663,317,310
2,147,483,647
PyPy 3-64
OK
TESTS
43
62
0
from collections import deque n, k = map(int, input().split()) a = deque([int(i) for i in input().split()]) if k >= n-1: print(n) exit() scores = [0 for i in range(n+1)] while a[0] != n: if a[0] > a[1]: scores[a[0]] += 1 if scores[a[0]] >= k: print(a[0]) ...
Title: Table Tennis Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so o...
```python from collections import deque n, k = map(int, input().split()) a = deque([int(i) for i in input().split()]) if k >= n-1: print(n) exit() scores = [0 for i in range(n+1)] while a[0] != n: if a[0] > a[1]: scores[a[0]] += 1 if scores[a[0]] >= k: print(a[...
3
605
B
Lazy Student
PROGRAMMING
1,700
[ "constructive algorithms", "data structures", "graphs" ]
null
null
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers *n* and *m* () — the number of vertices and the number of edges in the graph. Each of the next *m* lines describes an edge of the graph and consists of two integers *a**j* and *b**j* (1<=≤<=*a**j*<=≤<=109,<=*b**j*<==<={0,<=1}). The first of these numbers is the weight ...
If Vladislav has made a mistake and such graph doesn't exist, print <=-<=1. Otherwise print *m* lines. On the *j*-th line print a pair of vertices (*u**j*,<=*v**j*) (1<=≤<=*u**j*,<=*v**j*<=≤<=*n*,<=*u**j*<=≠<=*v**j*), that should be connected by the *j*-th edge. The edges are numbered in the same order as in the input...
[ "4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n", "3 3\n1 0\n2 1\n3 1\n" ]
[ "2 4\n1 4\n3 4\n3 1\n3 2\n", "-1\n" ]
none
1,000
[ { "input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2" }, { "input": "3 3\n1 0\n2 1\n3 1", "output": "-1" }, { "input": "2 1\n7 1", "output": "1 2" }, { "input": "3 2\n8 1\n9 1", "output": "1 2\n1 3" }, { "input": "3 3\n4 1\n5 0\n7 1", ...
1,554,541,484
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
108
307,200
class LazyStudent(): def __init__(self, n, m, edge_values): self.n = n self.m = m self.edge_values = edge_values for i in range(len(self.edge_values)): self.edge_values[i] = (self.edge_values[i][0], (self.edge_values[i][1]+1)%2, i) def check(self): sorted_edg...
Title: Lazy Student Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sittin...
```python class LazyStudent(): def __init__(self, n, m, edge_values): self.n = n self.m = m self.edge_values = edge_values for i in range(len(self.edge_values)): self.edge_values[i] = (self.edge_values[i][0], (self.edge_values[i][1]+1)%2, i) def check(self): ...
0
47
A
Triangular numbers
PROGRAMMING
800
[ "brute force", "math" ]
A. Triangular numbers
2
256
A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is the number of dots in a triangle with *n* dots on a side. . You can learn more about these numbers fr...
The first line contains the single number *n* (1<=≤<=*n*<=≤<=500) — the given integer.
If the given integer is a triangular number output YES, otherwise output NO.
[ "1\n", "2\n", "3\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "1", "output": "YES" }, { "input": "2", "output": "NO" }, { "input": "3", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "5", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "7", "output": "NO...
1,600,276,658
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
186
0
#rOkY #FuCk ################################## kOpAl ##################################### t=int(input()) if(t%2==0): print('NO') else: print('YES')
Title: Triangular numbers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A triangular number is the number of dots in an equilateral triangle uniformly filled with dots. For example, three dots can be arranged in a triangle; thus three is a triangular number. The *n*-th triangular number is t...
```python #rOkY #FuCk ################################## kOpAl ##################################### t=int(input()) if(t%2==0): print('NO') else: print('YES') ```
0
650
A
Watchmen
PROGRAMMING
1,400
[ "data structures", "geometry", "math" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs...
500
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { ...
1,570,333,682
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <iostream> #include<map> #include<bits/stdc++.h> using namespace std; int main() { //code int n; cin>>n; map<long long int, long long int> x; map<long long int, long long int> y; map<pair<long long int, long long int>,long long int> p; long long int a,b; whi...
Title: Watchmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They n...
```python #include <iostream> #include<map> #include<bits/stdc++.h> using namespace std; int main() { //code int n; cin>>n; map<long long int, long long int> x; map<long long int, long long int> y; map<pair<long long int, long long int>,long long int> p; long long int a,b;...
-1
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,642,574,719
2,147,483,647
Python 3
OK
TESTS
32
122
0
n=int(input()) val=list(map(int,input().split())) e,o=0,0 for i in range(n): if(val[i]%2==0): e+=1 else: o+=1 if(e>o): for i in range(n): if(val[i]%2!=0): print(i+1) break else: for i in range(n): if(val[i]%2==0): print(i+1) break
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()) val=list(map(int,input().split())) e,o=0,0 for i in range(n): if(val[i]%2==0): e+=1 else: o+=1 if(e>o): for i in range(n): if(val[i]%2!=0): print(i+1) break else: for i in range(n): if(val[i]%2==0): print(i+1) break ```
3.9695
0
none
none
none
0
[ "none" ]
null
null
Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowe...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of letters in the word written by Stepan. The second line contains the string *s* which has length that equals to *n* and contains only lowercase English letters — the word written by Stepan.
Print the single string — the word written by Stepan converted according to the rules described in the statement.
[ "13\npobeeeedaaaaa\n", "22\niiiimpleeemeentatiioon\n", "18\naeiouyaaeeiioouuyy\n", "24\naaaoooiiiuuuyyyeeeggghhh\n" ]
[ "pobeda\n", "implemeentatioon\n", "aeiouyaeeioouy\n", "aoiuyeggghhh\n" ]
none
0
[ { "input": "13\npobeeeedaaaaa", "output": "pobeda" }, { "input": "22\niiiimpleeemeentatiioon", "output": "implemeentatioon" }, { "input": "18\naeiouyaaeeiioouuyy", "output": "aeiouyaeeioouy" }, { "input": "24\naaaoooiiiuuuyyyeeeggghhh", "output": "aoiuyeggghhh" }, { ...
1,491,411,266
4,766
Python 3
OK
TESTS
34
420
6,553,600
n=int(input()) ss=input() dic= {} dic['a']=1 dic['e']=1 dic['i']=1 dic['o']=1 dic['u']=1 dic['y']=1 cnt=1 if(not ss[0] in dic): print(ss[0],end='') for i in range(1,n): if(ss[i]==ss[i-1]): cnt=cnt+1 else: if(ss[i-1] in dic): if(ss[i-1]=='e' or ss...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa". Sergey does not like such behavior, so he wants to write a program to format the words written by ...
```python n=int(input()) ss=input() dic= {} dic['a']=1 dic['e']=1 dic['i']=1 dic['o']=1 dic['u']=1 dic['y']=1 cnt=1 if(not ss[0] in dic): print(ss[0],end='') for i in range(1,n): if(ss[i]==ss[i-1]): cnt=cnt+1 else: if(ss[i-1] in dic): if(ss[i-1]=...
3