contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
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,634,738,459
2,147,483,647
Python 3
OK
TESTS
30
122
4,300,800
a = input() t = 0 c = 0 for ch in a: if ch.islower(): t += 1 else: c += 1 if t < c: a = a.upper() else: a = a.lower() print(a)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a = input() t = 0 c = 0 for ch in a: if ch.islower(): t += 1 else: c += 1 if t < c: a = a.upper() else: a = a.lower() print(a) ```
3.961489
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"...
The first line contains integer number *n* (1<=≀<=*n*<=≀<=100) β€” the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string β€” the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht...
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n100000...
1,629,885,144
2,147,483,647
Python 3
OK
TESTS
14
62
6,758,400
a=input() a=input() if int(a): print('1'+'0'*a.count('0')) else: print(0)
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two...
```python a=input() a=input() if int(a): print('1'+'0'*a.count('0')) else: print(0) ```
3
558
A
Lala Land and Apple Trees
PROGRAMMING
1,100
[ "brute force", "implementation", "sortings" ]
null
null
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t...
The first line contains one number *n* (1<=≀<=*n*<=≀<=100), the number of apple trees in Lala Land. The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≀<=*x**i*<=≀<=105, *x**i*<=β‰ <=0, 1<=≀<=*a**i*<=≀<=105), representing the position of the *i*-th tree and number of apples on it. It's guarant...
Output the maximum number of apples Amr can collect.
[ "2\n-1 5\n1 5\n", "3\n-2 2\n1 4\n-1 3\n", "3\n1 9\n3 5\n7 10\n" ]
[ "10", "9", "9" ]
In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples. In the second sample test the optimal solution is to go left to *x* =  - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ...
500
[ { "input": "2\n-1 5\n1 5", "output": "10" }, { "input": "3\n-2 2\n1 4\n-1 3", "output": "9" }, { "input": "3\n1 9\n3 5\n7 10", "output": "9" }, { "input": "1\n1 1", "output": "1" }, { "input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000", "output": "3...
1,585,686,572
2,147,483,647
PyPy 3
OK
TESTS
46
156
0
def takeOne(elem): return elem[0] num = int(input()) p = 0 n = 0 t = 0 trees = [] for i in range(num): tree = [int(x) for x in input().split()] trees.append(tree) if tree[0] > 0: p += 1 else: n += 1 t += tree[1] trees.sort(key=takeOne) if p < n - 1: for i in range(n - 1 - p): t -= trees[i][1]...
Title: Lala Land and Apple Trees Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere. Lala Land has exactly *n* apple trees. Tree num...
```python def takeOne(elem): return elem[0] num = int(input()) p = 0 n = 0 t = 0 trees = [] for i in range(num): tree = [int(x) for x in input().split()] trees.append(tree) if tree[0] > 0: p += 1 else: n += 1 t += tree[1] trees.sort(key=takeOne) if p < n - 1: for i in range(n - 1 - p): t -= t...
3
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,691,303,599
2,147,483,647
Python 3
OK
TESTS
81
92
0
n = int(input()) vec = 0 x = y = z = 0 while n > 0: n -= 1 vec = input().split() x = x + int(vec[0]) y = y + int(vec[1]) z = z + int(vec[2]) if x == y == z == 0: 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 n = int(input()) vec = 0 x = y = z = 0 while n > 0: n -= 1 vec = input().split() x = x + int(vec[0]) y = y + int(vec[1]) z = z + int(vec[2]) if x == y == z == 0: print("YES") else: print("NO") ```
3.977
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β€” the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β€” the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second oneΒ β€” 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,573,425,046
2,147,483,647
Python 3
OK
TESTS
27
216
0
import math as m a,b,c=map(int,input().split()) e1,e2,e3=m.sqrt((a*c)/b),m.sqrt((a*b)/c),m.sqrt((b*c)/a) print(int(4*(e1+e2+e3)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import math as m a,b,c=map(int,input().split()) e1,e2,e3=m.sqrt((a*c)/b),m.sqrt((a*b)/c),m.sqrt((b*c)/a) print(int(4*(e1+e2+e3))) ```
3
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
The first line of input contains an integer *n* (1<=≀<=*n*<=≀<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≀<=*a**i*<=≀<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not ...
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20...
1,693,584,839
2,147,483,647
Python 3
OK
TESTS
32
46
0
if __name__ == '__main__': n = int(input()) toys = input() toys = toys.split() toys = [int(x) for x in toys] sorted_toys = sorted(toys) print(*sorted_toys, sep=' ')
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the bo...
```python if __name__ == '__main__': n = int(input()) toys = input() toys = toys.split() toys = [int(x) for x in toys] sorted_toys = sorted(toys) print(*sorted_toys, sep=' ') ```
3
52
A
123-sequence
PROGRAMMING
900
[ "implementation" ]
A. 123-sequence
2
256
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
The first line contains an integer *n* (1<=≀<=*n*<=≀<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=3).
Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal.
[ "9\n1 3 2 2 2 1 1 2 3\n" ]
[ "5\n" ]
In the example all the numbers equal to 1 and 3 should be replaced by 2.
500
[ { "input": "9\n1 3 2 2 2 1 1 2 3", "output": "5" }, { "input": "6\n3 3 2 2 1 3", "output": "3" }, { "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7" }, { "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10" }, { "input": "2\n2 1", "output": "1" ...
1,654,021,493
2,147,483,647
Python 3
OK
TESTS
23
528
14,233,600
n = int(input()) a = list(map(int,input().split(" "))) ans = [] x = a.count(1) y = a.count(2) z = a.count(3) ans.append(x) ans.append(y) ans.append(z) ans.sort() print(ans[0]+ans[1])
Title: 123-sequence Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each...
```python n = int(input()) a = list(map(int,input().split(" "))) ans = [] x = a.count(1) y = a.count(2) z = a.count(3) ans.append(x) ans.append(y) ans.append(z) ans.sort() print(ans[0]+ans[1]) ```
3.841488
253
A
Boys and Girls
PROGRAMMING
1,100
[ "greedy" ]
null
null
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≀<=*i*<=&lt;<=*n*<=+<=*m*) such th...
The single line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100), separated by a space.
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi...
[ "3 3\n", "4 2\n" ]
[ "GBGBGB\n", "BGBGBB\n" ]
In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
500
[ { "input": "3 3", "output": "GBGBGB" }, { "input": "4 2", "output": "BGBGBB" }, { "input": "5 5", "output": "GBGBGBGBGB" }, { "input": "6 4", "output": "BGBGBGBGBB" }, { "input": "100 1", "output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
1,629,038,058
2,147,483,647
Python 3
OK
TESTS
23
154
6,963,200
a = open("input.txt",'r') # print(a) ar = a.read() ar = ar.split(' ') n = int(ar[0]) m = int(ar[1]) if n>m: s = m*"BG"+(n-m)*'B' f = open("output.txt", 'w') f.write(s) f.close() # print(s) elif m>=n: s = n*"GB"+(m-n)*'G' f = open("output.txt", 'w') f.write(s) f.close() # print(s)
Title: Boys and Girls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n...
```python a = open("input.txt",'r') # print(a) ar = a.read() ar = ar.split(' ') n = int(ar[0]) m = int(ar[1]) if n>m: s = m*"BG"+(n-m)*'B' f = open("output.txt", 'w') f.write(s) f.close() # print(s) elif m>=n: s = n*"GB"+(m-n)*'G' f = open("output.txt", 'w') f.write(s) f.close() # print(s) ``...
3
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,474,147,662
2,147,483,647
Python 3
OK
TESTS
24
61
0
position = input() turns = 0 if position[0] == 'a': turns = 2 elif position[0] == 'h': turns = 2 else: turns = 3 if position[1] == '1': print(turns*2-1) elif position[1] == '8': print(turns*2-1) else: print(turns*3-1)
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 position = input() turns = 0 if position[0] == 'a': turns = 2 elif position[0] == 'h': turns = 2 else: turns = 3 if position[1] == '1': print(turns*2-1) elif position[1] == '8': print(turns*2-1) else: print(turns*3-1) ```
3
730
H
Delete Them
PROGRAMMING
1,300
[ "constructive algorithms", "implementation" ]
null
null
Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pat...
The first line of the input contains two integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=100) β€” the total number of files and the number of files to be deleted. The following *n* lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dot...
If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them. If the required pattern doesn't exist, print the only line containing "No".
[ "3 2\nab\nac\ncd\n1 2\n", "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n", "4 4\na\nb\nc\ndd\n1 2 3 4\n", "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n" ]
[ "Yes\na?\n", "Yes\n?es?\n", "No\n", "Yes\n.???\n" ]
none
0
[ { "input": "3 2\nab\nac\ncd\n1 2", "output": "Yes\na?" }, { "input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5", "output": "Yes\n?es?" }, { "input": "4 4\na\nb\nc\ndd\n1 2 3 4", "output": "No" }, { "input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3", "output": "Yes\n.???...
1,654,743,440
2,147,483,647
PyPy 3-64
OK
TESTS
74
62
2,252,800
n, m = map(int, input().split()) s = [input() for i in range(n)] indices = set(map(lambda x: int(x)-1, input().split())) lengths = set([len(s[i]) for i in indices]) if len(lengths) != 1: print("No") exit(0) non_indices = set(range(n)) - indices l = lengths.pop() ans = [] for j in range(l): ch = ...
Title: Delete Them Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single dele...
```python n, m = map(int, input().split()) s = [input() for i in range(n)] indices = set(map(lambda x: int(x)-1, input().split())) lengths = set([len(s[i]) for i in indices]) if len(lengths) != 1: print("No") exit(0) non_indices = set(range(n)) - indices l = lengths.pop() ans = [] for j in range(l...
3
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=Γ—<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw...
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,687,142,367
2,147,483,647
Python 3
OK
TESTS
33
46
0
row1=list(map(int,input().split())) row2=list(map(int,input().split())) row3=list(map(int,input().split())) config1=[row1[0]+row1[1]+row2[0], sum(row1)+row2[1], row1[1]+row1[2]+row2[2]] config2=[row1[0]+row2[0]+row3[0]+row2[1], sum(row2)+row1[1]+row3[1], row1[2]+row2[2]+row3[2]+row2[1]] config3=[row2[0]+row3[0]+row3[1...
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=Γ—<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ...
```python row1=list(map(int,input().split())) row2=list(map(int,input().split())) row3=list(map(int,input().split())) config1=[row1[0]+row1[1]+row2[0], sum(row1)+row2[1], row1[1]+row1[2]+row2[2]] config2=[row1[0]+row2[0]+row3[0]+row2[1], sum(row2)+row1[1]+row3[1], row1[2]+row2[2]+row3[2]+row2[1]] config3=[row2[0]+row3...
3
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-...
The first line contains the only integer *n* (0<=≀<=*n*<=≀<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit β€” Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transform...
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,596,075,983
2,147,483,647
PyPy 3
OK
TESTS
51
312
22,118,400
num = input() ans = 0 temp = 0 while len(num) > 1: for x in num: ans += int(x) num = str(ans) ans = 0 temp += 1 print(temp)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came...
```python num = input() ans = 0 temp = 0 while len(num) > 1: for x in num: ans += int(x) num = str(ans) ans = 0 temp += 1 print(temp) ```
3.8822
371
C
Hamburgers
PROGRAMMING
1,600
[ "binary search", "brute force" ]
null
null
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (...
The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers *n...
Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0.
[ "BBBSSC\n6 4 1\n1 2 3\n4\n", "BBC\n1 10 1\n1 10 1\n21\n", "BSC\n1 1 1\n1 1 3\n1000000000000\n" ]
[ "2\n", "7\n", "200000000001\n" ]
none
1,500
[ { "input": "BBBSSC\n6 4 1\n1 2 3\n4", "output": "2" }, { "input": "BBC\n1 10 1\n1 10 1\n21", "output": "7" }, { "input": "BSC\n1 1 1\n1 1 3\n1000000000000", "output": "200000000001" }, { "input": "B\n1 1 1\n1 1 1\n381", "output": "382" }, { "input": "BSC\n3 5 6\n7...
1,654,269,616
2,147,483,647
Python 3
OK
TESTS
31
61
102,400
from collections import Counter def canBeMade(money,x,recipeB,recipeS,recipeC,nb,ns,nc,pb,ps,pc): costOfburgere = max(0,recipeB*x-nb)*pb+max(0,recipeS*x-ns)*ps+max(0,recipeC*x-nc)*pc if(money>=costOfburgere): return True else: return False def solve(money,rb,rs,rc,available_bread,av...
Title: Hamburgers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ...
```python from collections import Counter def canBeMade(money,x,recipeB,recipeS,recipeC,nb,ns,nc,pb,ps,pc): costOfburgere = max(0,recipeB*x-nb)*pb+max(0,recipeS*x-ns)*ps+max(0,recipeC*x-nc)*pc if(money>=costOfburgere): return True else: return False def solve(money,rb,rs,rc,availabl...
3
176
A
Trading Business
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin...
The first line contains three space-separated integers *n*, *m* and *k* (2<=≀<=*n*<=≀<=10, 1<=≀<=*m*,<=*k*<=≀<=100) β€” the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly. Then follow *n* blocks describing each planet. The first line of the *i*-th block has the p...
Print a single number β€” the maximum profit Qwerty can get.
[ "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n" ]
[ "16" ]
In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3Β·6 + 7Β·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3Β·9 + 7Β·9 = 90 units of money for the items, he sho...
500
[ { "input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5", "output": "16" }, { "input": "2 1 5\nA\n6 5 5\nB\n10 9 0", "output": "15" }, { "input": "2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopqrstu\n19 16 20\n12 7 14", "output": "0" }...
1,689,661,698
2,147,483,647
Python 3
OK
TESTS
51
92
102,400
n, m, k = map(int, input().split()) l = [] for i in range(n): s = input() for j in range(m): li = list(map(int, input().split())) l.append(li) max_earn = 0 for i in range(n): for j in range(n): if i != j: lji = [] for o in range(m): lji.append...
Title: Trading Business Time Limit: None seconds Memory Limit: None megabytes Problem Description: To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought...
```python n, m, k = map(int, input().split()) l = [] for i in range(n): s = input() for j in range(m): li = list(map(int, input().split())) l.append(li) max_earn = 0 for i in range(n): for j in range(n): if i != j: lji = [] for o in range(m): ...
3
53
A
Autocomplete
PROGRAMMING
1,100
[ "implementation" ]
A. Autocomplete
2
256
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≀<=*n*<=≀<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase...
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' o...
[ "next\n2\nnextpermutation\nnextelement\n", "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n" ]
[ "nextelement\n", "find\n", "find\n" ]
none
500
[ { "input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find" }, { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find" }, { "input": "kudljmxcse\n4\nkudljmxcse\nszje...
1,611,947,079
2,147,483,647
PyPy 3
OK
TESTS
25
186
0
w = input() n = int(input()) res = [] for tc in range(n): word = input() if w == word[0:len(w)]: res.append(word) if (len(res) > 0): res.sort() print(res[0]) else: print(w)
Title: Autocomplete Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens...
```python w = input() n = int(input()) res = [] for tc in range(n): word = input() if w == word[0:len(w)]: res.append(word) if (len(res) > 0): res.sort() print(res[0]) else: print(w) ```
3.9535
982
B
Bus of Characters
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation" ]
null
null
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The t...
Print $2n$ integers β€” the rows the passengers will take. The order of passengers should be the same as in input.
[ "2\n3 1\n0011\n", "6\n10 8 9 11 13 5\n010010011101\n" ]
[ "2 1 1 2 \n", "6 6 2 3 3 1 4 4 1 2 5 5 \n" ]
In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w...
1,000
[ { "input": "2\n3 1\n0011", "output": "2 1 1 2 " }, { "input": "6\n10 8 9 11 13 5\n010010011101", "output": "6 6 2 3 3 1 4 4 1 2 5 5 " }, { "input": "1\n1\n01", "output": "1 1 " }, { "input": "1\n1000000\n01", "output": "1 1 " }, { "input": "2\n1 1000000\n0011", ...
1,643,424,410
2,147,483,647
PyPy 3
OK
TESTS
49
1,232
39,219,200
import math import sys import queue from heapq import heappop, heappush import random def solve(): n = int(input()) w = list(map(int, input().split())) s = str(input()) row = {w[i]: i + 1 for i in range(n)} free_2 = [] for i in range(n): heappush(free_2, (w[i], w[i]))...
Title: Bus of Characters Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$...
```python import math import sys import queue from heapq import heappop, heappush import random def solve(): n = int(input()) w = list(map(int, input().split())) s = str(input()) row = {w[i]: i + 1 for i in range(n)} free_2 = [] for i in range(n): heappush(free_2, (w[...
3
468
C
Hack it!
PROGRAMMING
2,500
[ "binary search", "constructive algorithms", "math" ]
null
null
Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen...
The first line contains a single integer *a*Β (1<=≀<=*a*<=≀<=1018).
Print two integers: *l*,<=*r*Β (1<=≀<=*l*<=≀<=*r*<=&lt;<=10200) β€” the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists.
[ "46\n", "126444381000032\n" ]
[ "1 10\n", "2333333 2333333333333\n" ]
none
1,500
[ { "input": "46", "output": "1 10" }, { "input": "126444381000032", "output": "2333333 2333333333333" }, { "input": "69645082595", "output": "613752823618441225798858488535 713259406474207764329704856394" }, { "input": "70602205995", "output": "11 2492213340204320744986569...
1,645,195,131
2,147,483,647
PyPy 3-64
OK
TESTS
51
311
14,643,200
from collections import defaultdict a = defaultdict(set) mod = int(input()) def F(x: str): if(len(x) == 1): return int(x) * (int(x) + 1) // 2 else: f = int(x[0]) return f * (f-1) // 2 * (10**(len(x)-1)) + f * 45 * (len(x) - 1) * 10**(len(x)-2) + f * (int(x[1:]) + 1) + F(x[1:]) for i in range(10...
Title: Hack it! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little X has met the following problem recently. Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate Of course Little X ...
```python from collections import defaultdict a = defaultdict(set) mod = int(input()) def F(x: str): if(len(x) == 1): return int(x) * (int(x) + 1) // 2 else: f = int(x[0]) return f * (f-1) // 2 * (10**(len(x)-1)) + f * 45 * (len(x) - 1) * 10**(len(x)-2) + f * (int(x[1:]) + 1) + F(x[1:]) for i i...
3
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,668,105,107
2,147,483,647
Python 3
OK
TESTS
44
92
0
n=(input()) max0=0 count0=0 for c in n: if c=="0": count0+=1 else: if count0>max0: max0=count0 count0=0 if count0>max0: max0=count0 max1=0 count1=0 for c in n: if c=="1": count1+=1 else: if count1>max1: max1=count1 count1=0 if c...
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 n=(input()) max0=0 count0=0 for c in n: if c=="0": count0+=1 else: if count0>max0: max0=count0 count0=0 if count0>max0: max0=count0 max1=0 count1=0 for c in n: if c=="1": count1+=1 else: if count1>max1: max1=count1 cou...
3.977
182
B
Vasya's Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present β€” the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≀<=*d* for all *i* from 1 to *n*. The clock does n...
The first line contains the single number *d* β€” the maximum number of the day that Vasya's clock can show (1<=≀<=*d*<=≀<=106). The second line contains a single integer *n* β€” the number of months in the year (1<=≀<=*n*<=≀<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≀<=*a**i*<=≀<=*d*) β€” th...
Print a single number β€” the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ...
500
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2...
1,602,225,324
2,147,483,647
PyPy 3
OK
TESTS
40
280
1,638,400
d=int(input()) n=int(input()) count=0 arr=[int(x) for x in input().split()] for i in range(n-1): if d>arr[i]: count+=d-arr[i] print(count)
Title: Vasya's Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present β€” the clock that shows not only the time, but also the date. The clock's face can display any ...
```python d=int(input()) n=int(input()) count=0 arr=[int(x) for x in input().split()] for i in range(n-1): if d>arr[i]: count+=d-arr[i] print(count) ```
3
723
C
Polycarp at the Radio
PROGRAMMING
1,600
[ "greedy" ]
null
null
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others. We define as *b**j* th...
The first line of the input contains two integers *n* and *m* (1<=≀<=*m*<=≀<=*n*<=≀<=2000). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109), where *a**i* is the performer of the *i*-th song.
In the first line print two integers: the maximum possible value of the minimum among the *b**j* (1<=≀<=*j*<=≀<=*m*), where *b**j* is the number of songs in the changed playlist performed by the *j*-th band, and the minimum number of changes in the playlist Polycarp needs to make. In the second line print the changed ...
[ "4 2\n1 2 3 2\n", "7 3\n1 3 2 2 2 2 1\n", "4 4\n1000000000 100 7 1000000000\n" ]
[ "2 1\n1 2 1 2 \n", "2 1\n1 3 3 2 2 2 1 \n", "1 4\n1 2 3 4 \n" ]
In the first sample, after Polycarp's changes the first band performs two songs (*b*<sub class="lower-index">1</sub> = 2), and the second band also performs two songs (*b*<sub class="lower-index">2</sub> = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any chang...
1,500
[ { "input": "4 2\n1 2 3 2", "output": "2 1\n1 2 1 2 " }, { "input": "7 3\n1 3 2 2 2 2 1", "output": "2 1\n1 3 3 2 2 2 1 " }, { "input": "4 4\n1000000000 100 7 1000000000", "output": "1 4\n1 2 3 4 " }, { "input": "1 1\n1", "output": "1 0\n1 " }, { "input": "1 1\n381...
1,686,941,957
2,147,483,647
PyPy 3-64
OK
TESTS
50
93
4,812,800
import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N,M = map(int, input().split()) A = list(map(int, input().split())) others = [] lib = defaultdict(list) t = N//M m = N%M for i in range(N): if A[i]<=M: if len(lib[A[i]])<t: lib[A[i]].appe...
Title: Polycarp at the Radio Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polyc...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import defaultdict N,M = map(int, input().split()) A = list(map(int, input().split())) others = [] lib = defaultdict(list) t = N//M m = N%M for i in range(N): if A[i]<=M: if len(lib[A[i]])<t: lib[...
3
340
A
The Wall
PROGRAMMING
1,200
[ "math" ]
null
null
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th...
The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≀<=*x*,<=*y*<=≀<=1000, 1<=≀<=*a*,<=*b*<=≀<=2Β·109, *a*<=≀<=*b*).
Output a single integer β€” the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink.
[ "2 3 6 18\n" ]
[ "3" ]
Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18.
500
[ { "input": "2 3 6 18", "output": "3" }, { "input": "4 6 20 201", "output": "15" }, { "input": "15 27 100 10000", "output": "74" }, { "input": "105 60 3456 78910", "output": "179" }, { "input": "1 1 1000 100000", "output": "99001" }, { "input": "3 2 5 5...
1,411,317,446
2,147,483,647
Python 3
OK
TESTS
35
124
0
from math import ceil def gcd(a,b): while b: a,b=b,a%b return a a=list(map(int,input().split())) b=a[0]*a[1]//gcd(a[0],a[1]) print(int(a[3]/b)-ceil(a[2]/b)+1)
Title: The Wall Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub ...
```python from math import ceil def gcd(a,b): while b: a,b=b,a%b return a a=list(map(int,input().split())) b=a[0]*a[1]//gcd(a[0],a[1]) print(int(a[3]/b)-ceil(a[2]/b)+1) ```
3
652
C
Foe Pairs
PROGRAMMING
1,800
[ "combinatorics", "sortings", "two pointers" ]
null
null
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*,<=*a**i*<=β‰ <=*b**i*). Your task is to count the number of different intervals (*x*,<=*y*) (1<=≀<=*x*<=≀<=*y*<=≀<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=3Β·105) β€” the length of the permutation *p* and the number of foe pairs. The second line contains *n* distinct integers *p**i* (1<=≀<=*p**i*<=≀<=*n*) β€” the elements of the permutation *p*. Each of the next *m* lines contains two integers (*a**i*,<=*...
Print the only integer *c* β€” the number of different intervals (*x*,<=*y*) that does not contain any foe pairs. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "4 2\n1 3 2 4\n3 2\n2 4\n", "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n" ]
[ "5\n", "20\n" ]
In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4).
0
[ { "input": "4 2\n1 3 2 4\n3 2\n2 4", "output": "5" }, { "input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7", "output": "20" }, { "input": "2 1\n1 2\n1 2", "output": "2" }, { "input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1", "output": "39" }, { "input"...
1,665,729,588
2,147,483,647
PyPy 3-64
OK
TESTS
24
482
47,308,800
from sys import stdin input=lambda :stdin.readline()[:-1] n,m=map(int,input().split()) p=list(map(lambda x:int(x)-1,input().split())) q=[0]*n for i in range(n): q[p[i]]=i ng=[[] for i in range(n)] for i in range(m): x,y=map(lambda x:int(x)-1,input().split()) x=q[x] y=q[y] if x<y: ng[x].ap...
Title: Foe Pairs Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*,<=*a**i*<=β‰ <=*b**i*). Your task is to count the number of different intervals (*x*,<=*y*) (1<=...
```python from sys import stdin input=lambda :stdin.readline()[:-1] n,m=map(int,input().split()) p=list(map(lambda x:int(x)-1,input().split())) q=[0]*n for i in range(n): q[p[i]]=i ng=[[] for i in range(n)] for i in range(m): x,y=map(lambda x:int(x)-1,input().split()) x=q[x] y=q[y] if x<y: ...
3
764
A
Taymyr is calling you
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,...
The only string contains three integersΒ β€” *n*, *m* and *z* (1<=≀<=*n*,<=*m*,<=*z*<=≀<=104).
Print single integerΒ β€” the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls.
[ "1 1 10\n", "1 2 5\n", "2 3 9\n" ]
[ "10\n", "2\n", "1\n" ]
Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third testΒ β€” only the artist which comes on the sixth minute.
500
[ { "input": "1 1 10", "output": "10" }, { "input": "1 2 5", "output": "2" }, { "input": "2 3 9", "output": "1" }, { "input": "4 8 9", "output": "1" }, { "input": "7 9 2", "output": "0" }, { "input": "10000 10000 10000", "output": "1" }, { "i...
1,548,191,214
2,147,483,647
Python 3
OK
TESTS
32
109
0
def gcd(a, b): if(b == 0): return a return gcd(b, a%b) n, m, z = map(int, input().split()) lcm = (n*m)//gcd(n, m) print(z//lcm)
Title: Taymyr is calling you Time Limit: None seconds Memory Limit: None megabytes Problem Description: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com...
```python def gcd(a, b): if(b == 0): return a return gcd(b, a%b) n, m, z = map(int, input().split()) lcm = (n*m)//gcd(n, m) print(z//lcm) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,637,666,139
2,147,483,647
PyPy 3-64
OK
TESTS
36
156
0
# A. Die Roll y,z = map(int,input().split()) n = 7-max(y,z) if n%3==0 and n%2==0: print("1/1") elif n%3==0: print(str(n//3)+"/"+"2") elif n%2==0: print(str(n//2)+"/"+"3") else: print(str(n)+"/"+"6")
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python # A. Die Roll y,z = map(int,input().split()) n = 7-max(y,z) if n%3==0 and n%2==0: print("1/1") elif n%3==0: print(str(n//3)+"/"+"2") elif n%2==0: print(str(n//2)+"/"+"3") else: print(str(n)+"/"+"6") ```
3.922
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=1000, 0<=≀<=*x*<=≀<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≀<=*d**i*<=≀<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integersΒ β€” number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,637,004,087
2,147,483,647
Python 3
OK
TESTS
34
46
0
n,c = map(int,input().split()) countN = 0 for i in range(n): a,b = map(str,input().split()) b = int(b) if a == "+": c+=b if a == "-": if c<b: countN+=1 else: c-=b print(c,countN)
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python n,c = map(int,input().split()) countN = 0 for i in range(n): a,b = map(str,input().split()) b = int(b) if a == "+": c+=b if a == "-": if c<b: countN+=1 else: c-=b print(c,countN) ```
3
672
A
Summer Camp
PROGRAMMING
800
[ "implementation" ]
null
null
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to...
The only line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the position of the digit you need to print.
Print the *n*-th digit of the line.
[ "3\n", "11\n" ]
[ "3\n", "0\n" ]
In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit. In the second sample, the digit at position 11 is '0', it belongs to the integer 10.
500
[ { "input": "3", "output": "3" }, { "input": "11", "output": "0" }, { "input": "12", "output": "1" }, { "input": "13", "output": "1" }, { "input": "29", "output": "9" }, { "input": "30", "output": "2" }, { "input": "1000", "output": "3" ...
1,677,009,883
2,147,483,647
Python 3
OK
TESTS
37
46
0
print(''.join([str(i) for i in range(800)])[int(input())])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python print(''.join([str(i) for i in range(800)])[int(input())]) ```
3
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,...
The first line contains a single integer *n* (3<=≀<=*n*<=≀<=100)Β β€” the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≀<=*a**i*<=≀<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict...
Print a single number β€” the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic...
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9...
1,699,955,540
2,147,483,647
Python 3
OK
TESTS
19
46
0
n=int(input()) arr=list(map(int,input().split())) # delete at every index except 0 and n-1 mini=float('inf') for i in range(1,n-1): temp=arr.copy() removed_list=temp[0:i]+temp[i+1:] # for adjacnet element difference maxi=0 for j in range(len(removed_list)-1): maxi=max(max...
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 fo...
```python n=int(input()) arr=list(map(int,input().split())) # delete at every index except 0 and n-1 mini=float('inf') for i in range(1,n-1): temp=arr.copy() removed_list=temp[0:i]+temp[i+1:] # for adjacnet element difference maxi=0 for j in range(len(removed_list)-1): ma...
3
939
A
Love Triangle
PROGRAMMING
800
[ "graphs" ]
null
null
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≀<=*f**i*<=≀<=*n* and *f**i*<=β‰ <=*i*. We call a love triangle a situation ...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=5000)Β β€” the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≀<=*f**i*<=≀<=*n*, *f**i*<=β‰ <=*i*), meaning that the *i*-th plane likes the *f**i*-th.
Output Β«YESΒ» if there is a love triangle consisting of planes on Earth. Otherwise, output Β«NOΒ». You can output any letter in lower case or in upper case.
[ "5\n2 4 5 1 3\n", "5\n5 5 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle. In second example there are no love triangles.
500
[ { "input": "5\n2 4 5 1 3", "output": "YES" }, { "input": "5\n5 5 5 5 1", "output": "NO" }, { "input": "3\n3 1 2", "output": "YES" }, { "input": "10\n4 10 9 5 3 1 5 10 6 4", "output": "NO" }, { "input": "10\n5 5 4 9 10 9 9 5 3 1", "output": "YES" }, { "...
1,697,969,067
2,147,483,647
Python 3
OK
TESTS
16
46
409,600
import sys def input_lines(): return list(map(str.strip, sys.stdin.readlines())) def line_to_int_arr(line): return list(map(int, line.split(" "))) def print_arr(arr): for el in arr: print(el, end= ' ') print() lines = input_lines() n = int(lines[0]) arr = line_to_int_arr(lines[1]) for i in range(n): if arr...
Title: Love Triangle Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ...
```python import sys def input_lines(): return list(map(str.strip, sys.stdin.readlines())) def line_to_int_arr(line): return list(map(int, line.split(" "))) def print_arr(arr): for el in arr: print(el, end= ' ') print() lines = input_lines() n = int(lines[0]) arr = line_to_int_arr(lines[1]) for i in range(n...
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,693,152,160
2,147,483,647
Python 3
OK
TESTS
30
92
0
a = input() dx = 0 xx = 0 for i in a: if i.islower(): xx += 1 else: dx += 1 if xx < dx: print(a.upper()) else: print(a.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a = input() dx = 0 xx = 0 for i in a: if i.islower(): xx += 1 else: dx += 1 if xx < dx: print(a.upper()) else: print(a.lower()) ```
3.977
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: -...
The single line contains six space-separated integers *l**i* (1<=≀<=*l**i*<=≀<=9) β€” the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wΔ±thout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "...
1,558,364,366
2,147,483,647
Python 3
OK
TESTS
29
108
0
s=[int(n) for n in input().split()] j=0 for n in s: if s.count(n)>=4: j=n break if j==0: print('Alien') else: s.sort() del s[s.index(j):s.index(j)+4] if s[0]==s[1]: print('Elephant') else: print('Bear')
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an...
```python s=[int(n) for n in input().split()] j=0 for n in s: if s.count(n)>=4: j=n break if j==0: print('Alien') else: s.sort() del s[s.index(j):s.index(j)+4] if s[0]==s[1]: print('Elephant') else: print('Bear') ```
3
982
B
Bus of Characters
PROGRAMMING
1,300
[ "data structures", "greedy", "implementation" ]
null
null
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers: - an introvert always choose...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of rows in the bus. The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct. The t...
Print $2n$ integers β€” the rows the passengers will take. The order of passengers should be the same as in input.
[ "2\n3 1\n0011\n", "6\n10 8 9 11 13 5\n010010011101\n" ]
[ "2 1 1 2 \n", "6 6 2 3 3 1 4 4 1 2 5 5 \n" ]
In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w...
1,000
[ { "input": "2\n3 1\n0011", "output": "2 1 1 2 " }, { "input": "6\n10 8 9 11 13 5\n010010011101", "output": "6 6 2 3 3 1 4 4 1 2 5 5 " }, { "input": "1\n1\n01", "output": "1 1 " }, { "input": "1\n1000000\n01", "output": "1 1 " }, { "input": "2\n1 1000000\n0011", ...
1,558,177,973
2,147,483,647
Python 3
OK
TESTS
49
1,434
20,480,000
n = int(input()) s = list(map(int, input().split())) z = list(zip(s, range(1, n+1))) z.sort() z = [i[1] for i in z] p = [] k = 0 for i in input(): if i == '0': print(z[k]) p.append(z[k]) k+=1 if i == '1': print(p[-1]) p.pop()
Title: Bus of Characters Time Limit: None seconds Memory Limit: None megabytes Problem Description: In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$...
```python n = int(input()) s = list(map(int, input().split())) z = list(zip(s, range(1, n+1))) z.sort() z = [i[1] for i in z] p = [] k = 0 for i in input(): if i == '0': print(z[k]) p.append(z[k]) k+=1 if i == '1': print(p[-1]) p.pop() ```
3
731
A
Night at the Museum
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character...
The only line of input contains the name of some exhibitΒ β€” the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.
Print one integerΒ β€” the minimum number of rotations of the wheel, required to print the name given in the input.
[ "zeus\n", "map\n", "ares\n" ]
[ "18\n", "35\n", "34\n" ]
To print the string from the first sample it would be optimal to perform the following sequence of rotations: 1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations).
500
[ { "input": "zeus", "output": "18" }, { "input": "map", "output": "35" }, { "input": "ares", "output": "34" }, { "input": "l", "output": "11" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "...
1,697,638,374
2,147,483,647
Python 3
OK
TESTS
44
46
0
x=input() y="abcdefghijklmnopqrstuvwxyz" z=y[::-1] e=0 b=len(x) for i in range(0,b): if x[i] in y: c=y.index(x[i]) if x[i] in z: d=z.index(x[i])+1 if c<=d: e=e+c if d<c: e=e+d f=y[:c] g=y[c::] y=g+f z=y[::-1] print(e)
Title: Night at the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devis...
```python x=input() y="abcdefghijklmnopqrstuvwxyz" z=y[::-1] e=0 b=len(x) for i in range(0,b): if x[i] in y: c=y.index(x[i]) if x[i] in z: d=z.index(x[i])+1 if c<=d: e=e+c if d<c: e=e+d f=y[:c] g=y[c::] y=g+f z=y[::-1] print(e) ```
3
312
B
Archer
PROGRAMMING
1,300
[ "math", "probabilities" ]
null
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will...
A single line contains four integers .
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "1 2 1 2\n" ]
[ "0.666666666667" ]
none
1,000
[ { "input": "1 2 1 2", "output": "0.666666666667" }, { "input": "1 3 1 3", "output": "0.600000000000" }, { "input": "1 3 2 3", "output": "0.428571428571" }, { "input": "3 4 3 4", "output": "0.800000000000" }, { "input": "1 2 10 11", "output": "0.523809523810" ...
1,593,350,199
2,147,483,647
PyPy 3
OK
TESTS
31
156
20,172,800
a,b,c,d=[int(x) for x in input().split()] x=(1-a/b)*(1-c/d) ans=(a/b)*(1/(1-(x))) print(ans)
Title: Archer Time Limit: None seconds Memory Limit: None megabytes Problem Description: SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w...
```python a,b,c,d=[int(x) for x in input().split()] x=(1-a/b)*(1-c/d) ans=(a/b)*(1/(1-(x))) print(ans) ```
3
330
A
Cakeminator
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains...
The first line contains two integers *r* and *c* (2<=≀<=*r*,<=*c*<=≀<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β€” the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these: ...
Output the maximum number of cake cells that the cakeminator can eat.
[ "3 4\nS...\n....\n..S.\n" ]
[ "8\n" ]
For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats).
500
[ { "input": "3 4\nS...\n....\n..S.", "output": "8" }, { "input": "2 2\n..\n..", "output": "4" }, { "input": "2 2\nSS\nSS", "output": "0" }, { "input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..", "output": "14" }, { "input": "3 5\n..S..\nSSSSS\n..S..", "output": "...
1,607,062,085
2,147,483,647
PyPy 3
OK
TESTS
42
310
1,228,800
n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(input())) b = [] for i in range(len(a)): if 'S' not in a[i]: for j in range(m): b.append([i, j]) for i in range(m): flag = 0 for j in range(n): if a[j][i] == 'S': flag = 1 ...
Title: Cakeminator Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rectangular cake, represented as an *r*<=Γ—<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ—<=4 cake may look as follows: The cakeminator is going to eat the cake! Each ti...
```python n, m = map(int, input().split()) a = [] for i in range(n): a.append(list(input())) b = [] for i in range(len(a)): if 'S' not in a[i]: for j in range(m): b.append([i, j]) for i in range(m): flag = 0 for j in range(n): if a[j][i] == 'S': flag ...
3
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≀<=*n*<=≀<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX"...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, ...
1,553,845,059
2,147,483,647
Python 3
OK
TESTS
23
93
0
# import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("output1.out",'w') n=int(input()) h=input() a=[input() for i in range(n)] flag=0 x=0 while x<len(a): p=a[x][-3:]+"->"+a[x][0:3] if p in a: a.remove(a[x]) a.remove(p) else: flag=1 break if flag==1: print("contest") else: prin...
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei...
```python # import sys # sys.stdin=open("input.in",'r') # sys.stdout=open("output1.out",'w') n=int(input()) h=input() a=[input() for i in range(n)] flag=0 x=0 while x<len(a): p=a[x][-3:]+"->"+a[x][0:3] if p in a: a.remove(a[x]) a.remove(p) else: flag=1 break if flag==1: print("contest") el...
3
621
A
Wet Shark and Odd and Even
PROGRAMMING
900
[ "implementation" ]
null
null
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0.
The first line of the input contains one integer, *n* (1<=≀<=*n*<=≀<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.
Print the maximum possible even sum that can be obtained if we use some of the given integers.
[ "3\n1 2 3\n", "5\n999999999 999999999 999999999 999999999 999999999\n" ]
[ "6", "3999999996" ]
In the first sample, we can simply take all three integers for a total sum of 6. In the second sample Wet Shark should take any four out of five integers 999 999 999.
500
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "5\n999999999 999999999 999999999 999999999 999999999", "output": "3999999996" }, { "input": "1\n1", "output": "0" }, { "input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98", "output": "870" }, { "input": "15\...
1,553,673,310
2,147,483,647
Python 3
OK
TESTS
87
187
8,499,200
n = int(input()) arr = list(map(int , input().split())) sumx = 0 even = 0 odd = 0 mini = 1000000001 for x in arr : if (x%2)==0: even+=1 else : odd +=1 mini = min(mini,x) sumx += x if((sumx %2)==0): print(sumx) else : print(sumx-mini)
Title: Wet Shark and Odd and Even Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, th...
```python n = int(input()) arr = list(map(int , input().split())) sumx = 0 even = 0 odd = 0 mini = 1000000001 for x in arr : if (x%2)==0: even+=1 else : odd +=1 mini = min(mini,x) sumx += x if((sumx %2)==0): print(sumx) else : print(sumx-mini) ```
3
855
A
Tom Riddle's Diary
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of names in the list. Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
[ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n" ]
[ "NO\nNO\nNO\nNO\nYES\nYES\n", "NO\nYES\nYES\n" ]
In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* &lt; *i*, which means that answer for *i* = 5 is "YES".
500
[ { "input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES" }, { "input": "3\na\na\na", "output": "NO\nYES\nYES" }, { "input": "1\nzn", "output": "NO" }, { "input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb...
1,640,186,245
2,147,483,647
PyPy 3-64
OK
TESTS
55
109
0
d = {} query = int(input()) while (query): query = query - 1 s = input() if s in d: print("YES") else: d[s] = 1 print("NO")
Title: Tom Riddle's Diary Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ...
```python d = {} query = int(input()) while (query): query = query - 1 s = input() if s in d: print("YES") else: d[s] = 1 print("NO") ```
3
977
B
Two-gram
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β€” three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters...
The first line of the input contains integer number $n$ ($2 \le n \le 100$) β€” the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters.
Print the only line containing exactly two capital Latin letters β€” any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times.
[ "7\nABACABA\n", "5\nZZZAA\n" ]
[ "AB\n", "ZZ\n" ]
In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times.
0
[ { "input": "7\nABACABA", "output": "AB" }, { "input": "5\nZZZAA", "output": "ZZ" }, { "input": "26\nQWERTYUIOPASDFGHJKLZXCVBNM", "output": "AS" }, { "input": "2\nQA", "output": "QA" }, { "input": "2\nWW", "output": "WW" }, { "input": "11\nGGRRAATTZZZ",...
1,694,902,884
2,147,483,647
PyPy 3-64
OK
TESTS
22
62
0
#https://codeforces.com/problemset/problem/977/B n = int(input()) s = input() subst_dict = {} for x in range(1, n): subst_string = s[x-1:x+1] if(subst_string not in subst_dict): subst_dict[subst_string] = 1 else: subst_dict[subst_string] += 1 print(max(subst_dict, key=subst_dict....
Title: Two-gram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β€” three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to f...
```python #https://codeforces.com/problemset/problem/977/B n = int(input()) s = input() subst_dict = {} for x in range(1, n): subst_string = s[x-1:x+1] if(subst_string not in subst_dict): subst_dict[subst_string] = 1 else: subst_dict[subst_string] += 1 print(max(subst_dict, key=s...
3
967
B
Watering System
PROGRAMMING
1,000
[ "math", "sortings" ]
null
null
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After...
The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$)Β β€” the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)...
Print a single integerΒ β€” the number of holes Arkady should block.
[ "4 10 3\n2 2 2 2\n", "4 80 20\n3 2 1 4\n", "5 10 10\n1000 1 1 1 1\n" ]
[ "1\n", "0\n", "4\n" ]
In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady. In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les...
1,000
[ { "input": "4 10 3\n2 2 2 2", "output": "1" }, { "input": "4 80 20\n3 2 1 4", "output": "0" }, { "input": "5 10 10\n1000 1 1 1 1", "output": "4" }, { "input": "10 300 100\n20 1 3 10 8 5 3 6 4 3", "output": "1" }, { "input": "10 300 100\n20 25 68 40 60 37 44 85 23 ...
1,662,158,264
2,147,483,647
Python 3
OK
TESTS
26
109
6,348,800
# -*- coding: utf-8 -*- n, A, B = [int(x) for x in input().split()] holes = [int(x) for x in input().split()] total = sum(holes) first = holes[0] holes = holes[1:] holes.sort(reverse=True) ans = 0 for hole in holes: if A * first / total >= B: break total -= hole ans += 1 print(ans) ...
Title: Watering System Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi...
```python # -*- coding: utf-8 -*- n, A, B = [int(x) for x in input().split()] holes = [int(x) for x in input().split()] total = sum(holes) first = holes[0] holes = holes[1:] holes.sort(reverse=True) ans = 0 for hole in holes: if A * first / total >= B: break total -= hole ans += 1 print(ans) ...
3
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
The first input line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 β€” those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and...
Print a single number β€” the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second...
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1...
1,667,351,035
2,147,483,647
Python 3
OK
TESTS
49
92
0
# https://codeforces.com/problemset/problem/139/A def handle(): pages = int(input()) pages_per_day = input().split(" ") pages_per_day = [int(i) for i in pages_per_day] index = 0 while pages > 0: pages -= pages_per_day[index] if pages <= 0: return index + 1 index...
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s...
```python # https://codeforces.com/problemset/problem/139/A def handle(): pages = int(input()) pages_per_day = input().split(" ") pages_per_day = [int(i) for i in pages_per_day] index = 0 while pages > 0: pages -= pages_per_day[index] if pages <= 0: return index + 1 ...
3
687
A
NP-Hard Problem
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot...
The first line of the input contains two integers *n* and *m* (2<=≀<=*n*<=≀<=100<=000, 1<=≀<=*m*<=≀<=100<=000)Β β€” the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≀<=<=*u**i*,<=<=*v**i*<=<=≀<=<=*n*), denoting ...
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ...
[ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "1\n2 \n2\n1 3 \n", "-1\n" ]
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
500
[ { "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 " }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "-1" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1" }, { "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1" ...
1,615,087,393
2,147,483,647
Python 3
OK
TESTS
56
748
10,444,800
n,m=map(int,input().split()) g=[[] for i in range(n)] for i in range(m): u,v=map(int,input().split()) u-=1;v-=1 g[u].append(v) g[v].append(u) used=[-1]*n ok=True w=[[],[]] def bfs(start,color): used[start]=color w[color].append(start) q=[start] while q!=[]: ...
Title: NP-Hard Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ...
```python n,m=map(int,input().split()) g=[[] for i in range(n)] for i in range(m): u,v=map(int,input().split()) u-=1;v-=1 g[u].append(v) g[v].append(u) used=[-1]*n ok=True w=[[],[]] def bfs(start,color): used[start]=color w[color].append(start) q=[start] while q!=[]...
3
780
B
The Meeting Place Cannot Be Changed
PROGRAMMING
1,600
[ "binary search" ]
null
null
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ...
The first line contains single integer *n* (2<=≀<=*n*<=≀<=60<=000)Β β€” the number of friends. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≀<=*x**i*<=≀<=109)Β β€” the current coordinates of the friends, in meters. The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≀<=*v**i*<=≀<=109...
Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road. Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds.
[ "3\n7 1 3\n1 2 1\n", "4\n5 10 3 2\n2 3 2 4\n" ]
[ "2.000000000000\n", "1.400000000000\n" ]
In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds.
1,000
[ { "input": "3\n7 1 3\n1 2 1", "output": "2.000000000000" }, { "input": "4\n5 10 3 2\n2 3 2 4", "output": "1.400000000000" }, { "input": "3\n1 1000000000 2\n1 2 1000000000", "output": "333333332.999999999971" }, { "input": "2\n4 5\n10 8", "output": "0.055555555556" }, ...
1,639,312,604
2,147,483,647
Python 3
OK
TESTS
46
2,745
6,656,000
ile_ludzi = int(input()) ludzie = list(map(int, input().split())) szybkosci = list(map(int, input().split())) def CzyUdaSieSpodkac(czas): maxPocz = 0 minKoniec = 1e9 for i in range(ile_ludzi): droga = czas * szybkosci[i] poczatek = ludzie[i] - droga koniec = ludzi...
Title: The Meeting Place Cannot Be Changed Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction. At some points on the road...
```python ile_ludzi = int(input()) ludzie = list(map(int, input().split())) szybkosci = list(map(int, input().split())) def CzyUdaSieSpodkac(czas): maxPocz = 0 minKoniec = 1e9 for i in range(ile_ludzi): droga = czas * szybkosci[i] poczatek = ludzie[i] - droga koni...
3
702
A
Maximum Increase
PROGRAMMING
800
[ "dp", "greedy", "implementation" ]
null
null
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109).
Print the maximum length of an increasing subarray of the given array.
[ "5\n1 7 2 11 15\n", "6\n100 100 100 100 100 100\n", "3\n1 2 3\n" ]
[ "3\n", "1\n", "3\n" ]
none
0
[ { "input": "5\n1 7 2 11 15", "output": "3" }, { "input": "6\n100 100 100 100 100 100", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n1000000000", "output": "1" }, { "input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7...
1,660,758,440
2,147,483,647
Python 3
OK
TESTS
32
93
7,987,200
class Solution: def incSubarray(self,n,arr): i = j = 0 maxLen = 1 while j+1<n: if arr[j]<arr[j+1]: j += 1 else: maxLen = max(maxLen,j-i+1) j += 1 i = j maxLen = max(maxLen,j-i+1) retur...
Title: Maximum Increase Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called...
```python class Solution: def incSubarray(self,n,arr): i = j = 0 maxLen = 1 while j+1<n: if arr[j]<arr[j+1]: j += 1 else: maxLen = max(maxLen,j-i+1) j += 1 i = j maxLen = max(maxLen,j-i+1) ...
3
302
A
Eugeny and Array
PROGRAMMING
800
[ "implementation" ]
null
null
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=*n*). - The response to the query will be integer 1, if the elements of a...
The first line contains integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=*n*).
Print *m* integers β€” the responses to Eugene's queries in the order they occur in the input.
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n" ]
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n" ]
none
500
[ { "input": "2 3\n1 -1\n1 1\n1 2\n2 2", "output": "0\n1\n0" }, { "input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5", "output": "0\n1\n0\n1\n0" }, { "input": "3 3\n1 1 1\n2 2\n1 1\n1 1", "output": "0\n0\n0" }, { "input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1", "output": "...
1,610,777,482
2,147,483,647
Python 3
OK
TESTS
38
623
10,956,800
n,m=map(int, input().split()) a=input().split() x=a.count("-1") x=min(x, n-x) s="" for i in range(m): l, r=map(int, input().split()) if (r-l)% 2==1 and x>=(r-l+1)//2: s+="1\n" else: s+="0\n" print(s)
Title: Eugeny and Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries: - Query number *i* is given as a pair of integers *l**i*, *r**i* (...
```python n,m=map(int, input().split()) a=input().split() x=a.count("-1") x=min(x, n-x) s="" for i in range(m): l, r=map(int, input().split()) if (r-l)% 2==1 and x>=(r-l+1)//2: s+="1\n" else: s+="0\n" print(s) ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,633,082,286
2,147,483,647
Python 3
OK
TESTS
40
122
6,758,400
a = str(input()) b = str(input()) c = a[::-1] if len(a)==len(b): if b==a[::-1]: print("YES") else: print("NO") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python a = str(input()) b = str(input()) c = a[::-1] if len(a)==len(b): if b==a[::-1]: print("YES") else: print("NO") else: print("NO") ```
3.956911
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≀<=|*s*|<=≀<=50). The second line contains the string *t* (1<=≀<=|*t*|<=≀<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,594,973,737
2,147,483,647
Python 3
OK
TESTS
19
218
6,758,400
s1=input() s2=input() j=0 for i in range(len(s2)): if(s2[i]==s1[j]): j+=1 print(j+1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python s1=input() s2=input() j=0 for i in range(len(s2)): if(s2[i]==s1[j]): j+=1 print(j+1) ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ—<=*a*. What is the least number of flagstones needed to pave the...
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≀<=<=*n*,<=*m*,<=*a*<=≀<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3"...
1,680,957,117
2,147,483,647
Python 3
OK
TESTS
20
31
0
n, m, a = input().split() n = int(n) m = int(m) a = int(a) num_along_length = (n / a) if num_along_length > (n//a): num_along_length = int(num_along_length) + 1 else: num_along_length = n // a num_along_breadth = (m / a) if num_along_breadth > (m//a): num_along_breadth = int(num_along_bread...
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python n, m, a = input().split() n = int(n) m = int(m) a = int(a) num_along_length = (n / a) if num_along_length > (n//a): num_along_length = int(num_along_length) + 1 else: num_along_length = n // a num_along_breadth = (m / a) if num_along_breadth > (m//a): num_along_breadth = int(num_a...
3.9845
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β€” the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,678,233,134
2,147,483,647
PyPy 3
OK
TESTS
101
186
0
n = int(input()) lst = list(map(int, input().split())) p_from = [0] * n for i in range(n): y = lst[i] p_from[y - 1] = i + 1 print(*p_from)
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n = int(input()) lst = list(map(int, input().split())) p_from = [0] * n for i in range(n): y = lst[i] p_from[y - 1] = i + 1 print(*p_from) ```
3
53
A
Autocomplete
PROGRAMMING
1,100
[ "implementation" ]
A. Autocomplete
2
256
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co...
The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≀<=*n*<=≀<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase...
If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*. The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '&lt;' o...
[ "next\n2\nnextpermutation\nnextelement\n", "find\n4\nfind\nfindfirstof\nfindit\nfand\n", "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n" ]
[ "nextelement\n", "find\n", "find\n" ]
none
500
[ { "input": "next\n2\nnextpermutation\nnextelement", "output": "nextelement" }, { "input": "find\n4\nfind\nfindfirstof\nfindit\nfand", "output": "find" }, { "input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand", "output": "find" }, { "input": "kudljmxcse\n4\nkudljmxcse\nszje...
1,602,449,000
2,147,483,647
Python 3
OK
TESTS
25
218
0
# Taking the input from ther user s = input();l=[] for i in range(int(input())): l.append(input()) l = sorted(l) # If there is a prefect match print(s) for i in range(len(l)): if l[i] == s: print(s) exit() # Check for the best match if existed for i in range(len(l)): if l[i][...
Title: Autocomplete Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens...
```python # Taking the input from ther user s = input();l=[] for i in range(int(input())): l.append(input()) l = sorted(l) # If there is a prefect match print(s) for i in range(len(l)): if l[i] == s: print(s) exit() # Check for the best match if existed for i in range(len(l)): ...
3.9455
462
B
Appleman and Card Game
PROGRAMMING
1,300
[ "greedy" ]
null
null
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette...
The first line contains two integers *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=105). The next line contains *n* uppercase letters without spaces β€” the *i*-th letter describes the *i*-th card of the Appleman.
Print a single integer – the answer to the problem.
[ "15 10\nDZFDFZDFDDDDDDF\n", "6 4\nYJSNPI\n" ]
[ "82\n", "4\n" ]
In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin.
1,000
[ { "input": "15 10\nDZFDFZDFDDDDDDF", "output": "82" }, { "input": "6 4\nYJSNPI", "output": "4" }, { "input": "5 3\nAOWBY", "output": "3" }, { "input": "1 1\nV", "output": "1" }, { "input": "2 1\nWT", "output": "1" }, { "input": "2 2\nBL", "output":...
1,589,965,807
2,147,483,647
PyPy 3
OK
TESTS
41
155
1,843,200
(n,k)=map(int,input().split()) s=input() l=[0 for i in range(27)] for i in s: l[ord(i)-ord('A')]+=1 l.sort() l=l[::-1] s=0 for i in l: if(k>0): if(k>=i): s+=(i*i) k-=i else: s+=(k*k) k=0 else: break print(s) ...
Title: Appleman and Card Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally...
```python (n,k)=map(int,input().split()) s=input() l=[0 for i in range(27)] for i in s: l[ord(i)-ord('A')]+=1 l.sort() l=l[::-1] s=0 for i in l: if(k>0): if(k>=i): s+=(i*i) k-=i else: s+=(k*k) k=0 else: break print(s) ...
3
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,512,226,692
3,192
Python 3
OK
TESTS
26
233
5,529,600
k,p=input().split() k=int(k) p=int(p) n=1 a=0 t=0 while k: a+=1 if len(str(a))>n: n+=1 a=int("1"+"0"*(n-1)) s=str(a) t+=int(s+s[::-1]) k-=1 print(t%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,p=input().split() k=int(k) p=int(p) n=1 a=0 t=0 while k: a+=1 if len(str(a))>n: n+=1 a=int("1"+"0"*(n-1)) s=str(a) t+=int(s+s[::-1]) k-=1 print(t%p) ```
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≀<=*n*<=≀<=100, 2<=≀<=*t*<=≀<=10) β€” the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, β€” the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,684,439,543
2,147,483,647
Python 3
OK
TESTS
65
46
0
str_a = input() n , t = [int(x) for x in str_a.split(' ')] start = 10**(n-1) end = 10**(n) - 1 num = start found = False while num <= end: if num % t == 0: print(num) found = True break else: num += 1 if not found: print(-1)
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python str_a = input() n , t = [int(x) for x in str_a.split(' ')] start = 10**(n-1) end = 10**(n) - 1 num = start found = False while num <= end: if num % t == 0: print(num) found = True break else: num += 1 if not found: print(-1) ...
3
888
A
Local Extrema
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element can be called local maximum iff it is strictly greater than its neighbours (that is, *a**i*<=&gt;<=*...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of elements in array *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=1000) β€” the elements of array *a*.
Print the number of local extrema in the given array.
[ "3\n1 2 3\n", "4\n1 5 2 5\n" ]
[ "0\n", "2\n" ]
none
0
[ { "input": "3\n1 2 3", "output": "0" }, { "input": "4\n1 5 2 5", "output": "2" }, { "input": "1\n1", "output": "0" }, { "input": "1\n548", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "3\n3 2 3", "output": "1" }, { "inp...
1,547,580,879
2,147,483,647
Python 3
OK
TESTS
14
108
0
n = int(input()) arr = [int(i) for i in input().split()] c = 0 for i in range(1, n-1): if (arr[i] > arr[i-1] and arr[i] > arr[i+1]) or \ (arr[i] < arr[i-1] and arr[i] < arr[i+1]): c += 1 print(c)
Title: Local Extrema Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a*. Some element of this array *a**i* is a local minimum iff it is strictly less than both of its neighbours (that is, *a**i*<=&lt;<=*a**i*<=-<=1 and *a**i*<=&lt;<=*a**i*<=+<=1). Also the element c...
```python n = int(input()) arr = [int(i) for i in input().split()] c = 0 for i in range(1, n-1): if (arr[i] > arr[i-1] and arr[i] > arr[i+1]) or \ (arr[i] < arr[i-1] and arr[i] < arr[i+1]): c += 1 print(c) ```
3
195
A
Let's Watch Football
PROGRAMMING
1,000
[ "binary search", "brute force", "math" ]
null
null
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
The first line contains three space-separated integers *a*, *b* and *c* (1<=≀<=*a*,<=*b*,<=*c*<=≀<=1000,<=*a*<=&gt;<=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T...
Print a single number β€” the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
[ "4 1 1\n", "10 3 2\n", "13 12 1\n" ]
[ "3\n", "5\n", "1\n" ]
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 Β· 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch...
500
[ { "input": "4 1 1", "output": "3" }, { "input": "10 3 2", "output": "5" }, { "input": "13 12 1", "output": "1" }, { "input": "2 1 3", "output": "3" }, { "input": "6 2 4", "output": "8" }, { "input": "5 2 1", "output": "2" }, { "input": "2 1...
1,597,853,034
2,147,483,647
PyPy 3
OK
TESTS
49
310
0
a,b,c = input().split() a= int(a) b= int(b) c= int(c) ans = (((a-b)*c + b -1) // b) print(ans)
Title: Let's Watch Football Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ...
```python a,b,c = input().split() a= int(a) b= int(b) c= int(c) ans = (((a-b)*c + b -1) // b) print(ans) ```
3
656
D
Rosetta Problem
PROGRAMMING
2,100
[ "*special" ]
null
null
The input contains a single integer *a* (0<=≀<=*a*<=≀<=1<=000<=000).
Output a single integer.
[ "129\n" ]
[ "1\n" ]
none
0
[ { "input": "129", "output": "1" }, { "input": "0", "output": "0" }, { "input": "4", "output": "0" }, { "input": "6", "output": "0" }, { "input": "16", "output": "0" }, { "input": "299593", "output": "7" }, { "input": "398929", "output":...
1,490,965,138
2,147,483,647
Python 3
OK
TESTS
25
77
5,632,000
import collections c = collections.Counter(oct(int(input()))[2:]) print(c['1'])
Title: Rosetta Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Input Specification: The input contains a single integer *a* (0<=≀<=*a*<=≀<=1<=000<=000). Output Specification: Output a single integer. Demo Input: ['129\n'] Demo Output: ['1\n'] Note: none
```python import collections c = collections.Counter(oct(int(input()))[2:]) print(c['1']) ```
3
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
The first line contains an even integer *n* (2<=≀<=*n*<=≀<=50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β€” the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,616,592,361
2,147,483,647
PyPy 3
OK
TESTS
46
186
0
n = int(input()) string = str(input()) if((string.count('7') + string.count('4')) != n): print('NO') else: arr = [int(i) for i in string[:n // 2]] arr1 = [int(i) for i in string[n // 2:]] if(sum(arr) == sum(arr1)): print('YES') else: print('NO')
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) string = str(input()) if((string.count('7') + string.count('4')) != n): print('NO') else: arr = [int(i) for i in string[:n // 2]] arr1 = [int(i) for i in string[n // 2:]] if(sum(arr) == sum(arr1)): print('YES') else: print('NO') ```
3
46
A
Ball Game
PROGRAMMING
800
[ "brute force", "implementation" ]
A. Ball Game
2
256
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is...
The first line contains integer *n* (2<=≀<=*n*<=≀<=100) which indicates the number of kids in the circle.
In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces.
[ "10\n", "3\n" ]
[ "2 4 7 1 6 2 9 7 6\n", "2 1\n" ]
none
0
[ { "input": "10", "output": "2 4 7 1 6 2 9 7 6" }, { "input": "3", "output": "2 1" }, { "input": "4", "output": "2 4 3" }, { "input": "5", "output": "2 4 2 1" }, { "input": "6", "output": "2 4 1 5 4" }, { "input": "7", "output": "2 4 7 4 2 1" }, ...
1,492,532,142
2,147,483,647
Python 3
OK
TESTS
33
124
5,529,600
n = int(input()) cnt = 1 for i in range(1, n): if (cnt + i) % n == 0: cnt = n else: cnt = (cnt + i) % n print(cnt, end = ' ')
Title: Ball Game Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count. The game goes as follows. Kids stand in circle. Let's agree to think...
```python n = int(input()) cnt = 1 for i in range(1, n): if (cnt + i) % n == 0: cnt = n else: cnt = (cnt + i) % n print(cnt, end = ' ') ```
3.9587
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ...
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer β€” the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihn...
1,567,537,309
2,147,483,647
PyPy 3
OK
TESTS
58
140
0
word = input() letters_of_interests = ''.join([x if x in "niet" else '' for x in word]) nines="" count = 0 while(True): if count == 0: i = letters_of_interests.find('n') if i == -1: break else: letters_of_interests = letters_of_interests[0:i] + letters_o...
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiinetee...
```python word = input() letters_of_interests = ''.join([x if x in "niet" else '' for x in word]) nines="" count = 0 while(True): if count == 0: i = letters_of_interests.find('n') if i == -1: break else: letters_of_interests = letters_of_interests[0:i] +...
3
743
A
Vladik and flights
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad. Vladik knows *n* airports. All the airports are located on a straight line. Each airport has u...
The first line contains three integers *n*, *a*, and *b* (1<=≀<=*n*<=≀<=105, 1<=≀<=*a*,<=*b*<=≀<=*n*)Β β€” the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach. The second line contains a string with length *n*, which consists only of characters...
Print single integerΒ β€” the minimum cost Vladik has to pay to get to the olympiad.
[ "4 1 4\n1010\n", "5 5 2\n10110\n" ]
[ "1", "0" ]
In the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to th...
500
[ { "input": "4 1 4\n1010", "output": "1" }, { "input": "5 5 2\n10110", "output": "0" }, { "input": "10 9 5\n1011111001", "output": "1" }, { "input": "7 3 7\n1110111", "output": "0" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "10 3 3\n100101101...
1,627,276,235
2,147,483,647
Python 3
OK
TESTS
56
77
6,963,200
n,a,b=map(int,input().split()) s=input() i=int(s[a-1]) j=int(s[b-1]) if (i-j==1 )or (i-j==-1): print("1") else: print("0")
Title: Vladik and flights Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the o...
```python n,a,b=map(int,input().split()) s=input() i=int(s[a-1]) j=int(s[b-1]) if (i-j==1 )or (i-j==-1): print("1") else: print("0") ```
3
659
A
Round House
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th...
The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*a*<=≀<=*n*,<=<=-<=100<=≀<=*b*<=≀<=100)Β β€” the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.
Print a single integer *k* (1<=≀<=*k*<=≀<=*n*)Β β€” the number of the entrance where Vasya will be at the end of his walk.
[ "6 2 -5\n", "5 1 3\n", "3 2 7\n" ]
[ "3\n", "4\n", "3\n" ]
The first example is illustrated by the picture in the statements.
500
[ { "input": "6 2 -5", "output": "3" }, { "input": "5 1 3", "output": "4" }, { "input": "3 2 7", "output": "3" }, { "input": "1 1 0", "output": "1" }, { "input": "1 1 -1", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "100 ...
1,647,898,142
2,147,483,647
PyPy 3-64
OK
TESTS
50
77
0
a,b,c=map(int,input().split()) print((b+c-1)%a+1)
Title: Round House Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e...
```python a,b,c=map(int,input().split()) print((b+c-1)%a+1) ```
3
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,612,294,295
2,147,483,647
Python 3
OK
TESTS
31
77
0
a,b=map(int,input().split()) c=list(map(int,input().split())) d=list(map(int,input().split())) e=[] for i in c: if i in d: e.append(i) for j in e: print(j,end=" ")
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python a,b=map(int,input().split()) c=list(map(int,input().split())) d=list(map(int,input().split())) e=[] for i in c: if i in d: e.append(i) for j in e: print(j,end=" ") ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,603,101,851
2,147,483,647
Python 3
OK
TESTS
40
218
0
# -*- coding: utf-8 -*- """ Created on Mon Oct 19 18:00:30 2020 @author: Lenovo """ s=list(input()) t=list(input()) s.reverse() if s==t: print('YES') else: print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python # -*- coding: utf-8 -*- """ Created on Mon Oct 19 18:00:30 2020 @author: Lenovo """ s=list(input()) t=list(input()) s.reverse() if s==t: print('YES') else: print('NO') ```
3.9455
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,589,373,922
2,147,483,647
PyPy 3
OK
TESTS
81
312
20,172,800
number_of_vector = int(input()) resx = resy = resz = 0 for _ in range(number_of_vector): x, y, z = input().split(" ") x, y, z = int(x), int(y), int(z) resx += x resy += y resz += z if resx == 0 and resy == 0 and resz == 0: 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 number_of_vector = int(input()) resx = resy = resz = 0 for _ in range(number_of_vector): x, y, z = input().split(" ") x, y, z = int(x), int(y), int(z) resx += x resy += y resz += z if resx == 0 and resy == 0 and resz == 0: print("YES") else: print("NO") ```
3.884425
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers β€” *n* and *m* (2<=≀<=*n*<=&lt;<=*m*<=≀<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≀<=*n*<=&lt;<=*m*<=≀<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,619,527,922
2,147,483,647
PyPy 3
OK
TESTS
45
466
9,728,000
#!/usr/bin/python3 import sys import argparse import json from pprint import pprint def main(): n, m = map(int, sys.stdin.readline().rstrip().split(" ")) ints = [0]*51 ints[1] = 1 for i in range(2, 51): for j in range(i*2,51, i): ints[j] = 1 if ints[m] == 1: print("NO...
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python #!/usr/bin/python3 import sys import argparse import json from pprint import pprint def main(): n, m = map(int, sys.stdin.readline().rstrip().split(" ")) ints = [0]*51 ints[1] = 1 for i in range(2, 51): for j in range(i*2,51, i): ints[j] = 1 if ints[m] == 1: ...
3.86538
976
B
Lara Croft and the New Game
PROGRAMMING
1,300
[ "implementation", "math" ]
null
null
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e...
The only line contains three integers *n*, *m* and *k* (2<=≀<=*n*,<=*m*<=≀<=109, *n* is always even, 0<=≀<=*k*<=&lt;<=*n*Β·*m*). Note that *k* doesn't fit into 32-bit integer type!
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves *k* times.
[ "4 3 0\n", "4 3 11\n", "4 3 7\n" ]
[ "1 1\n", "1 2\n", "3 2\n" ]
Here is her path on matrix 4 by 3:
0
[ { "input": "4 3 0", "output": "1 1" }, { "input": "4 3 11", "output": "1 2" }, { "input": "4 3 7", "output": "3 2" }, { "input": "1000000000 2 1999999999", "output": "1 2" }, { "input": "1000000000 1000000000 999999999999999999", "output": "1 2" }, { "...
1,525,544,558
2,147,483,647
Python 3
OK
TESTS
84
92
7,065,600
n, m, k = map(int, input().split()) if k <= n - 1: print(k + 1, 1) exit(0) k -= n m -= 1 l = k // m c = k % m if l % 2 == 1: c = m - 1 - c l = n - l print(l, c + 2)
Title: Lara Croft and the New Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil...
```python n, m, k = map(int, input().split()) if k <= n - 1: print(k + 1, 1) exit(0) k -= n m -= 1 l = k // m c = k % m if l % 2 == 1: c = m - 1 - c l = n - l print(l, c + 2) ```
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,690,542,925
2,147,483,647
Python 3
OK
TESTS
102
62
0
a = input() b = input() h = "" for i in range(len(b)): if a[i] == "1" and b[i] == "1": h += "0" elif a[i] == "1" or b[i] == "1": h += "1" else: h += "0" print(h)
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() h = "" for i in range(len(b)): if a[i] == "1" and b[i] == "1": h += "0" elif a[i] == "1" or b[i] == "1": h += "1" else: h += "0" print(h) ```
3.9845
604
A
Uncowed Forces
PROGRAMMING
1,000
[ "implementation" ]
null
null
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a...
The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=≀<=*m**i*<=≀<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted. The second line contains five space-separated integers *w*1, *w*2, *w*3, ...
Print a single integer, the value of Kevin's final score.
[ "20 40 60 80 100\n0 1 2 3 4\n1 0\n", "119 119 119 119 119\n0 0 0 0 0\n10 0\n" ]
[ "4900\n", "4930\n" ]
In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro...
500
[ { "input": "20 40 60 80 100\n0 1 2 3 4\n1 0", "output": "4900" }, { "input": "119 119 119 119 119\n0 0 0 0 0\n10 0", "output": "4930" }, { "input": "3 6 13 38 60\n6 10 10 3 8\n9 9", "output": "5088" }, { "input": "21 44 11 68 75\n6 2 4 8 4\n2 8", "output": "4522" }, {...
1,529,805,265
2,147,483,647
Python 3
OK
TESTS
57
93
0
times = [int(x) for x in input().split()] wrong = [int(x) for x in input().split()] hacks = [int(x) for x in input().split()] max_scores = [500, 1000, 1500, 2000, 2500] total = 0 for i in range(len(max_scores)): total += max(0.3 * max_scores[i], (1 - times[i]/250) * max_scores[i] - 50 * wrong[i]) total += ...
Title: Uncowed Forces Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin...
```python times = [int(x) for x in input().split()] wrong = [int(x) for x in input().split()] hacks = [int(x) for x in input().split()] max_scores = [500, 1000, 1500, 2000, 2500] total = 0 for i in range(len(max_scores)): total += max(0.3 * max_scores[i], (1 - times[i]/250) * max_scores[i] - 50 * wrong[i]) ...
3
681
B
Economy Game
PROGRAMMING
1,300
[ "brute force" ]
null
null
Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the beginning of the game his game-coin score was equal to *n* and that ...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=109)Β β€” Kolya's initial game-coin score.
Print "YES" (without quotes) if it's possible that Kolya spent all of his initial *n* coins buying only houses, cars and computers. Otherwise print "NO" (without quotes).
[ "1359257\n", "17851817\n" ]
[ "YES", "NO" ]
In the first sample, one of the possible solutions is to buy one house, one car and one computer, spending 1 234 567 + 123 456 + 1234 = 1 359 257 game-coins in total.
1,000
[ { "input": "1359257", "output": "YES" }, { "input": "17851817", "output": "NO" }, { "input": "1000000000", "output": "YES" }, { "input": "17851818", "output": "YES" }, { "input": "438734347", "output": "YES" }, { "input": "43873430", "output": "YES...
1,496,870,659
2,147,483,647
Python 3
OK
TESTS
63
61
0
# Description of the problem can be found at http://codeforces.com/problemset/problem/681/B n = int(input()) for i in range(0, n // 1234567 + 1): for j in range(0, (n - i * 1234567) // 123456 + 1): if ((n - i * 1234567) - j * 123456) % 1234 == 0: print("YES") quit() print(...
Title: Economy Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0....
```python # Description of the problem can be found at http://codeforces.com/problemset/problem/681/B n = int(input()) for i in range(0, n // 1234567 + 1): for j in range(0, (n - i * 1234567) // 123456 + 1): if ((n - i * 1234567) - j * 123456) % 1234 == 0: print("YES") quit...
3
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,481,261,618
2,147,483,647
Python 3
OK
TESTS
32
186
0
n = int(input()) a = [int(i) for i in input().split()] even = sum(i%2 for i in a) if even ==1: for i in range(n): if a[i]%2 ==1: print(i+1) else: for i in range(n): if a[i]%2 ==0: 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()) a = [int(i) for i in input().split()] even = sum(i%2 for i in a) if even ==1: for i in range(n): if a[i]%2 ==1: print(i+1) else: for i in range(n): if a[i]%2 ==0: print(i+1) ```
3.9535
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,659,029,578
2,147,483,647
PyPy 3-64
OK
TESTS
81
154
0
x = [] y = [] z = [] n = int(input()) for i in range(n): a, b, c = map(int, input().split()) x.append(a) y.append(b) z.append(c) if sum(x) == 0 and sum(y) == 0 and sum(z) == 0: print("YES") else: print("NO") ''' x, y, z = 0, 0, 0 n = int(input()) for _ in range(n): x, y, z += map(int, input(...
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 x = [] y = [] z = [] n = int(input()) for i in range(n): a, b, c = map(int, input().split()) x.append(a) y.append(b) z.append(c) if sum(x) == 0 and sum(y) == 0 and sum(z) == 0: print("YES") else: print("NO") ''' x, y, z = 0, 0, 0 n = int(input()) for _ in range(n): x, y, z += map(i...
3.9615
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,686,223,669
2,147,483,647
Python 3
OK
TESTS
44
92
0
x = list(input()) one = 1 zero = 1 for i in range(len(x)-1): if x[i] == x[i+1] == '1': one += 1 if one >= 7: print('YES') break elif x[i] == x[i+1] == '0': zero += 1 if zero >= 7: print('YES') break elif (x[i...
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 x = list(input()) one = 1 zero = 1 for i in range(len(x)-1): if x[i] == x[i+1] == '1': one += 1 if one >= 7: print('YES') break elif x[i] == x[i+1] == '0': zero += 1 if zero >= 7: print('YES') break ...
3.977
898
A
Rounding
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which int...
The first line contains single integer *n* (0<=≀<=*n*<=≀<=109)Β β€” number that Vasya has.
Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer.
[ "5\n", "113\n", "1000000000\n", "5432359\n" ]
[ "0\n", "110\n", "1000000000\n", "5432360\n" ]
In the first example *n* = 5. Nearest integers, that ends up with zero are 0 and 10. Any of these answers is correct, so you can print 0 or 10.
500
[ { "input": "5", "output": "0" }, { "input": "113", "output": "110" }, { "input": "1000000000", "output": "1000000000" }, { "input": "5432359", "output": "5432360" }, { "input": "999999994", "output": "999999990" }, { "input": "10", "output": "10" ...
1,662,730,065
2,147,483,647
PyPy 3-64
OK
TESTS
64
77
0
q=[int(input())] ans=-1 while ans==-1: a=q.pop(0) if a%10==0: ans=a else : q.append(a-1) q.append(a+1) print(ans)
Title: Rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5...
```python q=[int(input())] ans=-1 while ans==-1: a=q.pop(0) if a%10==0: ans=a else : q.append(a-1) q.append(a+1) print(ans) ```
3
250
D
Building Bridge
PROGRAMMING
1,900
[ "geometry", "ternary search", "two pointers" ]
null
null
Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be vertical straight lines *x*<==<=*a* and *x*<==<=*b* (0<=&lt;<=*a*<=&lt;<=*b*). The west village lies i...
The first line contains integers *n*, *m*, *a*, *b* (1<=≀<=*n*,<=*m*<=≀<=105, 0<=&lt;<=*a*<=&lt;<=*b*<=&lt;<=106). The second line contains *n* integers in the ascending order: the *i*-th integer determines the coordinate of point *A**i* and equals *y**i* (|*y**i*|<=≀<=106). The third line contains *m* integers in ...
Print two integers β€” the numbers of points on the left (west) and right (east) banks, respectively, between which you need to build a bridge. You can assume that the points on the west bank are numbered from 1 to *n*, in the order in which they are given in the input. Similarly, the points on the east bank are numbered...
[ "3 2 3 5\n-2 -1 4\n-1 2\n7 3\n" ]
[ "2 2" ]
none
1,500
[ { "input": "3 2 3 5\n-2 -1 4\n-1 2\n7 3", "output": "2 2" }, { "input": "1 1 10 20\n5\n-5\n1", "output": "1 1" }, { "input": "2 2 1 2\n-1 10\n8 9\n3 7", "output": "1 1" }, { "input": "10 20 50 60\n-96 -75 32 37 42 43 44 57 61 65\n-95 -90 -86 -79 -65 -62 -47 -11 -8 -6 1 8 23 2...
1,612,341,427
2,147,483,647
PyPy 3
OK
TESTS
33
794
14,745,600
import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= 0) and...
Title: Building Bridge Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two villages are separated by a river that flows from the north to the south. The villagers want to build a bridge across the river to make it easier to move across the villages. The river banks can be assumed to be ve...
```python import sys def pro(): return sys.stdin.readline().strip() def rop(): return map(int, pro().split()) def main(): s = list(rop()) a = list(rop()) q = list(rop()) o = list(rop()) p = -1 t = (1e100, -1, -1) for i in range(s[1]): while not((p == - 1 or s[2] * q[i] - s[3] * a[p] >= ...
3
677
A
Vanya and Fence
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ...
The first line of the input contains two integers *n* and *h* (1<=≀<=*n*<=≀<=1000, 1<=≀<=*h*<=≀<=1000)Β β€” the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=2*h*), the *i*-th of them is equal to the height of the *i*-th person.
Print a single integerΒ β€” the minimum possible valid width of the road.
[ "3 7\n4 5 14\n", "6 1\n1 1 1 1 1 1\n", "6 5\n7 6 8 9 10 5\n" ]
[ "4\n", "6\n", "11\n" ]
In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4. In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough. In the third sample, all the persons have to bend, except the last one. The required m...
500
[ { "input": "3 7\n4 5 14", "output": "4" }, { "input": "6 1\n1 1 1 1 1 1", "output": "6" }, { "input": "6 5\n7 6 8 9 10 5", "output": "11" }, { "input": "10 420\n214 614 297 675 82 740 174 23 255 15", "output": "13" }, { "input": "10 561\n657 23 1096 487 785 66 481...
1,692,882,873
2,147,483,647
Python 3
OK
TESTS
29
46
0
n,h=map(int,input().split()) l=list(map(int,input().split())) width=0 for i in l: if i>h: width+=2 else: width+=1 print(width)
Title: Vanya and Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers...
```python n,h=map(int,input().split()) l=list(map(int,input().split())) width=0 for i in l: if i>h: width+=2 else: width+=1 print(width) ```
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
The first line of the input contains a positive integer *n* (1<=≀<=*n*<=≀<=2Β·109) β€” the length of Pasha's stick.
The output should contain a single integerΒ β€” the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "4...
1,603,724,896
2,147,483,647
PyPy 3
OK
TESTS
76
140
0
n = int(input()) print((n // 2 - 1) // 2 if n % 2 == 0 else 0)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv...
```python n = int(input()) print((n // 2 - 1) // 2 if n % 2 == 0 else 0) ```
3
804
B
Minimum number of steps
PROGRAMMING
1,400
[ "combinatorics", "greedy", "implementation", "math" ]
null
null
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109<=+<...
The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.
Print the minimum number of steps modulo 109<=+<=7.
[ "ab\n", "aab\n" ]
[ "1\n", "3\n" ]
The first example: "ab"  →  "bba". The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".
1,000
[ { "input": "ab", "output": "1" }, { "input": "aab", "output": "3" }, { "input": "aaaaabaabababaaaaaba", "output": "17307" }, { "input": "abaabaaabbabaabab", "output": "1795" }, { "input": "abbaa", "output": "2" }, { "input": "abbaaabaabaaaaabbbbaababaa...
1,603,994,345
2,147,483,647
PyPy 3
OK
TESTS
32
685
8,089,600
x = input() def power(x, y, p) : res = 1 # Initialize result # Update x if it is more # than or equal to p x = x % p if (x == 0) : return 0 while (y > 0) : # If y is odd, multiply # x with result if ((y & 1) == ...
Title: Minimum number of steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substr...
```python x = input() def power(x, y, p) : res = 1 # Initialize result # Update x if it is more # than or equal to p x = x % p if (x == 0) : return 0 while (y > 0) : # If y is odd, multiply # x with result if ((...
3
723
A
The New Year: Meeting Friends
PROGRAMMING
800
[ "implementation", "math", "sortings" ]
null
null
There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they...
The first line of the input contains three distinct integers *x*1, *x*2 and *x*3 (1<=≀<=*x*1,<=*x*2,<=*x*3<=≀<=100)Β β€” the coordinates of the houses of the first, the second and the third friends respectively.
Print one integerΒ β€” the minimum total distance the friends need to travel in order to meet together.
[ "7 1 4\n", "30 20 10\n" ]
[ "6\n", "20\n" ]
In the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.
500
[ { "input": "7 1 4", "output": "6" }, { "input": "30 20 10", "output": "20" }, { "input": "1 4 100", "output": "99" }, { "input": "100 1 91", "output": "99" }, { "input": "1 45 100", "output": "99" }, { "input": "1 2 3", "output": "2" }, { "...
1,681,734,511
2,147,483,647
Python 3
OK
TESTS
48
61
0
p,q,r=input (). split () p=int(p) q=int(q) r=int(r) m=max(p,q,r) s=min(p,q,r) sum=m-s #if p!=m or p!=s: # sum=m-p + s-p #elif q!=m or q!=s: # sum=m-q + s-q #else: # sum=(m-r )+ (r-s) print (sum)
Title: The New Year: Meeting Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are three friend living on the straight line *Ox* in Lineland. The first friend lives at the point *x*1, the second friend lives at the point *x*2, and the third friend lives at the point *x*3. They ...
```python p,q,r=input (). split () p=int(p) q=int(q) r=int(r) m=max(p,q,r) s=min(p,q,r) sum=m-s #if p!=m or p!=s: # sum=m-p + s-p #elif q!=m or q!=s: # sum=m-q + s-q #else: # sum=(m-r )+ (r-s) print (sum) ```
3
47
B
Coins
PROGRAMMING
1,200
[ "implementation" ]
B. Coins
2
256
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul...
The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters Β«AΒ», Β«BΒ» and Β«CΒ». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter t...
It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters Β«AΒ», Β«BΒ» and Β«CΒ» which represent the coins in the increasing order of their weights.
[ "A&gt;B\nC&lt;B\nA&gt;C\n", "A&lt;B\nB&gt;C\nC&gt;A\n" ]
[ "CBA", "ACB" ]
none
1,000
[ { "input": "A>B\nC<B\nA>C", "output": "CBA" }, { "input": "A<B\nB>C\nC>A", "output": "ACB" }, { "input": "A<C\nB<A\nB>C", "output": "Impossible" }, { "input": "A<B\nA<C\nB>C", "output": "ACB" }, { "input": "B>A\nC<B\nC>A", "output": "ACB" }, { "input":...
1,647,368,795
2,147,483,647
Python 3
OK
TESTS
50
92
0
l=[] for x in range(3) : a=input() l.append(a) ac,bc,cc=0,0,0 lm=[] ll=[] for x in range(len(l)): if '>' in l[x] : lm.append(l[x][0]) ll.append(l[x][2]) if '<' in l[x] : lm.append(l[x][2]) ll.append(l[x][0]) for x in lm : if x=='A' : ac+=1...
Title: Coins Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ...
```python l=[] for x in range(3) : a=input() l.append(a) ac,bc,cc=0,0,0 lm=[] ll=[] for x in range(len(l)): if '>' in l[x] : lm.append(l[x][0]) ll.append(l[x][2]) if '<' in l[x] : lm.append(l[x][2]) ll.append(l[x][0]) for x in lm : if x=='A' : ...
3.977
139
A
Petr and Book
PROGRAMMING
1,000
[ "implementation" ]
null
null
One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. S...
The first input line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 β€” those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and...
Print a single number β€” the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
[ "100\n15 20 20 15 10 30 45\n", "2\n1 0 0 0 0 0 0\n" ]
[ "6\n", "1\n" ]
Note to the first sample: By the end of Monday and therefore, by the beginning of Tuesday Petr has 85 pages left. He has 65 pages left by Wednesday, 45 by Thursday, 30 by Friday, 20 by Saturday and on Saturday Petr finishes reading the book (and he also has time to read 10 pages of something else). Note to the second...
500
[ { "input": "100\n15 20 20 15 10 30 45", "output": "6" }, { "input": "2\n1 0 0 0 0 0 0", "output": "1" }, { "input": "100\n100 200 100 200 300 400 500", "output": "1" }, { "input": "3\n1 1 1 1 1 1 1", "output": "3" }, { "input": "1\n1 1 1 1 1 1 1", "output": "1...
1,597,853,741
2,147,483,647
PyPy 3
OK
TESTS
49
280
1,331,200
# pages = int(input()) # days = [int(d) for d in input().split(' ')] # for i in range(7100): # pages -= days[i % 7] # if pages <= 0: # print((i % 7) + 1) # break pages = int(input()) days = [int(d) for d in input().split(' ')] # first attempt summ = 0 current_day = 1 while Tr...
Title: Petr and Book Time Limit: None seconds Memory Limit: None megabytes Problem Description: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight s...
```python # pages = int(input()) # days = [int(d) for d in input().split(' ')] # for i in range(7100): # pages -= days[i % 7] # if pages <= 0: # print((i % 7) + 1) # break pages = int(input()) days = [int(d) for d in input().split(' ')] # first attempt summ = 0 current_day = ...
3
918
B
Radio Station
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o...
The first line of input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000). The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=≀<=|*name*|<=≀<=10, *name* only consists of English lowercase...
Print *m* lines, the commands in the configuration file after Dustin did his task.
[ "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n", "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n" ]
[ "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n", "redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n" ]
none
1,000
[ { "input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;", "output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main" }, { "input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3...
1,692,686,371
2,147,483,647
PyPy 3-64
OK
TESTS
28
140
5,836,800
n, m = map(int, input().split()) names = {} outputs = [] for i in range(n): k , v = map(str , input().split()) names[v] = k for i in range(m): com = input() outputs.append(com + ' #'+ names[com.split()[1].replace(';','')]) print(outputs[i])
Title: Radio Station Time Limit: None seconds Memory Limit: None megabytes Problem Description: As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ...
```python n, m = map(int, input().split()) names = {} outputs = [] for i in range(n): k , v = map(str , input().split()) names[v] = k for i in range(m): com = input() outputs.append(com + ' #'+ names[com.split()[1].replace(';','')]) print(outputs[i]) ```
3
6
B
President's Office
PROGRAMMING
1,100
[ "implementation" ]
B. President's Office
2
64
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ...
The first line contains two separated by a space integer numbers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the length and the width of the office-room, and *c* character β€” the President's desk colour. The following *n* lines contain *m* characters each β€” the office-room description. It is guaranteed that the colour of each ...
Print the only number β€” the amount of President's deputies.
[ "3 4 R\nG.B.\n.RR.\nTTT.\n", "3 3 Z\n...\n.H.\n..Z\n" ]
[ "2\n", "0\n" ]
none
0
[ { "input": "3 4 R\nG.B.\n.RR.\nTTT.", "output": "2" }, { "input": "3 3 Z\n...\n.H.\n..Z", "output": "0" }, { "input": "1 1 C\nC", "output": "0" }, { "input": "2 2 W\nKW\nKW", "output": "1" }, { "input": "1 10 H\n....DDHHHH", "output": "1" }, { "input":...
1,681,942,685
2,147,483,647
PyPy 3-64
OK
TESTS
32
108
14,438,400
import sys # UP, DOWN, LEFT, RIGHT MOVES = [(-1, 0), (1, 0), (0, -1), (0, 1)] def main() -> None: matrix = [] r = 0 try: sys.setrecursionlimit(10000) read = sys.stdin.readline rows, cols, val = read().split() rows = int(rows) cols = int(cols) ...
Title: President's Office Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ...
```python import sys # UP, DOWN, LEFT, RIGHT MOVES = [(-1, 0), (1, 0), (0, -1), (0, 1)] def main() -> None: matrix = [] r = 0 try: sys.setrecursionlimit(10000) read = sys.stdin.readline rows, cols, val = read().split() rows = int(rows) cols = int(co...
3.865426
151
A
Soft Drinking
PROGRAMMING
800
[ "implementation", "math" ]
null
null
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt. To make a toast, each frie...
The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space.
Print a single integer β€” the number of toasts each friend can make.
[ "3 4 5 10 8 100 3 1\n", "5 100 10 1 19 90 4 3\n", "10 1000 1000 25 23 1 50 1\n" ]
[ "2\n", "3\n", "0\n" ]
A comment to the first sample: Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2.
500
[ { "input": "3 4 5 10 8 100 3 1", "output": "2" }, { "input": "5 100 10 1 19 90 4 3", "output": "3" }, { "input": "10 1000 1000 25 23 1 50 1", "output": "0" }, { "input": "1 7 4 5 5 8 3 2", "output": "4" }, { "input": "2 3 3 5 5 10 1 3", "output": "1" }, { ...
1,686,386,779
2,147,483,647
PyPy 3-64
OK
TESTS
27
124
0
n, k, l, c, d, p, nl, np = map(int, input().split()) q = (k * l) // nl w = (c * d) e = (p // np) print (min(q, w, e) // n)
Title: Soft Drinking Time Limit: None seconds Memory Limit: None megabytes Problem Description: This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut...
```python n, k, l, c, d, p, nl, np = map(int, input().split()) q = (k * l) // nl w = (c * d) e = (p // np) print (min(q, w, e) // n) ```
3
835
A
Key races
PROGRAMMING
800
[ "math" ]
null
null
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *...
The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≀<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≀<=1000)Β β€” the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th...
If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship".
[ "5 1 2 1 2\n", "3 3 1 1 1\n", "4 5 3 1 5\n" ]
[ "First\n", "Second\n", "Friendship\n" ]
In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participantΒ β€” in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participantΒ β€” in 5 milliseconds. So, ...
500
[ { "input": "5 1 2 1 2", "output": "First" }, { "input": "3 3 1 1 1", "output": "Second" }, { "input": "4 5 3 1 5", "output": "Friendship" }, { "input": "1000 1000 1000 1000 1000", "output": "Friendship" }, { "input": "1 1 1 1 1", "output": "Friendship" }, ...
1,577,352,402
2,147,483,647
PyPy 3
OK
TESTS
32
140
0
x = [int(i) for i in input().split()] s = x[0] v1 = x[1] v2 = x[2] t1 = x[3] t2 = x[4] satu = 2 * t1 + v1 * s dua = 2 * t2 + v2 * s if satu < dua: print("First") elif dua < satu: print("Second") else: print("Friendship")
Title: Key races Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t...
```python x = [int(i) for i in input().split()] s = x[0] v1 = x[1] v2 = x[2] t1 = x[3] t2 = x[4] satu = 2 * t1 + v1 * s dua = 2 * t2 + v2 * s if satu < dua: print("First") elif dua < satu: print("Second") else: print("Friendship") ```
3
1,006
A
Adjacent Replacements
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occu...
The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the elements of the array.
Print $n$ integers β€” $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array.
[ "5\n1 2 4 5 10\n", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n" ]
[ "1 1 3 5 9\n", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n" ]
The first example is described in the problem statement.
0
[ { "input": "5\n1 2 4 5 10", "output": "1 1 3 5 9" }, { "input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999" }, { "input": "1\n999999999", "output": "999999999" }, { "input": "1\n1000000000",...
1,659,265,595
2,147,483,647
Python 3
OK
TESTS
18
46
0
n=int(input()) l=list(map(int,input().split())) m=[] for i in l: if i%2==0: m.append(i-1) else: m.append(i) for i in m: print(i,end=" ")
Title: Adjacent Replacements Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace...
```python n=int(input()) l=list(map(int,input().split())) m=[] for i in l: if i%2==0: m.append(i-1) else: m.append(i) for i in m: print(i,end=" ") ```
3
814
B
An express train to reveries
PROGRAMMING
1,300
[ "constructive algorithms" ]
null
null
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation *p*1,<=*p*2,<=...,<=*p**n* of intege...
The first line of input contains a positive integer *n* (2<=≀<=*n*<=≀<=1<=000) β€” the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the sequence of colours in the firs...
Output *n* space-separated integers *p*1,<=*p*2,<=...,<=*p**n*, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
[ "5\n1 2 3 4 3\n1 2 5 4 5\n", "5\n4 4 2 3 1\n5 4 5 3 1\n", "4\n1 1 3 4\n1 4 3 4\n" ]
[ "1 2 5 4 3\n", "5 4 2 3 1\n", "1 2 3 4\n" ]
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
1,000
[ { "input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3" }, { "input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1" }, { "input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4" }, { "input": "10\n1 2 3 4 7 6 7 8 9 10\n1 2 3 4 5 6 5 8 9 10", "output": "1 2 3 4 5 6 7 8 9...
1,597,760,682
1,482
PyPy 3
OK
TESTS
54
171
2,048,000
import sys input = sys.stdin.readline from collections import * n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 for i in range(n): if a[i]!=b[i]: cnt += 1 if cnt==1: ans = [-1]*n flag = [False]*(n+1) for i in range(n): ...
Title: An express train to reveries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her...
```python import sys input = sys.stdin.readline from collections import * n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) cnt = 0 for i in range(n): if a[i]!=b[i]: cnt += 1 if cnt==1: ans = [-1]*n flag = [False]*(n+1) for i in ran...
3
803
D
Magazine Ad
PROGRAMMING
1,900
[ "binary search", "greedy" ]
null
null
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
The first line contains number *k* (1<=≀<=*k*<=≀<=105). The second line contains the text of the ad β€” non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters.
Output minimal width of the ad.
[ "4\ngarage for sa-le\n", "4\nEdu-ca-tion-al Ro-unds are so fun\n" ]
[ "7\n", "10\n" ]
Here all spaces are replaced with dots. In the first example one of possible results after all word wraps looks like this: The second example:
0
[ { "input": "4\ngarage for sa-le", "output": "7" }, { "input": "4\nEdu-ca-tion-al Ro-unds are so fun", "output": "10" }, { "input": "1\nj", "output": "1" }, { "input": "10\nb", "output": "1" }, { "input": "1\nQGVsfZevMD", "output": "10" }, { "input": "1...
1,558,811,972
2,147,483,647
PyPy 3
OK
TESTS
30
467
51,712,000
#Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue #sys.stdin = open("input.txt", "r") MOD = 10**9+7 sys.setrecursionlimit(1000000) def ok(w): i = 0 c = 0 l = 0 while i < len(x): if c+x[i] <= w: c += x[i] i += 1 else: ...
Title: Magazine Ad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen...
```python #Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue #sys.stdin = open("input.txt", "r") MOD = 10**9+7 sys.setrecursionlimit(1000000) def ok(w): i = 0 c = 0 l = 0 while i < len(x): if c+x[i] <= w: c += x[i] i += 1 else...
3
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,640,923,694
2,147,483,647
PyPy 3-64
OK
TESTS
81
310
5,427,200
import math, sys, collections input = sys.stdin.readline istr = lambda: input().strip() inum = lambda: int(input().strip()) imap = lambda: map(int,input().strip().split()) ilist = lambda: list(map(int, input().strip().split())) try: matrix, sums = [], [0, 0, 0] T = inum() for i in range(T): ...
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 import math, sys, collections input = sys.stdin.readline istr = lambda: input().strip() inum = lambda: int(input().strip()) imap = lambda: map(int,input().strip().split()) ilist = lambda: list(map(int, input().strip().split())) try: matrix, sums = [], [0, 0, 0] T = inum() for i in ran...
3.912391
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,619,693,307
2,147,483,647
Python 3
OK
TESTS
30
124
0
a=input().strip() cu=0 cl=0 for i in a: if i.isupper(): cu+=1 else: cl+=1 if cu>cl: print(a.upper()) else: print(a.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python a=input().strip() cu=0 cl=0 for i in a: if i.isupper(): cu+=1 else: cl+=1 if cu>cl: print(a.upper()) else: print(a.lower()) ```
3.969
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,652,924,281
2,147,483,647
Python 3
OK
TESTS
40
92
4,300,800
s=input() t=input() k=[] for i in range(len(t)): k.append(t[len(t)-i-1]) n="".join(k) if n==s: print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s=input() t=input() k=[] for i in range(len(t)): k.append(t[len(t)-i-1]) n="".join(k) if n==s: print("YES") else: print("NO") ```
3.968989
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ...
The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the elements of array. The third line contains integer *m* (1<=≀<=*m*<=≀<=105) β€” the number of queries. The ...
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, o...
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4...
1,628,945,673
2,147,483,647
Python 3
OK
TESTS
34
372
16,588,800
def main_function(): n = int(input()) a = [int(i) for i in input().split(" ")] m = int(input()) b = [int(i) for i in input().split(" ")] hash = [0 for i in range(n + 10)] for i in range(n): hash[a[i]] = i + 1 #print(hash) vasya = 0 petya = 0 for j in b: ...
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c...
```python def main_function(): n = int(input()) a = [int(i) for i in input().split(" ")] m = int(input()) b = [int(i) for i in input().split(" ")] hash = [0 for i in range(n + 10)] for i in range(n): hash[a[i]] = i + 1 #print(hash) vasya = 0 petya = 0 for j...
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,601,134,252
2,147,483,647
Python 3
OK
TESTS
40
218
0
s = input() t = input() y = s[::-1] if t == y: print('YES') else: print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s = input() t = input() y = s[::-1] if t == y: print('YES') else: print('NO') ```
3.9455
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ...
The only line contains two integers: *n* and *m* (3<=≀<=*n*,<=*m*<=≀<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#...
1,674,322,948
2,147,483,647
PyPy 3-64
OK
TESTS
28
62
0
n,k = map(int,input().split()) check = True a = True while(n): if(check): print("#"*k) check=False else: if(a):print("."*(k-1)+"#");a=False; else:print("#"+"."*(k-1));a=True; check=True n-=1
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*...
```python n,k = map(int,input().split()) check = True a = True while(n): if(check): print("#"*k) check=False else: if(a):print("."*(k-1)+"#");a=False; else:print("#"+"."*(k-1));a=True; check=True n-=1 ```
3
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
The first line contains the only integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the number of cookies in the *i*-th bag.
Print in the only line the only number β€” the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β€” 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, t...
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,563,277,614
2,147,483,647
Python 3
OK
TESTS
52
218
0
n, a = int(input()), list(map(lambda x: int(x) % 2, input().split(" "))) c = a.count(1) if c % 2 == 1: print(c) else: print(n-c)
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan...
```python n, a = int(input()), list(map(lambda x: int(x) % 2, input().split(" "))) c = a.count(1) if c % 2 == 1: print(c) else: print(n-c) ```
3
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≀<=|*s*|<=≀<=50). The second line contains the string *t* (1<=≀<=|*t*|<=≀<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,660,444,749
2,147,483,647
PyPy 3-64
OK
TESTS
19
92
0
stones = list(input()) instructions = list(input()) p = 1 for i in instructions: if stones[p - 1] == i: p += 1 print(p)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python stones = list(input()) instructions = list(input()) p = 1 for i in instructions: if stones[p - 1] == i: p += 1 print(p) ```
3
586
A
Alena's Schedule
PROGRAMMING
900
[ "implementation" ]
null
null
Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes). The University works in such a way that every day it...
The first line of the input contains a positive integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of lessons at the university. The second line contains *n* numbers *a**i* (0<=≀<=*a**i*<=≀<=1). Number *a**i* equals 0, if Alena doesn't have the *i*-th pairs, otherwise it is equal to 1. Numbers *a*1,<=*a*2,<=...,<=*a**n* ar...
Print a single number β€” the number of pairs during which Alena stays at the university.
[ "5\n0 1 0 1 1\n", "7\n1 0 1 0 0 1 0\n", "1\n0\n" ]
[ "4\n", "4\n", "0\n" ]
In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home.
500
[ { "input": "5\n0 1 0 1 1", "output": "4" }, { "input": "7\n1 0 1 0 0 1 0", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 0", "output": "0" }, { "input": "2\n0 1", "output": "1" }, { ...
1,587,740,121
2,147,483,647
PyPy 3
OK
TESTS
60
155
0
n=int(input()) l=list(map(int,input().split())) c=0 for i in range(n-2): if(l[i]==1 and l[i+1]==0 and l[i+2]==1): c=c+1 print(c+l.count(1))
Title: Alena's Schedule Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alena has successfully passed the entrance exams to the university and is now looking forward to start studying. One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic ...
```python n=int(input()) l=list(map(int,input().split())) c=0 for i in range(n-2): if(l[i]==1 and l[i+1]==0 and l[i+2]==1): c=c+1 print(c+l.count(1)) ```
3
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=108). The second line contains a single integer *m* (1<=≀<=*m*<=≀<=108).
Output a single integerΒ β€” the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,660,981,021
2,147,483,647
Python 3
OK
TESTS
49
46
0
a=int(input()) if a>30:print(input()) else:print(int(input())%(2**a))
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" prob...
```python a=int(input()) if a>30:print(input()) else:print(int(input())%(2**a)) ```
3
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,678,591,584
2,147,483,647
Python 3
OK
TESTS
44
92
0
s = input() def isDangerous(): count = 1 for i in range(1, len(s)): prev = s[i - 1] curr = s[i] if prev == curr: count += 1 else: count = 1 if count == 7: print("YES") return print("NO") isDangerous() ...
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 s = input() def isDangerous(): count = 1 for i in range(1, len(s)): prev = s[i - 1] curr = s[i] if prev == curr: count += 1 else: count = 1 if count == 7: print("YES") return print("NO") isDangerous() ...
3.977
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,529,209,224
624
Python 3
OK
TESTS
31
92
0
import math if __name__=="__main__": n,m=input().strip().split(' ') n,m=[int(n),int(m)] c=list(map(int,input().strip().split(' '))) d=list(map(int,input().strip().split(' '))) for x in range(0,len(c)): if c[x] not in d: c[x]=-1 for x in range(0,len(c)): if c...
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python import math if __name__=="__main__": n,m=input().strip().split(' ') n,m=[int(n),int(m)] c=list(map(int,input().strip().split(' '))) d=list(map(int,input().strip().split(' '))) for x in range(0,len(c)): if c[x] not in d: c[x]=-1 for x in range(0,len(c)): ...
3
1,006
A
Adjacent Replacements
PROGRAMMING
800
[ "implementation" ]
null
null
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occu...
The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the elements of the array.
Print $n$ integers β€” $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array.
[ "5\n1 2 4 5 10\n", "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n" ]
[ "1 1 3 5 9\n", "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n" ]
The first example is described in the problem statement.
0
[ { "input": "5\n1 2 4 5 10", "output": "1 1 3 5 9" }, { "input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999" }, { "input": "1\n999999999", "output": "999999999" }, { "input": "1\n1000000000",...
1,622,179,751
1,751
Python 3
OK
TESTS
18
77
204,800
# cook your dish here # from math import factorial, ceil, pow, sqrt, floor, gcd from sys import stdin, stdout from collections import defaultdict, Counter, deque from bisect import bisect_left, bisect_right # import sympy # from itertools import permutations # import numpy as np # n = int(stdin....
Title: Adjacent Replacements Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace...
```python # cook your dish here # from math import factorial, ceil, pow, sqrt, floor, gcd from sys import stdin, stdout from collections import defaultdict, Counter, deque from bisect import bisect_left, bisect_right # import sympy # from itertools import permutations # import numpy as np # n = ...
3
816
A
Karen and Morning
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palin...
The first and only line of input contains a single string in the format hh:mm (00<=≀<= hh <=≀<=23, 00<=≀<= mm <=≀<=59).
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
[ "05:39\n", "13:31\n", "23:59\n" ]
[ "11\n", "0\n", "1\n" ]
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome. In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome. In the third test case, the minimum number of minutes Karen should s...
500
[ { "input": "05:39", "output": "11" }, { "input": "13:31", "output": "0" }, { "input": "23:59", "output": "1" }, { "input": "13:32", "output": "69" }, { "input": "14:40", "output": "1" }, { "input": "14:00", "output": "41" }, { "input": "05:...
1,666,646,827
2,147,483,647
Python 3
OK
TESTS
160
46
0
current_time=str(input()) hour=int(current_time[0:2]) minute=int(current_time[3:]) counter=0 dosao_je_tren=False while dosao_je_tren != True: a=str(str(hour)+str(minute)) if hour<10: a=str("0"+str(hour)+str(minute)) if minute<10: a=str(str(hour)+"0"+str(minute)) if hour<10 and...
Title: Karen and Morning Time Limit: None seconds Memory Limit: None megabytes Problem Description: Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. Wh...
```python current_time=str(input()) hour=int(current_time[0:2]) minute=int(current_time[3:]) counter=0 dosao_je_tren=False while dosao_je_tren != True: a=str(str(hour)+str(minute)) if hour<10: a=str("0"+str(hour)+str(minute)) if minute<10: a=str(str(hour)+"0"+str(minute)) if h...
3