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
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,693,769,151
2,147,483,647
PyPy 3
OK
TESTS
29
93
0
def solve(a: int, b: int, c: int) -> int: count=0 L=[a+b*c,a*(b+c),a*b*c,(a+b)*c,a*b+c,a+b+c] count=max(L) return (count) a=int(input()) b=int(input()) c=int(input()) print(solve(a, b, c))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ...
```python def solve(a: int, b: int, c: int) -> int: count=0 L=[a+b*c,a*(b+c),a*b*c,(a+b)*c,a*b+c,a+b+c] count=max(L) return (count) a=int(input()) b=int(input()) c=int(input()) print(solve(a, b, c)) ```
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,642,609,330
2,147,483,647
Python 3
OK
TESTS
102
46
0
a = input() b = input() length = len(a) i = 0 while i < length: ai = a[i] bi = b[i] if ai != bi: print("1", end='') else: print("0", end='') i += 1
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python a = input() b = input() length = len(a) i = 0 while i < length: ai = a[i] bi = b[i] if ai != bi: print("1", end='') else: print("0", end='') i += 1 ```
3.9885
926
B
Add Points
PROGRAMMING
1,800
[]
null
null
There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct. Determine the number *m* — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000) — the number of points. The second line contains a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
Print a single integer *m* — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
[ "3\n-5 10 5\n", "6\n100 200 400 300 600 500\n", "4\n10 9 0 -1\n" ]
[ "1\n", "0\n", "8\n" ]
In the first example you can add one point with coordinate 0. In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
0
[ { "input": "3\n-5 10 5", "output": "1" }, { "input": "6\n100 200 400 300 600 500", "output": "0" }, { "input": "4\n10 9 0 -1", "output": "8" }, { "input": "3\n1 4 7", "output": "0" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "3\n1 2 6", "...
1,521,305,655
4,755
Python 3
OK
TESTS
134
295
15,667,200
n = int(input()) a = [int(x) for x in input().strip().split()] a = sorted(a) d = [] for i in range(len(a) - 1): d.append(a[i + 1] - a[i]) def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) g = d[0] for e in d: g = gcd(g, e) cnt = len(a) prin...
Title: Add Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* points on a straight line, and the *i*-th point among them is located at *x**i*. All these coordinates are distinct. Determine the number *m* — the smallest number of points you should add on the line to make ...
```python n = int(input()) a = [int(x) for x in input().strip().split()] a = sorted(a) d = [] for i in range(len(a) - 1): d.append(a[i + 1] - a[i]) def gcd(a, b): if(b == 0): return a else: return gcd(b, a % b) g = d[0] for e in d: g = gcd(g, e) cnt = le...
3
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,689,521,158
2,147,483,647
Python 3
OK
TESTS
20
92
0
w = int(input()) if w==1 or w==2: print("NO") elif w % 2 == 0: print("YES") 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()) if w==1 or w==2: print("NO") elif w % 2 == 0: print("YES") else: print("NO") ```
3.954
847
E
Packmen
PROGRAMMING
1,800
[ "binary search", "dp" ]
null
null
A game field is a strip of 1<=×<=*n* square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial ...
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the length of the game field. The second line contains the description of the game field consisting of *n* symbols. If there is symbol '.' in position *i* — the cell *i* is empty. If there is symbol '*' in position *i* — in the cell *i* contains an ast...
Print minimum possible time after which Packmen can eat all asterisks.
[ "7\n*..P*P*\n", "10\n.**PP.*P.*\n" ]
[ "3\n", "2\n" ]
In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ...
0
[ { "input": "7\n*..P*P*", "output": "3" }, { "input": "10\n.**PP.*P.*", "output": "2" }, { "input": "19\n**P.*..*..P..*.*P**", "output": "7" }, { "input": "12\nP**.*P*P*P**", "output": "3" }, { "input": "58\n..P.P*.P*.P...PPP...P*....*..*.**......*P.*P.....**P...*P...
1,691,834,318
2,147,483,647
PyPy 3
OK
TESTS
77
202
5,120,000
n = int(input()) string = input() player = [] food = [] for i in range(len(string)): if string[i] == "*": food.append(i) elif string[i] == "P": player.append(i) def check(t): idx = 0 for i in range(len(player)): loc = player[i] if idx == len(food):break ...
Title: Packmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: A game field is a strip of 1<=×<=*n* square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target c...
```python n = int(input()) string = input() player = [] food = [] for i in range(len(string)): if string[i] == "*": food.append(i) elif string[i] == "P": player.append(i) def check(t): idx = 0 for i in range(len(player)): loc = player[i] if idx == len(foo...
3
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len...
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o...
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form...
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, ...
1,644,254,201
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
d1,d2,d3 = map(int, input().split()) s = d1+d2+d3 x = (d1*2) + (d2*2) if d1+d2 == d3 : print(s) else : print(x)
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the...
```python d1,d2,d3 = map(int, input().split()) s = d1+d2+d3 x = (d1*2) + (d2*2) if d1+d2 == d3 : print(s) else : print(x) ```
0
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342...
1,627,834,903
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
6,758,400
t = int(input()) looking = True for _ in range(t): s = input() if looking: name, before, after = s.split() b = int(before) a = int(after) if a > 2400 and b >= 2400: looking = False print("NO" if looking else "YES")
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ...
```python t = int(input()) looking = True for _ in range(t): s = input() if looking: name, before, after = s.split() b = int(before) a = int(after) if a > 2400 and b >= 2400: looking = False print("NO" if looking else "YES") ```
0
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,693,024,309
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
92
0
import sys import math inp = sys.stdin.readline out = sys.stdout.write def main(): n = int(inp()) if (n == 1): out("-1") return out(f"{n} ") for i in range(1, n): out(f"{i} ") if __name__ == "__main__": main()
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python import sys import math inp = sys.stdin.readline out = sys.stdout.write def main(): n = int(inp()) if (n == 1): out("-1") return out(f"{n} ") for i in range(1, n): out(f"{i} ") if __name__ == "__main__": main() ```
0
598
A
Tricky Sum
PROGRAMMING
900
[ "math" ]
null
null
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*.
The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109).
Print the requested sum for each of *t* integers *n* given in the input.
[ "2\n4\n1000000000\n" ]
[ "-4\n499999998352516354\n" ]
The answer for the first sample is explained in the statement.
0
[ { "input": "2\n4\n1000000000", "output": "-4\n499999998352516354" }, { "input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25" }, { "input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53", "output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130...
1,678,197,871
871
PyPy 3
OK
TESTS
21
93
1,228,800
t = int(input()) for p in range(t): x = int(input()) k = 1 cnt = 0 while(k <= x): k *= 2 cnt += 1 ans = cnt print(x * (x + 1) // 2 - 2 * (2 ** ans) + 2)
Title: Tricky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be...
```python t = int(input()) for p in range(t): x = int(input()) k = 1 cnt = 0 while(k <= x): k *= 2 cnt += 1 ans = cnt print(x * (x + 1) // 2 - 2 * (2 ** ans) + 2) ```
3
255
B
Code Parsing
PROGRAMMING
1,200
[ "implementation" ]
null
null
Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime: 1. Find two consecutive characters in the string, such that the first of them equals "y", and the ...
The first line contains a non-empty string *s*. It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.
In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string *s*.
[ "x\n", "yxyxy\n", "xxxxxy\n" ]
[ "x\n", "y\n", "xxxx\n" ]
In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change. In the second test the transformation will be like this: 1. string "yxyxy" transforms into string "xyyxy"; 1. string "xyyxy" transforms into string "xyxyy"; 1. ...
1,000
[ { "input": "x", "output": "x" }, { "input": "yxyxy", "output": "y" }, { "input": "xxxxxy", "output": "xxxx" }, { "input": "yxyyxyyx", "output": "yy" }, { "input": "yxxyxyx", "output": "x" }, { "input": "xxx", "output": "xxx" }, { "input": "...
1,699,025,954
2,147,483,647
PyPy 3
OK
TESTS
49
498
9,830,400
s=input() cx = 0 cy = 0 for c in s: if c == "x": cx+=1 else: cy+=1 if cx > cy: out = "x"*(cx-cy) else: out = "y"*(cy-cx) print(out)
Title: Code Parsing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string *s*, consisting of characters "x" and "y", and uses two following operations at runtime: 1...
```python s=input() cx = 0 cy = 0 for c in s: if c == "x": cx+=1 else: cy+=1 if cx > cy: out = "x"*(cx-cy) else: out = "y"*(cy-cx) print(out) ```
3
1,004
B
Sonya and Exhibition
PROGRAMMING
1,300
[ "constructive algorithms", "greedy", "implementation", "math" ]
null
null
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the exhibition. Sonya can put either a rose or a lily in the $i$-th position. Thus each of $n$ positions shoul...
The first line contains two integers $n$ and $m$ ($1\leq n, m\leq 10^3$) — the number of flowers and visitors respectively. Each of the next $m$ lines contains two integers $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq n$), meaning that $i$-th visitor will visit all flowers from $l_i$ to $r_i$ inclusive.
Print the string of $n$ characters. The $i$-th symbol should be «0» if you want to put a rose in the $i$-th position, otherwise «1» if you want to put a lily. If there are multiple answers, print any.
[ "5 3\n1 3\n2 4\n2 5\n", "6 3\n5 6\n1 4\n4 6\n" ]
[ "01100", "110010" ]
In the first example, Sonya can put roses in the first, fourth, and fifth positions, and lilies in the second and third positions; - in the segment $[1\ldots3]$, there are one rose and two lilies, so the beauty is equal to $1\cdot 2=2$; - in the segment $[2\ldots4]$, there are one rose and two lilies, so the beauty ...
1,000
[ { "input": "5 3\n1 3\n2 4\n2 5", "output": "01010" }, { "input": "6 3\n5 6\n1 4\n4 6", "output": "010101" }, { "input": "10 4\n3 3\n1 6\n9 9\n10 10", "output": "0101010101" }, { "input": "1 1\n1 1", "output": "0" }, { "input": "1000 10\n3 998\n2 1000\n1 999\n2 100...
1,530,841,926
2,147,483,647
Python 3
OK
TESTS
27
109
0
n,k=[int(x) for x in input().split()] for i in range(k): a=input() a='0' s='' for i in range(n): s+=a if a=='0': a='1' else: a='0' print(s)
Title: Sonya and Exhibition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are $n$ flowers in a row in the ...
```python n,k=[int(x) for x in input().split()] for i in range(k): a=input() a='0' s='' for i in range(n): s+=a if a=='0': a='1' else: a='0' print(s) ```
3
545
B
Equidistant String
PROGRAMMING
1,100
[ "greedy" ]
null
null
Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define the distance between two strings *s* and *t* of the same length consisting of digits zero and one as the...
The first line contains string *s* of length *n*. The second line contains string *t* of length *n*. The length of string *n* is within range from 1 to 105. It is guaranteed that both strings contain only digits zero and one.
Print a string of length *n*, consisting of digits zero and one, that meets the problem statement. If no such string exist, print on a single line "impossible" (without the quotes). If there are multiple possible answers, print any of them.
[ "0001\n1011\n", "000\n111\n" ]
[ "0011\n", "impossible\n" ]
In the first sample different answers are possible, namely — 0010, 0011, 0110, 0111, 1000, 1001, 1100, 1101.
1,000
[ { "input": "0001\n1011", "output": "0011" }, { "input": "000\n111", "output": "impossible" }, { "input": "1010101011111110111111001111111111111111111111101101110111111111111110110110101011111110110111111101\n01011111110001000101000011000101010000000110000000000110110000011001000011101110...
1,686,001,568
2,147,483,647
PyPy 3-64
OK
TESTS
54
826
10,752,000
s = input() t = input() p = "" c = 0 for i in range(len(s)): if s[i] == t[i]: p += s[i] else: c += 1 if c % 2 == 1: p += s[i] else: p += t[i] if c % 2 == 1: print("impossible") else: print(p)
Title: Equidistant String Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings contain only digits zero and one. She uses the definition of Hamming distance: We will define ...
```python s = input() t = input() p = "" c = 0 for i in range(len(s)): if s[i] == t[i]: p += s[i] else: c += 1 if c % 2 == 1: p += s[i] else: p += t[i] if c % 2 == 1: print("impossible") else: print(p) ```
3
548
B
Mike and Fun
PROGRAMMING
1,400
[ "brute force", "dp", "greedy", "implementation" ]
null
null
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of row number *i* by (*i*,<=*j*). Mike's hands are on his ears (since he's the judge) and each bear s...
The first line of input contains three integers *n*, *m* and *q* (1<=≤<=*n*,<=*m*<=≤<=500 and 1<=≤<=*q*<=≤<=5000). The next *n* lines contain the grid description. There are *m* integers separated by spaces in each line. Each of these numbers is either 0 (for mouth) or 1 (for eyes). The next *q* lines contain the inf...
After each round, print the current score of the bears.
[ "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n" ]
[ "3\n4\n3\n3\n4\n" ]
none
1,000
[ { "input": "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3", "output": "3\n4\n3\n3\n4" }, { "input": "2 2 10\n1 1\n0 1\n1 1\n2 1\n1 1\n2 2\n1 1\n2 1\n2 2\n2 2\n1 1\n1 1", "output": "1\n2\n2\n2\n1\n1\n1\n1\n2\n1" }, { "input": "2 2 10\n1 1\n0 1\n2 2\n2 2\n1 1\...
1,607,518,627
2,147,483,647
PyPy 3
OK
TESTS
35
374
7,475,200
n,m,q = map(int,input().split()) grid =[]*m for i in range(n): grid.append(list(map(int,input().split()))) #print(grid) count = [] for i in range(n): c=0 tmp=0 for j in range(m): if grid[i][j]==1: c+=1 else: tmp=max(c,tmp) c=0 ...
Title: Mike and Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an *n*<=×<=*m* grid, there's exactly one bear in each cell. We denote the bear standing in column number *j* of ...
```python n,m,q = map(int,input().split()) grid =[]*m for i in range(n): grid.append(list(map(int,input().split()))) #print(grid) count = [] for i in range(n): c=0 tmp=0 for j in range(m): if grid[i][j]==1: c+=1 else: tmp=max(c,tmp) ...
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,687,056,220
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
46
0
a=int(input()) b=int(input()) c=int(input()) p=[a+b*c, a*b+c,a*c+b,(a+b)*c,(b+c)*a,(c+a)*b,a+b+c,a*b*c] print(max(p))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ...
```python a=int(input()) b=int(input()) c=int(input()) p=[a+b*c, a*b+c,a*c+b,(a+b)*c,(b+c)*a,(c+a)*b,a+b+c,a*b*c] print(max(p)) ```
0
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≤<=*l*<=≤<=*r*<=≤<=*n*, *c*1,<=*c*2 are lowercase English letters), ...
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n...
1,567,936,070
2,147,483,647
PyPy 3
OK
TESTS
47
155
0
from math import ceil def main(): n,m = [int(v) for v in input().split()] inp = input() for i in range(m): s,e,source, target = [v for v in input().split()] start = int(s)-1 end = int(e)-1 inp = inp[0:start] + inp[start:end + 1].replace(source, target) + inp[end +...
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ...
```python from math import ceil def main(): n,m = [int(v) for v in input().split()] inp = input() for i in range(m): s,e,source, target = [v for v in input().split()] start = int(s)-1 end = int(e)-1 inp = inp[0:start] + inp[start:end + 1].replace(source, target) +...
3
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes th...
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose bal...
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { ...
1,680,576,163
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
python Copy code n = int(input()) # number of houses t = list(map(int, input().split())) # list of house numbers # sort the house numbers in ascending order t.sort() # initialize variables i = 0 j = 0 k = 0 found = False # loop through the house numbers to find a valid set of 3 houses while k < n...
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri...
```python python Copy code n = int(input()) # number of houses t = list(map(int, input().split())) # list of house numbers # sort the house numbers in ascending order t.sort() # initialize variables i = 0 j = 0 k = 0 found = False # loop through the house numbers to find a valid set of 3 houses w...
-1
729
E
Subordinates
PROGRAMMING
1,900
[ "constructive algorithms", "data structures", "graphs", "greedy", "sortings" ]
null
null
There are *n* workers in a company, each of them has a unique id from 1 to *n*. Exaclty one of them is a chief, his id is *s*. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his imme...
The first line contains two positive integers *n* and *s* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*s*<=≤<=*n*) — the number of workers and the id of the chief. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=*n*<=-<=1), where *a**i* is the number of superiors (not only immediate) the worker with...
Print the minimum number of workers that could make a mistake.
[ "3 2\n2 0 2\n", "5 3\n1 0 0 4 1\n" ]
[ "1\n", "2\n" ]
In the first example it is possible that only the first worker made a mistake. Then: - the immediate superior of the first worker is the second worker, - the immediate superior of the third worker is the first worker, - the second worker is the chief.
2,000
[ { "input": "3 2\n2 0 2", "output": "1" }, { "input": "5 3\n1 0 0 4 1", "output": "2" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 1\n0 0", "output": "1" }, { "input": "2 1\n0 1", "output": "0" }, { "input": "2 1\n1 0", "output": "2" }, ...
1,567,565,789
2,147,483,647
PyPy 3
OK
TESTS
99
296
15,872,000
[n, s] = [int(x) for x in input().split()] a = [int(x) for x in input().split()] mistakes = 0 mistakes += (a[s-1] is not 0) a[s - 1] = 0 numSuperiors = [0]*(2*100000+100) for superiors in a: numSuperiors[superiors] += 1 cachedMistakes = 0 while numSuperiors[0] != 1: cachedMistakes += 1 ...
Title: Subordinates Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* workers in a company, each of them has a unique id from 1 to *n*. Exaclty one of them is a chief, his id is *s*. Each worker except the chief has exactly one immediate superior. There was a request to each o...
```python [n, s] = [int(x) for x in input().split()] a = [int(x) for x in input().split()] mistakes = 0 mistakes += (a[s-1] is not 0) a[s - 1] = 0 numSuperiors = [0]*(2*100000+100) for superiors in a: numSuperiors[superiors] += 1 cachedMistakes = 0 while numSuperiors[0] != 1: cachedMista...
3
892
A
Greed
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<...
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower).
[ "2\n3 5\n3 6\n", "3\n6 8 9\n6 10 12\n", "5\n0 0 5 0 0\n1 1 8 10 5\n", "4\n4 1 0 3\n5 2 2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n" ]
In the first sample, there are already 2 cans, so the answer is "YES".
500
[ { "input": "2\n3 5\n3 6", "output": "YES" }, { "input": "3\n6 8 9\n6 10 12", "output": "NO" }, { "input": "5\n0 0 5 0 0\n1 1 8 10 5", "output": "YES" }, { "input": "4\n4 1 0 3\n5 2 2 3", "output": "YES" }, { "input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9...
1,594,340,600
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
139
20,172,800
n = int(input()) l1 = [int(x) for x in input().split()] b = [int(x) for x in input().split()] i=0 l2=[] while i<len(b): l2.append(b[i]-l1[i]) l1[i]=max(0,l1[i]-b[i]) i+=1 l2.sort(reverse=True) #print(l1,l2) cap=l2[0]+l2[1] #print(cap,sum(l1)) if sum(l1)>cap: print("NO") else: p...
Title: Greed Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he c...
```python n = int(input()) l1 = [int(x) for x in input().split()] b = [int(x) for x in input().split()] i=0 l2=[] while i<len(b): l2.append(b[i]-l1[i]) l1[i]=max(0,l1[i]-b[i]) i+=1 l2.sort(reverse=True) #print(l1,l2) cap=l2[0]+l2[1] #print(cap,sum(l1)) if sum(l1)>cap: print("NO") el...
0
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" ...
1,591,257,704
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
93
0
s=input() three=['a1','a8','h1','h8'] if s in three: print(3) elif s[1]=='1' or s[1]=='8': print(5) else: print(8)
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check...
```python s=input() three=['a1','a8','h1','h8'] if s in three: print(3) elif s[1]=='1' or s[1]=='8': print(5) else: print(8) ```
0
519
D
A and B and Interesting Substrings
PROGRAMMING
1,800
[ "data structures", "dp", "two pointers" ]
null
null
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
The first line contains 26 integers *x**a*,<=*x**b*,<=...,<=*x**z* (<=-<=105<=≤<=*x**i*<=≤<=105) — the value assigned to letters *a*,<=*b*,<=*c*,<=...,<=*z* respectively. The second line contains string *s* of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to...
Print the answer to the problem.
[ "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n" ]
[ "2\n", "2\n" ]
In the first sample test strings satisfying the condition above are *abca* and *bcab*. In the second sample test strings satisfying the condition above are two occurences of *aa*.
2,000
[ { "input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab", "output": "2" }, { "input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa", "output": "2" }, { "input": "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naabbccdd", "output": "4" }, { ...
1,689,496,982
2,147,483,647
PyPy 3-64
MEMORY_LIMIT_EXCEEDED
TESTS
5
233
268,390,400
l=list(map(int,input().split())) s=input() o = 97 res=0 t={} temp=0 ans=[] n=len(s) for i in range(len(s)): p=n-1 while p>i: if s[i]==s[p]: ans.append(s[i:p+1]) p-=1 a_sum=[] for j in range(len(ans)): sum_=0 if len(ans[j])>2: str_=ans[j][1:-1] ...
Title: A and B and Interesting Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B al...
```python l=list(map(int,input().split())) s=input() o = 97 res=0 t={} temp=0 ans=[] n=len(s) for i in range(len(s)): p=n-1 while p>i: if s[i]==s[p]: ans.append(s[i:p+1]) p-=1 a_sum=[] for j in range(len(ans)): sum_=0 if len(ans[j])>2: str_=ans[j][...
0
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,695,208,874
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
40
92
0
word = input() #1000000001 #checking for 1 consOne = 0 oneDangerous=False for i in word: if consOne>=7: oneDangerous=True if i=='1': consOne+=1 else: consOne=0 consZero = 0 zeroDangerous=False for i in word: if consZero>=7: zeroDangerous=True if i=='0': consZe...
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python word = input() #1000000001 #checking for 1 consOne = 0 oneDangerous=False for i in word: if consOne>=7: oneDangerous=True if i=='1': consOne+=1 else: consOne=0 consZero = 0 zeroDangerous=False for i in word: if consZero>=7: zeroDangerous=True if i=='0': ...
0
196
A
Lexicographically Maximum Subsequence
PROGRAMMING
1,100
[ "greedy", "strings" ]
null
null
You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k*<=≤<=|*s*|) a subsequence of string *s*<==<=*s*1*s*2... *s*|*s*|. St...
The single line contains a non-empty string *s*, consisting only of lowercase English letters. The string's length doesn't exceed 105.
Print the lexicographically maximum subsequence of string *s*.
[ "ababba\n", "abbcbccacbbcbaaba\n" ]
[ "bbba\n", "cccccbba\n" ]
Let's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters). The first sample: aBaBBA The second sample: abbCbCCaCbbCBaaBA
500
[ { "input": "ababba", "output": "bbba" }, { "input": "abbcbccacbbcbaaba", "output": "cccccbba" }, { "input": "thankstosamarasauteddybearsforthiscontest", "output": "yttt" }, { "input": "cantouristsolveitlessthaninoneminute", "output": "vute" }, { "input": "areprete...
1,578,567,221
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
12,697,600
from collections import Counter as c s = list(input()) #m = max(s) new = "" cnt = c(s) d = cnt.copy() k = cnt.keys() k = sorted(k, reverse = True) for i in s: if i == k[0]: new += i d[i] -= 1 if not(d[i]): k.pop(0) else: d[i] -= 1 if not(d[...
Title: Lexicographically Maximum Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s*...
```python from collections import Counter as c s = list(input()) #m = max(s) new = "" cnt = c(s) d = cnt.copy() k = cnt.keys() k = sorted(k, reverse = True) for i in s: if i == k[0]: new += i d[i] -= 1 if not(d[i]): k.pop(0) else: d[i] -= 1 ...
0
417
B
Crash
PROGRAMMING
1,400
[ "implementation" ]
null
null
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check. Each participant is identified by some unique positive i...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of solutions. Each of the following *n* lines contains two integers separated by space *x* and *k* (0<=≤<=*x*<=≤<=105; 1<=≤<=*k*<=≤<=105) — the number of previous unique solutions and the identifier of the participant.
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
[ "2\n0 1\n1 1\n", "4\n0 1\n1 2\n1 1\n0 2\n", "4\n0 1\n1 1\n0 1\n0 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
1,000
[ { "input": "2\n0 1\n1 1", "output": "YES" }, { "input": "4\n0 1\n1 2\n1 1\n0 2", "output": "NO" }, { "input": "4\n0 1\n1 1\n0 1\n0 2", "output": "YES" }, { "input": "4\n7 1\n4 2\n8 2\n1 8", "output": "NO" }, { "input": "2\n0 8\n0 5", "output": "YES" }, { ...
1,397,750,325
1,125
Python 3
CHALLENGED
CHALLENGES
9
61
0
solutions = [0] * 10001 for notes in range(int(input())): x, k = map(int, input().split()) if x > solutions[k]: print('NO') break elif x == solutions[k]: solutions[k] += 1 else: print('YES')
Title: Crash Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions wi...
```python solutions = [0] * 10001 for notes in range(int(input())): x, k = map(int, input().split()) if x > solutions[k]: print('NO') break elif x == solutions[k]: solutions[k] += 1 else: print('YES') ```
-1
883
H
Palindromic Cut
PROGRAMMING
1,800
[ "brute force", "implementation", "strings" ]
null
null
Kolya has a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits. He wants to rearrange the symbols in *s* and cut it into the minimum number of parts so that each part is a palindrome and all parts have the same lengths. A palindrome is a string which reads the same backward as forw...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=4·105) — the length of string *s*. The second line contains a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits.
Print to the first line an integer *k* — minimum number of palindromes into which you can cut a given string. Print to the second line *k* strings — the palindromes themselves. Separate them by a space. You are allowed to print palindromes in arbitrary order. All of them should have the same length.
[ "6\naabaac\n", "8\n0rTrT022\n", "2\naA\n" ]
[ "2\naba aca ", "1\n02TrrT20 ", "2\na A \n" ]
none
0
[ { "input": "6\naabaac", "output": "2\naba aca " }, { "input": "8\n0rTrT022", "output": "1\n02TrrT20 " }, { "input": "2\naA", "output": "2\na A " }, { "input": "1\ns", "output": "1\ns " }, { "input": "10\n6IIC6CCIIC", "output": "1\n6CCIIIICC6 " }, { "in...
1,508,576,307
3,206
Python 3
WRONG_ANSWER
TESTS1
0
46
5,120,000
from collections import Counter n = int(input()) s = input() counter = Counter(s) l = list(counter.items()) l.sort(key = lambda x : 1 - (x[1] % 2)) ans = [] if l[0][1] % 2 == 0: ans.append('') for q in l: c = q[0] n = q[1] if n % 2 != 0: ans.append(c * n) else: ans[0] = c * (n // 2) + ...
Title: Palindromic Cut Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya has a string *s* of length *n* consisting of lowercase and uppercase Latin letters and digits. He wants to rearrange the symbols in *s* and cut it into the minimum number of parts so that each part is a palindrom...
```python from collections import Counter n = int(input()) s = input() counter = Counter(s) l = list(counter.items()) l.sort(key = lambda x : 1 - (x[1] % 2)) ans = [] if l[0][1] % 2 == 0: ans.append('') for q in l: c = q[0] n = q[1] if n % 2 != 0: ans.append(c * n) else: ans[0] = c * (...
0
895
B
XK Segments
PROGRAMMING
1,700
[ "binary search", "math", "sortings", "two pointers" ]
null
null
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and...
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Print one integer — the answer to the problem.
[ "4 2 1\n1 3 5 7\n", "4 2 0\n5 3 1 7\n", "5 3 1\n3 3 3 3 3\n" ]
[ "3\n", "4\n", "25\n" ]
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
1,000
[ { "input": "4 2 1\n1 3 5 7", "output": "3" }, { "input": "4 2 0\n5 3 1 7", "output": "4" }, { "input": "5 3 1\n3 3 3 3 3", "output": "25" }, { "input": "5 3 4\n24 13 1 24 24", "output": "4" }, { "input": "4 2 2\n1 3 5 7", "output": "2" }, { "input": "5...
1,511,896,089
2,147,483,647
Python 3
OK
TESTS
69
343
14,438,400
from bisect import bisect_left R=lambda:map(int,input().split()) n,x,k=R() a=sorted(R()) z=((u,((u-1)//x+k)*x) for u in a) print(sum(bisect_left(a,l+x)-bisect_left(a,max(u,l)) for u,l in z))
Title: XK Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should ...
```python from bisect import bisect_left R=lambda:map(int,input().split()) n,x,k=R() a=sorted(R()) z=((u,((u-1)//x+k)*x) for u in a) print(sum(bisect_left(a,l+x)-bisect_left(a,max(u,l)) for u,l in z)) ```
3
950
B
Intercepted Message
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred...
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of blocks in the first and in the second messages. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=106) — the length of the blocks that form the first message. The third line contains *m* integers *...
Print the maximum number of files the intercepted array could consist of.
[ "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8\n", "3 3\n1 10 100\n1 100 10\n", "1 4\n4\n1 1 1 1\n" ]
[ "3\n", "2\n", "1\n" ]
In the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8. In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Not...
1,000
[ { "input": "7 6\n2 5 3 1 11 4 4\n7 8 2 4 1 8", "output": "3" }, { "input": "3 3\n1 10 100\n1 100 10", "output": "2" }, { "input": "1 4\n4\n1 1 1 1", "output": "1" }, { "input": "1 1\n1000000\n1000000", "output": "1" }, { "input": "3 5\n2 2 9\n2 1 4 2 4", "outp...
1,666,588,004
2,147,483,647
PyPy 3-64
OK
TESTS
59
77
19,865,600
n, m = list(map(int, input().split())) an = list(map(int, input().split())) am = list(map(int, input().split())) pa = 0 pb = 0 runningSuma = an[0] runningSumb = am[0] count = 0 while (pa < n and pb < m): if (runningSuma == runningSumb and runningSuma != 0): count+=1 pa+=1 pb+=1 ...
Title: Intercepted Message Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the mes...
```python n, m = list(map(int, input().split())) an = list(map(int, input().split())) am = list(map(int, input().split())) pa = 0 pb = 0 runningSuma = an[0] runningSumb = am[0] count = 0 while (pa < n and pb < m): if (runningSuma == runningSumb and runningSuma != 0): count+=1 pa+=1 pb+...
3
39
F
Pacifist frogs
PROGRAMMING
1,300
[ "implementation" ]
F. Pacifist frogs
2
64
Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to *...
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=109, 1<=≤<=*m*,<=*k*<=≤<=100) — the number of hills, frogs and mosquitoes respectively. The second line contains *m* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the lengths of the frogs’ jumps. The third line contains *k* integers — the numbers of the ...
In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to *m* in the order of the jump length given in the input data.
[ "5 3 5\n2 3 4\n1 2 3 4 5\n", "1000000000 2 3\n2 5\n999999995 999999998 999999996\n" ]
[ "2\n2 3\n", "1\n2\n" ]
none
0
[ { "input": "5 3 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3" }, { "input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2" }, { "input": "1 1 1\n1\n1", "output": "1\n1" }, { "input": "2 2 1\n2 1\n1", "output": "1\n1" }, { "input": "3 2 2\n2 4\n3...
1,582,359,797
2,147,483,647
PyPy 3
OK
TESTS
35
404
2,048,000
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(...
Title: Pacifist frogs Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that c...
```python """ // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip ...
3.883741
453
A
Little Pony and Expected Maximum
PROGRAMMING
1,600
[ "probabilities" ]
null
null
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots...
A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105).
Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4.
[ "6 1\n", "6 3\n", "2 2\n" ]
[ "3.500000000000\n", "4.958333333333\n", "1.750000000000\n" ]
Consider the third test example. If you've made two tosses: 1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2. 1. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1. 1. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2. 1. You can get 2 in t...
500
[ { "input": "6 1", "output": "3.500000000000" }, { "input": "6 3", "output": "4.958333333333" }, { "input": "2 2", "output": "1.750000000000" }, { "input": "5 4", "output": "4.433600000000" }, { "input": "5 8", "output": "4.814773760000" }, { "input": "...
1,548,867,253
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
1,000
1,228,800
from sys import stdin,stdout from collections import defaultdict,Counter from bisect import bisect,bisect_left import math def f(k,n,m): return k*((k**n-(k-1)**n)/(m**n)) #stdin = open('input.txt','r') I = stdin.readline m,n = map(int,I().split()) ans = 0 for i in range(1,m+1): ans+=f(i,n,m...
Title: Little Pony and Expected Maximum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were ...
```python from sys import stdin,stdout from collections import defaultdict,Counter from bisect import bisect,bisect_left import math def f(k,n,m): return k*((k**n-(k-1)**n)/(m**n)) #stdin = open('input.txt','r') I = stdin.readline m,n = map(int,I().split()) ans = 0 for i in range(1,m+1): an...
0
380
C
Sereja and Brackets
PROGRAMMING
2,000
[ "data structures", "schedules" ]
null
null
Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). The answer to the *i*-th query is the length o...
The first line contains a sequence of characters *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*n*<=≤<=106) without any spaces. Each character is either a "(" or a ")". The second line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains a pair of integers. The *i*-th line contains ...
Print the answer to each question on a single line. Print the answers in the order they go in the input.
[ "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n" ]
[ "0\n0\n2\n10\n4\n6\n6\n" ]
A subsequence of length |*x*| of string *s* = *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string *x* = *s*<sub class="lower-index">*k*<sub class="lower-index">1</sub></sub>*s*<sub class="lower-index">*k*<s...
1,500
[ { "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10", "output": "0\n0\n2\n10\n4\n6\n6" }, { "input": "(((((()((((((((((()((()(((((\n1\n8 15", "output": "0" }, { "input": "((()((())(((((((((()(()(()(((((((((((((((()(()((((((((((((((()(((((((((((((((((((()(((\n39\n28 56\n39 ...
1,671,298,063
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
62
0
from sys import stdin as cin from sys import stdout as cout def brafast(bras:list,start, end)->int: lcount = 0 dic = {} mx =0 for i in range(start,end+1): if bras[i] == '(': lcount += 1 elif bras[i] == ')' and lcount >0: lcount -= 1 mx += ...
Title: Sereja and Brackets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has a bracket sequence *s*1,<=*s*2,<=...,<=*s**n*, or, in other words, a string *s* of length *n*, consisting of characters "(" and ")". Sereja needs to answer *m* queries, each of them is described by two i...
```python from sys import stdin as cin from sys import stdout as cout def brafast(bras:list,start, end)->int: lcount = 0 dic = {} mx =0 for i in range(start,end+1): if bras[i] == '(': lcount += 1 elif bras[i] == ')' and lcount >0: lcount -= 1 ...
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,634,767,297
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
17,715,200
n=int(input()) ch=input() L=[int(i)%2 for i in ch.split()] print(L) for i in range(len(L)): if L.count(L[i])==1: print(i+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n=int(input()) ch=input() L=[int(i)%2 for i in ch.split()] print(L) for i in range(len(L)): if L.count(L[i])==1: print(i+1) ```
0
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,688,023,733
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
0
r,g,b = map(int, input().split()) t1,t2,t3 = r,g,b mix = min(r,g,b) r -= mix g -= mix b -= mix red = 0 blue = 0 green = 0 while r: if r >= 3: red += 1 r -= 3 else: break while g: if g >= 3: green += 1 g -= 3 else: break while b: ...
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 r,g,b = map(int, input().split()) t1,t2,t3 = r,g,b mix = min(r,g,b) r -= mix g -= mix b -= mix red = 0 blue = 0 green = 0 while r: if r >= 3: red += 1 r -= 3 else: break while g: if g >= 3: green += 1 g -= 3 else: break w...
0
588
B
Duff in Love
PROGRAMMING
1,300
[ "math" ]
null
null
Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has only divisors of positive integer *n* (and he has all of them). As a birthday present, Malek want...
The first and only line of input contains one integer, *n* (1<=≤<=*n*<=≤<=1012).
Print the answer in one line.
[ "10\n", "12\n" ]
[ "10\n", "6\n" ]
In first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely. In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4 = 2<sup class="upper-index">2</sup>, so 12 is not lovely, while 6 is indeed lovely.
1,000
[ { "input": "10", "output": "10" }, { "input": "12", "output": "6" }, { "input": "1", "output": "1" }, { "input": "2", "output": "2" }, { "input": "4", "output": "2" }, { "input": "8", "output": "2" }, { "input": "3", "output": "3" }, ...
1,552,918,974
2,147,483,647
Python 3
OK
TESTS
53
561
0
n = int(input()) member =[] i = 2 ans =1 while(1): if i*i <=n : if n%i ==0: while(n%i ==0): n //=i ans*=i member.append(i) i+=1 else:break print(ans*n if len(member)>0 else n)
Title: Duff in Love Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is in love with lovely numbers! A positive integer *x* is called lovely if and only if there is no such positive integer *a*<=&gt;<=1 such that *a*2 is a divisor of *x*. Malek has a number store! In his store, he has...
```python n = int(input()) member =[] i = 2 ans =1 while(1): if i*i <=n : if n%i ==0: while(n%i ==0): n //=i ans*=i member.append(i) i+=1 else:break print(ans*n if len(member)>0 else n) ```
3
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,578,352,312
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
import math n=int(input()) u=0 l=0 d=0 for i in range(n): x, y=map(int,input().split()) u+=x l+=x xs=x%2 ys=y%2 if xs!=ys: d=1 if u%2!=0 and l%2!=0: if d==1: print(1) else: print(-1) else: print(-1) ...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python import math n=int(input()) u=0 l=0 d=0 for i in range(n): x, y=map(int,input().split()) u+=x l+=x xs=x%2 ys=y%2 if xs!=ys: d=1 if u%2!=0 and l%2!=0: if d==1: print(1) else: print(-1) else: print(-1) ...
0
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady...
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whe...
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO"...
1,644,194,038
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
30
0
l=input() l=l.split() n=int(l[0]) t=int(l[1]) k=int(l[2]) d=int(l[3]) x=d/t n=n-(x*k) if n>0: if d%t!=0: print("YES") else: if n>k: print("YES") else: print("NO") else: print("NO")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu...
```python l=input() l=l.split() n=int(l[0]) t=int(l[1]) k=int(l[2]) d=int(l[3]) x=d/t n=n-(x*k) if n>0: if d%t!=0: print("YES") else: if n>k: print("YES") else: print("NO") else: print("NO") ```
0
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d...
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "inpu...
1,590,040,232
2,147,483,647
PyPy 3
OK
TESTS
41
155
0
import math n = int(input()) names = {1:'Sheldon', 2:'Leonard', 3:'Penny', 4:'Rajesh', 5:'Howard'} r = 0 while(5*(2**r) < n): n-= 5*(2**r) r+=1 print(names[math.ceil(n/(2**r))])
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin...
```python import math n = int(input()) names = {1:'Sheldon', 2:'Leonard', 3:'Penny', 4:'Rajesh', 5:'Howard'} r = 0 while(5*(2**r) < n): n-= 5*(2**r) r+=1 print(names[math.ceil(n/(2**r))]) ```
3.9225
173
B
Chamber of Secrets
PROGRAMMING
1,800
[ "dfs and similar", "shortest paths" ]
null
null
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anyb...
The first line of the input contains two integer numbers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=1000). Each of the next *n* lines contains *m* characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.
Print the minimum number of columns to make magic or -1 if it's impossible to do.
[ "3 3\n.#.\n...\n.#.\n", "4 3\n##.\n...\n.#.\n.#.\n" ]
[ "2\n", "2\n" ]
The figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk...
1,000
[ { "input": "3 3\n.#.\n...\n.#.", "output": "2" }, { "input": "4 3\n##.\n...\n.#.\n.#.", "output": "2" }, { "input": "3 3\n###\n###\n###", "output": "2" }, { "input": "3 4\n..##\n....\n..#.", "output": "2" }, { "input": "4 3\n#.#\n...\n...\n.##", "output": "2" ...
1,698,962,146
2,147,483,647
Python 3
OK
TESTS
105
996
54,886,400
from collections import deque n, m = map(int, input().split()) arr = [[] for _ in range(n + m)] ret = -1 q, q2= deque([0]), deque([0]) s = set([0]) for x in range(n): row = input() for y in range(m): if row[y] == '#': arr[x].append(y + n) arr[y + n].append(x) while q: temp =...
Title: Chamber of Secrets Time Limit: None seconds Memory Limit: None megabytes Problem Description: "The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter...
```python from collections import deque n, m = map(int, input().split()) arr = [[] for _ in range(n + m)] ret = -1 q, q2= deque([0]), deque([0]) s = set([0]) for x in range(n): row = input() for y in range(m): if row[y] == '#': arr[x].append(y + n) arr[y + n].append(x) while q: ...
3
650
A
Watchmen
PROGRAMMING
1,400
[ "data structures", "geometry", "math" ]
null
null
Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manha...
The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide.
Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel.
[ "3\n1 1\n7 5\n1 5\n", "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1\n" ]
[ "2\n", "11\n" ]
In the first sample, the distance between watchman 1 and watchman 2 is equal to |1 - 7| + |1 - 5| = 10 for Doctor Manhattan and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bcb5b7064b5f02088da0fdcf677e6fda495dd0df.png" style="max-width: 100.0%;max-height: 100.0%;"/> for Daniel. For pairs...
500
[ { "input": "3\n1 1\n7 5\n1 5", "output": "2" }, { "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11" }, { "input": "10\n46 -55\n46 45\n46 45\n83 -55\n46 45\n83 -55\n46 45\n83 45\n83 45\n46 -55", "output": "33" }, { "input": "1\n-5 -90", "output": "0" }, { ...
1,619,926,510
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
93
307,200
from collections import defaultdict n = int(input()) X = defaultdict((lambda : 0)) Y = defaultdict((lambda : 0)) S = set() cnt = 0 for _ in range(n): x, y = map(int, input().split()) S.add((x, y)) cnt += X[x] cnt += Y[y] X[x] += 1 Y[y] += 1 d = n - len(S) print(cnt - d)
Title: Watchmen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They n...
```python from collections import defaultdict n = int(input()) X = defaultdict((lambda : 0)) Y = defaultdict((lambda : 0)) S = set() cnt = 0 for _ in range(n): x, y = map(int, input().split()) S.add((x, y)) cnt += X[x] cnt += Y[y] X[x] += 1 Y[y] += 1 d = n - len(S) print(...
0
897
B
Chtholly's request
PROGRAMMING
1,300
[ "brute force" ]
null
null
— I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thinking about a problem for days: If a number is palindrome and length of its decimal representation with...
The first line contains two integers *k* and *p* (1<=≤<=*k*<=≤<=105,<=1<=≤<=*p*<=≤<=109).
Output single integer — answer to the problem.
[ "2 100\n", "5 30\n" ]
[ "33\n", "15\n" ]
In the first example, the smallest zcy number is 11, and the second smallest zcy number is 22. In the second example, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/68fffad54395f7d920ad0384e07c6215ddc64141.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
1,000
[ { "input": "2 100", "output": "33" }, { "input": "5 30", "output": "15" }, { "input": "42147 412393322", "output": "251637727" }, { "input": "77809 868097296", "output": "440411873" }, { "input": "5105 443422097", "output": "363192634" }, { "input": "7...
1,513,534,875
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
5,529,600
k=int(input()) p=int(input()) ans=0 for i in range(1,k+1): a=str(i) a+=a[::-1] ans+=int(a) print(ans%p)
Title: Chtholly's request Time Limit: None seconds Memory Limit: None megabytes Problem Description: — I experienced so many great things. — You gave me memories like dreams... But I have to leave now... — One last request, can you... — Help me solve a Codeforces problem? — ...... — What? Chtholly has been thi...
```python k=int(input()) p=int(input()) ans=0 for i in range(1,k+1): a=str(i) a+=a[::-1] ans+=int(a) print(ans%p) ```
-1
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,596,961,863
2,147,483,647
Python 3
OK
TESTS
102
109
6,656,000
def result(a,b): r = "" for (x,y) in zip(a, b): if x != y: r += '1' else: r += '0' print(r) if __name__ == "__main__": a = input(); b = input(); result(a,b)
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 def result(a,b): r = "" for (x,y) in zip(a, b): if x != y: r += '1' else: r += '0' print(r) if __name__ == "__main__": a = input(); b = input(); result(a,b) ```
3.960352
769
A
Year of University Entrance
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed tha...
Print the year of Igor's university entrance.
[ "3\n2014 2016 2015\n", "1\n2050\n" ]
[ "2015\n", "2050\n" ]
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
500
[ { "input": "3\n2014 2016 2015", "output": "2015" }, { "input": "1\n2050", "output": "2050" }, { "input": "1\n2010", "output": "2010" }, { "input": "1\n2011", "output": "2011" }, { "input": "3\n2010 2011 2012", "output": "2011" }, { "input": "3\n2049 20...
1,646,598,680
2,147,483,647
Python 3
OK
TESTS
45
46
0
n = int(input()) print(sorted(input().split())[n//2])
Title: Year of University Entrance Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond...
```python n = int(input()) print(sorted(input().split())[n//2]) ```
3
143
A
Help Vasilisa the Wise 2
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with tha...
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the colum...
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any.
[ "3 7\n4 6\n5 5\n", "11 10\n13 8\n5 16\n", "1 2\n3 4\n5 6\n", "10 10\n10 10\n10 10\n" ]
[ "1 2\n3 4\n", "4 7\n9 1\n", "-1\n", "-1\n" ]
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9.
500
[ { "input": "3 7\n4 6\n5 5", "output": "1 2\n3 4" }, { "input": "11 10\n13 8\n5 16", "output": "4 7\n9 1" }, { "input": "1 2\n3 4\n5 6", "output": "-1" }, { "input": "10 10\n10 10\n10 10", "output": "-1" }, { "input": "5 13\n8 10\n11 7", "output": "3 2\n5 8" ...
1,689,261,442
2,147,483,647
PyPy 3-64
OK
TESTS
52
124
1,945,600
r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) flag = False for x in range(1, 10): for y in range(1, 10): for x1 in range(1, 10): for y1 in range(1, 10): if x + y == c1 and x1 + y1 == c2 and x + x1 == r1 and y + y1...
Title: Help Vasilisa the Wise 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know wha...
```python r1, r2 = map(int, input().split()) c1, c2 = map(int, input().split()) d1, d2 = map(int, input().split()) flag = False for x in range(1, 10): for y in range(1, 10): for x1 in range(1, 10): for y1 in range(1, 10): if x + y == c1 and x1 + y1 == c2 and x + x1 == r1 ...
3
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of hi...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*be...
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before...
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342...
1,642,222,803
2,147,483,647
PyPy 3-64
OK
TESTS
60
109
0
n=int(input()) p=0 for i in range(n): a=input().split() if int(a[1])>=2400 and int(a[1])<int(a[2]): p=1 break if p==1: print('YES') else: print('NO')
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ...
```python n=int(input()) p=0 for i in range(n): a=input().split() if int(a[1])>=2400 and int(a[1])<int(a[2]): p=1 break if p==1: print('YES') else: print('NO') ```
3
809
E
Surprise me!
PROGRAMMING
3,100
[ "divide and conquer", "math", "number theory", "trees" ]
null
null
Tired of boring dates, Leha and Noora decided to play a game. Leha found a tree with *n* vertices numbered from 1 to *n*. We remind you that tree is an undirected graph without cycles. Each vertex *v* of a tree has a number *a**v* written on it. Quite by accident it turned out that all values written on vertices are d...
The first line of input contains one integer number *n* (2<=≤<=*n*<=≤<=2·105)  — number of vertices in a tree. The second line contains *n* different numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) separated by spaces, denoting the values written on a tree vertices. Each of the next *n*<=-<=1 lines contains...
In a single line print a number equal to *P*·*Q*<=-<=1 modulo 109<=+<=7.
[ "3\n1 2 3\n1 2\n2 3\n", "5\n5 4 3 1 2\n3 5\n1 2\n4 3\n2 5\n" ]
[ "333333338\n", "8\n" ]
Euler's totient function φ(*n*) is the number of such *i* that 1 ≤ *i* ≤ *n*,and *gcd*(*i*, *n*) = 1, where *gcd*(*x*, *y*) is the greatest common divisor of numbers *x* and *y*. There are 6 variants of choosing vertices by Leha and Noora in the first testcase: - *u* = 1, *v* = 2, *f*(1, 2) = φ(*a*<sub class="lower-...
2,500
[]
1,689,437,215
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689437215.1884954")# 1689437215.188516
Title: Surprise me! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tired of boring dates, Leha and Noora decided to play a game. Leha found a tree with *n* vertices numbered from 1 to *n*. We remind you that tree is an undirected graph without cycles. Each vertex *v* of a tree has a numb...
```python print("_RANDOM_GUESS_1689437215.1884954")# 1689437215.188516 ```
0
812
A
Sagheer and Crossroads
PROGRAMMING
1,200
[ "implementation" ]
null
null
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
The input consists of four lines with each line describing a road part given in a counter-clockwise order. Each line contains four integers *l*, *s*, *r*, *p* — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.
On a single line, print "YES" if an accident is possible, and "NO" otherwise.
[ "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n" ]
[ "YES\n", "NO\n", "NO\n" ]
In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4. In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.
500
[ { "input": "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1", "output": "YES" }, { "input": "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1", "output": "NO" }, { "input": "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0", "output": "NO" }, { "input": "0 0 0 0\n0 0 0 1\n0 0 0 1\n0 0 0 1", "output": "NO" }, ...
1,496,328,298
1,798
PyPy 3
OK
TESTS
93
108
0
l1, s1, r1, p1 = map(int, input().split()) l2, s2, r2, p2 = map(int, input().split()) l3, s3, r3, p3 = map(int, input().split()) l4, s4, r4, p4 = map(int, input().split()) if (p1 and (r1 or s1 or l1 or r4 or l2 or s3)) or (p2 and (r2 or s2 or l2 or l3 or r1 or s4)) or \ (p3 and (r3 or s3 or l3 or l4 or r2 or ...
Title: Sagheer and Crossroads Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 l...
```python l1, s1, r1, p1 = map(int, input().split()) l2, s2, r2, p2 = map(int, input().split()) l3, s3, r3, p3 = map(int, input().split()) l4, s4, r4, p4 = map(int, input().split()) if (p1 and (r1 or s1 or l1 or r4 or l2 or s3)) or (p2 and (r2 or s2 or l2 or l3 or r1 or s4)) or \ (p3 and (r3 or s3 or l3 or l4...
3
58
B
Coins
PROGRAMMING
1,300
[ "greedy" ]
B. Coins
2
256
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be d...
The first and only line contains an integer *n* (1<=≤<=*n*<=≤<=106) which represents the denomination of the most expensive coin.
Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination *n* of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coin...
[ "10\n", "4\n", "3\n" ]
[ "10 5 1\n", "4 2 1\n", "3 1\n" ]
none
1,000
[ { "input": "10", "output": "10 5 1" }, { "input": "4", "output": "4 2 1" }, { "input": "3", "output": "3 1" }, { "input": "2", "output": "2 1" }, { "input": "5", "output": "5 1" }, { "input": "6", "output": "6 3 1" }, { "input": "7", "o...
1,605,891,154
2,147,483,647
Python 3
OK
TESTS
50
248
409,600
import math from collections import deque def solve(n): d = deque() d.append(n) while n % 2 == 0 : n //=2 d.append(n) for j in range(3 , int(math.sqrt(n)) + 1): while n % j == 0 : n //= j d.append(n) if n > 2 : if n not i...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly *n* Berland dollars. Also the following...
```python import math from collections import deque def solve(n): d = deque() d.append(n) while n % 2 == 0 : n //=2 d.append(n) for j in range(3 , int(math.sqrt(n)) + 1): while n % j == 0 : n //= j d.append(n) if n > 2 : ...
3.937237
489
A
SwapSort
PROGRAMMING
1,200
[ "greedy", "implementation", "sortings" ]
null
null
In this problem your goal is to sort an array consisting of *n* integers in at most *n* swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after another. Note that in this problem you do not have to minimize the number o...
The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=3000) — the number of array elements. The second line contains elements of array: *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the *i*-th element of the array. The elements are numerated from 0 to *n*<=-<=1 from left to r...
In the first line print *k* (0<=≤<=*k*<=≤<=*n*) — the number of swaps. Next *k* lines must contain the descriptions of the *k* swaps, one per line. Each swap should be printed as a pair of integers *i*, *j* (0<=≤<=*i*,<=*j*<=≤<=*n*<=-<=1), representing the swap of elements *a**i* and *a**j*. You can print indices in th...
[ "5\n5 2 5 1 4\n", "6\n10 20 20 40 60 60\n", "2\n101 100\n" ]
[ "2\n0 3\n4 2\n", "0\n", "1\n0 1\n" ]
none
500
[ { "input": "5\n5 2 5 1 4", "output": "2\n0 3\n4 2" }, { "input": "6\n10 20 20 40 60 60", "output": "0" }, { "input": "2\n101 100", "output": "1\n0 1" }, { "input": "1\n1000", "output": "0" }, { "input": "2\n1000000000 -1000000000", "output": "1\n0 1" }, { ...
1,689,852,206
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
31
0
def swap_sort(arr): n = len(arr) swaps = [] for i in range(n): for j in range(n - 1): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] swaps.append((j, j + 1)) return swaps n = int(input()) arr = list(map(int, input()...
Title: SwapSort Time Limit: None seconds Memory Limit: None megabytes Problem Description: In this problem your goal is to sort an array consisting of *n* integers in at most *n* swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecu...
```python def swap_sort(arr): n = len(arr) swaps = [] for i in range(n): for j in range(n - 1): if arr[j] > arr[j + 1]: arr[j], arr[j + 1] = arr[j + 1], arr[j] swaps.append((j, j + 1)) return swaps n = int(input()) arr = list(map(in...
0
445
A
DZY Loves Chessboard
PROGRAMMING
1,200
[ "dfs and similar", "implementation" ]
null
null
DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with th...
The first line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). Each of the next *n* lines contains a string of *m* characters: the *j*-th character of the *i*-th string is either "." or "-". A "." means that the corresponding cell (in the *i*-th row and the *j*-th column) is good, while a ...
Output must contain *n* lines, each line must contain a string of *m* characters. The *j*-th character of the *i*-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It ...
[ "1 1\n.\n", "2 2\n..\n..\n", "3 3\n.-.\n---\n--." ]
[ "B\n", "BW\nWB\n", "B-B\n---\n--B" ]
In the first sample, DZY puts a single black chessman. Of course putting a white one is also OK. In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output. In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.
500
[ { "input": "1 1\n.", "output": "B" }, { "input": "2 2\n..\n..", "output": "BW\nWB" }, { "input": "3 3\n.-.\n---\n--.", "output": "B-B\n---\n--B" }, { "input": "3 1\n-\n.\n.", "output": "-\nW\nB" }, { "input": "11 11\n-----------\n-----------\n-----------\n--------...
1,679,429,787
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
# t = int(input()) t = 1 def adj(i, j, n, m): neighbours = [ [i-1,j], [i,j+1], [i+1,j], [i,j-1] ] # print(neighbours) for i in range(4): x = neighbours[i] if x[0] > n-1 or x[0] < 0: neighbours[i] = None elif x[1] > m-1 or x[1] < 0: neighbours[i] = None # print(neighbours) retur...
Title: DZY Loves Chessboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves chessboard, and he enjoys playing with it. He has a chessboard of *n* rows and *m* columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. ...
```python # t = int(input()) t = 1 def adj(i, j, n, m): neighbours = [ [i-1,j], [i,j+1], [i+1,j], [i,j-1] ] # print(neighbours) for i in range(4): x = neighbours[i] if x[0] > n-1 or x[0] < 0: neighbours[i] = None elif x[1] > m-1 or x[1] < 0: neighbours[i] = None # print(neighbour...
0
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ...
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\...
1,418,027,884
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
6,041,600
n = int(input()) seq = list(map(int, input().split())) seq = sorted(seq)[::-1] score = 0 SUM = sum(seq) inc = 0 for i in range(n): score += SUM - inc last, seq = seq[-1], seq[:-1] inc += last if not seq: break score += last print(score)
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all...
```python n = int(input()) seq = list(map(int, input().split())) seq = sorted(seq)[::-1] score = 0 SUM = sum(seq) inc = 0 for i in range(n): score += SUM - inc last, seq = seq[-1], seq[:-1] inc += last if not seq: break score += last print(score) ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consi...
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* bel...
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,616,072,144
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
204,800
n = int(input()) m = int(input()) val = {} for i in range(m): tmp = list(input().split()) a = tmp[0] b = tmp[1] if len(a) <= len(b): val[a] = a else: val[a] = b lecture = list(input().split()) ans = '' for x in lecture: ans += (val[x] + ' ') print(ans)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first ...
```python n = int(input()) m = int(input()) val = {} for i in range(m): tmp = list(input().split()) a = tmp[0] b = tmp[1] if len(a) <= len(b): val[a] = a else: val[a] = b lecture = list(input().split()) ans = '' for x in lecture: ans += (val[x] + ' ') print(ans) ...
-1
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,605,972,900
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
3,000
7,065,600
from math import sqrt def getMaxAndMin(cities): sol = [] # brute force over the whole cities for i in range(len(cities)): distances = [] for j in range(len(cities)): if cities[i] != cities[j]: x1 = cities[i] x2 = cities[j] ...
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love...
```python from math import sqrt def getMaxAndMin(cities): sol = [] # brute force over the whole cities for i in range(len(cities)): distances = [] for j in range(len(cities)): if cities[i] != cities[j]: x1 = cities[i] x2 = cities[j] ...
0
764
B
Timofey and cubes
PROGRAMMING
900
[ "constructive algorithms", "implementation" ]
null
null
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents. In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup...
The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order.
Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order. It can be shown that the answer is unique.
[ "7\n4 3 7 6 9 1 2\n", "8\n6 1 4 2 5 6 9 2\n" ]
[ "2 3 9 6 7 1 4", "2 1 6 2 5 4 9 6" ]
Consider the first sample. 1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha...
1,000
[ { "input": "7\n4 3 7 6 9 1 2", "output": "2 3 9 6 7 1 4" }, { "input": "8\n6 1 4 2 5 6 9 2", "output": "2 1 6 2 5 4 9 6" }, { "input": "1\n1424", "output": "1424" }, { "input": "9\n-7 9 -4 9 -6 11 15 2 -10", "output": "-10 9 15 9 -6 11 -4 2 -7" }, { "input": "2\n2...
1,656,603,266
2,147,483,647
Python 3
OK
TESTS
34
327
14,233,600
n=int(input()) ar=input().split() for i in range(1,n//2+1,2): ar[i-1],ar[-i]=ar[-i],ar[i-1] print(*ar)
Title: Timofey and cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p...
```python n=int(input()) ar=input().split() for i in range(1,n//2+1,2): ar[i-1],ar[-i]=ar[-i],ar[i-1] print(*ar) ```
3
931
A
Friends Meeting
PROGRAMMING
800
[ "brute force", "greedy", "implementation", "math" ]
null
null
Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes acco...
The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1000) — the initial position of the first friend. The second line contains a single integer *b* (1<=≤<=*b*<=≤<=1000) — the initial position of the second friend. It is guaranteed that *a*<=≠<=*b*.
Print the minimum possible total tiredness if the friends meet in the same point.
[ "3\n4\n", "101\n99\n", "5\n10\n" ]
[ "1\n", "2\n", "9\n" ]
In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1. In the second example the first friend should move by one to the left, an...
500
[ { "input": "3\n4", "output": "1" }, { "input": "101\n99", "output": "2" }, { "input": "5\n10", "output": "9" }, { "input": "1\n2", "output": "1" }, { "input": "1\n1000", "output": "250000" }, { "input": "999\n1000", "output": "1" }, { "inpu...
1,659,896,004
2,147,483,647
PyPy 3-64
OK
TESTS
40
77
0
a = int(input()) b = int(input()) def tiredness(point_one, point_two): difference = abs(point_one - point_two) steps_for_each = int(difference / 2) result = steps_for_each * (steps_for_each + 1) if (difference % 2 != 0): result += (steps_for_each + 1) return result pri...
Title: Friends Meeting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two friends are on the coordinate axis *Ox* in points with integer coordinates. One of them is in the point *x*1<==<=*a*, another one is in the point *x*2<==<=*b*. Each of the friends can move by one along the line in...
```python a = int(input()) b = int(input()) def tiredness(point_one, point_two): difference = abs(point_one - point_two) steps_for_each = int(difference / 2) result = steps_for_each * (steps_for_each + 1) if (difference % 2 != 0): result += (steps_for_each + 1) return resul...
3
670
D2
Magic Powder - 2
PROGRAMMING
1,500
[ "binary search", "implementation" ]
null
null
The term of this problem is the same as the previous one, the only exception — increased restrictions.
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*<=≤<=109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where the *i*-th number is equal to the number of gram...
Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.
[ "1 1000000000\n1\n1000000000\n", "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1\n", "3 1\n2 1 4\n11 3 16\n", "4 3\n4 3 5 6\n11 12 14 20\n" ]
[ "2000000000\n", "0\n", "4\n", "3\n" ]
none
500
[ { "input": "1 1000000000\n1\n1000000000", "output": "2000000000" }, { "input": "10 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3 1\n2 1 4\n11 3 16", "output": "4" ...
1,673,029,284
2,147,483,647
PyPy 3-64
OK
TESTS
150
140
19,456,000
n,k = map(int,input().split()) a = list((map(int,input().split()))) b = list((map(int,input().split()))) low = 0 high = 1e18 while (low < high): mid = (low + high + 1)//2 req = 0 for i in range(0,n): req = req + max(0,(mid*a[i])-b[i]) if req > k: high = mid - 1 else: ...
Title: Magic Powder - 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: The term of this problem is the same as the previous one, the only exception — increased restrictions. Input Specification: The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*k*...
```python n,k = map(int,input().split()) a = list((map(int,input().split()))) b = list((map(int,input().split()))) low = 0 high = 1e18 while (low < high): mid = (low + high + 1)//2 req = 0 for i in range(0,n): req = req + max(0,(mid*a[i])-b[i]) if req > k: high = mid - 1 ...
3
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,542,623,981
2,147,483,647
Python 3
OK
TESTS
30
278
204,800
from collections import deque n, p1, p2, p3, t1, t2 = map(int, input().split()) d = {1: p1, 2: p2, 3: p3} LR = [tuple(map(int, input().split())) for _ in range(n)] q = deque(sorted( [(LR[_][0], 'left') for _ in range(n)] + [(LR[_][1], 'right') for _ in range(n)] )) p, m, t, T = 0, 1, LR[0][0], LR[-1][...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python from collections import deque n, p1, p2, p3, t1, t2 = map(int, input().split()) d = {1: p1, 2: p2, 3: p3} LR = [tuple(map(int, input().split())) for _ in range(n)] q = deque(sorted( [(LR[_][0], 'left') for _ in range(n)] + [(LR[_][1], 'right') for _ in range(n)] )) p, m, t, T = 0, 1, LR[0][0...
3.860619
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe...
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": ...
1,699,304,904
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
62
0
from sys import stdin def main(): suma = [int(x) for x in stdin.readline().split("+")] if len(suma) == 1: print(suma[i]) else: suma.sort() resp = "" for i in range(len(suma)): resp += str(suma[i]) + "+" resp = resp.strip("+") print(resp)...
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak...
```python from sys import stdin def main(): suma = [int(x) for x in stdin.readline().split("+")] if len(suma) == 1: print(suma[i]) else: suma.sort() resp = "" for i in range(len(suma)): resp += str(suma[i]) + "+" resp = resp.strip("+") p...
-1
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,674,454,148
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
s = input() lw = 0 up = 0 for i in range(0,s.__len__()): if s[i].islower(): lw+=1; else: up+=1; if(lw > up): print(s.lower()) else: print(s.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s = input() lw = 0 up = 0 for i in range(0,s.__len__()): if s[i].islower(): lw+=1; else: up+=1; if(lw > up): print(s.lower()) else: print(s.upper()) ```
0
803
C
Maximal GCD
PROGRAMMING
1,900
[ "constructive algorithms", "greedy", "math" ]
null
null
You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divi...
The first line consists of two numbers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1010).
If the answer exists then output *k* numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
[ "6 3\n", "8 2\n", "5 3\n" ]
[ "1 2 3\n", "2 6\n", "-1\n" ]
none
0
[ { "input": "6 3", "output": "1 2 3" }, { "input": "8 2", "output": "2 6" }, { "input": "5 3", "output": "-1" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output": "-1" }, { "input": "2 1", "output": "2" }, { "input": "2 10000000...
1,497,850,919
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
62
0
data=input() ss=int(data.split(" ")[0]) nn=int(data.split(" ")[1]) base=(nn**2+nn)/2 i=int(ss/base) result=[] lss=0 if i==0: print (-1) elif i!=0: for x in range(1,nn): result.append(str((i)*x)) lss+=(i)*x result.append(str(ss-lss)) print (" ".join(result))
Title: Maximal GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given positive integer number *n*. You should create such strictly increasing sequence of *k* positive numbers *a*1,<=*a*2,<=...,<=*a**k*, that their sum is equal to *n* and greatest common divisor is maximal. Grea...
```python data=input() ss=int(data.split(" ")[0]) nn=int(data.split(" ")[1]) base=(nn**2+nn)/2 i=int(ss/base) result=[] lss=0 if i==0: print (-1) elif i!=0: for x in range(1,nn): result.append(str((i)*x)) lss+=(i)*x result.append(str(ss-lss)) print (" ".join(result)) ``...
0
186
A
Comparing Strings
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Mish...
The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co...
Print "YES", if the dwarves belong to the same race. Otherwise, print "NO".
[ "ab\nba\n", "aa\nab\n" ]
[ "YES\n", "NO\n" ]
- First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b".
500
[ { "input": "ab\nba", "output": "YES" }, { "input": "aa\nab", "output": "NO" }, { "input": "a\nza", "output": "NO" }, { "input": "vvea\nvvae", "output": "YES" }, { "input": "rtfabanpc\natfabrnpc", "output": "YES" }, { "input": "mt\ntm", "output": "Y...
1,605,178,243
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
372
2,048,000
s1 = input() s2 = input() if(not len(s1) == len(s2)): print("NO") exit() i = 0 j =len(s1)-1 while i<j+1 and s1[i] == s2[i]: i += 1 while j>=0 and s1[j] == s2[j]: j -= 1 s1[i],s1[j] = s1[j],s1[i] if(s1 == s2): print("YES") else: print('NO')
Title: Comparing Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ...
```python s1 = input() s2 = input() if(not len(s1) == len(s2)): print("NO") exit() i = 0 j =len(s1)-1 while i<j+1 and s1[i] == s2[i]: i += 1 while j>=0 and s1[j] == s2[j]: j -= 1 s1[i],s1[j] = s1[j],s1[i] if(s1 == s2): print("YES") else: print('NO') ```
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,563,456,351
2,147,483,647
Python 3
OK
TESTS
81
248
0
m=[] s=[] l=[] for _ in range(int(input())): l.append(list(map(int,input().split()))) for j in range(len(l[0])): for i in range(len(l)): m.append(l[i][j]) s.append(m) m=[] if all(list(map(lambda x:sum(x)==0,s))): print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python m=[] s=[] l=[] for _ in range(int(input())): l.append(list(map(int,input().split()))) for j in range(len(l[0])): for i in range(len(l)): m.append(l[i][j]) s.append(m) m=[] if all(list(map(lambda x:sum(x)==0,s))): print('YES') else: print('NO') ```
3.938
828
A
Restaurant Tables
PROGRAMMING
1,200
[ "implementation" ]
null
null
In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate...
The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d...
Print the total number of people the restaurant denies service to.
[ "4 1 2\n1 2 1 1\n", "4 1 1\n1 1 2 1\n" ]
[ "0\n", "2\n" ]
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin...
500
[ { "input": "4 1 2\n1 2 1 1", "output": "0" }, { "input": "4 1 1\n1 1 2 1", "output": "2" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 1 2\n2 2", "output": "0" }, { "input": "5 1 3\n1 2 2 2 1", "output": "1" }, { "input": "7 6 1\n1 1 1 1 1 1...
1,613,939,161
2,147,483,647
PyPy 3
OK
TESTS
97
155
12,492,800
n, a, b = map(int, input().split()) groups = list(map(int, input().split())) # b = b * 2 halfFilled = 0 ans = 0 for i in range(n): if groups[i] == 1: if a > 0: a -= 1 elif b > 0: b -= 1 halfFilled += 1 elif halfFilled > 0: halfFilled -= 1 else: ans += 1 else: if b > 0: b ...
Title: Restaurant Tables Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, i...
```python n, a, b = map(int, input().split()) groups = list(map(int, input().split())) # b = b * 2 halfFilled = 0 ans = 0 for i in range(n): if groups[i] == 1: if a > 0: a -= 1 elif b > 0: b -= 1 halfFilled += 1 elif halfFilled > 0: halfFilled -= 1 else: ans += 1 else: if b >...
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,689,772,599
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
m = input().split(" ") A = [] for i in range(int(m[0])+1): k = input() A.append(k) print(A) C="" D="" for a in range(int(m[0])): for b in range(int(m[1])): if A[a][b] == "*": if str(a) in C: C=C.strip(str(a)) else: C=C+str(a) ...
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 m = input().split(" ") A = [] for i in range(int(m[0])+1): k = input() A.append(k) print(A) C="" D="" for a in range(int(m[0])): for b in range(int(m[1])): if A[a][b] == "*": if str(a) in C: C=C.strip(str(a)) else: C=C+s...
-1
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c...
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo...
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,656,594,395
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
3,000
6,553,600
n = input() cities = list(map(int, input().split())) timp_list = [] for current_city in cities: for city in cities: if current_city != city: timp_list.append(abs(current_city-city)) print(f"{min(timp_list)} {max(timp_list)}") timp_list.clear()
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love...
```python n = input() cities = list(map(int, input().split())) timp_list = [] for current_city in cities: for city in cities: if current_city != city: timp_list.append(abs(current_city-city)) print(f"{min(timp_list)} {max(timp_list)}") timp_list.clear() ```
0
710
A
King Moves
PROGRAMMING
800
[ "implementation" ]
null
null
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik...
The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'.
Print the only integer *x* — the number of moves permitted for the king.
[ "e4\n" ]
[ "8\n" ]
none
0
[ { "input": "e4", "output": "8" }, { "input": "a1", "output": "3" }, { "input": "h8", "output": "3" }, { "input": "a4", "output": "5" }, { "input": "g7", "output": "8" }, { "input": "e1", "output": "5" }, { "input": "b2", "output": "8" ...
1,600,501,570
2,147,483,647
Python 3
OK
TESTS
24
108
307,200
s = input() if(s == 'a1'): print(3) elif(s == 'a8'): print(3) elif(s == 'h1'): print(3) elif(s == 'h8'): print(3) elif(s[0] == 'a'): print(5) elif(s[0] == 'h'): print(5) elif(s[1] == '1'): print(5) elif(s[1] == '8'): print(5) else: print(8)
Title: King Moves Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check...
```python s = input() if(s == 'a1'): print(3) elif(s == 'a8'): print(3) elif(s == 'h1'): print(3) elif(s == 'h8'): print(3) elif(s[0] == 'a'): print(5) elif(s[0] == 'h'): print(5) elif(s[1] == '1'): print(5) elif(s[1] == '8'): print(5) else: print(8) ```
3
475
A
Bayan Bus
PROGRAMMING
1,100
[ "implementation" ]
null
null
The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. The event coordinator has a list of *k* participants who should be picked up at the airport. When a...
The only line of input contains integer *k*, (0<=≤<=*k*<=≤<=34), denoting the number of participants.
Print the figure of a bus with *k* passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six ...
[ "9\n", "20\n" ]
[ "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n", "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O.O.#.#.#.#.#.|.|\n|O.......................|\n|O.O.O.O.O.O.#.#.#.#.#.|.|...
none
500
[ { "input": "9", "output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+" }, { "input": "20", "output": "+------------------------+\n|O.O.O.O.O.O.O.#.#.#.#.|D|)\n|O.O.O.O.O....
1,488,304,053
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
62
4,608,000
k = int(input()) bus = [] bus.append([]) bus.append([]) bus.append([]) bus.append([]) row = 0 for i in range(k): bus[row].append("O") row = (row + 1) % len(bus) if (i > 4 and row == 2): row += 1 for i in range(11 - len(bus[0])): bus[0].append("#") for i in range(11 - len(bus[1])): bus[1]....
Title: Bayan Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. The ...
```python k = int(input()) bus = [] bus.append([]) bus.append([]) bus.append([]) bus.append([]) row = 0 for i in range(k): bus[row].append("O") row = (row + 1) % len(bus) if (i > 4 and row == 2): row += 1 for i in range(11 - len(bus[0])): bus[0].append("#") for i in range(11 - len(bus[1])): ...
0
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,684,278,123
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
108
18,841,600
n = int(input()) MAX = int(10e5) l = [19] for i in range(2, MAX + 1000): if (l[len(l) - 1] + 9) % 10 != 0: l.append(l[len(l) - 1] + 9) else: l.append(l[len(l) - 1] + 18) print(l[n-1])
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 n = int(input()) MAX = int(10e5) l = [19] for i in range(2, MAX + 1000): if (l[len(l) - 1] + 9) % 10 != 0: l.append(l[len(l) - 1] + 9) else: l.append(l[len(l) - 1] + 18) print(l[n-1]) ```
0
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,610,033,245
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
12
2,000
307,200
import sys def count(n): old = [0]*4 curr = [0]*4 curr[0] = curr[1] = curr[2] = 1 curr[3] = 0 for i in range(n-1): old[0], old[1], old[2], old[3]= curr[0], curr[1], curr[2], curr[3] curr[0] = (old[1] + old[2] + old[3]) % 1000000007 curr[1] = (old[0] + old[2] + old[3]) % 1000000007 curr[2] = (...
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python import sys def count(n): old = [0]*4 curr = [0]*4 curr[0] = curr[1] = curr[2] = 1 curr[3] = 0 for i in range(n-1): old[0], old[1], old[2], old[3]= curr[0], curr[1], curr[2], curr[3] curr[0] = (old[1] + old[2] + old[3]) % 1000000007 curr[1] = (old[0] + old[2] + old[3]) % 1000000007 c...
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,574,281,960
2,147,483,647
PyPy 3
OK
TESTS
32
280
0
n = int(input()) lists = list(map(int, input().rstrip().split())) for i in range(len(lists)): for j in range(len(lists)): if i != j: if abs(lists[i]-lists[j])%2 == 1: c = 0 else: c = 1 break if c == 0: i...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) lists = list(map(int, input().rstrip().split())) for i in range(len(lists)): for j in range(len(lists)): if i != j: if abs(lists[i]-lists[j])%2 == 1: c = 0 else: c = 1 break if c == 0: ...
3.93
115
A
Party
PROGRAMMING
900
[ "dfs and similar", "graphs", "trees" ]
null
null
A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immedi...
The first line contains integer *n* (1<=≤<=*n*<=≤<=2000) — the number of employees. The next *n* lines contain the integers *p**i* (1<=≤<=*p**i*<=≤<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate...
Print a single integer denoting the minimum number of groups that will be formed in the party.
[ "5\n-1\n1\n2\n1\n-1\n" ]
[ "3\n" ]
For the first example, three groups are sufficient, for example: - Employee 1 - Employees 2 and 4 - Employees 3 and 5
500
[ { "input": "5\n-1\n1\n2\n1\n-1", "output": "3" }, { "input": "4\n-1\n1\n2\n3", "output": "4" }, { "input": "12\n-1\n1\n2\n3\n-1\n5\n6\n7\n-1\n9\n10\n11", "output": "4" }, { "input": "6\n-1\n-1\n2\n3\n1\n1", "output": "3" }, { "input": "3\n-1\n1\n1", "output": ...
1,660,048,677
2,147,483,647
Python 3
OK
TESTS
106
124
409,600
from collections import deque n = int(input()) company = {} maximum = 0 for i in range(1, n+1): e = int(input()) if e not in company: company[e] = [i] else: company[e].append(i) def bfs(root): q = deque() q.append((root, 0)) level = 0 while q: curr,...
Title: Party Time Limit: None seconds Memory Limit: None megabytes Problem Description: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of an...
```python from collections import deque n = int(input()) company = {} maximum = 0 for i in range(1, n+1): e = int(input()) if e not in company: company[e] = [i] else: company[e].append(i) def bfs(root): q = deque() q.append((root, 0)) level = 0 while q: ...
3
859
B
Lazy Security Guard
PROGRAMMING
1,000
[ "brute force", "geometry", "math" ]
null
null
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ...
Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route.
Print the minimum perimeter that can be achieved.
[ "4\n", "11\n", "22\n" ]
[ "8\n", "14\n", "20\n" ]
Here are some possible shapes for the examples: <img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/>
750
[ { "input": "4", "output": "8" }, { "input": "11", "output": "14" }, { "input": "22", "output": "20" }, { "input": "3", "output": "8" }, { "input": "1024", "output": "128" }, { "input": "101", "output": "42" }, { "input": "30", "output":...
1,572,550,941
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
139
0
import math n = int(input()) a = math.floor(math.sqrt(n)) b = a while a * b <= n: b += 1 b -= 1 rectangle = 2 * a + b appendix = n % (a * b) if appendix > 0: rectangle += b - appendix appendix += 2 else: rectangle += a print(rectangle + appendix)
Title: Lazy Security Guard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is...
```python import math n = int(input()) a = math.floor(math.sqrt(n)) b = a while a * b <= n: b += 1 b -= 1 rectangle = 2 * a + b appendix = n % (a * b) if appendix > 0: rectangle += b - appendix appendix += 2 else: rectangle += a print(rectangle + appendix) ```
0
215
B
Olympic Medal
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/...
The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta...
Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists.
[ "3 1 2 3\n1 2\n3 3 2 1\n1 2\n", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n" ]
[ "2.683281573000\n", "2.267786838055\n" ]
In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1.
500
[ { "input": "3 1 2 3\n1 2\n3 3 2 1\n1 2", "output": "2.683281573000" }, { "input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "output": "2.267786838055" }, { "input": "1 5\n1 3\n1 7\n515 892", "output": "3.263613058533" }, { "input": "2 3 2\n3 2 3 1\n2 2 1\n733 883", "output": "2....
1,657,442,307
2,147,483,647
Python 3
OK
TESTS
31
92
512,000
from math import sqrt max_ans = 0 r1s = list(map(int,input().split()))[1:] p1s = list(map(int,input().split()))[1:] p2s = list(map(int,input().split()))[1:] A,B = map(int,input().split()) p2 = min(p2s) r1 = max(r1s) for p1 in p1s : r2 = sqrt((r1**2*p1*B)/((A*p2)+(B*p1))) if r2 > max_ans : m...
Title: Olympic Medal Time Limit: None seconds Memory Limit: None megabytes Problem Description: The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/...
```python from math import sqrt max_ans = 0 r1s = list(map(int,input().split()))[1:] p1s = list(map(int,input().split()))[1:] p2s = list(map(int,input().split()))[1:] A,B = map(int,input().split()) p2 = min(p2s) r1 = max(r1s) for p1 in p1s : r2 = sqrt((r1**2*p1*B)/((A*p2)+(B*p1))) if r2 > max_ans ...
3
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ...
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 ...
1,696,509,127
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
92
0
n = int(input()) a = list(map(int,input().split())) m = min(a) for i in range(a.count(m)): a.remove(m) print(min(a))
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis...
```python n = int(input()) a = list(map(int,input().split())) m = min(a) for i in range(a.count(m)): a.remove(m) print(min(a)) ```
-1
670
B
Game of Robots
PROGRAMMING
1,000
[ "implementation" ]
null
null
In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109. At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. A...
The first line contains two positive integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(2·109,<=*n*·(*n*<=+<=1)<=/<=2). The second line contains the sequence *id*1,<=*id*2,<=...,<=*id**n* (1<=≤<=*id**i*<=≤<=109) — identifiers of roborts. It is guaranteed that all identifiers are different.
Print the *k*-th pronounced identifier (assume that the numeration starts from 1).
[ "2 2\n1 2\n", "4 5\n10 4 18 3\n" ]
[ "1\n", "4\n" ]
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As *k* = 2, the answer equals to 1. In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As *k* = 5, the answer equals to 4.
750
[ { "input": "2 2\n1 2", "output": "1" }, { "input": "4 5\n10 4 18 3", "output": "4" }, { "input": "1 1\n4", "output": "4" }, { "input": "2 1\n5 1", "output": "5" }, { "input": "2 2\n1 4", "output": "1" }, { "input": "2 3\n6 7", "output": "7" }, ...
1,649,154,766
2,147,483,647
PyPy 3-64
OK
TESTS
143
155
17,612,800
n,k=list(map(int,input().split())) arr=list(map(int,input().split())) c=1 s=0 while True: s=s+c if s>(k-1): break else: c=c+1 continue v=k-(s-c) print(arr[v-1])
Title: Game of Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: In late autumn evening *n* robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109. At some moment, robots decided to play the game "Snowball". Below there are t...
```python n,k=list(map(int,input().split())) arr=list(map(int,input().split())) c=1 s=0 while True: s=s+c if s>(k-1): break else: c=c+1 continue v=k-(s-c) print(arr[v-1]) ```
3
237
A
Free Cash
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors. Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe. Note that the time is...
Print a single integer — the minimum number of cashes, needed to serve all clients next day.
[ "4\n8 0\n8 10\n8 10\n8 45\n", "3\n0 12\n10 11\n22 22\n" ]
[ "2\n", "1\n" ]
In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away. In the second sample all visitors will come in different times, so ...
500
[ { "input": "4\n8 0\n8 10\n8 10\n8 45", "output": "2" }, { "input": "3\n0 12\n10 11\n22 22", "output": "1" }, { "input": "5\n12 8\n15 27\n15 27\n16 2\n19 52", "output": "2" }, { "input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23", "output": "3" }, { "input": "...
1,623,203,415
2,147,483,647
PyPy 3
OK
TESTS
67
1,746
12,800,000
def solve(n, ll): cnt = 1 temp = [1] for i in range(1, n): if ll[i] == ll[i-1]: temp.append(temp[i-1] + 1) cnt = max(cnt, temp[i]) else: temp.append(1) cnt = max(cnt, 1) return cnt n = int(input()) ll = [] for i in ...
Title: Free Cash Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l...
```python def solve(n, ll): cnt = 1 temp = [1] for i in range(1, n): if ll[i] == ll[i-1]: temp.append(temp[i-1] + 1) cnt = max(cnt, temp[i]) else: temp.append(1) cnt = max(cnt, 1) return cnt n = int(input()) ll = [] ...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,646,325,965
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
def solve(): s = input() prev = -1 for i in 'hello': if i in s[prev + 1:]: prev = s[prev + 1:].find(i) + prev + 1 else: return 'NO' return 'YES' print(solve())
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python def solve(): s = input() prev = -1 for i in 'hello': if i in s[prev + 1:]: prev = s[prev + 1:].find(i) + prev + 1 else: return 'NO' return 'YES' print(solve()) ```
3.969
374
B
Inna and Nine
PROGRAMMING
1,500
[ "combinatorics", "greedy" ]
null
null
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nin...
The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes.
In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "369727\n", "123456789987654321\n", "1\n" ]
[ "2\n", "1\n", "1\n" ]
Notes to the samples In the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979. In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.
1,000
[ { "input": "369727", "output": "2" }, { "input": "123456789987654321", "output": "1" }, { "input": "1", "output": "1" }, { "input": "3636363636363454545454543636363636454545452727272727218181818181999111777", "output": "1512" }, { "input": "1188", "output": "1...
1,557,907,859
2,147,483,647
Python 3
OK
TESTS
25
202
204,800
s = input() n = len(s) res = 1 cnt = 1 for i in range(n-1): if int(s[i]) + int(s[i+1]) == 9: cnt+=1 else: if cnt % 2 == 1: res = res * (cnt // 2 + 1) cnt = 1 if cnt % 2 == 1: res = res * (cnt // 2 + 1) print(res)
Title: Inna and Nine Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9. Inna wants...
```python s = input() n = len(s) res = 1 cnt = 1 for i in range(n-1): if int(s[i]) + int(s[i+1]) == 9: cnt+=1 else: if cnt % 2 == 1: res = res * (cnt // 2 + 1) cnt = 1 if cnt % 2 == 1: res = res * (cnt // 2 + 1) print(res) ```
3
753
A
Santa Claus and Candies
PROGRAMMING
1,000
[ "dp", "greedy", "math" ]
null
null
Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has.
The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has.
Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them.
[ "5\n", "9\n", "2\n" ]
[ "2\n2 3\n", "3\n3 5 1\n", "1\n2 \n" ]
none
500
[ { "input": "5", "output": "2\n1 4 " }, { "input": "9", "output": "3\n1 2 6 " }, { "input": "2", "output": "1\n2 " }, { "input": "1", "output": "1\n1 " }, { "input": "3", "output": "2\n1 2 " }, { "input": "1000", "output": "44\n1 2 3 4 5 6 7 8 9 10 ...
1,591,269,143
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
109
0
candies = int(input()) def fact(i): answer = 1 for _ in range(1,i+1): answer *= _ return(answer) i ,poop = 1,1 while (candies>poop): i+=1 poop = fact(i) children = i-1 print(children) for i in range (1, children): print(i,end=" ") candies= candies - i print(candies)
Title: Santa Claus and Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer n...
```python candies = int(input()) def fact(i): answer = 1 for _ in range(1,i+1): answer *= _ return(answer) i ,poop = 1,1 while (candies>poop): i+=1 poop = fact(i) children = i-1 print(children) for i in range (1, children): print(i,end=" ") candies= candies - i print(c...
0
441
A
Valera and Antique Items
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfec...
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space...
In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
[ "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n" ]
[ "3\n1 2 3\n", "0\n\n" ]
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the...
500
[ { "input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3" }, { "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0" }, { "input": "2 100001\n1 895737\n1 541571", "output": "0" }, { "input": "1 1000000\n1 100...
1,566,451,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n,k=map(int,input().split()) array=[] for i in range(n): array.append(list(map(int, input().split()))) c=0 for i in range(n): for j in range(array[i][0]): if k>array[i][j]: c+=1 break print(c) for i in range(1,c+1): print(i,end=" ")
Title: Valera and Antique Items Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the...
```python n,k=map(int,input().split()) array=[] for i in range(n): array.append(list(map(int, input().split()))) c=0 for i in range(n): for j in range(array[i][0]): if k>array[i][j]: c+=1 break print(c) for i in range(1,c+1): print(i,end=" ") ```
0
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<...
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e...
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels ...
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", ...
1,674,497,326
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
31
0
t,r=map(int,input().split()) t1=t if t%10==0: print(1) else: cou=1 if 10%(t%10)!=0: while t%10!=r: cou+=1 t+=t1 print(cou) else: print(10//(t%10))
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his ...
```python t,r=map(int,input().split()) t1=t if t%10==0: print(1) else: cou=1 if 10%(t%10)!=0: while t%10!=r: cou+=1 t+=t1 print(cou) else: print(10//(t%10)) ```
0
46
C
Hamsters and Tigers
PROGRAMMING
1,600
[ "two pointers" ]
C. Hamsters and Tigers
2
256
Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all the hamsters stood together and all the tigers also stood together...
The first line contains number *n* (2<=≤<=*n*<=≤<=1000) which indicates the total number of animals in the arena. The second line contains the description of the animals' positions. The line consists of *n* symbols "H" and "T". The "H"s correspond to hamsters and the "T"s correspond to tigers. It is guaranteed that at ...
Print the single number which is the minimal number of swaps that let the trainer to achieve his goal.
[ "3\nHTH\n", "9\nHTHTHTHHT\n" ]
[ "0\n", "2\n" ]
In the first example we shouldn't move anybody because the animals of each species already stand apart from the other species. In the second example you may swap, for example, the tiger in position 2 with the hamster in position 5 and then — the tiger in position 9 with the hamster in position 7.
0
[ { "input": "3\nHTH", "output": "0" }, { "input": "9\nHTHTHTHHT", "output": "2" }, { "input": "2\nTH", "output": "0" }, { "input": "4\nHTTH", "output": "0" }, { "input": "4\nHTHT", "output": "1" }, { "input": "7\nTTTHTTT", "output": "0" }, { ...
1,692,182,694
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
def min_swaps(n, s): tigers = s.count("T") hamsters = n - tigers window_size = hamsters min_swaps = float('inf') initial_window = s[:window_size] tigers_in_window = initial_window.count("T") hamsters_in_window = window_size - tigers_in_window min_swaps = min(min_swaps, tigers...
Title: Hamsters and Tigers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap ...
```python def min_swaps(n, s): tigers = s.count("T") hamsters = n - tigers window_size = hamsters min_swaps = float('inf') initial_window = s[:window_size] tigers_in_window = initial_window.count("T") hamsters_in_window = window_size - tigers_in_window min_swaps = min(min_swa...
0
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ...
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": ...
1,654,104,074
2,147,483,647
PyPy 3-64
OK
TESTS
32
46
0
a,b = list(map(int, input().split())) ans = a while a >= b: c = a // b d = a % b ans += c a = c a += d print(ans)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s...
```python a,b = list(map(int, input().split())) ans = a while a >= b: c = a // b d = a % b ans += c a = c a += d print(ans) ```
3
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,654,494,438
2,147,483,647
Python 3
OK
TESTS
45
62
0
#!/usr/bin/env/python # -*- coding: utf-8 -*- import math a, b, n = list(map(int, input().split())) ab = [a, b] turn = 0 while True: g = math.gcd(ab[turn], n) if g <= n: n -= g else: print(1 - turn) break turn = 1 - turn
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python #!/usr/bin/env/python # -*- coding: utf-8 -*- import math a, b, n = list(map(int, input().split())) ab = [a, b] turn = 0 while True: g = math.gcd(ab[turn], n) if g <= n: n -= g else: print(1 - turn) break turn = 1 - turn ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl...
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the thi...
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853...
1,649,950,113
2,147,483,647
Python 3
OK
TESTS
41
46
0
n = int(input()) w = list(map(int,input().split())) b = w[:] for i in range(len(w)): if w[i] != max(w): w[i] = w[i] + (max(w)-w[i]) print(sum(w)-sum(b))
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens...
```python n = int(input()) w = list(map(int,input().split())) b = w[:] for i in range(len(w)): if w[i] != max(w): w[i] = w[i] + (max(w)-w[i]) print(sum(w)-sum(b)) ```
3
909
C
Python Indentation
PROGRAMMING
1,800
[ "dp" ]
null
null
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. Simple statements are written in a single line, one per line. An ex...
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement.
Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7.
[ "4\ns\nf\nf\ns\n", "4\nf\ns\nf\ns\n" ]
[ "1\n", "2\n" ]
In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one. In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one...
1,500
[ { "input": "4\ns\nf\nf\ns", "output": "1" }, { "input": "4\nf\ns\nf\ns", "output": "2" }, { "input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns...
1,514,394,160
1,660
Python 3
RUNTIME_ERROR
PRETESTS
4
607
8,294,400
p = 1000000007 n = int(input()) c = [] for i in range(n): c.append(str(input())) memo = {} def dp(idx, layer, last): #assigned first idx-1 people, prev layer = layer, prev char = last if idx == len(c): return 1 if (idx, layer, last) in memo: return memo[(idx, layer, last)] if last == 'f': me...
Title: Python Indentation Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python...
```python p = 1000000007 n = int(input()) c = [] for i in range(n): c.append(str(input())) memo = {} def dp(idx, layer, last): #assigned first idx-1 people, prev layer = layer, prev char = last if idx == len(c): return 1 if (idx, layer, last) in memo: return memo[(idx, layer, last)] if last == ...
-1
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,617,196,686
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
307,200
def str_list(s, char): output_list = [] collector = "" for i in range(len(s)): if s[i] == char: if collector: output_list.append(int(collector)) collector = "" else: collector += s[i] output_list.append(int(collector)) ...
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python def str_list(s, char): output_list = [] collector = "" for i in range(len(s)): if s[i] == char: if collector: output_list.append(int(collector)) collector = "" else: collector += s[i] output_list.append(int(colle...
0
741
E
Arpa’s abnormal DNA and Mehrdad’s deep interest
PROGRAMMING
3,400
[ "data structures", "string suffix structures" ]
null
null
All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor. Sipa put A...
The first line contains strings *S*, *T* and integer *q* (1<=≤<=|*S*|,<=|*T*|,<=*q*<=≤<=105) — Arpa's DNA, the DNA of a normal man, and the number of Mehrdad's questions. The strings *S* and *T* consist only of small English letters. Next *q* lines describe the Mehrdad's questions. Each of these lines contain five int...
Print *q* integers. The *j*-th of them should be the number *i* of the most interesting option among those that satisfy the conditions of the *j*-th question. If there is no option *i* satisfying the conditions in some question, print -1.
[ "abc d 4\n0 3 2 0 0\n0 3 1 0 0\n1 2 1 0 0\n0 1 3 2 2\n", "abbbbbbaaa baababaaab 10\n1 2 1 0 0\n2 7 8 4 7\n2 3 9 2 8\n3 4 6 1 1\n0 8 5 2 4\n2 8 10 4 7\n7 10 1 0 0\n1 4 6 0 2\n0 9 8 0 6\n4 8 5 0 1\n" ]
[ "2 3 2 -1 \n", "1 4 2 -1 2 4 10 1 1 5 \n" ]
Explanation of first sample case: In the first question Sipa has two options: dabc (*i* = 0) and abdc (*i* = 2). The latter (abcd) is better than abdc, so answer is 2. In the last question there is no *i* such that 0 ≤ *i* ≤ 1 and <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7cc85c61d9...
2,500
[]
1,689,652,254
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
print("_RANDOM_GUESS_1689652253.9684505")# 1689652253.9684684
Title: Arpa’s abnormal DNA and Mehrdad’s deep interest Time Limit: None seconds Memory Limit: None megabytes Problem Description: All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is intereste...
```python print("_RANDOM_GUESS_1689652253.9684505")# 1689652253.9684684 ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len...
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o...
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form...
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, ...
1,623,515,805
2,147,483,647
Python 3
OK
TESTS
21
62
0
a,b,c=map(int,input().split()) print(min(2*(a+b+c-max(a,b,c)),a+b+c))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the...
```python a,b,c=map(int,input().split()) print(min(2*(a+b+c-max(a,b,c)),a+b+c)) ```
3
493
B
Vasya and Wrestling
PROGRAMMING
1,400
[ "implementation" ]
null
null
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105). The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin...
If the first wrestler wins, print string "first", otherwise print "second"
[ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n" ]
[ "second\n", "first\n", "second\n" ]
Sequence *x*  =  *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y*  =  *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*|  &gt;  |...
1,000
[ { "input": "5\n1\n2\n-3\n-4\n3", "output": "second" }, { "input": "3\n-1\n-2\n3", "output": "first" }, { "input": "2\n4\n-4", "output": "second" }, { "input": "7\n1\n2\n-3\n4\n5\n-6\n7", "output": "first" }, { "input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-...
1,435,518,105
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
n = int(input()) s1, s2 = '', '' for i in range(n) : m = input() if m[0] == '-': s2 += m[1:] else: s1 += m if s1 == s2: if int(m) < 0: print('second') else: print('first') elif s1 > s2: print('first') else: print('second')
Title: Vasya and Wrestling Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers ...
```python n = int(input()) s1, s2 = '', '' for i in range(n) : m = input() if m[0] == '-': s2 += m[1:] else: s1 += m if s1 == s2: if int(m) < 0: print('second') else: print('first') elif s1 > s2: print('first') else: print('second') ```
0
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *...
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that ...
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "in...
1,553,074,670
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
import sys sys.setrecursionlimit(1000000) nVertices = int(input()) edges = [[] for _ in xrange(nVertices + 1)] for _ in xrange(nVertices - 1): u, v = map(int, input().split()) edges[u].append(v) edges[v].append(u) count = [0, 0] def dfs(parent, child, type): count[type] += 1 for next in edges[chi...
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a gra...
```python import sys sys.setrecursionlimit(1000000) nVertices = int(input()) edges = [[] for _ in xrange(nVertices + 1)] for _ in xrange(nVertices - 1): u, v = map(int, input().split()) edges[u].append(v) edges[v].append(u) count = [0, 0] def dfs(parent, child, type): count[type] += 1 for next in...
-1
31
B
Sysadmin Bob
PROGRAMMING
1,500
[ "greedy", "implementation", "strings" ]
B. Sysadmin Bob
0
256
Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitra...
The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».
If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of the...
[ "a@aa@a\n", "a@a@a\n", "@aa@a\n" ]
[ "a@a,a@a\n", "No solution\n", "No solution\n" ]
none
1,000
[ { "input": "a@aa@a", "output": "a@a,a@a" }, { "input": "a@a@a", "output": "No solution" }, { "input": "@aa@a", "output": "No solution" }, { "input": "aba@caba@daba", "output": "aba@c,aba@daba" }, { "input": "asd@qwasd@qwasd@qwasd@qwasd@qw", "output": "asd@q,wa...
1,542,647,127
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
108
0
import math x = input() y = x.split('@') flag = 0 """print(y) print(len(y))""" for i in range(0,len(y)): if len(y[i]) <=1 and i>=1 and i<len(y)-1: print("No solution") flag = 1 break if len(y[i])==0: print("No solution") flag = 1 break if flag==0: print(y[0],end="") for i in range...
Title: Sysadmin Bob Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: Email address in Berland is a string of the form *A*@*B*, where *A* and *B* are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of t...
```python import math x = input() y = x.split('@') flag = 0 """print(y) print(len(y))""" for i in range(0,len(y)): if len(y[i]) <=1 and i>=1 and i<len(y)-1: print("No solution") flag = 1 break if len(y[i])==0: print("No solution") flag = 1 break if flag==0: print(y[0],end="") for ...
0
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array.
In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the...
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", ...
1,658,244,961
361
Python 3
OK
TESTS
28
46
102,400
from collections import defaultdict n = int(input()) a = list(map(int, input().split())) d = defaultdict(lambda : 0) for i in a: d[i] = 1 ans = [] for i in a[::-1]: if d[i] == 1: ans.append(i) d[i] = 0 print(len(ans)) for i in ans[::-1]: print(i, end = " ") print()
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the re...
```python from collections import defaultdict n = int(input()) a = list(map(int, input().split())) d = defaultdict(lambda : 0) for i in a: d[i] = 1 ans = [] for i in a[::-1]: if d[i] == 1: ans.append(i) d[i] = 0 print(len(ans)) for i in ans[::-1]: print(i, end = " ") print() ...
3
618
C
Constellation
PROGRAMMING
1,600
[ "geometry", "implementation" ]
null
null
Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are located at the same position. In the evening Noku is going to take a look at the night sky. He would lik...
The first line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=100<=000). Each of the next *n* lines contains two integers *x**i* and *y**i* (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). It is guaranteed that no two stars lie at the same point, and there does not exist a line such that all stars lie on that line.
Print three distinct integers on a single line — the indices of the three points that form a triangle that satisfies the conditions stated in the problem. If there are multiple possible answers, you may print any of them.
[ "3\n0 1\n1 0\n1 1\n", "5\n0 0\n0 2\n2 0\n2 2\n1 1\n" ]
[ "1 2 3\n", "1 3 5\n" ]
In the first sample, we can print the three indices in any order. In the second sample, we have the following picture. Note that the triangle formed by starts 1, 4 and 3 doesn't satisfy the conditions stated in the problem, as point 5 is not strictly outside of this triangle (it lies on it's border).
1,500
[ { "input": "3\n0 1\n1 0\n1 1", "output": "1 2 3" }, { "input": "5\n0 0\n0 2\n2 0\n2 2\n1 1", "output": "1 3 5" }, { "input": "3\n819934317 939682125\n487662889 8614219\n-557136619 382982369", "output": "1 3 2" }, { "input": "10\n25280705 121178189\n219147240 -570920213\n-8298...
1,484,732,406
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
22,016,000
#By Tianyi Chen from fractions import Fraction n=int(input()) l=[None]*n for _ in range(n): a,b=input().split() a=int(a)+1000000001 b=int(b)+1000000001 l[_]=(Fraction(a,b),a+b,_+1) l.sort() for i in range(3): print(l[i][2],end=' ')
Title: Constellation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cat Noku has obtained a map of the night sky. On this map, he found a constellation with *n* stars numbered from 1 to *n*. For each *i*, the *i*-th star is located at coordinates (*x**i*,<=*y**i*). No two stars are locate...
```python #By Tianyi Chen from fractions import Fraction n=int(input()) l=[None]*n for _ in range(n): a,b=input().split() a=int(a)+1000000001 b=int(b)+1000000001 l[_]=(Fraction(a,b),a+b,_+1) l.sort() for i in range(3): print(l[i][2],end=' ') ```
0
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *...
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that ...
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "in...
1,676,649,685
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
819,200
sets = [set(), set()] def bipartite(edges, V, i, visited): if V == 0: return True pending = [] sets[0].add(i) pending.append(i) while pending: current = pending.pop() visited[current] = True currentSet = 0 if current in sets[0] else 1 for neighbor in edges[current]: if neighbor not in sets...
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a gra...
```python sets = [set(), set()] def bipartite(edges, V, i, visited): if V == 0: return True pending = [] sets[0].add(i) pending.append(i) while pending: current = pending.pop() visited[current] = True currentSet = 0 if current in sets[0] else 1 for neighbor in edges[current]: if neighbor n...
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,678,889,395
2,147,483,647
Python 3
OK
TESTS
30
92
0
word = input() count_uc = 0 count_lc = 0 for c in word: if c.isupper(): count_uc += 1 else: count_lc += 1 if count_uc > count_lc: print(word.upper()) else: print(word.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python word = input() count_uc = 0 count_lc = 0 for c in word: if c.isupper(): count_uc += 1 else: count_lc += 1 if count_uc > count_lc: print(word.upper()) else: print(word.lower()) ```
3.977
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,579,939,087
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
108
0
n,x = map(int,input().split()) t = n i = 1 flag = 0 while True: if t//pow(10,x) >= 1: flag = 1 break k = (t%(pow(10,i)))//10**(i-1) if k%2 == 1 and k != 5: break elif k == 5: t = t*2 elif k%2 == 0: t = t*5 i = i + 1 print(t*10**max((x-i),0))
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 n,x = map(int,input().split()) t = n i = 1 flag = 0 while True: if t//pow(10,x) >= 1: flag = 1 break k = (t%(pow(10,i)))//10**(i-1) if k%2 == 1 and k != 5: break elif k == 5: t = t*2 elif k%2 == 0: t = t*5 i = i + 1 print(t*10**max((x-i),0)) ```
0
17
C
Balance
PROGRAMMING
2,500
[ "dp" ]
C. Balance
3
128
Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations: - to take two adjacent characters and replace the second character with the first one, - to...
The first line contains integer *n* (1<=≤<=*n*<=≤<=150) — the length of the given string *s*. Next line contains the given string *s*. The initial string can be balanced as well, in this case it should be counted too. The given string *s* consists only of characters a, b and c.
Output the only number — the number of different balanced strings that can be obtained by performing the described operations, perhaps multiple times, on the given string *s*, modulo 51123987.
[ "4\nabca\n", "4\nabbc\n", "2\nab\n" ]
[ "7\n", "3\n", "1\n" ]
In the first sample it is possible to get 51 different strings through the described operations, but only 7 of them are balanced: «abca», «bbca», «bcca», «bcaa», «abcc», «abbc», «aabc». In the second sample: «abbc», «aabc», «abcc». In the third sample there is only one balanced string — «ab» itself.
0
[]
1,666,000,237
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
# LUOGU_RID: 90323224 print(51123986)
Title: Balance Time Limit: 3 seconds Memory Limit: 128 megabytes Problem Description: Nick likes strings very much, he likes to rotate them, sort them, rearrange characters within a string... Once he wrote a random string of characters a, b, c on a piece of paper and began to perform the following operations: - t...
```python # LUOGU_RID: 90323224 print(51123986) ```
0
385
A
Bear and Raspberry
PROGRAMMING
1,000
[ "brute force", "greedy", "implementation" ]
null
null
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=≤<=*i*<=≤<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry. Unfo...
The first line contains two space-separated integers, *n* and *c* (2<=≤<=*n*<=≤<=100,<=0<=≤<=*c*<=≤<=100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100...
Print a single integer — the answer to the problem.
[ "5 1\n5 10 7 3 20\n", "6 2\n100 1 10 40 10 40\n", "3 0\n1 2 3\n" ]
[ "3\n", "97\n", "0\n" ]
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da...
500
[ { "input": "5 1\n5 10 7 3 20", "output": "3" }, { "input": "6 2\n100 1 10 40 10 40", "output": "97" }, { "input": "3 0\n1 2 3", "output": "0" }, { "input": "2 0\n2 1", "output": "1" }, { "input": "10 5\n10 1 11 2 12 3 13 4 14 5", "output": "4" }, { "in...
1,683,474,046
2,147,483,647
Python 3
OK
TESTS
32
46
0
n,c=map(int, input().split()) l=list(map(int, input().split())) l1=[] for i in range(n-1): a=l[i]-l[i+1]-c l1.append(a) if (max(l1)>0): print(max(l1)) else: print(0)
Title: Bear and Raspberry Time Limit: None seconds Memory Limit: None megabytes Problem Description: The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1...
```python n,c=map(int, input().split()) l=list(map(int, input().split())) l1=[] for i in range(n-1): a=l[i]-l[i+1]-c l1.append(a) if (max(l1)>0): print(max(l1)) else: print(0) ```
3
580
C
Kefa and Park
PROGRAMMING
1,500
[ "dfs and similar", "graphs", "trees" ]
null
null
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the v...
The first line contains two integers, *n* and *m* (2<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=*n*) — the number of vertices of the tree and the maximum number of consecutive vertices with cats that is still ok for Kefa. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where each *a**i* either equals to 0 (then ...
A single integer — the number of distinct leaves of a tree the path to which from Kefa's home contains at most *m* consecutive vertices with cats.
[ "4 1\n1 1 0 0\n1 2\n1 3\n1 4\n", "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n" ]
[ "2\n", "2\n" ]
Let us remind you that a tree is a connected graph on *n* vertices and *n* - 1 edge. A rooted tree is a tree with a special vertex called root. In a rooted tree among any two vertices connected by an edge, one vertex is a parent (the one closer to the root), and the other one is a child. A vertex is called a leaf, if i...
1,500
[ { "input": "4 1\n1 1 0 0\n1 2\n1 3\n1 4", "output": "2" }, { "input": "7 1\n1 0 1 1 0 0 0\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7", "output": "2" }, { "input": "3 2\n1 1 1\n1 2\n2 3", "output": "0" }, { "input": "5 2\n1 1 0 1 1\n1 2\n2 3\n3 4\n4 5", "output": "1" }, { "inpu...
1,692,616,024
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
34
420
21,811,200
from sys import setrecursionlimit setrecursionlimit(10**6) def countways(edges, cat, v, p, count): if cat[v-1] == 1: count += 1 else: count = 0 if count > m: return 0 if len(edges[v]) == 1: return 1 num = 0 for j in range(len(edges[v])): i...
Title: Kefa and Park Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of *n* vertices with the root at vertex 1. Vertex 1 also contains Kefa's house...
```python from sys import setrecursionlimit setrecursionlimit(10**6) def countways(edges, cat, v, p, count): if cat[v-1] == 1: count += 1 else: count = 0 if count > m: return 0 if len(edges[v]) == 1: return 1 num = 0 for j in range(len(edges[v])): ...
-1
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,694,164,288
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
str = str(input()) delete = ['A','a','E','e','Y','y','O','o','U','u','I','i'] str_1 = '' for letter in str: if letter not in delete: str_1 = str_1 + letter str_1.lower() result = list(str_1) print('.'.join(result))
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 str = str(input()) delete = ['A','a','E','e','Y','y','O','o','U','u','I','i'] str_1 = '' for letter in str: if letter not in delete: str_1 = str_1 + letter str_1.lower() result = list(str_1) print('.'.join(result)) ```
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,624,115,612
2,147,483,647
Python 3
OK
TESTS
30
186
512,000
from sys import stdin, stdout from string import ascii_letters, ascii_lowercase, ascii_uppercase from collections import Counter # with open('testcase.txt', 'r') as stdin: # _ = stdin.readline() string = stdin.readline().rstrip() lower = tuple(i for i in string if i in ascii_lowercase) if len(lower) >= len(s...
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 from sys import stdin, stdout from string import ascii_letters, ascii_lowercase, ascii_uppercase from collections import Counter # with open('testcase.txt', 'r') as stdin: # _ = stdin.readline() string = stdin.readline().rstrip() lower = tuple(i for i in string if i in ascii_lowercase) if len(lower...
3.952546
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the h...
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th...
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "inp...
1,666,420,726
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
102,400
from collections import * from math import * from functools import lru_cache def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) t = 1 for _ in range(t): ...
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ...
```python from collections import * from math import * from functools import lru_cache def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) t = 1 for _ in ...
0