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
552
E
Vanya and Brackets
PROGRAMMING
2,100
[ "brute force", "dp", "expression parsing", "greedy", "implementation", "strings" ]
null
null
Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
The first line contains expression *s* (1<=≤<=|*s*|<=≤<=5001, |*s*| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs <=+<= and <=*<=. The number of signs <=*<= doesn't exceed 15.
In the first line print the maximum possible value of an expression.
[ "3+5*7+8*4\n", "2+3*5\n", "3*4*5\n" ]
[ "303\n", "25\n", "60\n" ]
Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
2,500
[ { "input": "3+5*7+8*4", "output": "303" }, { "input": "2+3*5", "output": "25" }, { "input": "3*4*5", "output": "60" }, { "input": "5*5*5*5*5*5*5*5*5*5*5*5*5*5*5*5", "output": "152587890625" }, { "input": "2*2+2*2", "output": "16" }, { "input": "1+1+1+1...
1,475,622,266
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
77
0
s=input() r=[-1] t=s.find('*') while-1!=t:r+=[t];t=s.find('*',t+1) r+=[len(s)] print(max(eval(s[:r[i-1]+1]+'('+s[r[i-1]+1:r[i]]+')'+s[r[i]:])for i in range(1,len(r))))
Title: Vanya and Brackets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya is doing his maths homework. He has an expression of form , where *x*1,<=*x*2,<=...,<=*x**n* are digits from 1 to 9, and sign represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one...
```python s=input() r=[-1] t=s.find('*') while-1!=t:r+=[t];t=s.find('*',t+1) r+=[len(s)] print(max(eval(s[:r[i-1]+1]+'('+s[r[i-1]+1:r[i]]+')'+s[r[i]:])for i in range(1,len(r)))) ```
0
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,696,182,852
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
w=int(input()) while w<=100 and w>=100: if w%2==0 and w!=2: print ("YES") elif w==2: print ("NO") else: print ("NO")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python w=int(input()) while w<=100 and w>=100: if w%2==0 and w!=2: print ("YES") elif w==2: print ("NO") else: print ("NO") ```
0
813
A
The Contest
PROGRAMMING
1,100
[ "implementation" ]
null
null
Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in *a**i* time units (his solutions are always correct). At any moment of time he can be thinking ab...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=105) — the time Pasha needs to solve *i*th problem. The third line contains one integer *m* (0<=≤<=*m*<=≤<=1000) — the number of periods of time when the website is work...
If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets).
[ "2\n3 4\n2\n1 4\n7 9\n", "1\n5\n1\n1 4\n", "1\n5\n1\n1 5\n" ]
[ "7\n", "-1\n", "5\n" ]
In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again. In the second example Pasha invents...
0
[ { "input": "2\n3 4\n2\n1 4\n7 9", "output": "7" }, { "input": "1\n5\n1\n1 4", "output": "-1" }, { "input": "1\n5\n1\n1 5", "output": "5" }, { "input": "5\n100000 100000 100000 100000 100000\n0", "output": "-1" }, { "input": "5\n886 524 128 4068 298\n3\n416 3755\n4...
1,614,249,912
312
PyPy 3
OK
TESTS
29
108
102,400
import sys #import re #sys.stdin=open('.in','r') #sys.stdout=open('.out','w') #import math #import random #import time #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): retur...
Title: The Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of *n* problems, and Pasha solves *i*th problem in ...
```python import sys #import re #sys.stdin=open('.in','r') #sys.stdout=open('.out','w') #import math #import random #import time #sys.setrecursionlimit(int(1e6)) input = sys.stdin.readline ############ ---- USER DEFINED INPUT FUNCTIONS ---- ############ def inp(): return(int(input())) def inara(): ...
3
409
H
A + B Strikes Back
PROGRAMMING
1,500
[ "*special", "brute force", "constructive algorithms", "dsu", "implementation" ]
null
null
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output the sum of the given integers.
[ "5 14\n", "381 492\n" ]
[ "19\n", "873\n" ]
none
0
[ { "input": "5 14", "output": "19" }, { "input": "381 492", "output": "873" }, { "input": "536 298", "output": "834" }, { "input": "143 522", "output": "665" }, { "input": "433 126", "output": "559" }, { "input": "723 350", "output": "1073" }, {...
1,664,614,329
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
0
0
n, m = [int(i) for i in input().split()] print(n + m)
Title: A + B Strikes Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input ...
```python n, m = [int(i) for i in input().split()] print(n + m) ```
0
294
C
Shaass and Lights
PROGRAMMING
1,900
[ "combinatorics", "number theory" ]
null
null
There are *n* lights aligned in a row. These lights are numbered 1 to *n* from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at that moment) if there's at least one adjacent light which is a...
The first line of the input contains two integers *n* and *m* where *n* is the number of lights in the sequence and *m* is the number of lights which are initially switched on, (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*m*<=≤<=*n*). The second line contains *m* distinct integers, each between 1 to *n* inclusive, denoting the indices...
In the only line of the output print the number of different possible ways to switch on all the lights modulo 1000000007 (109<=+<=7).
[ "3 1\n1\n", "4 2\n1 4\n", "11 2\n4 8\n" ]
[ "1\n", "2\n", "6720\n" ]
none
1,500
[ { "input": "3 1\n1", "output": "1" }, { "input": "4 2\n1 4", "output": "2" }, { "input": "11 2\n4 8", "output": "6720" }, { "input": "4 2\n1 3", "output": "2" }, { "input": "4 4\n1 2 3 4", "output": "1" }, { "input": "4 2\n1 3", "output": "2" }, ...
1,578,315,475
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
109
307,200
def fac(x): pr = 1 for i in range(2, x + 1): pr *= i return pr n, m = map(int, input().split()) a = list(map(int, input().split())) x = a[0] - 1 y = n - a[-1] mn1 = 1 mn2 = 1 for i in range(1, m): mn1 *= fac(a[i] - a[i - 1] - 1) mn2 *= (2 ** (a[i] - a[i - 1] - 2)) ans = fac(n - m) // (fac(x) * fac(y) * mn1) * ...
Title: Shaass and Lights Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* lights aligned in a row. These lights are numbered 1 to *n* from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light ...
```python def fac(x): pr = 1 for i in range(2, x + 1): pr *= i return pr n, m = map(int, input().split()) a = list(map(int, input().split())) x = a[0] - 1 y = n - a[-1] mn1 = 1 mn2 = 1 for i in range(1, m): mn1 *= fac(a[i] - a[i - 1] - 1) mn2 *= (2 ** (a[i] - a[i - 1] - 2)) ans = fac(n - m) // (fac(x) * fac(y)...
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,674,635,958
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
import math count_iter = int(input()) counter = {} history = [] while count_iter: name, score = input().split() if name not in counter: counter[name] = int(score) else: counter[name] += int(score) history.append((int(score), name)) count_iter -= 1 max_number = -math...
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python import math count_iter = int(input()) counter = {} history = [] while count_iter: name, score = input().split() if name not in counter: counter[name] = int(score) else: counter[name] += int(score) history.append((int(score), name)) count_iter -= 1 max_numb...
0
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh...
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759...
1,584,542,998
298
PyPy 3
OK
TESTS
30
310
1,228,800
import sys n=int(input()) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) b[i]=a[i]+b[i] for i in range(n): for j in range(n): if a[i]==b[j] and b[i]==a[j] and i!=j: print("YES") sys.exit() print("NO")
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ...
```python import sys n=int(input()) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) b[i]=a[i]+b[i] for i in range(n): for j in range(n): if a[i]==b[j] and b[i]==a[j] and i!=j: print("YES") sys.exit() print("NO") ```
3.920211
265
B
Roadside Trees (Simplified Edition)
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wants to eat all nuts. Now Liss is on the root of the tree with the number 1. In one second Liss can perform one of the fol...
The first line contains an integer *n* (1<=<=≤<=<=*n*<=≤<=105) — the number of trees. Next *n* lines contains the height of trees: *i*-th line contains an integer *h**i* (1<=≤<=*h**i*<=≤<=104) — the height of the tree with the number *i*.
Print a single integer — the minimal time required to eat all nuts in seconds.
[ "2\n1\n2\n", "5\n2\n1\n2\n1\n1\n" ]
[ "5\n", "14\n" ]
none
1,000
[ { "input": "2\n1\n2", "output": "5" }, { "input": "5\n2\n1\n2\n1\n1", "output": "14" }, { "input": "1\n1", "output": "2" } ]
1,596,716,316
2,147,483,647
Python 3
OK
TESTS
15
560
8,908,800
size = int(input()) height = [] for i in range(size): temp = int(input()) height.append(temp) steps = 0 for i in range(size): if i == 0: steps+=height[i]+1 else : if height[i]<height[i-1]: steps+=height[i-1]-height[i]+1+1 else: steps+=1+(heigh...
Title: Roadside Trees (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: Squirrel Liss loves nuts. There are *n* trees (numbered 1 to *n* from west to east) along a street and there is a delicious nut on the top of each tree. The height of the tree *i* is *h**i*. Liss wan...
```python size = int(input()) height = [] for i in range(size): temp = int(input()) height.append(temp) steps = 0 for i in range(size): if i == 0: steps+=height[i]+1 else : if height[i]<height[i-1]: steps+=height[i-1]-height[i]+1+1 else: steps...
3
412
C
Pattern
PROGRAMMING
1,200
[ "implementation", "strings" ]
null
null
Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check whether a particular string meets the certain rules. In this task, a pattern will be a string con...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of patterns. Next *n* lines contain the patterns. It is guaranteed that the patterns can only consist of small English letters and symbols '?'. All patterns are non-empty and have the same length. The total length of all the patterns does no...
In a single line print the answer to the problem — the pattern with the minimal number of signs '?', which intersects with each of the given ones. If there are several answers, print any of them.
[ "2\n?ab\n??b\n", "2\na\nb\n", "1\n?a?b\n" ]
[ "xab\n", "?\n", "cacb\n" ]
Consider the first example. Pattern xab intersects with each of the given patterns. Pattern ??? also intersects with each of the given patterns, but it contains more question signs, hence it is not an optimal answer. Clearly, xab is the optimal answer, because it doesn't contain any question sign. There are a lot of ot...
1,500
[ { "input": "2\n?ab\n??b", "output": "xab" }, { "input": "2\na\nb", "output": "?" }, { "input": "1\n?a?b", "output": "cacb" }, { "input": "1\n?", "output": "x" }, { "input": "3\nabacaba\nabacaba\nabacaba", "output": "abacaba" }, { "input": "3\nabc?t\n?b...
1,679,937,242
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
109
0
n = int(input()) patterns = [] for i in range(n): patterns.append(input().strip()) min_question_marks = float('inf') min_string = '' for i in range(26**len(patterns[0])): # Generate the string s = '' j = i for k in range(len(patterns[0])): if patterns[0][k] == '?': s += chr(j ...
Title: Pattern Time Limit: None seconds Memory Limit: None megabytes Problem Description: Developers often face with regular expression patterns. A pattern is usually defined as a string consisting of characters and metacharacters that sets the rules for your search. These patterns are most often used to check wheth...
```python n = int(input()) patterns = [] for i in range(n): patterns.append(input().strip()) min_question_marks = float('inf') min_string = '' for i in range(26**len(patterns[0])): # Generate the string s = '' j = i for k in range(len(patterns[0])): if patterns[0][k] == '?': s...
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,685,658,851
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
import sys sys.stdin = open("2.in", "r") n = int(input()) score_dict = dict() max_score = -sys.maxsize max_name = "" for i in range(n): name, point = input().split() point = int(point) if name in score_dict: score_dict[name] += point else: score_dict[name] = point if...
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python import sys sys.stdin = open("2.in", "r") n = int(input()) score_dict = dict() max_score = -sys.maxsize max_name = "" for i in range(n): name, point = input().split() point = int(point) if name in score_dict: score_dict[name] += point else: score_dict[name] = point ...
-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,690,886,248
2,147,483,647
Python 3
OK
TESTS
101
92
0
n = int(input()) gift_list = input().split(' ') index = 0 list = [] output_string = str() for value in range(0,n): list.append(value) # creating a template list to do work for item in gift_list : list[int(item) -1] = gift_list.index(item) +1 for item in list : output_string += str(item) + ' ' p...
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n = int(input()) gift_list = input().split(' ') index = 0 list = [] output_string = str() for value in range(0,n): list.append(value) # creating a template list to do work for item in gift_list : list[int(item) -1] = gift_list.index(item) +1 for item in list : output_string += str(item...
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000).
The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,694,641,095
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) if n % 2 == 0: ans = n // 2 res = [2] * ans else: ans = (n-3) // 2 res = [2] * ans + [3] print(ans+1) print(*res)
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python n = int(input()) if n % 2 == 0: ans = n // 2 res = [2] * ans else: ans = (n-3) // 2 res = [2] * ans + [3] print(ans+1) print(*res) ```
0
588
A
Duff and Meat
PROGRAMMING
900
[ "greedy" ]
null
null
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day.
Print the minimum money needed to keep Duff happy for *n* days, in one line.
[ "3\n1 3\n2 2\n3 1\n", "3\n1 3\n2 1\n3 2\n" ]
[ "10\n", "8\n" ]
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
750
[ { "input": "3\n1 3\n2 2\n3 1", "output": "10" }, { "input": "3\n1 3\n2 1\n3 2", "output": "8" }, { "input": "1\n39 52", "output": "2028" }, { "input": "2\n25 56\n94 17", "output": "2998" }, { "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321" }...
1,537,272,464
2,147,483,647
Python 3
OK
TESTS
30
498
7,782,400
import math def main(): n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) s=0 mt=101 for i in range(n): if mt>a[i][1]: mt=a[i][1] s=s+a[i][0]*mt print(s) if __name__=='__main__': main()
Title: Duff and Meat Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her ...
```python import math def main(): n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) s=0 mt=101 for i in range(n): if mt>a[i][1]: mt=a[i][1] s=s+a[i][0]*mt print(s) if __name__=='__main__': main() ```
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,698,846,612
2,147,483,647
Python 3
OK
TESTS
34
92
0
n = int(input()) stones = input() count = 0 current = stones[0] for s in stones[1:]: if s == current: count += 1 current = s print(count)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python n = int(input()) stones = input() count = 0 current = stones[0] for s in stones[1:]: if s == current: count += 1 current = s print(count) ```
3
260
C
Balls and Boxes
PROGRAMMING
1,700
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right. Once Vasya chose one of the boxes, let's assume that its number is *i*, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began pu...
The first line of the input contains two integers *n* and *x* (2<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=*n*), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, where integer *a**i*...
Print *n* integers, where the *i*-th one represents the number of balls in the box number *i* before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them.
[ "4 4\n4 3 1 6\n", "5 2\n3 2 0 2 7\n", "3 3\n2 3 1\n" ]
[ "3 2 5 4 ", "2 1 4 1 6 ", "1 2 3 " ]
none
1,500
[ { "input": "4 4\n4 3 1 6", "output": "3 2 5 4 " }, { "input": "5 2\n3 2 0 2 7", "output": "2 1 4 1 6 " }, { "input": "3 3\n2 3 1", "output": "1 2 3 " }, { "input": "10 3\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000...
1,601,524,557
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
n, x = map(int, input().split()) ar = list(map(int, input().split())) min_boxes = 1000000001 min_idx = -1 for i in range(n): if ar[i] < min_boxes: min_boxes = ar[i] min_idx = i ans = list(ar) for i in range(n): if i != min_idx: ans[i] -= ar[min_idx] res = 0 x -= 1 if x > mi...
Title: Balls and Boxes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya had *n* boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to *n* from left to right. Once Vasya chose one of the boxes, let's assume that its number is *i*, took ...
```python n, x = map(int, input().split()) ar = list(map(int, input().split())) min_boxes = 1000000001 min_idx = -1 for i in range(n): if ar[i] < min_boxes: min_boxes = ar[i] min_idx = i ans = list(ar) for i in range(n): if i != min_idx: ans[i] -= ar[min_idx] res = 0 x -= 1 ...
0
1,009
C
Annoying Present
PROGRAMMING
1,700
[ "greedy", "math" ]
null
null
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $m$ changes of the following form. For some int...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes. Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
[ "2 3\n-1 3\n0 0\n-1 -4\n", "3 2\n0 2\n5 0\n" ]
[ "-2.500000000000000\n", "7.000000000000000\n" ]
none
0
[ { "input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000" }, { "input": "3 2\n0 2\n5 0", "output": "7.000000000000000" }, { "input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64", "output": "-16.500000000000000" }, { "input": "1 1\n0 0", ...
1,532,018,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
n = [int(i) for i in input().split()] x = n[0]//2 sum1 = 0 sum2 = 0 for i in range(n[0]): sum1+=i sum2+=(i + 1 - x) f = 0 for j in range(n[1]): x = [int(i) for i in input().split()] if(x[1]>0): f += n[0] * x[0] + max(sum1,sum2)*x[1] else: f += n[0] * x[0] + min(sum1,sum2)*x[1] print(f/n[0])
Title: Annoying Present Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c...
```python n = [int(i) for i in input().split()] x = n[0]//2 sum1 = 0 sum2 = 0 for i in range(n[0]): sum1+=i sum2+=(i + 1 - x) f = 0 for j in range(n[1]): x = [int(i) for i in input().split()] if(x[1]>0): f += n[0] * x[0] + max(sum1,sum2)*x[1] else: f += n[0] * x[0] + min(sum1,sum2)*x[1] print(f/n[0]) ```
0
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,692,201,331
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
1,843,200
k=int(input()) l=int(input()) n=int(input()) m=int(input()) d=int(input()) s=0 if min(k,l,n,m)==1: print(d) else: for i in range(1,d+1): if i%l==0 or i%k==0 or i%n==0 or i%m==0: s+=1 print(s)
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 k=int(input()) l=int(input()) n=int(input()) m=int(input()) d=int(input()) s=0 if min(k,l,n,m)==1: print(d) else: for i in range(1,d+1): if i%l==0 or i%k==0 or i%n==0 or i%m==0: s+=1 print(s) ```
3
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,664,778,911
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
0
k = int(input()) x= int(1e9+ 1) id = 10 count = 0 for i in range(0,x): id += 9 s = id o = 0 while s >= 1: o += s % 10 s = s // 10 if o == 10: count += 1 if count == k: print(id) break
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python k = int(input()) x= int(1e9+ 1) id = 10 count = 0 for i in range(0,x): id += 9 s = id o = 0 while s >= 1: o += s % 10 s = s // 10 if o == 10: count += 1 if count == k: print(id) break ```
0
679
A
Bear and Prime 100
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two d...
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu...
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hi...
750
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" ...
1,594,392,180
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
58
155
20,172,800
from sys import stdout ans=0 for i in[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]: print(i) stdout.flush() if input()=='yes': ans+=1 if i*i<100: print(i*i) stdout.flush() if input()=='yes':ans+=1 if ans==2:exit(print('composite')) print('prim...
Title: Bear and Prime 100 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i...
```python from sys import stdout ans=0 for i in[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]: print(i) stdout.flush() if input()=='yes': ans+=1 if i*i<100: print(i*i) stdout.flush() if input()=='yes':ans+=1 if ans==2:exit(print('composite')) p...
0
112
B
Petya and Square
PROGRAMMING
1,200
[ "implementation", "math" ]
B. Petya and Square
2
256
Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not ha...
The first line contains three space-separated integers 2*n*, *x* and *y* (2<=≤<=2*n*<=≤<=100,<=1<=≤<=*x*,<=*y*<=≤<=2*n*), representing the length of a square's side and the coordinates of the marked cell. It is guaranteed that 2*n* is even. The coordinates of the marked cell are represented by a pair of numbers *x* *y...
If the square is possible to cut, print "YES", otherwise print "NO" (without the quotes).
[ "4 1 1\n", "2 2 2\n" ]
[ "YES\n", "NO\n" ]
A sample test from the statement and one of the possible ways of cutting the square are shown in the picture:
1,000
[ { "input": "4 1 1", "output": "YES" }, { "input": "2 2 2", "output": "NO" }, { "input": "8 2 5", "output": "YES" }, { "input": "6 1 6", "output": "YES" }, { "input": "2 1 1", "output": "NO" }, { "input": "2 1 2", "output": "NO" }, { "input"...
1,696,670,486
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
124
0
n, x, y = map(int, input().split()) notOK = x in [n, n+1] and y in [n, n+1] print(["YES","NO"][notOK])
Title: Petya and Square Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya loves playing with squares. Mum bought him a square 2*n*<=×<=2*n* in size. Petya marked a cell inside the square and now he is solving the following task. The task is to draw a broken line that would go along...
```python n, x, y = map(int, input().split()) notOK = x in [n, n+1] and y in [n, n+1] print(["YES","NO"][notOK]) ```
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,697,106,660
2,147,483,647
Python 3
OK
TESTS
71
92
0
s = 0 maxim = 0 for i in range(int(input())): a,b = map(int, input().split()) s -= a s += b maxim = max(maxim, s) print(maxim)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python s = 0 maxim = 0 for i in range(int(input())): a,b = map(int, input().split()) s -= a s += b maxim = max(maxim, s) print(maxim) ```
3
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", ...
1,666,386,033
2,147,483,647
Python 3
OK
TESTS
70
46
0
string = input() minimo = 0 saltoactual = 1 for letra in string: if letra not in("AEIOUY"): saltoactual += 1 if minimo < saltoactual: minimo = saltoactual elif letra in("AEIOUY"): saltoactual = 1 print(minimo)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en...
```python string = input() minimo = 0 saltoactual = 1 for letra in string: if letra not in("AEIOUY"): saltoactual += 1 if minimo < saltoactual: minimo = saltoactual elif letra in("AEIOUY"): saltoactual = 1 print(minimo) ```
3
633
D
Fibonacci-ish
PROGRAMMING
2,000
[ "brute force", "dp", "hashing", "implementation", "math" ]
null
null
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if 1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=2<==<=*f**n*<=+<=1<=+<=*f**n* for all *n*<=≥<=0. You are given some sequence of integers *a*1,<=*a...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the length of the sequence *a**i*. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=109).
Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.
[ "3\n1 2 -1\n", "5\n28 35 7 14 21\n" ]
[ "3\n", "4\n" ]
In the first sample, if we rearrange elements of the sequence as  - 1, 2, 1, the whole sequence *a*<sub class="lower-index">*i*</sub> would be Fibonacci-ish. In the second sample, the optimal way to rearrange elements is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/16f1f7e35511b29cb1396...
1,750
[ { "input": "3\n1 2 -1", "output": "3" }, { "input": "5\n28 35 7 14 21", "output": "4" }, { "input": "11\n-9 -1 -10 9 7 -4 0 -8 -3 3 5", "output": "5" }, { "input": "10\n-4 -8 -8 8 -9 0 -7 9 1 0", "output": "4" }, { "input": "2\n2 2", "output": "2" }, { ...
1,683,435,590
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
311
0
n = int(input()) a = list(map(int, input().split())) a_dict = {} for x in a: a_dict[x] = a_dict.get(x, 0) + 1 a.sort() ans = 0 for i in range(n): for j in range(i+1, n): f0, f1 = a[i], a[j] cnt = 2 while f0 + f1 in a_dict and a_dict[f0 + f1] > 0: f0, f1 = f1, f0 + f1 ...
Title: Fibonacci-ish Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if 1. the sequence consists of at least two elements 1. *f*0 and *f*1 are arbitrary 1. *f**n*<=+<=...
```python n = int(input()) a = list(map(int, input().split())) a_dict = {} for x in a: a_dict[x] = a_dict.get(x, 0) + 1 a.sort() ans = 0 for i in range(n): for j in range(i+1, n): f0, f1 = a[i], a[j] cnt = 2 while f0 + f1 in a_dict and a_dict[f0 + f1] > 0: f0, f1 = f1, f0 +...
0
103
B
Cthulhu
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
B. Cthulhu
2
256
...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super...
The first line contains two integers — the number of vertices *n* and the number of edges *m* of the graph (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=). Each of the following *m* lines contains a pair of integers *x* and *y*, that show that an edge exists between vertices *x* and *y* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*). Fo...
Print "NO", if the graph is not Cthulhu and "FHTAGN!" if it is.
[ "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4\n", "6 5\n5 6\n4 6\n3 1\n5 1\n1 2\n" ]
[ "FHTAGN!", "NO" ]
Let us denote as a simple cycle a set of *v* vertices that can be numbered so that the edges will only exist between vertices number 1 and 2, 2 and 3, ..., *v* - 1 and *v*, *v* and 1. A tree is a connected undirected graph consisting of *n* vertices and *n* - 1 edges (*n* &gt; 0). A rooted tree is a tree where one ve...
1,000
[ { "input": "6 6\n6 3\n6 4\n5 1\n2 5\n1 4\n5 4", "output": "FHTAGN!" }, { "input": "6 5\n5 6\n4 6\n3 1\n5 1\n1 2", "output": "NO" }, { "input": "10 10\n4 10\n8 5\n2 8\n4 9\n9 3\n2 7\n10 6\n10 2\n9 8\n1 8", "output": "FHTAGN!" }, { "input": "5 4\n1 5\n1 3\n1 4\n3 2", "outpu...
1,434,407,536
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
186
0
def dfs(graph, start): visited[start] = True for i in graph[start]: if not visited[i]: dfs(graph, i) a, b = list(map(int, input().split(' '))) g = {} for i in range(1, a+1): g[i] = [] for i in range(b): x, y = map(int, input().split(' ')) g[x].append(y) g[y]...
Title: Cthulhu Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu... Whereas on the other end of the world Pentagon is actively colle...
```python def dfs(graph, start): visited[start] = True for i in graph[start]: if not visited[i]: dfs(graph, i) a, b = list(map(int, input().split(' '))) g = {} for i in range(1, a+1): g[i] = [] for i in range(b): x, y = map(int, input().split(' ')) g[x].append(y)...
0
796
A
Buying A House
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ...
The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=...
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
[ "5 1 20\n0 27 32 21 19\n", "7 3 50\n62 0 0 0 99 33 22\n", "10 5 100\n1 0 1 0 0 0 0 0 1 1\n" ]
[ "40", "30", "20" ]
In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters. In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a...
500
[ { "input": "5 1 20\n0 27 32 21 19", "output": "40" }, { "input": "7 3 50\n62 0 0 0 99 33 22", "output": "30" }, { "input": "10 5 100\n1 0 1 0 0 0 0 0 1 1", "output": "20" }, { "input": "5 3 1\n1 1 0 0 1", "output": "10" }, { "input": "5 5 5\n1 0 5 6 0", "outpu...
1,579,811,520
2,147,483,647
Python 3
OK
TESTS
58
124
307,200
n, m, k = map(int, input().split()) a = list(map(int, input().split())) a.insert(0, 0) if m == 1: for i in range(m, len(a)): if (a[i] <= k) and (a[i] != 0): print((i - m) * 10) break elif m == n: for i in range(m, 0, -1): if (a[i] <= k) and (a[i] != 0): ...
Title: Buying A House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us. The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li...
```python n, m, k = map(int, input().split()) a = list(map(int, input().split())) a.insert(0, 0) if m == 1: for i in range(m, len(a)): if (a[i] <= k) and (a[i] != 0): print((i - m) * 10) break elif m == n: for i in range(m, 0, -1): if (a[i] <= k) and (a[i] != 0)...
3
773
A
Success Rate
PROGRAMMING
1,700
[ "binary search", "math" ]
null
null
You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equal to *x*<=/<=*y*. Your favorite rational number in the [0;1] range is *p*<=/<=*q*. Now you wonde...
The first line contains a single integer *t* (1<=≤<=*t*<=≤<=1000) — the number of test cases. Each of the next *t* lines contains four integers *x*, *y*, *p* and *q* (0<=≤<=*x*<=≤<=*y*<=≤<=109; 0<=≤<=*p*<=≤<=*q*<=≤<=109; *y*<=&gt;<=0; *q*<=&gt;<=0). It is guaranteed that *p*<=/<=*q* is an irreducible fraction. Hacks...
For each test case, output a single integer equal to the smallest number of submissions you have to make if you want your success rate to be equal to your favorite rational number, or -1 if this is impossible to achieve.
[ "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1\n" ]
[ "4\n10\n0\n-1\n" ]
In the first example, you have to make 4 successful submissions. Your success rate will be equal to 7 / 14, or 1 / 2. In the second example, you have to make 2 successful and 8 unsuccessful submissions. Your success rate will be equal to 9 / 24, or 3 / 8. In the third example, there is no need to make any new submiss...
500
[ { "input": "4\n3 10 1 2\n7 14 3 8\n20 70 2 7\n5 6 1 1", "output": "4\n10\n0\n-1" }, { "input": "8\n0 1 0 1\n0 2 1 2\n0 3 1 1\n1 2 0 1\n1 2 1 1\n2 2 0 1\n3 3 1 2\n4 4 1 1", "output": "0\n2\n-1\n-1\n-1\n-1\n3\n0" }, { "input": "5\n1 1000000000 1 2\n1 1000000000 1 2\n1 1000000000 1 2\n1 100...
1,494,174,156
2,256
Python 3
WRONG_ANSWER
PRETESTS
0
46
0
def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) class solution: def __init__(self, a=0, b=0): self.x = a self.y = b def eu (a, b, sol): if a == 0: sol.x = 0 sol.y = 1 return b sol2 = solution() d = eu (b%a, ...
Title: Success Rate Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made *y* submissions, out of which *x* have been successful. Thus, your current success rate on Codeforces is equ...
```python def gcd(a, b): if b == 0: return a else: return gcd(b, a % b) class solution: def __init__(self, a=0, b=0): self.x = a self.y = b def eu (a, b, sol): if a == 0: sol.x = 0 sol.y = 1 return b sol2 = solution() d =...
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,693,489,144
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
x=map(int,input().split()) h=min(x) print(h)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python x=map(int,input().split()) h=min(x) print(h) ```
0
197
B
Limit
PROGRAMMING
1,400
[ "math" ]
null
null
You are given two polynomials: - *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*. Calculate limit .
The first line contains two space-separated integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=100) — degrees of polynomials *P*(*x*) and *Q*(*x*) correspondingly. The second line contains *n*<=+<=1 space-separated integers — the factors of polynomial *P*(*x*): *a*0, *a*1, ..., *a**n*<=-<=1, *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100...
If the limit equals <=+<=∞, print "Infinity" (without quotes). If the limit equals <=-<=∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where *p...
[ "2 1\n1 1 1\n2 5\n", "1 0\n-1 3\n2\n", "0 1\n1\n1 0\n", "2 2\n2 1 6\n4 5 -7\n", "1 1\n9 0\n-5 2\n" ]
[ "Infinity\n", "-Infinity\n", "0/1\n", "1/2\n", "-9/5\n" ]
Let's consider all samples: 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c28febca257452afdfcbd6984ba8623911f9bdbc.png" style="max-width: 100.0%;max-height: 100.0%;"/> 1. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1e55ecd04e54a45e5e0092ec9a5c1ea03bb...
500
[ { "input": "2 1\n1 1 1\n2 5", "output": "Infinity" }, { "input": "1 0\n-1 3\n2", "output": "-Infinity" }, { "input": "0 1\n1\n1 0", "output": "0/1" }, { "input": "2 2\n2 1 6\n4 5 -7", "output": "1/2" }, { "input": "1 1\n9 0\n-5 2", "output": "-9/5" }, { ...
1,547,035,410
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
47
436
1,126,400
from fractions import Fraction n,m = map(int,input().split()) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) if n > m: if l1[0] <0 and l2[0] < 0: print("Infinity") else: if l1[0] < 0 or l2[0] < 0: print("-Infinity") else: print("Infinity") elif n==m: print(Fraction(l1[0],l2[0]...
Title: Limit Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two polynomials: - *P*(*x*)<==<=*a*0·*x**n*<=+<=*a*1·*x**n*<=-<=1<=+<=...<=+<=*a**n*<=-<=1·*x*<=+<=*a**n* and - *Q*(*x*)<==<=*b*0·*x**m*<=+<=*b*1·*x**m*<=-<=1<=+<=...<=+<=*b**m*<=-<=1·*x*<=+<=*b**m*. Calculate l...
```python from fractions import Fraction n,m = map(int,input().split()) l1 = list(map(int,input().split())) l2 = list(map(int,input().split())) if n > m: if l1[0] <0 and l2[0] < 0: print("Infinity") else: if l1[0] < 0 or l2[0] < 0: print("-Infinity") else: print("Infinity") elif n==m: print(Fraction(l...
0
28
A
Bender Problem
PROGRAMMING
1,600
[ "implementation" ]
A. Bender Problem
2
256
Robot Bender decided to make Fray a birthday present. He drove *n* nails and numbered them from 1 to *n* in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordin...
The first line contains two positive integers *n* and *m* (4<=≤<=*n*<=≤<=500,<=2<=≤<=*m*<=≤<=500, *n* is even) — the amount of nails and the amount of rods. *i*-th of the following *n* lines contains a pair of integers, denoting the coordinates of the *i*-th nail. Nails should be connected in the same order as they are...
If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output *n* numbers — *i*-th of them should be the number of rod, which fold place is attached to the *i*-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.
[ "4 2\n0 0\n0 2\n2 2\n2 0\n4 4\n", "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3\n", "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3\n" ]
[ "YES\n1 -1 2 -1 \n", "YES\n1 -1 2 -1 3 -1 \n", "NO\n" ]
none
500
[ { "input": "4 2\n0 0\n0 2\n2 2\n2 0\n4 4", "output": "YES\n1 -1 2 -1 " }, { "input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n3 2 3", "output": "YES\n1 -1 2 -1 3 -1 " }, { "input": "6 3\n0 0\n1 0\n1 1\n2 1\n2 2\n0 2\n2 2 3", "output": "NO" }, { "input": "4 4\n0 0\n0 1\n1 1\n1 0\n1...
1,577,357,021
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
216
307,200
n,m = map(int,input().split()) s = [] for i in range(n): a = map(int,input().split()) a = list(a) s.append(a) s_chet = [] for i in range(1,n-1,2): #Проход по четным гвоздям q = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1])) s_chet.append(q) q1 = abs(sum(s[-1])-sum(...
Title: Bender Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Robot Bender decided to make Fray a birthday present. He drove *n* nails and numbered them from 1 to *n* in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices shou...
```python n,m = map(int,input().split()) s = [] for i in range(n): a = map(int,input().split()) a = list(a) s.append(a) s_chet = [] for i in range(1,n-1,2): #Проход по четным гвоздям q = abs(sum(s[i])-sum(s[i-1])) + abs(sum(s[i])-sum(s[i+1])) s_chet.append(q) q1 = abs(sum(s...
0
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean...
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ...
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "outp...
1,678,950,848
2,147,483,647
Python 3
OK
TESTS
31
46
0
a=input() b=input() d='qwertyuiopasdfghjkl;zxcvbnm,./' c='' for x in b: if a=='R': c+=d[d.index(x)-1] else: c+=d[d.index(x)+1] print(c)
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately....
```python a=input() b=input() d='qwertyuiopasdfghjkl;zxcvbnm,./' c='' for x in b: if a=='R': c+=d[d.index(x)-1] else: c+=d[d.index(x)+1] print(c) ```
3
645
C
Enduring Exodus
PROGRAMMING
1,600
[ "binary search", "two pointers" ]
null
null
In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel consists of *n* rooms located in a row, some of which are occupie...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=&lt;<=*n*<=≤<=100<=000) — the number of rooms in the hotel and the number of cows travelling with Farmer John. The second line contains a string of length *n* describing the rooms. The *i*-th character of the string will be '0' if the *i*-th roo...
Print the minimum possible distance between Farmer John's room and his farthest cow.
[ "7 2\n0100100\n", "5 1\n01010\n", "3 2\n000\n" ]
[ "2\n", "2\n", "1\n" ]
In the first sample, Farmer John can book room 3 for himself, and rooms 1 and 4 for his cows. The distance to the farthest cow is 2. Note that it is impossible to make this distance 1, as there is no block of three consecutive unoccupied rooms. In the second sample, Farmer John can book room 1 for himself and room 3 f...
1,500
[ { "input": "7 2\n0100100", "output": "2" }, { "input": "5 1\n01010", "output": "2" }, { "input": "3 2\n000", "output": "1" }, { "input": "10 1\n1101111101", "output": "6" }, { "input": "2 1\n00", "output": "1" }, { "input": "3 1\n010", "output": "2...
1,507,328,301
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
204,800
n, k = [int(_) for _ in input().split()] a = input() l = 0 r = 0 total = 0 k += 1 while True: if a[r] == '0': total += 1 if total == k: break r += 1 dis = n i = l for j in range(l, r+1): if a[j] == '1': continue cur_dis = max(j-l, r-j) if cur_dis > dis...
Title: Enduring Exodus Time Limit: None seconds Memory Limit: None megabytes Problem Description: In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his *k* cows have decided to stay at the luxuriou...
```python n, k = [int(_) for _ in input().split()] a = input() l = 0 r = 0 total = 0 k += 1 while True: if a[r] == '0': total += 1 if total == k: break r += 1 dis = n i = l for j in range(l, r+1): if a[j] == '1': continue cur_dis = max(j-l, r-j) if cur...
0
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,693,230,805
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
def strings(s): res=[] vow="AEIOUaeiou" for c in s: if c not in s: res.append('.') if c.isupper(): res.append(c.islower()) else: res.append(c) return ''.join(res) s=input() ans=strings(s) print(ans)
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters...
```python def strings(s): res=[] vow="AEIOUaeiou" for c in s: if c not in s: res.append('.') if c.isupper(): res.append(c.islower()) else: res.append(c) return ''.join(res) s=input() ans=strings(s) print(ans) ```
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,689,515,981
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
154
0
n1=input() n2=input() n3=input() l1=[] for i in n1: l1.append(i) for k in n2: l1.append(k) l2=[] fl=True for j in n3: if j in l1: l1.remove(j) else: fl=False if fl==True: print("YES") else: print("NO")
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 n1=input() n2=input() n3=input() l1=[] for i in n1: l1.append(i) for k in n2: l1.append(k) l2=[] fl=True for j in n3: if j in l1: l1.remove(j) else: fl=False if fl==True: print("YES") else: print("NO") ```
0
733
A
Grasshopper And the String
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowels of the English alphabet. Jump ability is the maximum possible length of ...
The first line contains non-empty string consisting of capital English letters. It is guaranteed that the length of the string does not exceed 100.
Print single integer *a* — the minimum jump ability of the Grasshopper (in the number of symbols) that is needed to overcome the given string, jumping only on vowels.
[ "ABABBBACFEYUKOTT\n", "AAA\n" ]
[ "4", "1" ]
none
500
[ { "input": "ABABBBACFEYUKOTT", "output": "4" }, { "input": "AAA", "output": "1" }, { "input": "A", "output": "1" }, { "input": "B", "output": "2" }, { "input": "AEYUIOAEIYAEOUIYOEIUYEAOIUEOEAYOEIUYAEOUIYEOIKLMJNHGTRWSDZXCVBNMHGFDSXVWRTPPPLKMNBXIUOIUOIUOIUOOIU", ...
1,633,849,134
2,147,483,647
PyPy 3
OK
TESTS
70
108
20,172,800
pre='AEIOUY' s=input() s='A'+s+'A' ans=0;begin=0 for i in range(len(s)): if s[i] in pre : ans=max(ans,i-begin) begin=i print(ans)
Title: Grasshopper And the String Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far en...
```python pre='AEIOUY' s=input() s='A'+s+'A' ans=0;begin=0 for i in range(len(s)): if s[i] in pre : ans=max(ans,i-begin) begin=i print(ans) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,619,197,743
2,147,483,647
Python 3
OK
TESTS
102
77
0
number1, number2= input(), input() p="" for i in range(len(number1)): if number1[i]!=number2[i]: q='1' p=p+q else: q='0' p=p+q print(p)
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 number1, number2= input(), input() p="" for i in range(len(number1)): if number1[i]!=number2[i]: q='1' p=p+q else: q='0' p=p+q print(p) ```
3.98075
252
A
Little Xor
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, such that the *xor* of all numbers from this segment was maximal possible. Help him with that. ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains the space-separated integers from the array. All numbers are non-negative integers strictly less than 230.
Print a single integer — the required maximal *xor* of a segment of consecutive elements.
[ "5\n1 2 1 1 2\n", "3\n1 2 7\n", "4\n4 2 4 8\n" ]
[ "3\n", "7\n", "14\n" ]
In the first sample one of the optimal segments is the segment that consists of the first and the second array elements, if we consider the array elements indexed starting from one. The second sample contains only one optimal segment, which contains exactly one array element (element with index three).
500
[ { "input": "5\n1 2 1 1 2", "output": "3" }, { "input": "3\n1 2 7", "output": "7" }, { "input": "4\n4 2 4 8", "output": "14" }, { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "16\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15", "output": "15" }, { "inpu...
1,599,328,438
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
218
0
n=int(input()) a=list(map(int,input().split())) max=a[0] for i in range (n): k=a[i] if k>max: max=k for j in range (i,n): k=k^a[j] if k>max: max=k print(max)
Title: Little Xor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of *n* elements. Petya immediately decided to find there a segment of consecutive elements, ...
```python n=int(input()) a=list(map(int,input().split())) max=a[0] for i in range (n): k=a[i] if k>max: max=k for j in range (i,n): k=k^a[j] if k>max: max=k print(max) ```
0
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ...
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,680,642,402
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n, a, b = map(int, input().split()) complexities = list(map(int, input().split())) count = 0 for x in range(1, max(complexities)+1): A_tasks = [task for task in complexities if task >= x] B_tasks = [task for task in complexities if task <= x] if len(A_tasks) == a and len(B_tasks) == b: co...
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th...
```python n, a, b = map(int, input().split()) complexities = list(map(int, input().split())) count = 0 for x in range(1, max(complexities)+1): A_tasks = [task for task in complexities if task >= x] B_tasks = [task for task in complexities if task <= x] if len(A_tasks) == a and len(B_tasks) == b: ...
0
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. W...
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output":...
1,505,656,462
2,961
Python 3
RUNTIME_ERROR
PRETESTS
0
46
0
def lcm(a,b): m = a*b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a+b) x = int(input()) y = int(input()) a= 1 for i in range(0,y): a *= 10 print(str(lcm(x,a)))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000....
```python def lcm(a,b): m = a*b while a != 0 and b != 0: if a > b: a %= b else: b %= a return m // (a+b) x = int(input()) y = int(input()) a= 1 for i in range(0,y): a *= 10 print(str(lcm(x,a))) ```
-1
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,644,645,094
2,147,483,647
PyPy 3-64
OK
TESTS
34
78
614,400
import sys input = sys.stdin.readline N, x = map(int, input().split()) COMMANDS = [input().split() for _ in range(N)] ds = 0 for command in COMMANDS : action, amount = command amount = int(amount) if action == "+" : x += amount else : if x < amount : ds += 1 else : x -= amount print(x, ds)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python import sys input = sys.stdin.readline N, x = map(int, input().split()) COMMANDS = [input().split() for _ in range(N)] ds = 0 for command in COMMANDS : action, amount = command amount = int(amount) if action == "+" : x += amount else : if x < amount : ds += 1 else : x -= amount print(x, d...
3
161
A
Dress'em in Vests!
PROGRAMMING
1,300
[ "binary search", "brute force", "greedy", "two pointers" ]
null
null
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him...
The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i...
In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests. In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are ...
[ "5 3 0 0\n1 2 3 3 4\n1 3 5\n", "3 3 2 2\n1 5 9\n3 5 7\n" ]
[ "2\n1 1\n3 2\n", "3\n1 1\n2 2\n3 3\n" ]
In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one. In the second sample the vest size can differ...
1,000
[ { "input": "5 3 0 0\n1 2 3 3 4\n1 3 5", "output": "2\n1 1\n3 2" }, { "input": "3 3 2 2\n1 5 9\n3 5 7", "output": "3\n1 1\n2 2\n3 3" }, { "input": "1 1 0 0\n1\n1", "output": "1\n1 1" }, { "input": "1 1 0 0\n1\n2", "output": "0" }, { "input": "2 3 1 4\n1 5\n1 2 2", ...
1,696,736,578
2,147,483,647
PyPy 3
OK
TESTS
84
842
15,564,800
def tolerance_test(s, v, x, y): if(v >= s-x and v <= s+y): return True return False n, m, x, y = tuple([int(x) for x in input().split()]) soldiers = [int(x) for x in input().split()] vests = [int(x) for x in input().split()] count = 0 s_p = 0 v_p = 0 indices_store = [] while(s_p < len(soldiers) and v_p < len(vests...
Title: Dress'em in Vests! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the s...
```python def tolerance_test(s, v, x, y): if(v >= s-x and v <= s+y): return True return False n, m, x, y = tuple([int(x) for x in input().split()]) soldiers = [int(x) for x in input().split()] vests = [int(x) for x in input().split()] count = 0 s_p = 0 v_p = 0 indices_store = [] while(s_p < len(soldiers) and v_p <...
3
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ...
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "ou...
1,696,468,593
2,147,483,647
Python 3
OK
TESTS
36
92
0
import sys n=int(input()) b={4,7,44,77,47,74,444,777,744,474,447,477,747,774} for i in b: if n%i==0: print("YES") sys.exit() print("NO")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python import sys n=int(input()) b={4,7,44,77,47,74,444,777,744,474,447,477,747,774} for i in b: if n%i==0: print("YES") sys.exit() print("NO") ```
3
965
C
Greedy Arkady
PROGRAMMING
2,000
[ "math" ]
null
null
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ...
The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ...
Print a single integer — the maximum possible number of candies Arkady can give to himself. Note that it is always possible to choose some valid $x$.
[ "20 4 5 2\n", "30 9 4 1\n" ]
[ "8\n", "4\n" ]
In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total...
1,500
[ { "input": "20 4 5 2", "output": "8" }, { "input": "30 9 4 1", "output": "4" }, { "input": "2 2 1 1", "output": "1" }, { "input": "42 20 5 29", "output": "5" }, { "input": "1000000000000000000 135 1000000000000000 1000", "output": "8325624421831635" }, { ...
1,530,523,712
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
77
0
import sys from math import ceil, floor args = [int(x) for x in input().split(' ')] n = args[0] k = args[1] M = args[2] D = args[3] m = 0 argmin = 0 for x in range(ceil(n/(k*D)),M+1): bonbons = x*ceil(n/(k*x)) #print('x = ',x, ', bonbons = ',bonbons) if bonbons > m : argmin = x m = bonbons ...
Title: Greedy Arkady Time Limit: None seconds Memory Limit: None megabytes Problem Description: $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka...
```python import sys from math import ceil, floor args = [int(x) for x in input().split(' ')] n = args[0] k = args[1] M = args[2] D = args[3] m = 0 argmin = 0 for x in range(ceil(n/(k*D)),M+1): bonbons = x*ceil(n/(k*x)) #print('x = ',x, ', bonbons = ',bonbons) if bonbons > m : argmin = x m ...
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,590,224,262
2,147,483,647
Python 3
OK
TESTS
30
218
0
s=input() c='' flag1,flag2=0,0 for i in s: if(i.isupper()): flag1+=1 else: flag2+=1 if(flag1==flag2): for i in s: c+=i.lower() elif(flag1>flag2): for i in s: c+=i.upper() else: for i in s: c+=i.lower() print(c)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() c='' flag1,flag2=0,0 for i in s: if(i.isupper()): flag1+=1 else: flag2+=1 if(flag1==flag2): for i in s: c+=i.lower() elif(flag1>flag2): for i in s: c+=i.upper() else: for i in s: c+=i.lower() print(c) ...
3.9455
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,573,969,182
2,147,483,647
PyPy 3
OK
TESTS
35
156
0
n = int(input()) lst = sorted(list(map(int, input().split()))) mid = (n-1)//2 print(lst[mid])
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python n = int(input()) lst = sorted(list(map(int, input().split()))) mid = (n-1)//2 print(lst[mid]) ```
3
416
B
Art Union
PROGRAMMING
1,300
[ "brute force", "dp", "implementation" ]
null
null
A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color...
The first line of the input contains integers *m*,<=*n* (1<=≤<=*m*<=≤<=50000,<=1<=≤<=*n*<=≤<=5), where *m* is the number of pictures and *n* is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains *n* integers *t**i*1,<=*t**i*2,<=...,<=*t**in* (1<=≤<=*t**ij*<=≤<=1000), ...
Print the sequence of *m* integers *r*1,<=*r*2,<=...,<=*r**m*, where *r**i* is the moment when the *n*-th painter stopped working on the *i*-th picture.
[ "5 1\n1\n2\n3\n4\n5\n", "4 2\n2 5\n3 1\n5 3\n10 1\n" ]
[ "1 3 6 10 15 ", "7 8 13 21 " ]
none
1,000
[ { "input": "5 1\n1\n2\n3\n4\n5", "output": "1 3 6 10 15 " }, { "input": "4 2\n2 5\n3 1\n5 3\n10 1", "output": "7 8 13 21 " }, { "input": "1 1\n66", "output": "66 " }, { "input": "2 2\n1 1\n1 1", "output": "2 3 " }, { "input": "2 2\n10 1\n10 1", "output": "11 2...
1,685,669,418
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
m, n = [int(x) for x in input().split()] t = [[0]*n for _ in range(m)] for i in range(m): t[i] = [int(x) for x in input().split()] dp = [[0]*n for _ in range(m)] for i in range(m): for j in range(n): if i > 0: dp[i][j] = dp[i-1][j] if j > 0: dp[i][j] = dp[i]...
Title: Art Union Time Limit: None seconds Memory Limit: None megabytes Problem Description: A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of *n* painters who decided to organize their work as follows. Each painter uses only the color that was assigned t...
```python m, n = [int(x) for x in input().split()] t = [[0]*n for _ in range(m)] for i in range(m): t[i] = [int(x) for x in input().split()] dp = [[0]*n for _ in range(m)] for i in range(m): for j in range(n): if i > 0: dp[i][j] = dp[i-1][j] if j > 0: dp[i][...
0
298
A
Snow Footprints
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave...
The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=1000). The second line contains the description of the road — the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's gu...
Print two space-separated integers — the values of *s* and *t*. If there are several possible solutions you can print any of them.
[ "9\n..RRLL...\n", "11\n.RRRLLLLL..\n" ]
[ "3 4\n", "7 5\n" ]
The first test sample is the one in the picture.
500
[ { "input": "11\n.RRRLLLLL..", "output": "7 5" }, { "input": "4\n.RL.", "output": "3 2" }, { "input": "3\n.L.", "output": "2 1" }, { "input": "3\n.R.", "output": "2 3" } ]
1,678,128,968
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n = int(input()) l = list(input()) s = 0 t = 0 r = True for i in range(0,n-1): if l[i]!="." and r: s = i+1 r = False elif l[i]==".": t = i if l[s] == "R" and l[t] == "R": print(s,t) r = True elif l[s] == "L" and l[t] == "L": print(t,s) r = True elif not r...
Title: Snow Footprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *...
```python n = int(input()) l = list(input()) s = 0 t = 0 r = True for i in range(0,n-1): if l[i]!="." and r: s = i+1 r = False elif l[i]==".": t = i if l[s] == "R" and l[t] == "R": print(s,t) r = True elif l[s] == "L" and l[t] == "L": print(t,s) r = True ...
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,675,764,239
2,147,483,647
Python 3
OK
TESTS
83
46
0
# LUOGU_RID: 101647844 n, k = map(int, input().split()) s = input() x = s.find('G') y = s.find('T') print(((y - x) % k == 0 and s[x:y:k].find('#') == -1 and s[x:y:-k].find('#') == -1) and 'YES' or 'NO')
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 # LUOGU_RID: 101647844 n, k = map(int, input().split()) s = input() x = s.find('G') y = s.find('T') print(((y - x) % k == 0 and s[x:y:k].find('#') == -1 and s[x:y:-k].find('#') == -1) and 'YES' or 'NO') ```
3
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and...
The first line of the input contains a single integer *l* (1<=≤<=*l*<=≤<=1<=000) — the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≤<=*p*,<=*q*<=≤<=500) — the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ...
Print a single real number — the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer ...
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n...
1,455,808,287
2,147,483,647
PyPy 3
OK
TESTS
45
109
0
m=input() l=int(m) n=input() p=int(n) o=input() q=int(o) a=l/(p+q) print(a*p) print("\n")
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en...
```python m=input() l=int(m) n=input() p=int(n) o=input() q=int(o) a=l/(p+q) print(a*p) print("\n") ```
3
322
B
Ciel and Flowers
PROGRAMMING
1,600
[ "combinatorics", "math" ]
null
null
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3...
The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers.
Print the maximal number of bouquets Fox Ciel can make.
[ "3 6 9\n", "4 4 4\n", "0 0 0\n" ]
[ "6\n", "4\n", "0\n" ]
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets. In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
1,000
[ { "input": "3 6 9", "output": "6" }, { "input": "4 4 4", "output": "4" }, { "input": "0 0 0", "output": "0" }, { "input": "0 3 6", "output": "3" }, { "input": "7 8 9", "output": "7" }, { "input": "8 8 9", "output": "8" }, { "input": "15 3 9...
1,373,733,688
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
33
78
102,400
s = input() r,g,b = map(int,s.split()) print(max([i+(r-i)//3+(g-i)//3+(b-i)//3 for i in range(3)]))
Title: Ciel and Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: - To make a "red bouquet", it needs 3 red fl...
```python s = input() r,g,b = map(int,s.split()) print(max([i+(r-i)//3+(g-i)//3+(b-i)//3 for i in range(3)])) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,617,276,314
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
0
first_num=int(input("")) second_num=int(input("")) if first_num == 1 and second_num ==2: print(first_num) elif first_num == 1 : print(second_num//2) elif second_num ==2 : print(first_num) else: print(first_num//2 + second_num)
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 first_num=int(input("")) second_num=int(input("")) if first_num == 1 and second_num ==2: print(first_num) elif first_num == 1 : print(second_num//2) elif second_num ==2 : print(first_num) else: print(first_num//2 + second_num) ```
-1
559
B
Equivalent Strings
PROGRAMMING
1,700
[ "divide and conquer", "hashing", "sortings", "strings" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equival...
1,000
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { ...
1,591,515,239
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
88
2,000
1,638,400
a = input() b = input() def judge(left, right): if left == right: return 1 n = len(left) if n % 2: return 0 mid = n//2 l1 = left[:mid] l2 = left[mid:] r1 = right[:mid] r2 = right[mid:] if (judge(l1, r1) and judge(l2, r2)) or (judge(l1, r2) and judge(l2, r1)): ...
Title: Equivalent Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split str...
```python a = input() b = input() def judge(left, right): if left == right: return 1 n = len(left) if n % 2: return 0 mid = n//2 l1 = left[:mid] l2 = left[mid:] r1 = right[:mid] r2 = right[mid:] if (judge(l1, r1) and judge(l2, r2)) or (judge(l1, r2) and judge(l2, r1...
0
331
C1
The Great Julya Calendar
PROGRAMMING
1,100
[ "dp" ]
null
null
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open ...
The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co...
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
[ "24\n" ]
[ "5" ]
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
20
[ { "input": "24", "output": "5" }, { "input": "0", "output": "0" }, { "input": "3", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "2" }, { "input": "31", "output": "6" }, ...
1,575,239,222
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS1
12
496
6,553,600
# https://codeforces.com/problemset/problem/331/C1 import math def to_digits(n): return [int(d) for d in str(n)] def to_integer(digits): accum = 0 factor = 1 for d in reversed(digits): accum += factor * d factor *= 10 return accum def split(digits): d = 0 index = 0 ...
Title: The Great Julya Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i...
```python # https://codeforces.com/problemset/problem/331/C1 import math def to_digits(n): return [int(d) for d in str(n)] def to_integer(digits): accum = 0 factor = 1 for d in reversed(digits): accum += factor * d factor *= 10 return accum def split(digits): d = 0 in...
-1
758
B
Blown Garland
PROGRAMMING
1,100
[ "brute force", "implementation", "number theory" ]
null
null
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is workin...
The first and the only line contains the string *s* (4<=≤<=|*s*|<=≤<=100), which describes the garland, the *i*-th symbol of which describes the color of the *i*-th light bulb in the order from the beginning of garland: - 'R' — the light bulb is red, - 'B' — the light bulb is blue, - 'Y' — the light bulb is yellow...
In the only line print four integers *k**r*,<=*k**b*,<=*k**y*,<=*k**g* — the number of dead light bulbs of red, blue, yellow and green colors accordingly.
[ "RYBGRYBGR\n", "!RGYB\n", "!!!!YGRB\n", "!GB!RG!Y!\n" ]
[ "0 0 0 0", "0 1 0 0", "1 1 1 1", "2 1 1 0" ]
In the first example there are no dead light bulbs. In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.
1,000
[ { "input": "RYBGRYBGR", "output": "0 0 0 0" }, { "input": "!RGYB", "output": "0 1 0 0" }, { "input": "!!!!YGRB", "output": "1 1 1 1" }, { "input": "!GB!RG!Y!", "output": "2 1 1 0" }, { "input": "RYBG", "output": "0 0 0 0" }, { "input": "!Y!!!Y!!G!!!G!!...
1,694,521,374
2,147,483,647
PyPy 3-64
OK
TESTS
65
62
0
s = input() ans = "" for j in range(4): for i in s[j::4]: if i!='!': ans += i break arr = {} arr['R'] = 0 arr['B'] = 0 arr['Y'] = 0 arr['G'] = 0 for j in range(4): for i in s[j::4]: if i=='!': arr[ans[j]] += 1 for i in "RBYG": pri...
Title: Blown Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland. Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for ...
```python s = input() ans = "" for j in range(4): for i in s[j::4]: if i!='!': ans += i break arr = {} arr['R'] = 0 arr['B'] = 0 arr['Y'] = 0 arr['G'] = 0 for j in range(4): for i in s[j::4]: if i=='!': arr[ans[j]] += 1 for i in "RBYG"...
3
339
D
Xenia and Bit Operations
PROGRAMMING
1,700
[ "data structures", "trees" ]
null
null
Xenia the beginner programmer has a sequence *a*, consisting of 2*n* non-negative integers: *a*1,<=*a*2,<=...,<=*a*2*n*. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value *v* for *a*. Namely, it takes several iterations to calculate value *v*. At the ...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=17,<=1<=≤<=*m*<=≤<=105). The next line contains 2*n* integers *a*1,<=*a*2,<=...,<=*a*2*n* (0<=≤<=*a**i*<=&lt;<=230). Each of the next *m* lines contains queries. The *i*-th line contains integers *p**i*,<=*b**i* (1<=≤<=*p**i*<=≤<=2*n*,<=0<=≤<=*b**i*<=&lt;<...
Print *m* integers — the *i*-th integer denotes value *v* for sequence *a* after the *i*-th query.
[ "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n" ]
[ "1\n3\n3\n3\n" ]
For more information on the bit operations, you can follow this link: http://en.wikipedia.org/wiki/Bitwise_operation
2,000
[ { "input": "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2", "output": "1\n3\n3\n3" }, { "input": "1 1\n1 1\n1 1", "output": "1" }, { "input": "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31", "output": "27\n27\n31\n26\n14\n12\n10\n12\n26\n31" }, { "input": "1 10\n22 1...
1,695,141,771
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
19
2,000
19,251,200
import sys;input=sys.stdin.readline n,m=map(int,input().split()) a=[*map(int,input().split())] n=2**n tree=[0]*4*n def build(v,tl,tr): if tl==tr:tree[v]=a[tl];return 0 tm=tl+tr>>1 t=build(v*2,tl,tm)^1 build(v*2+1,tm+1,tr) if t:tree[v]=tree[v*2]|tree[v*2+1] else:tree[v]=tree[v*2]^tree[...
Title: Xenia and Bit Operations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner programmer has a sequence *a*, consisting of 2*n* non-negative integers: *a*1,<=*a*2,<=...,<=*a*2*n*. Xenia is currently studying bit operations. To better understand how they work, Xenia dec...
```python import sys;input=sys.stdin.readline n,m=map(int,input().split()) a=[*map(int,input().split())] n=2**n tree=[0]*4*n def build(v,tl,tr): if tl==tr:tree[v]=a[tl];return 0 tm=tl+tr>>1 t=build(v*2,tl,tm)^1 build(v*2+1,tm+1,tr) if t:tree[v]=tree[v*2]|tree[v*2+1] else:tree[v]=tree[...
0
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≤<=*x*1,<=*x*2,<=*x*3<=≤<=100) — the coordinates of the houses of the first, the second and the third friends respectively.
Print one integer — the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,675,218,985
2,147,483,647
Python 3
OK
TESTS
48
62
0
x = list(map(int, input().split())) maxi = max(x) x.remove(maxi) mini = min(x) x.remove(mini) result = maxi - x[0] result += x[0] - mini print(result)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python x = list(map(int, input().split())) maxi = max(x) x.remove(maxi) mini = min(x) x.remove(mini) result = maxi - x[0] result += x[0] - mini print(result) ```
3
518
A
Vitaly and Strings
PROGRAMMING
1,600
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and str...
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ...
500
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "inp...
1,608,109,682
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
8
140
0
s=list(input()) s1=list(input()) ans = "No such string" r=0 for i in range(len(s)): if s[i]!=s1[i]: r+=1 for i in range(len(s)): if ord(s[i])+1<ord(s1[i]): ans = ''.join(s[:i]) + chr(ord(s[i])+1) + ''.join(s[i+1:]) break elif ord(s[i])+1==ord(s1[i]) and r>1: ans = ''.join(s[:...
Title: Vitaly and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provi...
```python s=list(input()) s1=list(input()) ans = "No such string" r=0 for i in range(len(s)): if s[i]!=s1[i]: r+=1 for i in range(len(s)): if ord(s[i])+1<ord(s1[i]): ans = ''.join(s[:i]) + chr(ord(s[i])+1) + ''.join(s[i+1:]) break elif ord(s[i])+1==ord(s1[i]) and r>1: ans = '...
0
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,698,007,154
2,147,483,647
Python 3
OK
TESTS
34
46
0
x = int(input()) p = x//5 + (x % 5)//4 + (x % 5 % 4)//3 + (x % 5 % 4 % 3)//2 + (x % 5 % 4 % 3 % 2) print(p)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x = int(input()) p = x//5 + (x % 5)//4 + (x % 5 % 4)//3 + (x % 5 % 4 % 3)//2 + (x % 5 % 4 % 3 % 2) print(p) ```
3
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,697,527,281
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
30
0
s=input() a=s[0]+s[1:].upper() if len(s)==1: print(s.upper()) elif s==s.lower() or s==s.capitalize() and len(s)>1: print(s) elif s==s.upper(): print(s.lower()) elif s==a: print(s.capitalize()) else: print(s)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python s=input() a=s[0]+s[1:].upper() if len(s)==1: print(s.upper()) elif s==s.lower() or s==s.capitalize() and len(s)>1: print(s) elif s==s.upper(): print(s.lower()) elif s==a: print(s.capitalize()) else: print(s) ```
0
833
A
The Meaningless Game
PROGRAMMING
1,700
[ "math", "number theory" ]
null
null
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's score is...
In the first string, the number of games *n* (1<=≤<=*n*<=≤<=350000) is given. Each game is represented by a pair of scores *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) – the results of Slastyona and Pushok, correspondingly.
For each pair of scores, answer "Yes" if it's possible for a game to finish with given score, and "No" otherwise. You can output each letter in arbitrary case (upper or lower).
[ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n" ]
[ "Yes\nYes\nYes\nNo\nNo\nYes\n" ]
First game might have been consisted of one round, in which the number 2 would have been chosen and Pushok would have won. The second game needs exactly two rounds to finish with such result: in the first one, Slastyona would have said the number 5, and in the second one, Pushok would have barked the number 3.
500
[ { "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes" }, { "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\nNo\nNo" }, { "input": "1\n12004 18012002", "output": "Yes" }, { "input": "1\n3331 11095561", "output": "Yes...
1,626,396,955
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
108
21,606,400
import math t = int(input()) def primefac(n): pf = [] while not n % 2: n //= 2 pf.append(2) for i in range(3, int(math.sqrt(n))+1, 2): while not n % i: n //= i pf.append(i) if n > 2: pf.append(n) occ = {} for i...
Title: The Meaningless Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Th...
```python import math t = int(input()) def primefac(n): pf = [] while not n % 2: n //= 2 pf.append(2) for i in range(3, int(math.sqrt(n))+1, 2): while not n % i: n //= i pf.append(i) if n > 2: pf.append(n) occ = {} ...
0
609
A
USB Flash Drives
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives.
The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives. The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt...
Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives.
[ "3\n5\n2\n1\n3\n", "3\n6\n2\n3\n2\n", "2\n5\n5\n10\n" ]
[ "2\n", "3\n", "1\n" ]
In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second.
0
[ { "input": "3\n5\n2\n1\n3", "output": "2" }, { "input": "3\n6\n2\n3\n2", "output": "3" }, { "input": "2\n5\n5\n10", "output": "1" }, { "input": "5\n16\n8\n1\n3\n4\n9", "output": "2" }, { "input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "output": "2" ...
1,621,317,603
2,147,483,647
Python 3
OK
TESTS
34
62
0
n=int(input()) m=int(input()) a=[] for i in range(n): a.append(int(input())) a=list(sorted(a)) a=a[::-1] su=0 for i in range(n): su+=a[i] if su>=m: print(i+1) break
Title: USB Flash Drives Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of...
```python n=int(input()) m=int(input()) a=[] for i in range(n): a.append(int(input())) a=list(sorted(a)) a=a[::-1] su=0 for i in range(n): su+=a[i] if su>=m: print(i+1) break ```
3
678
B
The Same Calendar
PROGRAMMING
1,600
[ "implementation" ]
null
null
The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next year after *y* when the calendar will be exactly the same. Help ...
The only line contains integer *y* (1000<=≤<=*y*<=&lt;<=100'000) — the year of the calendar.
Print the only integer *y*' — the next year after *y* when the calendar will be the same. Note that you should find the first year after *y* with the same calendar.
[ "2016\n", "2000\n", "50501\n" ]
[ "2044\n", "2028\n", "50507\n" ]
Today is Monday, the 13th of June, 2016.
0
[ { "input": "2016", "output": "2044" }, { "input": "2000", "output": "2028" }, { "input": "50501", "output": "50507" }, { "input": "1000", "output": "1006" }, { "input": "1900", "output": "1906" }, { "input": "1899", "output": "1905" }, { "i...
1,507,027,805
2,147,483,647
Python 3
OK
TESTS
40
77
512,000
import datetime y=int(input()) y_temp=y%400 if y_temp==0: print(y+28) else: y_2_28=datetime.datetime(y_temp,2,28).weekday() y_3_1=datetime.datetime(y_temp,3,1).weekday() count=1 while datetime.datetime(y_temp+count,2,28).weekday()!=y_2_28 or datetime.datetime(y_temp+count,3,1).weekday()!=y_3_1: cou...
Title: The Same Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: The girl Taylor has a beautiful calendar for the year *y*. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful t...
```python import datetime y=int(input()) y_temp=y%400 if y_temp==0: print(y+28) else: y_2_28=datetime.datetime(y_temp,2,28).weekday() y_3_1=datetime.datetime(y_temp,3,1).weekday() count=1 while datetime.datetime(y_temp+count,2,28).weekday()!=y_2_28 or datetime.datetime(y_temp+count,3,1).weekday()!=y_3...
3
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t...
Print a single number — the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ...
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10...
1,697,527,821
2,147,483,647
Python 3
OK
TESTS
67
280
18,227,200
n=int(input()) li=[[int(j) for j in input().split()] for _ in range(n)] ans=2 for i in range(1,n-1): x,h=li[i][0],li[i][1] if x-li[i-1][0]>h: ans+=1 elif x+h<li[i+1][0]: ans+=1 li[i][0]+=h print(ans if n>1 else 1)
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b...
```python n=int(input()) li=[[int(j) for j in input().split()] for _ in range(n)] ans=2 for i in range(1,n-1): x,h=li[i][0],li[i][1] if x-li[i-1][0]>h: ans+=1 elif x+h<li[i+1][0]: ans+=1 li[i][0]+=h print(ans if n>1 else 1) ```
3
305
A
Strange Addition
PROGRAMMING
1,600
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choo...
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
[ "4\n100 10 1 0\n", "3\n2 70 3\n" ]
[ "4\n0 1 10 100 ", "2\n2 70 " ]
none
500
[ { "input": "4\n100 10 1 0", "output": "4\n0 1 10 100 " }, { "input": "3\n2 70 3", "output": "2\n2 70 " }, { "input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29", "output": "4\n0 6 30 100 " }, { "inp...
1,530,469,596
2,147,483,647
Python 3
OK
TESTS
35
218
0
n = int(input().strip()) lst = list(map(int, input().strip().split())) l1 = ['0']*lst.count(0) + ['100']*lst.count(100) l2 = [] for i in range(n): if lst[i] > 0 and lst[i] < 10: l2.append(str(lst[i])) break l3 = [] for i in range(n): if lst[i] % 10 == 0 and lst[i] not in [0, 100]: ...
Title: Strange Addition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. ...
```python n = int(input().strip()) lst = list(map(int, input().strip().split())) l1 = ['0']*lst.count(0) + ['100']*lst.count(100) l2 = [] for i in range(n): if lst[i] > 0 and lst[i] < 10: l2.append(str(lst[i])) break l3 = [] for i in range(n): if lst[i] % 10 == 0 and lst[i] not in [0, ...
3
39
D
Cubical Planet
PROGRAMMING
1,100
[ "math" ]
D. Cubical Planet
2
64
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the mom...
The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.
Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".
[ "0 0 0\n0 1 0\n", "1 1 0\n0 1 0\n", "0 0 0\n1 1 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
0
[ { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "0 0 0\n1 0 0", "output": "YES" }, { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 ...
1,566,260,487
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
248
0
readints = lambda: map(int, input().split(' ')) a,b,c=readints() x,y,z=readints() if a!=x and b!=y and c!=c: print('NO') else: print('YES')
Title: Cubical Planet Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite v...
```python readints = lambda: map(int, input().split(' ')) a,b,c=readints() x,y,z=readints() if a!=x and b!=y and c!=c: print('NO') else: print('YES') ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,523,113,157
2,147,483,647
Python 3
OK
TESTS
30
184
7,065,600
s = input() u = d = 0 for i in s: if i == i.upper(): u += 1 else: d += 1 print(s.upper() if u > d else s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s = input() u = d = 0 for i in s: if i == i.upper(): u += 1 else: d += 1 print(s.upper() if u > d else s.lower()) ```
3.940839
285
C
Building Permutation
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. You ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105) — the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109).
Print a single number — the minimum number of moves. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "2\n3 0\n", "3\n-1 -1 2\n" ]
[ "2\n", "6\n" ]
In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2, 1). In the second sample you need 6 moves to build permutation (1, 3, 2).
1,500
[ { "input": "2\n3 0", "output": "2" }, { "input": "3\n-1 -1 2", "output": "6" }, { "input": "5\n-3 5 -3 3 3", "output": "10" }, { "input": "10\n9 6 -2 4 1 1 1 9 6 2", "output": "18" }, { "input": "9\n2 0 0 6 5 4 1 9 3", "output": "15" }, { "input": "100...
1,486,359,916
2,147,483,647
Python 3
OK
TESTS
33
996
29,286,400
n = int(input()) l = list(map(int, input().split())) l.sort() res = 0 for i in range(1, n + 1): res += abs(i - l[i-1]) print(res)
Title: Building Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *...
```python n = int(input()) l = list(map(int, input().split())) l.sort() res = 0 for i in range(1, n + 1): res += abs(i - l[i-1]) print(res) ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,689,605,178
2,147,483,647
PyPy 3
OK
TESTS
31
184
0
import sys input = sys.stdin.readline print = sys.stdout.write n = int(input()) s = sum(list(map(int,input().split()))) ans = s / n print("%f" %ans)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python import sys input = sys.stdin.readline print = sys.stdout.write n = int(input()) s = sum(list(map(int,input().split()))) ans = s / n print("%f" %ans) ```
3
296
A
Yaroslav and Permutations
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements.
In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.
[ "1\n1\n", "3\n1 1 2\n", "4\n7 7 7 7\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample the initial array fits well. In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it. In the third sample Yarosav can't get the array he needs.
500
[ { "input": "1\n1", "output": "YES" }, { "input": "3\n1 1 2", "output": "YES" }, { "input": "4\n7 7 7 7", "output": "NO" }, { "input": "4\n479 170 465 146", "output": "YES" }, { "input": "5\n996 437 605 996 293", "output": "YES" }, { "input": "6\n727 53...
1,615,451,175
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
409,600
n = int(input()) arr = list(map(int, input().split())) if len(arr) < 2: print("YES") else: from collections import Counter d = Counter(arr) if d.most_common(1)[0][1] > len(arr)//2: print("NO") else: print("YES")
Title: Yaroslav and Permutations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would...
```python n = int(input()) arr = list(map(int, input().split())) if len(arr) < 2: print("YES") else: from collections import Counter d = Counter(arr) if d.most_common(1)[0][1] > len(arr)//2: print("NO") else: print("YES") ```
0
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must...
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "outpu...
1,696,255,049
2,147,483,647
PyPy 3
OK
TESTS
25
93
0
#python 3.7.1 cube = int(input()) Sum = 0 level=1 all_need=0 while( all_need < cube): Sum +=level level +=1 all_need += Sum if(all_need == cube): print(level-1) else: print(level-2)
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t...
```python #python 3.7.1 cube = int(input()) Sum = 0 level=1 all_need=0 while( all_need < cube): Sum +=level level +=1 all_need += Sum if(all_need == cube): print(level-1) else: print(level-2) ```
3
757
A
Gotta Catch Em' All!
PROGRAMMING
1,000
[ "implementation" ]
null
null
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*. The string *s* contains lowercase and uppercase English letters, i.e. .
Output a single integer, the answer to the problem.
[ "Bulbbasaur\n", "F\n", "aBddulbasaurrgndgbualdBdsagaurrgndbb\n" ]
[ "1\n", "0\n", "2\n" ]
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
500
[ { "input": "Bulbbasaur", "output": "1" }, { "input": "F", "output": "0" }, { "input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2" }, { "input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "output": "5" }, { "input": "BBBBBBB...
1,485,807,057
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
62
4,608,000
spisok = [str(x) for x in input()] number_B = spisok.count('B') number_b = spisok.count('b') number_l = spisok.count('l') number_a = spisok.count('a') number_s = spisok.count('s') number_u = spisok.count('u') number_r = spisok.count('r') letters1 = [number_B, number_l, number_b, number_s, number_r] letters2 = ...
Title: Gotta Catch Em' All! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess...
```python spisok = [str(x) for x in input()] number_B = spisok.count('B') number_b = spisok.count('b') number_l = spisok.count('l') number_a = spisok.count('a') number_s = spisok.count('s') number_u = spisok.count('u') number_r = spisok.count('r') letters1 = [number_B, number_l, number_b, number_s, number_r] l...
0
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to ze...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", ...
1,619,733,052
2,147,483,647
PyPy 3
OK
TESTS
79
171
9,420,800
import sys def main(): s = set(sys.stdin.read().strip().split()[1:]) s.discard('0') return len(s) print(main())
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second ...
```python import sys def main(): s = set(sys.stdin.read().strip().split()[1:]) s.discard('0') return len(s) print(main()) ```
3
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "i...
1,559,205,556
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
109
0
def sum_digits(x): res = 0 while x > 0: res += x % 10 x //= 10 return res n = int(input()) res = [] for i in range(1, 82): if n - i + sum_digits(n-i) == n: res.append(n-i) print(len(res)) print(*res)
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answe...
```python def sum_digits(x): res = 0 while x > 0: res += x % 10 x //= 10 return res n = int(input()) res = [] for i in range(1, 82): if n - i + sum_digits(n-i) == n: res.append(n-i) print(len(res)) print(*res) ```
0
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest in...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000...
1,563,041,870
470
PyPy 3
WRONG_ANSWER
TESTS
3
124
0
import math p=input().rstrip().split(' ') print(math.gcd(int(p[0]),int(p[1])))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre...
```python import math p=input().rstrip().split(' ') print(math.gcd(int(p[0]),int(p[1]))) ```
0
230
A
Dragons
PROGRAMMING
1,000
[ "greedy", "sortings" ]
null
null
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirit...
The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it.
On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't.
[ "2 2\n1 99\n100 0\n", "10 1\n100 100\n" ]
[ "YES\n", "NO\n" ]
In the first sample Kirito's strength initially equals 2. As the first dragon's strength is less than 2, Kirito can fight it and defeat it. After that he gets the bonus and his strength increases to 2 + 99 = 101. Now he can defeat the second dragon and move on to the next level. In the second sample Kirito's strength ...
500
[ { "input": "2 2\n1 99\n100 0", "output": "YES" }, { "input": "10 1\n100 100", "output": "NO" }, { "input": "123 2\n78 10\n130 0", "output": "YES" }, { "input": "999 2\n1010 10\n67 89", "output": "YES" }, { "input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "output": "YE...
1,697,838,621
2,147,483,647
Python 3
OK
TESTS
54
92
0
s, n = map(int, input().split()) dragons = [] for _ in range(n): x, y = map(int, input().split()) dragons.append((x, y)) dragons.sort() # Sort dragons based on their strength for dragon in dragons: if s > dragon[0]: s += dragon[1] else: print("NO") exit(0) print("YES") ...
Title: Dragons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the du...
```python s, n = map(int, input().split()) dragons = [] for _ in range(n): x, y = map(int, input().split()) dragons.append((x, y)) dragons.sort() # Sort dragons based on their strength for dragon in dragons: if s > dragon[0]: s += dragon[1] else: print("NO") exit(0) print("Y...
3
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,685,440,536
2,147,483,647
Python 3
OK
TESTS
159
405
18,227,200
n, m = map(int, input().split()) base_sold, gains = [], [] for _ in range(n): k, l = map(int, input().split()) gain = min(k*2, l) - min(k, l) gains.append(gain) base_sold.append(min(k, l)) targ = sorted(zip(gains, base_sold), reverse=True) ans = 0 for i in range(n): if i < m: ans += targ[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 n, m = map(int, input().split()) base_sold, gains = [], [] for _ in range(n): k, l = map(int, input().split()) gain = min(k*2, l) - min(k, l) gains.append(gain) base_sold.append(min(k, l)) targ = sorted(zip(gains, base_sold), reverse=True) ans = 0 for i in range(n): if i < m: ans...
3
596
B
Wilbur and Array
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109).
Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*.
[ "5\n1 2 3 4 5\n", "4\n1 2 2 1\n" ]
[ "5", "3" ]
In the first sample, Wilbur may successively choose indices 1, 2, 3, 4, and 5, and add 1 to corresponding suffixes. In the second sample, Wilbur first chooses indices 1 and 2 and adds 1 to corresponding suffixes, then he chooses index 4 and subtract 1.
1,000
[ { "input": "5\n1 2 3 4 5", "output": "5" }, { "input": "4\n1 2 2 1", "output": "3" }, { "input": "3\n1 2 4", "output": "4" }, { "input": "6\n1 2 3 6 5 4", "output": "8" }, { "input": "10\n2 1 4 3 6 5 8 7 10 9", "output": "19" }, { "input": "7\n12 6 12 ...
1,447,828,050
2,250
Python 3
WRONG_ANSWER
TESTS
3
61
0
n = int(input()) B = [int(x) for x in input().split(' ')] l = 0 t = 0 for b in B: t += abs(t-b) l = b print(t)
Title: Wilbur and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+...
```python n = int(input()) B = [int(x) for x in input().split(' ')] l = 0 t = 0 for b in B: t += abs(t-b) l = b print(t) ```
0
518
A
Vitaly and Strings
PROGRAMMING
1,600
[ "constructive algorithms", "strings" ]
null
null
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli...
The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and str...
If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them.
[ "a\nc\n", "aaa\nzzz\n", "abcdefg\nabcdefh\n" ]
[ "b\n", "kkk\n", "No such string\n" ]
String *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t* = *t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ...
500
[ { "input": "a\nc", "output": "b" }, { "input": "aaa\nzzz", "output": "kkk" }, { "input": "abcdefg\nabcdefh", "output": "No such string" }, { "input": "abcdefg\nabcfefg", "output": "abcdefh" }, { "input": "frt\nfru", "output": "No such string" }, { "inp...
1,540,460,569
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
s = input () t = input() def string (string1, string2): ans ="" for i in range (len(string1)): if ord(string2[i]) - ord(string1[i])>=2: ans += chr(ord(string1[i])+1) else: ans = "No such string" return ans print(string(s,t))
Title: Vitaly and Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provi...
```python s = input () t = input() def string (string1, string2): ans ="" for i in range (len(string1)): if ord(string2[i]) - ord(string1[i])>=2: ans += chr(ord(string1[i])+1) else: ans = "No such string" return ans print(string(s,t)) ```
0
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they shoul...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { ...
1,599,049,959
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
140
0
n=int(input()) s=input() ans=[] for i in s: if i=='1' or ans=='0' : continue if i=='4' : ans.append('3') ans.append('2') ans.append('2') elif i=='6' : ans.append('3') ans.append('2') ans.append('5') elif i=='8' : ans.append('...
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that cont...
```python n=int(input()) s=input() ans=[] for i in s: if i=='1' or ans=='0' : continue if i=='4' : ans.append('3') ans.append('2') ans.append('2') elif i=='6' : ans.append('3') ans.append('2') ans.append('5') elif i=='8' : an...
0
794
C
Naming Company
PROGRAMMING
1,800
[ "games", "greedy", "sortings" ]
null
null
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided to play a game. The company name will consist of *n* letters. Oleg and Igor ...
The first line of input contains a string *s* of length *n* (1<=≤<=*n*<=≤<=3·105). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially. The second line of input contains a string *t* of length *n*. All characters of the string are lowercase English lett...
The output should contain a string of *n* lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
[ "tinkoff\nzscoder\n", "xxxxxx\nxxxxxx\n", "ioi\nimo\n" ]
[ "fzfsirk\n", "xxxxxx\n", "ioi\n" ]
One way to play optimally in the first sample is as follows : - Initially, the company name is ???????.- Oleg replaces the first question mark with 'f'. The company name becomes f??????.- Igor replaces the second question mark with 'z'. The company name becomes fz?????.- Oleg replaces the third question mark with '...
1,750
[ { "input": "tinkoff\nzscoder", "output": "fzfsirk" }, { "input": "xxxxxx\nxxxxxx", "output": "xxxxxx" }, { "input": "ioi\nimo", "output": "ioi" }, { "input": "abc\naaa", "output": "aab" }, { "input": "reddit\nabcdef", "output": "dfdeed" }, { "input": "...
1,525,202,072
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
61
7,065,600
a = input() b = input() a_count = [a.count(chr(ord('a') + x)) for x in range(26)] b_count = [b.count(chr(ord('a') + x)) for x in range(26)] length = len(a) result = length * ['a'] left = 0 right = length - 1 i = 0 while i < length: mi, ma = 0, 25 while a_count[mi] == 0: mi = mi + 1 wh...
Title: Naming Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this p...
```python a = input() b = input() a_count = [a.count(chr(ord('a') + x)) for x in range(26)] b_count = [b.count(chr(ord('a') + x)) for x in range(26)] length = len(a) result = length * ['a'] left = 0 right = length - 1 i = 0 while i < length: mi, ma = 0, 25 while a_count[mi] == 0: mi = mi +...
0
305
A
Strange Addition
PROGRAMMING
1,600
[ "brute force", "constructive algorithms", "implementation" ]
null
null
Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of *k* distinct non-negative integers *d*1,<=*d*2,<=...,<=*d**k*. Vasya wants to choo...
The first input line contains integer *k* (1<=≤<=*k*<=≤<=100) — the number of integers. The second line contains *k* distinct space-separated integers *d*1,<=*d*2,<=...,<=*d**k* (0<=≤<=*d**i*<=≤<=100).
In the first line print a single integer *n* the maximum number of the chosen integers. In the second line print *n* distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order.
[ "4\n100 10 1 0\n", "3\n2 70 3\n" ]
[ "4\n0 1 10 100 ", "2\n2 70 " ]
none
500
[ { "input": "4\n100 10 1 0", "output": "4\n0 1 10 100 " }, { "input": "3\n2 70 3", "output": "2\n2 70 " }, { "input": "39\n16 72 42 70 17 36 32 40 47 94 27 30 100 55 23 77 67 28 49 50 53 83 38 33 60 65 62 64 6 66 69 86 96 75 85 0 89 73 29", "output": "4\n0 6 30 100 " }, { "inp...
1,689,346,949
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689346949.433353")# 1689346949.433394
Title: Strange Addition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Unfortunately, Vasya can only sum pairs of integers (*a*, *b*), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. ...
```python print("_RANDOM_GUESS_1689346949.433353")# 1689346949.433394 ```
0
893
C
Rumor
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "greedy" ]
null
null
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it. Now he tries to solve a quest. The task is to come to a settlement named Ove...
The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends. The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor. ...
Print one number — the minimum amount of gold Vova has to spend in order to finish the quest.
[ "5 2\n2 5 3 4 8\n1 4\n4 5\n", "10 0\n1 2 3 4 5 6 7 8 9 10\n", "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n" ]
[ "10\n", "55\n", "15\n" ]
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor. In the second example Vova has to bribe everyone. In the third example ...
0
[ { "input": "5 2\n2 5 3 4 8\n1 4\n4 5", "output": "10" }, { "input": "10 0\n1 2 3 4 5 6 7 8 9 10", "output": "55" }, { "input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10", "output": "15" }, { "input": "1 0\n0", "output": "0" }, { "input": "1 0\n10000000...
1,645,017,890
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
4
982
22,016,000
def dfs(v, adj, colors, color): colors[v] = color for u in adj[v]: if colors[u] == -1: dfs(u, adj, colors, color) n, m = map(int, input().split()) c = list(map(int, input().split())) if c.count(0) == n: print(0) else: adj = [[] for _ in range(n)] for _ in range(m...
Title: Rumor Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte...
```python def dfs(v, adj, colors, color): colors[v] = color for u in adj[v]: if colors[u] == -1: dfs(u, adj, colors, color) n, m = map(int, input().split()) c = list(map(int, input().split())) if c.count(0) == n: print(0) else: adj = [[] for _ in range(n)] for _ ...
-1
601
A
The Two Routes
PROGRAMMING
1,600
[ "graphs", "shortest paths" ]
null
null
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to...
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=...
Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1.
[ "4 2\n1 3\n3 4\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n" ]
[ "2\n", "-1\n", "3\n" ]
In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo...
500
[ { "input": "4 2\n1 3\n3 4", "output": "2" }, { "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1" }, { "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3" }, { "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4" }, { "input": "3 1\n1 2", "output": "...
1,700,236,314
2,147,483,647
Python 3
OK
TESTS
59
467
6,451,200
import collections n,r=map(int,input().split()) train={i:[] for i in range(1,n+1)} bus={i:[j for j in range(1,n+1) if j!=i] for i in range(1,n+1)} for i in range(r): a,b=map(int,input().split()) train[a].append(b) train[b].append(a) bus[a].remove(b) bus[b].remove(a) def bfs(s,dic): q=...
Title: The Two Routes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet...
```python import collections n,r=map(int,input().split()) train={i:[] for i in range(1,n+1)} bus={i:[j for j in range(1,n+1) if j!=i] for i in range(1,n+1)} for i in range(r): a,b=map(int,input().split()) train[a].append(b) train[b].append(a) bus[a].remove(b) bus[b].remove(a) def bfs(s,dic...
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integer — the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,692,340,071
2,147,483,647
Python 3
OK
TESTS
29
46
0
a,b=map(int,input().split()) c=list(map(int,input().split())) c1=0 for i in c: if i<=b: c1+=1 else: c1+=2 print(c1)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python a,b=map(int,input().split()) c=list(map(int,input().split())) c1=0 for i in c: if i<=b: c1+=1 else: c1+=2 print(c1) ```
3
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and m...
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......
1,600,102,288
2,147,483,647
Python 3
OK
TESTS
36
216
307,200
n, m = map(int, input().split()) dmap = [] for i in range(n): dmap.append(list(input())) if 1 == dmap[i].count("*"): answer_column = i if 2 == dmap[-1].count("*"): filled_column = i indec1 = [i for i, j in enumerate(dmap[filled_column]) if j == "*"] indec2 = [i for i, j in enume...
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma...
```python n, m = map(int, input().split()) dmap = [] for i in range(n): dmap.append(list(input())) if 1 == dmap[i].count("*"): answer_column = i if 2 == dmap[-1].count("*"): filled_column = i indec1 = [i for i, j in enumerate(dmap[filled_column]) if j == "*"] indec2 = [i for i, ...
3
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red...
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,699,726,537
2,147,483,647
Python 3
OK
TESTS
34
92
0
c=0 x=input() n=input() l=list(n) for i in range(len(l)-1): if(l[i]==l[i+1]): c+=1 print(c)
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row ...
```python c=0 x=input() n=input() l=list(n) for i in range(len(l)-1): if(l[i]==l[i+1]): c+=1 print(c) ```
3
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all...
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3...
1,678,649,175
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
2,000
24,985,600
n = int(input()) ma = [[] for x in range(n)] zflag = 0 zindex = [0,0] for i in range(n): j = 0 inp = input().split() for x in inp: if x == '0': ma[i].append(10) zflag = 1 zindex = [i,j] else: ma[i].append(int(x)) j += 1 c...
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down fro...
```python n = int(input()) ma = [[] for x in range(n)] zflag = 0 zindex = [0,0] for i in range(n): j = 0 inp = input().split() for x in inp: if x == '0': ma[i].append(10) zflag = 1 zindex = [i,j] else: ma[i].append(int(x)) ...
0
369
A
Valera and Plates
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. We know that Valera can cook only two types of dishes. He can...
The first line of the input contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=1000) — the number of the planned days, the number of clean bowls and the number of clean plates. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=2). If *a**i* equals one, then on day *i* Val...
Print a single integer — the minimum number of times Valera will need to wash a plate/bowl.
[ "3 1 1\n1 2 1\n", "4 3 1\n1 1 1 1\n", "3 1 2\n2 2 2\n", "8 2 2\n1 2 1 2 1 2 1 2\n" ]
[ "1\n", "1\n", "0\n", "4\n" ]
In the first sample Valera will wash a bowl only on the third day, so the answer is one. In the second sample, Valera will have the first type of the dish during all four days, and since there are only three bowls, he will wash a bowl exactly once. In the third sample, Valera will have the second type of dish for all...
500
[ { "input": "3 1 1\n1 2 1", "output": "1" }, { "input": "4 3 1\n1 1 1 1", "output": "1" }, { "input": "3 1 2\n2 2 2", "output": "0" }, { "input": "8 2 2\n1 2 1 2 1 2 1 2", "output": "4" }, { "input": "2 100 100\n2 2", "output": "0" }, { "input": "1 1 1\...
1,649,356,245
2,147,483,647
Python 3
OK
TESTS
63
46
0
n, m, k=map(int, input().split()) a=list(map(int, input().split())) v1=a.count(1) v2=a.count(2) h=v2-k if(h<0): h=0 l=v1+h-m if(l<0): l=0 print(l)
Title: Valera and Plates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a lazy student. He has *m* clean bowls and *k* clean plates. Valera has made an eating plan for the next *n* days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, ...
```python n, m, k=map(int, input().split()) a=list(map(int, input().split())) v1=a.count(1) v2=a.count(2) h=v2-k if(h<0): h=0 l=v1+h-m if(l<0): l=0 print(l) ```
3
913
B
Christmas Spruce
PROGRAMMING
1,200
[ "implementation", "trees" ]
null
null
Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a ...
The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*). Vertex 1 is the root. It's guaranteed that the root ha...
Print "Yes" if the tree is a spruce and "No" otherwise.
[ "4\n1\n1\n1\n", "7\n1\n1\n1\n2\n2\n2\n", "8\n1\n1\n1\n1\n3\n3\n3\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
The first example: <img class="tex-graphics" src="https://espresso.codeforces.com/8dd976913226df83d535dfa66193f5525f8471bc.png" style="max-width: 100.0%;max-height: 100.0%;"/> The second example: <img class="tex-graphics" src="https://espresso.codeforces.com/44dad5804f5290a2e026c9c41a15151562df8682.png" style="max-w...
750
[ { "input": "4\n1\n1\n1", "output": "Yes" }, { "input": "7\n1\n1\n1\n2\n2\n2", "output": "No" }, { "input": "8\n1\n1\n1\n1\n3\n3\n3", "output": "Yes" }, { "input": "3\n1\n1", "output": "No" }, { "input": "13\n1\n2\n2\n2\n1\n6\n6\n6\n1\n10\n10\n10", "output": "N...
1,630,683,976
2,147,483,647
Python 3
OK
TESTS
31
62
107,417,600
from sys import stdin , setrecursionlimit input = stdin.readline setrecursionlimit(10**8) import threading def dfs(p): global ans if(len(child[p]) == 0):return 1 leafs = 0 for i in child[p]: leafs += dfs(i) if(leafs < 3):ans = 'No' return 0 child , ans = None , None def main():...
Title: Christmas Spruce Time Limit: None seconds Memory Limit: None megabytes Problem Description: Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there ex...
```python from sys import stdin , setrecursionlimit input = stdin.readline setrecursionlimit(10**8) import threading def dfs(p): global ans if(len(child[p]) == 0):return 1 leafs = 0 for i in child[p]: leafs += dfs(i) if(leafs < 3):ans = 'No' return 0 child , ans = None , None d...
3
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,685,707,496
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
a,b,s=map(int,input().split()) if a<0: a=-1*a if b<0: b=-1*b c=a+b if s==c: print("YES") elif s>c: if (s-c)%2==0: print("YES") else: print("NO") else: print("NO")
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 a,b,s=map(int,input().split()) if a<0: a=-1*a if b<0: b=-1*b c=a+b if s==c: print("YES") elif s>c: if (s-c)%2==0: print("YES") else: print("NO") else: print("NO") ```
3
688
B
Lovely Palindromes
PROGRAMMING
1,000
[ "constructive algorithms", "math" ]
null
null
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=10100<=000).
Print the *n*-th even-length palindrome number.
[ "1\n", "10\n" ]
[ "11\n", "1001\n" ]
The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.
1,000
[ { "input": "1", "output": "11" }, { "input": "10", "output": "1001" }, { "input": "11", "output": "1111" }, { "input": "12", "output": "1221" }, { "input": "100", "output": "100001" }, { "input": "1321", "output": "13211231" }, { "input": "...
1,694,961,939
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
def yzd_solution(n): if n % 10 == 0: print((n * 10**len(str(n))) + 1) else: print((n * 10**len(str(n))) + n) n = int(input()) yzd_solution(n)
Title: Lovely Palindromes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is tr...
```python def yzd_solution(n): if n % 10 == 0: print((n * 10**len(str(n))) + 1) else: print((n * 10**len(str(n))) + n) n = int(input()) yzd_solution(n) ```
0
421
A
Pasha and Hamsters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hams...
The first line contains integers *n*, *a*, *b* (1<=≤<=*n*<=≤<=100; 1<=≤<=*a*,<=*b*<=≤<=*n*) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers — the numbers of the apples Arthur likes. The next line...
Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them.
[ "4 2 3\n1 2\n2 3 4\n", "5 5 2\n3 4 1 2 5\n2 3\n" ]
[ "1 1 2 2\n", "1 1 1 1 1\n" ]
none
500
[ { "input": "4 2 3\n1 2\n2 3 4", "output": "1 1 2 2" }, { "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1" }, { "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 7...
1,632,159,345
2,147,483,647
Python 3
OK
TESTS
32
77
6,963,200
n,a,b = map(int,input().split(' ')) a1=list(map(int,input().split(' '))) b1=list(map(int,input().split(' '))) a1=sorted(a1) b1=sorted(b1) m=[] for i in range(0,n): if i+1 in a1: m.append(1) elif i+1 in b1: m.append(2) print(*m)
Title: Pasha and Hamsters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between...
```python n,a,b = map(int,input().split(' ')) a1=list(map(int,input().split(' '))) b1=list(map(int,input().split(' '))) a1=sorted(a1) b1=sorted(b1) m=[] for i in range(0,n): if i+1 in a1: m.append(1) elif i+1 in b1: m.append(2) print(*m) ```
3
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,694,378,880
2,147,483,647
PyPy 3-64
OK
TESTS
58
62
2,048,000
n, a, b, c = map(int, input().split()) res = [-1] * (n + 1) res[0] = 0 for i in range(1, n + 1): cur = -1 if i >= a: cur = max(cur, res[i - a]) if i >= b: cur = max(cur, res[i - b]) if i >= c: cur = max(cur, res[i - c]) if cur > -1: cur += 1 res[i...
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the...
```python n, a, b, c = map(int, input().split()) res = [-1] * (n + 1) res[0] = 0 for i in range(1, n + 1): cur = -1 if i >= a: cur = max(cur, res[i - a]) if i >= b: cur = max(cur, res[i - b]) if i >= c: cur = max(cur, res[i - c]) if cur > -1: cur += 1 ...
3
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 ...
1,647,583,798
2,147,483,647
Python 3
OK
TESTS
50
124
0
n,a,b=map(int,input().split()) s=n-a if(s>b): s=b+1 print(s)
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h...
```python n,a,b=map(int,input().split()) s=n-a if(s>b): s=b+1 print(s) ```
3
16
C
Monitor
PROGRAMMING
1,800
[ "binary search", "number theory" ]
C. Monitor
0
64
Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *x*:<=*y* became popular with users. That's why the company wants to reduce monitor AB999...
The first line of the input contains 4 integers — *a*, *b*, *x* and *y* (1<=≤<=*a*,<=*b*,<=*x*,<=*y*<=≤<=2·109).
If the answer exists, output 2 positive integers — screen parameters of the reduced size model. Output 0 0 otherwise.
[ "800 600 4 3\n", "1920 1200 16 9\n", "1 1 1 2\n" ]
[ "800 600\n", "1920 1080\n", "0 0\n" ]
none
0
[ { "input": "800 600 4 3", "output": "800 600" }, { "input": "1920 1200 16 9", "output": "1920 1080" }, { "input": "1 1 1 2", "output": "0 0" }, { "input": "1002105126 227379125 179460772 1295256518", "output": "0 0" }, { "input": "625166755 843062051 1463070160 19...
1,660,358,398
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
62
0
def f(): if (a*y)%x == 0: k = (a*y)//x if k != 0 and k <= b: print(a,k) return 0 if (b*x)%y==0: k = (b*x)//y if k!= 0 and k <= a: print(k,b) return 0 print(0,0) a,b,x,y = map(int,input().split()) f()
Title: Monitor Time Limit: 0 seconds Memory Limit: 64 megabytes Problem Description: Reca company makes monitors, the most popular of their models is AB999 with the screen size *a*<=×<=*b* centimeters. Because of some production peculiarities a screen parameters are integer numbers. Recently the screen sides ratio *...
```python def f(): if (a*y)%x == 0: k = (a*y)//x if k != 0 and k <= b: print(a,k) return 0 if (b*x)%y==0: k = (b*x)//y if k!= 0 and k <= a: print(k,b) return 0 print(0,0) a,b,x,y = map(int,input().split()) f() ```
0
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,648,415,689
2,147,483,647
Python 3
OK
TESTS
33
62
0
n = 0 for i in input(): n = 2*n + (1, 2)[i == "7"] print(n)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python n = 0 for i in input(): n = 2*n + (1, 2)[i == "7"] print(n) ```
3
94
A
Restoring Password
PROGRAMMING
900
[ "implementation", "strings" ]
A. Restoring Password
2
256
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ...
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
[ "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1...
[ "12345678\n", "30234919\n" ]
none
500
[ { "input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "output": "12345678" }, { "input": "1010110111100100001010010001101010110111001011011...
1,674,035,262
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
code_password = input() code_numbers = {} for i in range(10): d[i] = input() for i in range(0, 71, 10): print(code_numbers[code_password[i:i + 10]], end='')
Title: Restoring Password Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a...
```python code_password = input() code_numbers = {} for i in range(10): d[i] = input() for i in range(0, 71, 10): print(code_numbers[code_password[i:i + 10]], end='') ```
-1
159
D
Palindrome pairs
PROGRAMMING
1,500
[ "*special", "brute force", "dp", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (*a*,<=*b*,<=*x*,<=*y*) such that 1<=≤<=*a*<=≤<=*b*<=&lt;<=*x*<=≤<=*y*<=≤<=|*s*| and substrings *s*[*a*....
The first line of input contains a non-empty string *s* which consists of lowercase letters ('a'...'z'), *s* contains at most 2000 characters.
Output a single number — the quantity of pairs of non-overlapping palindromic substrings of *s*. Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier.
[ "aa\n", "aaa\n", "abacaba\n" ]
[ "1\n", "5\n", "36\n" ]
none
2,000
[ { "input": "aa", "output": "1" }, { "input": "aaa", "output": "5" }, { "input": "abacaba", "output": "36" }, { "input": "aaaaaaaaaa", "output": "495" }, { "input": "aabbb", "output": "24" }, { "input": "abbaa", "output": "18" }, { "input": ...
1,682,117,977
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
import sys input = lambda: sys.stdin.readline().rstrip() S = input() N = len(S) def deal(S): ls = [1]*N for i in range(N): l,r=i-1,i+1 while l>=0 and r<N and S[l]==S[r]: ls[r]+=1 l-=1 r+=1 for i in range(1,N): if S[i-1]==S[i]: ...
Title: Palindrome pairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (*...
```python import sys input = lambda: sys.stdin.readline().rstrip() S = input() N = len(S) def deal(S): ls = [1]*N for i in range(N): l,r=i-1,i+1 while l>=0 and r<N and S[l]==S[r]: ls[r]+=1 l-=1 r+=1 for i in range(1,N): if S[i-1]==...
0
0
none
none
none
0
[ "none" ]
null
null
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ...
The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length.
Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.
[ "aaba\nabaa\n", "aabb\nabab\n" ]
[ "YES\n", "NO\n" ]
In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a". In the second sample the first string can be splitted into strings "aa" and "bb", that are equival...
0
[ { "input": "aaba\nabaa", "output": "YES" }, { "input": "aabb\nabab", "output": "NO" }, { "input": "a\na", "output": "YES" }, { "input": "a\nb", "output": "NO" }, { "input": "ab\nab", "output": "YES" }, { "input": "ab\nba", "output": "YES" }, { ...
1,437,993,588
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
82
2,000
1,024,000
a = input() b = input() def equal_str(a, b): ma = len(a) mb = len(b) if ma & 1: return a == b; ma >>= 1 mb >>= 1 if (equal_str(a[0 : ma], b[0 : mb]) and equal_str(a[ma:], b[mb:])) or (equal_str(a[0 : ma], b[mb:]) and equal_str(a[ma:], b[0 : mb])): return True retur...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases: 1. They are equal. 1. If we split string *a* into t...
```python a = input() b = input() def equal_str(a, b): ma = len(a) mb = len(b) if ma & 1: return a == b; ma >>= 1 mb >>= 1 if (equal_str(a[0 : ma], b[0 : mb]) and equal_str(a[ma:], b[mb:])) or (equal_str(a[0 : ma], b[mb:]) and equal_str(a[ma:], b[0 : mb])): return True ...
0
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb...
1,689,167,877
2,147,483,647
Python 3
OK
TESTS
55
46
0
def check_diary_possession(n, names): possession = set() for name in names: if name in possession: print("YES") else: print("NO") possession.add(name) # Read input n = int(input()) names = [] for _ in range(n): names.append(input().lower(...
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ...
```python def check_diary_possession(n, names): possession = set() for name in names: if name in possession: print("YES") else: print("NO") possession.add(name) # Read input n = int(input()) names = [] for _ in range(n): names.append(inpu...
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,699,889,930
2,147,483,647
Python 3
OK
TESTS
32
576
512,000
a, b, c = map(int, input().split()) d = [0] * (c // a) e = [0] * (c // b) y = 0 f = 0 for i in range(a, c+1, a): d[y] = i y += 1 for i in range(b, c+1, b): e[f] = i f += 1 r = 0 for i in range(0, len(d)): if d[i] in e: r += 1 print(r)
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 a, b, c = map(int, input().split()) d = [0] * (c // a) e = [0] * (c // b) y = 0 f = 0 for i in range(a, c+1, a): d[y] = i y += 1 for i in range(b, c+1, b): e[f] = i f += 1 r = 0 for i in range(0, len(d)): if d[i] in e: r += 1 print(r) ```
3