contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
14
A
Letter
PROGRAMMING
800
[ "implementation" ]
A. Letter
1
64
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w...
The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that ...
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
[ "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n", "3 3\n***\n*.*\n***\n" ]
[ "***\n*..\n***\n*..\n***\n", "***\n*.*\n***\n" ]
none
0
[ { "input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "output": "***\n*..\n***\n*..\n***" }, { "input": "3 3\n***\n*.*\n***", "output": "***\n*.*\n***" }, { "input": "1 1\n*", "output": "*" }, { "input": "2 1\n*\n*", "output": "*\n*" }, { "input"...
1,596,430,229
2,147,483,647
Python 3
OK
TESTS
30
218
6,963,200
def q14a(): n, m = tuple([int(num) for num in input().split()]) rows_of_array = [] for i in range(n): temp_str = input() rows_of_array.append(temp_str) rows_of_array = q14a_cut(rows_of_array) rows_of_array.reverse() rows_of_array = q14a_cut(rows_of_array) rows_of_array.reverse() transposed = ["".join(list(t...
Title: Letter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe...
```python def q14a(): n, m = tuple([int(num) for num in input().split()]) rows_of_array = [] for i in range(n): temp_str = input() rows_of_array.append(temp_str) rows_of_array = q14a_cut(rows_of_array) rows_of_array.reverse() rows_of_array = q14a_cut(rows_of_array) rows_of_array.reverse() transposed = ["".j...
3.83912
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next ite...
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "i...
1,627,649,195
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
33,587,200
from bisect import * n, k = map(int, input().split()) s = input() mas = sorted([ord(s[i]) for i in range(len(s))]) def f(s,mas, key): w = bisect_left(mas, ord(key)) if w == len(mas): return None else: q = s.find(key) del mas[w] s = s[:q] + '' + s[q + 1:] ...
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is...
```python from bisect import * n, k = map(int, input().split()) s = input() mas = sorted([ord(s[i]) for i in range(len(s))]) def f(s,mas, key): w = bisect_left(mas, ord(key)) if w == len(mas): return None else: q = s.find(key) del mas[w] s = s[:q] + '' + s[q + ...
0
158
A
Next Round
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate...
The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence...
Output the number of participants who advance to the next round.
[ "8 5\n10 9 8 7 7 7 5 5\n", "4 2\n0 0 0 0\n" ]
[ "6\n", "0\n" ]
In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
500
[ { "input": "8 5\n10 9 8 7 7 7 5 5", "output": "6" }, { "input": "4 2\n0 0 0 0", "output": "0" }, { "input": "5 1\n1 1 1 1 1", "output": "5" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "1 1\n10", "output": "1" }, { "input": "17 14\n16 15...
1,696,814,391
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
62
0
n, k = map(int, input().split()) x = input().split() y = int(x[k-1]) if (y > 0): i = k while (int(x[i]) == y): k+=1 i+=1 print(k) else: print(x.index("0"))
Title: Next Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of *n* p...
```python n, k = map(int, input().split()) x = input().split() y = int(x[k-1]) if (y > 0): i = k while (int(x[i]) == y): k+=1 i+=1 print(k) else: print(x.index("0")) ```
-1
760
B
Frodo and pillows
PROGRAMMING
1,500
[ "binary search", "greedy" ]
null
null
*n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as many pillows as possible. Of course, it's not always possible to share pillows equally, but any hobbit ge...
The only line contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=*m*<=≤<=109, 1<=≤<=*k*<=≤<=*n*) — the number of hobbits, the number of pillows and the number of Frodo's bed.
Print single integer — the maximum number of pillows Frodo can have so that no one is hurt.
[ "4 6 2\n", "3 10 3\n", "3 6 1\n" ]
[ "2\n", "4\n", "3\n" ]
In the first example Frodo can have at most two pillows. In this case, he can give two pillows to the hobbit on the first bed, and one pillow to each of the hobbits on the third and the fourth beds. In the second example Frodo can take at most four pillows, giving three pillows to each of the others. In the third exa...
1,000
[ { "input": "4 6 2", "output": "2" }, { "input": "3 10 3", "output": "4" }, { "input": "3 6 1", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "1 1 1", "output": "1" }, { "input": "1 1000000000 1", "output": "1000000000" }, { ...
1,486,300,365
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
4,608,000
s = [int(x) for x in input().split()] n = s[0] m = s[1] k = s[2] if n == m: print(1) else: c = (m//n)+1 print(c)
Title: Frodo and pillows Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* hobbits are planning to spend the night at Frodo's house. Frodo has *n* beds standing in a row and *m* pillows (*n*<=≤<=*m*). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants as ma...
```python s = [int(x) for x in input().split()] n = s[0] m = s[1] k = s[2] if n == m: print(1) else: c = (m//n)+1 print(c) ```
0
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "64009798...
1,651,102,326
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
def main(): l, r = map(int, input().split()) if l == int(1): l += 1 if 2 * l > r : print(-1) return a = l; b = 2 * l - 1; c = 2 * l print(a, b, c) if __name__ == '__main__': main()
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different st...
```python def main(): l, r = map(int, input().split()) if l == int(1): l += 1 if 2 * l > r : print(-1) return a = l; b = 2 * l - 1; c = 2 * l print(a, b, c) if __name__ == '__main__': main() ```
0
985
B
Switches and Lamps
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*...
The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guar...
Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch.
[ "4 5\n10101\n01000\n00111\n10000\n", "4 5\n10100\n01000\n00110\n00101\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "4 5\n10101\n01000\n00111\n10000", "output": "YES" }, { "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO" }, { "input": "1 5\n11111", "output": "NO" }, { "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES" }, { "input": "1 1\n1", ...
1,585,813,712
4,712
Python 3
WRONG_ANSWER
TESTS
11
1,715
17,612,800
n,m = map(int,input().split()) lis=[] for i in range(n): l = list(input()) lis.append(l) lam=[0]*m for i in range(n): c=0 for j in range(m): if lis[i][j]=='1' and lam[j]==0: c=1 if lis[i][j]=='1': lam[j]=1 # print(lam) if c==0: ...
Title: Switches and Lamps Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th...
```python n,m = map(int,input().split()) lis=[] for i in range(n): l = list(input()) lis.append(l) lam=[0]*m for i in range(n): c=0 for j in range(m): if lis[i][j]=='1' and lam[j]==0: c=1 if lis[i][j]=='1': lam[j]=1 # print(lam) if c==...
0
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,569,595,638
2,147,483,647
Python 3
OK
TESTS
40
248
0
ber=input() ber=list(ber) bir=input() bir=list(bir) n=len(ber) transber=[] for i in range(n): transber.append(ber[n-1-i]) if transber==bir: 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 ber=input() ber=list(ber) bir=input() bir=list(bir) n=len(ber) transber=[] for i in range(n): transber.append(ber[n-1-i]) if transber==bir: print('YES') else: print('NO') ```
3.938
689
A
Mike and Cellphone
PROGRAMMING
1,400
[ "brute force", "constructive algorithms", "implementation" ]
null
null
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and ...
The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in.
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line.
[ "3\n586\n", "2\n09\n", "9\n123456789\n", "3\n911\n" ]
[ "NO\n", "NO\n", "YES\n", "YES\n" ]
You can find the picture clarifying the first sample case in the statement above.
500
[ { "input": "3\n586", "output": "NO" }, { "input": "2\n09", "output": "NO" }, { "input": "9\n123456789", "output": "YES" }, { "input": "3\n911", "output": "YES" }, { "input": "3\n089", "output": "NO" }, { "input": "3\n159", "output": "YES" }, { ...
1,659,894,453
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
n = int(raw_input()) s = raw_input() a = [] for i in range(10): a.append(True) for i in range(n): c = int(s[i]) a[c] = False inc = 0 if a[1] and a[2] and a[3]: inc = -3 if a[7] and a[9] and a[0]: inc = +3 if a[1] and a[4] and a[7] and a[0]: inc = -1 if a[3] and a[6] and a[9] and a[0]: inc = +1 i...
Title: Mike and Cellphone Time Limit: None seconds Memory Limit: None megabytes Problem Description: While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equ...
```python n = int(raw_input()) s = raw_input() a = [] for i in range(10): a.append(True) for i in range(n): c = int(s[i]) a[c] = False inc = 0 if a[1] and a[2] and a[3]: inc = -3 if a[7] and a[9] and a[0]: inc = +3 if a[1] and a[4] and a[7] and a[0]: inc = -1 if a[3] and a[6] and a[9] and a[0]: i...
-1
437
B
The Child and Set
PROGRAMMING
1,500
[ "bitmasks", "greedy", "implementation", "sortings" ]
null
null
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set *S*: - its elements were distinct integers from 1 to *limit*; - the value of wa...
The first line contains two integers: *sum*,<=*limit* (1<=≤<=*sum*,<=*limit*<=≤<=105).
In the first line print an integer *n* (1<=≤<=*n*<=≤<=105), denoting the size of *S*. Then print the elements of set *S* in any order. If there are multiple answers, print any of them. If it's impossible to find a suitable set, print -1.
[ "5 5\n", "4 3\n", "5 1\n" ]
[ "2\n4 5\n", "3\n2 3 1\n", "-1\n" ]
In sample test 1: *lowbit*(4) = 4, *lowbit*(5) = 1, 4 + 1 = 5. In sample test 2: *lowbit*(1) = 1, *lowbit*(2) = 2, *lowbit*(3) = 1, 1 + 2 + 1 = 4.
1,500
[ { "input": "5 5", "output": "2\n4 5" }, { "input": "4 3", "output": "3\n2 3 1" }, { "input": "5 1", "output": "-1" }, { "input": "54321 12345", "output": "7008\n8958 8925 11009 10808 8221 9771 11269 7017 6416 11723 10324 5654 6569 10454 9164 10754 6069 7913 12154 11111 73...
1,662,309,606
2,147,483,647
PyPy 3-64
OK
TESTS
33
171
7,987,200
import sys input = sys.stdin.readline s, l = map(int, input().split()) d = [] f = 0 for i in range(1, l+1): x = i c = 1 while 1: if i & 1: d.append((c, x)) f += c break c *= 2 i >>= 1 if i == 0: d.append((c, ...
Title: The Child and Set Time Limit: None seconds Memory Limit: None megabytes Problem Description: At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers some...
```python import sys input = sys.stdin.readline s, l = map(int, input().split()) d = [] f = 0 for i in range(1, l+1): x = i c = 1 while 1: if i & 1: d.append((c, x)) f += c break c *= 2 i >>= 1 if i == 0: d.a...
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,688,128,838
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
92
0
n= input() c=0 while len(n)!=1: k=0 while int(n)//10 !=0: k+=int(n)%10 n=str(int(n)//10) c+=1 k+=int(n)%10 n= str(k) print(n) print(c)
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 n= input() c=0 while len(n)!=1: k=0 while int(n)//10 !=0: k+=int(n)%10 n=str(int(n)//10) c+=1 k+=int(n)%10 n= str(k) print(n) print(c) ```
0
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,519,513,715
2,147,483,647
Python 3
OK
TESTS
14
62
5,632,000
n = int(input()) a = list(map(int, input().split())) num = 0 for i in range(1, n - 1): if (a[i - 1] < a[i] and a[i] > a[i + 1]) or (a[i - 1] > a[i] and a[i] < a[i + 1]): num += 1 print(num)
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()) a = list(map(int, input().split())) num = 0 for i in range(1, n - 1): if (a[i - 1] < a[i] and a[i] > a[i + 1]) or (a[i - 1] > a[i] and a[i] < a[i + 1]): num += 1 print(num) ```
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,681,924,755
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n,m,v=map(int,input().split()) n=(n//v)*(m//v) print(n)
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,v=map(int,input().split()) n=(n//v)*(m//v) print(n) ```
0
12
C
Fruits
PROGRAMMING
1,100
[ "greedy", "implementation", "sortings" ]
C. Fruits
1
256
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of A...
The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of t...
Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
[ "5 3\n4 2 1 10 5\napple\norange\nmango\n", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n" ]
[ "7 19\n", "11 30\n" ]
none
0
[ { "input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19" }, { "input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30" }, { "input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl", "output": "173 173" }, { "input"...
1,619,464,774
2,147,483,647
PyPy 3
OK
TESTS
25
124
1,228,800
n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[] for i in range(m): c=input() for j in b: if j[1]==c: j[0]+=1 break else: b.append([1,c]) b.sort() b=b[::-1] d=0 e=0 a.sort() for i in range(len(b)): d+=b[i][0]*a[i] e+=b...
Title: Fruits Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some ...
```python n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[] for i in range(m): c=input() for j in b: if j[1]==c: j[0]+=1 break else: b.append([1,c]) b.sort() b=b[::-1] d=0 e=0 a.sort() for i in range(len(b)): d+=b[i][0]*a[i]...
3.935711
765
C
Table Tennis Game 2
PROGRAMMING
1,200
[ "math" ]
null
null
Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly *k* points, the score is reset and a new set begins. Across all the sets Misha scored *a* poi...
The first line contains three space-separated integers *k*, *a* and *b* (1<=≤<=*k*<=≤<=109, 0<=≤<=*a*,<=*b*<=≤<=109, *a*<=+<=*b*<=&gt;<=0).
If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.
[ "11 11 5\n", "11 2 3\n" ]
[ "1\n", "-1\n" ]
Note that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.
1,250
[ { "input": "11 11 5", "output": "1" }, { "input": "11 2 3", "output": "-1" }, { "input": "1 5 9", "output": "14" }, { "input": "2 3 3", "output": "2" }, { "input": "1 1000000000 1000000000", "output": "2000000000" }, { "input": "2 3 5", "output": "...
1,487,086,904
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
k, a, b = map(int, input().split()) if a < b: a, b = b, a if a < k || (a%k != 0 && b < k): print("NO") else print("YES")
Title: Table Tennis Game 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scor...
```python k, a, b = map(int, input().split()) if a < b: a, b = b, a if a < k || (a%k != 0 && b < k): print("NO") else print("YES") ```
-1
489
C
Given Length and Sum of Digits...
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should be non-negative integers written in the decimal base without leading zeroes.
The single line of the input contains a pair of integers *m*, *s* (1<=≤<=*m*<=≤<=100,<=0<=≤<=*s*<=≤<=900) — the length and the sum of the digits of the required numbers.
In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).
[ "2 15\n", "3 0\n" ]
[ "69 96\n", "-1 -1\n" ]
none
1,500
[ { "input": "2 15", "output": "69 96" }, { "input": "3 0", "output": "-1 -1" }, { "input": "2 1", "output": "10 10" }, { "input": "3 10", "output": "109 910" }, { "input": "100 100", "output": "1000000000000000000000000000000000000000000000000000000000000000000...
1,681,909,722
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
31
0
m, s = map(int, input().split()); print( "-1, -1" if (s>9*m or (s<1 and m!=1)) else f"{int(10**(m-1)+((s-1)%9+1)*10**((s-1)//9)-1)} {10**m-10**(m-(s-1)//9-1)*(9-(s-1)%9)}" )
Title: Given Length and Sum of Digits... Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a positive integer *m* and a non-negative integer *s*. Your task is to find the smallest and the largest of the numbers that have length *m* and sum of digits *s*. The required numbers should ...
```python m, s = map(int, input().split()); print( "-1, -1" if (s>9*m or (s<1 and m!=1)) else f"{int(10**(m-1)+((s-1)%9+1)*10**((s-1)//9)-1)} {10**m-10**(m-(s-1)//9-1)*(9-(s-1)%9)}" ) ```
0
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,689,096,220
2,147,483,647
Python 3
OK
TESTS
27
46
0
n=int(input()) ans=0 for i in range(n): p,q=input().split() p=int(p) q=int(q) if (q-p) >= 2: ans += 1 print(ans)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python n=int(input()) ans=0 for i in range(n): p,q=input().split() p=int(p) q=int(q) if (q-p) >= 2: ans += 1 print(ans) ```
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,580,913,337
2,147,483,647
Python 3
OK
TESTS
37
124
0
u=int(input()) g=1 r='' for i in range(1,u+1): r=r+str(i) print(r[u-1])
Title: Summer Camp Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems. This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1...
```python u=int(input()) g=1 r='' for i in range(1,u+1): r=r+str(i) print(r[u-1]) ```
3
257
A
Sockets
PROGRAMMING
1,100
[ "greedy", "implementation", "sortings" ]
null
null
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets. Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —...
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
[ "3 5 3\n3 1 2\n", "4 7 2\n3 3 2 4\n", "5 5 1\n1 3 1 2 1\n" ]
[ "1\n", "2\n", "-1\n" ]
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices. One of the optimal ways in the second test sample is to ...
500
[ { "input": "3 5 3\n3 1 2", "output": "1" }, { "input": "4 7 2\n3 3 2 4", "output": "2" }, { "input": "5 5 1\n1 3 1 2 1", "output": "-1" }, { "input": "4 5 8\n3 2 4 3", "output": "0" }, { "input": "5 10 1\n4 3 4 2 4", "output": "3" }, { "input": "7 13 2...
1,689,425,970
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1689425970.2198203")# 1689425970.2198377
Title: Sockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets. Overall Vasya has got *m* devices and *k* electrical sockets in his f...
```python print("_RANDOM_GUESS_1689425970.2198203")# 1689425970.2198377 ```
0
939
E
Maximize!
PROGRAMMING
1,800
[ "binary search", "greedy", "ternary search", "two pointers" ]
null
null
You are given a multiset *S* consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to *S*, the newly added integer is not less than any number in it. 1. Find a subset *s* of the set *S* such that the value is maximum possible. Here *max*(*s*) means maximum valu...
The first line contains a single integer *Q* (1<=≤<=*Q*<=≤<=5·105) — the number of queries. Each of the next *Q* lines contains a description of query. For queries of type 1 two integers 1 and *x* are given, where *x* (1<=≤<=*x*<=≤<=109) is a number that you should add to *S*. It's guaranteed that *x* is not less than...
Output the answer for each query of the second type in the order these queries are given in input. Each number should be printed in separate line. Your answer is considered correct, if each of your answers has absolute or relative error not greater than 10<=-<=6. Formally, let your answer be *a*, and the jury's answe...
[ "6\n1 3\n2\n1 4\n2\n1 8\n2\n", "4\n1 1\n1 4\n1 5\n2\n" ]
[ "0.0000000000\n0.5000000000\n3.0000000000\n", "2.0000000000\n" ]
none
2,500
[ { "input": "6\n1 3\n2\n1 4\n2\n1 8\n2", "output": "0.0000000000\n0.5000000000\n3.0000000000" }, { "input": "4\n1 1\n1 4\n1 5\n2", "output": "2.0000000000" }, { "input": "8\n1 7\n1 26\n1 40\n1 45\n1 64\n2\n1 88\n1 94", "output": "31.6666666667" }, { "input": "9\n1 35\n2\n2\n1 ...
1,654,953,295
2,147,483,647
Python 3
OK
TESTS
30
1,980
59,596,800
import sys sys.setrecursionlimit(2 * 10 ** 6) def test(): # print(solve([1, 4, 5], [0, 1, 5, 10])) pass def main(): ops = [] n = int(input()) for _ in range(n): t = input() if t == '2': ops.append([2, 0]) else: ops.append(list(map(int, t.split()))...
Title: Maximize! Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a multiset *S* consisting of positive integers (initially empty). There are two kind of queries: 1. Add a positive integer to *S*, the newly added integer is not less than any number in it. 1. Find a subset ...
```python import sys sys.setrecursionlimit(2 * 10 ** 6) def test(): # print(solve([1, 4, 5], [0, 1, 5, 10])) pass def main(): ops = [] n = int(input()) for _ in range(n): t = input() if t == '2': ops.append([2, 0]) else: ops.append(list(map(int, t...
3
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider t...
Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling t...
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { ...
1,591,164,687
2,147,483,647
PyPy 3
OK
TESTS
45
468
10,752,000
n = int(input()) l = list(map(int,input().split())) mi = min(l) if l.count(mi)==1: print(l.index(mi)+1) else: print("Still Rozdil")
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha...
```python n = int(input()) l = list(map(int,input().split())) mi = min(l) if l.count(mi)==1: print(l.index(mi)+1) else: print("Still Rozdil") ```
3
606
A
Magic Spheres
PROGRAMMING
1,200
[ "implementation" ]
null
null
Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible,...
The first line of the input contains three integers *a*, *b* and *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=1<=000<=000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=1<=000<=000) — the number o...
If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No".
[ "4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n" ]
[ "Yes\n", "No\n", "Yes\n" ]
In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what...
500
[ { "input": "4 4 0\n2 1 2", "output": "Yes" }, { "input": "5 6 1\n2 7 2", "output": "No" }, { "input": "3 3 3\n2 2 2", "output": "Yes" }, { "input": "0 0 0\n0 0 0", "output": "Yes" }, { "input": "0 0 0\n0 0 1", "output": "No" }, { "input": "0 1 0\n0 0 0...
1,595,681,013
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
108
6,656,000
ini = list(map(int, input().split())) fin = list(map(int, input().split())) ext = 0 les = 0 for i, j in zip(ini, fin): if i >= j: ext += i-j else: les += j-i if ext >= 2 * les: print("Yes") else: print("No")
Title: Magic Spheres Time Limit: None seconds Memory Limit: None megabytes Problem Description: Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been see...
```python ini = list(map(int, input().split())) fin = list(map(int, input().split())) ext = 0 les = 0 for i, j in zip(ini, fin): if i >= j: ext += i-j else: les += j-i if ext >= 2 * les: print("Yes") else: print("No") ```
0
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,697,410,219
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
sum = 0 ls = [] for i in range(4): add = int(input()) ls.append(add) num = int(input()) for i in range(1,num+1): for j in range(4): if num % ls[j] == 0: sum += 1 break print(sum)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python sum = 0 ls = [] for i in range(4): add = int(input()) ls.append(add) num = int(input()) for i in range(1,num+1): for j in range(4): if num % ls[j] == 0: sum += 1 break print(sum) ```
0
118
B
Present from Lena
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to *n* as the pattern. The digits will form a rhombus. The largest digit *n* should be located in the centre. The digits should decrease as they approach the edges. For example, for *n*<==<=5 t...
The first line contains the single integer *n* (2<=≤<=*n*<=≤<=9).
Print a picture for the given *n*. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.
[ "2\n", "3\n" ]
[ "0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0\n", "0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0\n" ]
none
1,000
[ { "input": "2", "output": " 0\n 0 1 0\n0 1 2 1 0\n 0 1 0\n 0" }, { "input": "3", "output": " 0\n 0 1 0\n 0 1 2 1 0\n0 1 2 3 2 1 0\n 0 1 2 1 0\n 0 1 0\n 0" }, { "input": "4", "output": " 0\n 0 1 0\n 0 1 2 1 0\n 0 1 2 3 2 1 0\n0 1 2 3 4 3 2 1 0...
1,696,247,976
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
# 118/B n = int(input()) for i in range(n+1): print(" " * (n - i) + " ".join(map(str, range(i+1))) + " " + " ".join(map(str, range(i-1, -1, -1)))) for i in range(n-1, -1, -1): print(" " * (n - i) + " ".join(map(str, range(i+1))) + " " + " ".join(map(str, range(i-1, -1, -1))))
Title: Present from Lena Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to *n* as the pattern. The digits will form a rhombus. The largest digit *n* should be loc...
```python # 118/B n = int(input()) for i in range(n+1): print(" " * (n - i) + " ".join(map(str, range(i+1))) + " " + " ".join(map(str, range(i-1, -1, -1)))) for i in range(n-1, -1, -1): print(" " * (n - i) + " ".join(map(str, range(i+1))) + " " + " ".join(map(str, range(i-1, -1, -1)))) ```
0
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *...
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num...
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "ou...
1,626,106,052
2,147,483,647
Python 3
OK
TESTS
52
139
17,612,800
nA, nB = map(int, input().split()) k, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) n1 = a[k-1] flag = 0 for i in range(m): j = i+1 if b[-j] > n1: flag = 0 else: flag = 1 break if flag == 0: print("YES") els...
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi...
```python nA, nB = map(int, input().split()) k, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) n1 = a[k-1] flag = 0 for i in range(m): j = i+1 if b[-j] > n1: flag = 0 else: flag = 1 break if flag == 0: print("...
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,663,627,642
2,147,483,647
Python 3
OK
TESTS
40
92
0
word=input() reversedWord=input() print("YES") if(word[::-1]==reversedWord) 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 word=input() reversedWord=input() print("YES") if(word[::-1]==reversedWord) else print("NO") ```
3.977
725
A
Jumping Ball
PROGRAMMING
1,000
[ "implementation" ]
null
null
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '&lt;' and '&gt;'. When the ball hits the bumper at pos...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '&lt;' and '&gt;'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
[ "4\n&lt;&lt;&gt;&lt;\n", "5\n&gt;&gt;&gt;&gt;&gt;\n", "4\n&gt;&gt;&lt;&lt;\n" ]
[ "2", "5", "0" ]
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
500
[ { "input": "4\n<<><", "output": "2" }, { "input": "5\n>>>>>", "output": "5" }, { "input": "4\n>><<", "output": "0" }, { "input": "3\n<<>", "output": "3" }, { "input": "3\n<<<", "output": "3" }, { "input": "3\n><<", "output": "0" }, { "input...
1,477,150,046
1,346
Python 3
RUNTIME_ERROR
PRETESTS
5
108
1,740,800
a = int(input()) st = [x for x in input()] total = 0 j = 0 while st[j] == '<' and j <= len(st)-1: total += 1 j += 1 j = len(st)-1 while st[j] == '>' and j >= 0: total += 1 j -= 1 print(total)
Title: Jumping Ball Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b...
```python a = int(input()) st = [x for x in input()] total = 0 j = 0 while st[j] == '<' and j <= len(st)-1: total += 1 j += 1 j = len(st)-1 while st[j] == '>' and j >= 0: total += 1 j -= 1 print(total) ```
-1
257
A
Sockets
PROGRAMMING
1,100
[ "greedy", "implementation", "sortings" ]
null
null
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets. Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp...
The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —...
Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.
[ "3 5 3\n3 1 2\n", "4 7 2\n3 3 2 4\n", "5 5 1\n1 3 1 2 1\n" ]
[ "1\n", "2\n", "-1\n" ]
In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices. One of the optimal ways in the second test sample is to ...
500
[ { "input": "3 5 3\n3 1 2", "output": "1" }, { "input": "4 7 2\n3 3 2 4", "output": "2" }, { "input": "5 5 1\n1 3 1 2 1", "output": "-1" }, { "input": "4 5 8\n3 2 4 3", "output": "0" }, { "input": "5 10 1\n4 3 4 2 4", "output": "3" }, { "input": "7 13 2...
1,655,853,080
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
154
0
n,m,k = input().split() a= [int(x) for x in input().split()] a.sort(reverse=True) x=0 w=0 if int(k)>=int(m): print('0') else: for i in range(int(n)): x+=a[i] if x+ int(k)-i-1>=int(m): print(i+1) w=1 break if w==0: print(-1)
Title: Sockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets. Overall Vasya has got *m* devices and *k* electrical sockets in his f...
```python n,m,k = input().split() a= [int(x) for x in input().split()] a.sort(reverse=True) x=0 w=0 if int(k)>=int(m): print('0') else: for i in range(int(n)): x+=a[i] if x+ int(k)-i-1>=int(m): print(i+1) w=1 break if w==0: print(-1) ```
0
101
B
Buses
PROGRAMMING
1,700
[ "binary search", "data structures", "dp" ]
B. Buses
2
265
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly *n*<=+<=1 bus stops. All of them are numbered with integers from 0 to *n* in the order in which ...
The first line contains two space-separated integers: *n* and *m* (1<=≤<=*n*<=≤<=109,<=0<=≤<=*m*<=≤<=105). Then follow *m* lines each containing two integers *s**i*,<=*t**i*. They are the numbers of starting stops and end stops of the buses (0<=≤<=*s**i*<=&lt;<=*t**i*<=≤<=*n*).
Print the only number — the number of ways to get to the school modulo 1000000007 (109<=+<=7).
[ "2 2\n0 1\n1 2\n", "3 2\n0 1\n1 2\n", "5 5\n0 1\n0 2\n0 3\n0 4\n0 5\n" ]
[ "1\n", "0\n", "16\n" ]
The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two. In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0. In the third test Gerald can either get or n...
1,000
[ { "input": "2 2\n0 1\n1 2", "output": "1" }, { "input": "3 2\n0 1\n1 2", "output": "0" }, { "input": "5 5\n0 1\n0 2\n0 3\n0 4\n0 5", "output": "16" }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "0" }, { "input": "10 10\n0 1\n0 2\n0 3\n0 4\n0 5\n0 6\n0 7\n0 8\n0 9\...
1,532,628,297
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
43
2,000
31,027,200
a,b=map(int,input().split()) z=[] g=10**9+7 def f(): return map(int,input().split()) if b==0: print (0) else: s=set() for i in range(b): x,y=f() z.append((x,y)) s.add(x) s.add(y) s.add (0) s.add (a) s = sorted(list(s)) a=len(s)-1 s=di...
Title: Buses Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly *n*<=+<=1...
```python a,b=map(int,input().split()) z=[] g=10**9+7 def f(): return map(int,input().split()) if b==0: print (0) else: s=set() for i in range(b): x,y=f() z.append((x,y)) s.add(x) s.add(y) s.add (0) s.add (a) s = sorted(list(s)) a=len(s)-1...
0
3
C
Tic-tac-toe
PROGRAMMING
1,800
[ "brute force", "games", "implementation" ]
C. Tic-tac-toe
1
64
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the...
The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero).
Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.
[ "X0X\n.0.\n.X.\n" ]
[ "second\n" ]
none
0
[ { "input": "X0X\n.0.\n.X.", "output": "second" }, { "input": "0.X\nXX.\n000", "output": "illegal" }, { "input": "XXX\n.0.\n000", "output": "illegal" }, { "input": "XXX\n...\n000", "output": "illegal" }, { "input": "X.X\nX..\n00.", "output": "second" }, { ...
1,430,721,928
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
29
124
0
__author__ = 'Darren' def solve(): import sys stdin = sys.stdin if True else open('data') board = [line for line in stdin] crosses, noughts = 0, 0 for row in board: for col in row: if col == 'X': crosses += 1 elif col == '0': ...
Title: Tic-tac-toe Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ...
```python __author__ = 'Darren' def solve(): import sys stdin = sys.stdin if True else open('data') board = [line for line in stdin] crosses, noughts = 0, 0 for row in board: for col in row: if col == 'X': crosses += 1 elif col == '0': ...
0
911
C
Three Garlands
PROGRAMMING
1,400
[ "brute force", "constructive algorithms" ]
null
null
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s...
The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands.
If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES. Otherwise, print NO.
[ "2 2 3\n", "4 2 3\n" ]
[ "YES\n", "NO\n" ]
In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't...
0
[ { "input": "2 2 3", "output": "YES" }, { "input": "4 2 3", "output": "NO" }, { "input": "1499 1498 1500", "output": "NO" }, { "input": "1500 1500 1500", "output": "NO" }, { "input": "100 4 1", "output": "YES" }, { "input": "4 2 4", "output": "YES" ...
1,590,600,687
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
109
0
a,b,c=map(int,input().split()) if a==b==c: print("NO") elif a==b or b==c or a==c : print("YES") elif a%b==0 and a%c==0: print("YES") else: print("NO")
Title: Three Garlands Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on. When a garland is switched on, it periodically changes its st...
```python a,b,c=map(int,input().split()) if a==b==c: print("NO") elif a==b or b==c or a==c : print("YES") elif a%b==0 and a%c==0: print("YES") else: print("NO") ```
0
979
A
Pizza, Pizza, Pizza!!!
PROGRAMMING
1,000
[ "math" ]
null
null
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to cele...
A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces.
A single integer — the number of straight cuts Shiro needs.
[ "3\n", "4\n" ]
[ "2", "5" ]
To cut the round pizza into quarters one has to make two cuts through the center with angle $90^{\circ}$ between them. To cut the round pizza into five equal parts one has to make five cuts.
500
[ { "input": "3", "output": "2" }, { "input": "4", "output": "5" }, { "input": "10", "output": "11" }, { "input": "10000000000", "output": "10000000001" }, { "input": "1234567891", "output": "617283946" }, { "input": "7509213957", "output": "37546069...
1,569,316,893
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
109
409,600
from collections import Counter n=int(input()) s=str(input()) s1=str(input()) s2=str(input()) t=len(s) l=Counter(s) l1=Counter(s1) l2=Counter(s2) k=max(l.values()) k1=max(l1.values()) k2=max(l2.values()) #print(k,k1,k2) if n+k>=t: if k==t and n!=0: if n==1: k=k-1 else: ...
Title: Pizza, Pizza, Pizza!!! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthd...
```python from collections import Counter n=int(input()) s=str(input()) s1=str(input()) s2=str(input()) t=len(s) l=Counter(s) l1=Counter(s1) l2=Counter(s2) k=max(l.values()) k1=max(l1.values()) k2=max(l2.values()) #print(k,k1,k2) if n+k>=t: if k==t and n!=0: if n==1: k=k-1 ...
-1
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,426,753,205
2,147,483,647
Python 3
OK
TESTS
46
124
0
# coding: utf-8 def check(num): for ch in num: if ch!=4 and ch!=7: return False if sum(num[:len(num)//2]) != sum(num[len(num)//2:]): return False return True n = input() if check([int(i) for i in input()]): 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 # coding: utf-8 def check(num): for ch in num: if ch!=4 and ch!=7: return False if sum(num[:len(num)//2]) != sum(num[len(num)//2:]): return False return True n = input() if check([int(i) for i in input()]): print('YES') else: print('NO') ```
3
935
A
Fafa and his Company
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em...
The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company.
Print a single integer representing the answer to the problem.
[ "2\n", "10\n" ]
[ "1\n", "3\n" ]
In the second sample Fafa has 3 ways: - choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them.
500
[ { "input": "2", "output": "1" }, { "input": "10", "output": "3" }, { "input": "3", "output": "1" }, { "input": "4", "output": "2" }, { "input": "6", "output": "3" }, { "input": "13", "output": "1" }, { "input": "100000", "output": "35" ...
1,636,370,597
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
93
19,865,600
if n>=2: n=int(input()) l=0 for i in range(1,(n//2)+1): if (n-i)%i==0: l+=1 print(l)
Title: Fafa and his Company Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp...
```python if n>=2: n=int(input()) l=0 for i in range(1,(n//2)+1): if (n-i)%i==0: l+=1 print(l) ```
-1
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,690,152,086
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
def Maximum_Increase(arr): maxmax = 0 maxi = 0 for i in range(0,len(arr)): if i ==0 : maxi+=1 continue if arr[i] > arr[i-1]: maxi+=1 else: maxi = 1 if maxi >= maxmax : maxmax = maxi return...
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 def Maximum_Increase(arr): maxmax = 0 maxi = 0 for i in range(0,len(arr)): if i ==0 : maxi+=1 continue if arr[i] > arr[i-1]: maxi+=1 else: maxi = 1 if maxi >= maxmax : maxmax = maxi ...
0
169
B
Replacing Digits
PROGRAMMING
1,100
[ "greedy" ]
null
null
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. ...
The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain lead...
Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes.
[ "1024\n010\n", "987\n1234567\n" ]
[ "1124\n", "987\n" ]
none
1,000
[ { "input": "1024\n010", "output": "1124" }, { "input": "987\n1234567", "output": "987" }, { "input": "10\n1", "output": "11" }, { "input": "11\n1", "output": "11" }, { "input": "12\n2", "output": "22" }, { "input": "1\n0", "output": "1" }, { ...
1,689,596,324
2,147,483,647
Python 3
OK
TESTS
75
592
3,891,200
a = [i for i in input()] s = sorted([i for i in input()], reverse=True) i, j = 0, 0 while i < len(a) and j < len(s): if a[i] < s[j]: a[i] = s[j] j += 1 i += 1 print(int("".join(a)))
Title: Replacing Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary ...
```python a = [i for i in input()] s = sorted([i for i in input()], reverse=True) i, j = 0, 0 while i < len(a) and j < len(s): if a[i] < s[j]: a[i] = s[j] j += 1 i += 1 print(int("".join(a))) ```
3
460
B
Little Dima and Equation
PROGRAMMING
1,500
[ "brute force", "implementation", "math", "number theory" ]
null
null
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions *x* (0<=&lt;<=*x*<=&lt;<=109) of the equation: where *a*, *b*, *c* are some predetermined constant values and function *s*(*x*) determines the sum of all digi...
The first line contains three space-separated integers: *a*,<=*b*,<=*c* (1<=≤<=*a*<=≤<=5; 1<=≤<=*b*<=≤<=10000; <=-<=10000<=≤<=*c*<=≤<=10000).
Print integer *n* — the number of the solutions that you've found. Next print *n* integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.
[ "3 2 8\n", "1 2 -18\n", "2 2 -1\n" ]
[ "3\n10 2008 13726 ", "0\n", "4\n1 31 337 967 " ]
none
1,000
[ { "input": "3 2 8", "output": "3\n10 2008 13726 " }, { "input": "1 2 -18", "output": "0" }, { "input": "2 2 -1", "output": "4\n1 31 337 967 " }, { "input": "1 1 0", "output": "9\n1 2 3 4 5 6 7 8 9 " }, { "input": "1 37 963", "output": "16\n1000 1111 1222 1333 ...
1,644,566,113
2,147,483,647
PyPy 3
OK
TESTS
48
92
0
def number_sum(number): number = str(number) num_sum = 0 for elem in number: num_sum += int(elem) return num_sum def main(): a,b,c = map(int,input().split()) answers = [] for i in range(1,82): if 0<b*i**a+c<10**9 and number_sum(b*i**a+c) == i: answers...
Title: Little Dima and Equation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions *x* (0<=&lt;<=*x*<=&lt;<=109) of the equation: w...
```python def number_sum(number): number = str(number) num_sum = 0 for elem in number: num_sum += int(elem) return num_sum def main(): a,b,c = map(int,input().split()) answers = [] for i in range(1,82): if 0<b*i**a+c<10**9 and number_sum(b*i**a+c) == i: ...
3
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,611,434,441
2,147,483,647
PyPy 3
OK
TESTS
27
216
0
x, y, z = map(int, input().split()) a = (x * y / z) ** 0.5 b = (y * z / x) ** 0.5 c = (z * x / y) ** 0.5 print(4 * int(a + b + c)) # print(a, b, c)
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 x, y, z = map(int, input().split()) a = (x * y / z) ** 0.5 b = (y * z / x) ** 0.5 c = (z * x / y) ** 0.5 print(4 * int(a + b + c)) # print(a, b, c) ```
3
727
A
Transformation: from A to B
PROGRAMMING
1,000
[ "brute force", "dfs and similar", "math" ]
null
null
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10·*x*<=+<=1). You need to he...
The first line contains two positive integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=109) — the number which Vasily has and the number he wants to have.
If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k* — the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x...
[ "2 162\n", "4 42\n", "100 40021\n" ]
[ "YES\n5\n2 4 8 81 162 \n", "NO\n", "YES\n5\n100 200 2001 4002 40021 \n" ]
none
1,000
[ { "input": "2 162", "output": "YES\n5\n2 4 8 81 162 " }, { "input": "4 42", "output": "NO" }, { "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 " }, { "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 " }, ...
1,617,907,207
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
77
0
a, b = map(int, input().split()) ans = [] while b >= a: ans.append(b) if b % 2 == 1: b = (b - 1) // 10 else: b //= 2 if ans[-1] != a: print('NO') else: print('YES') print(len(ans)) print(*ans[::-1])
Title: Transformation: from A to B Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2·*x*); - app...
```python a, b = map(int, input().split()) ans = [] while b >= a: ans.append(b) if b % 2 == 1: b = (b - 1) // 10 else: b //= 2 if ans[-1] != a: print('NO') else: print('YES') print(len(ans)) print(*ans[::-1]) ```
0
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,677,187,218
2,147,483,647
Python 3
OK
TESTS
32
46
0
from math import gcd n,m,z = [int(n) for n in input().split()] print(z//(n*m//gcd(n,m)))
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 from math import gcd n,m,z = [int(n) for n in input().split()] print(z//(n*m//gcd(n,m))) ```
3
7
C
Line
PROGRAMMING
1,800
[ "math", "number theory" ]
C. Line
1
256
A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
The first line contains three integers *A*, *B* and *C* (<=-<=2·109<=≤<=*A*,<=*B*,<=*C*<=≤<=2·109) — corresponding coefficients of the line equation. It is guaranteed that *A*2<=+<=*B*2<=&gt;<=0.
If the required point exists, output its coordinates, otherwise output -1.
[ "2 5 3\n" ]
[ "6 -3\n" ]
none
0
[ { "input": "2 5 3", "output": "6 -3" }, { "input": "0 2 3", "output": "-1" }, { "input": "931480234 -1767614767 -320146190", "output": "-98880374013340920 -52107006370101410" }, { "input": "-1548994394 -1586527767 -1203252104", "output": "-878123061596147680 8573488141506...
1,670,412,730
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
62
0
# LUOGU_RID: 96773615 import math # Read A, B, and C from standard input A = int(input()) B = int(input()) C = int(input()) # Compute the least common multiple of A and B lcm = abs(A * B) // math.gcd(A, B) # Divide A and C by the least common multiple A //= lcm C //= lcm # Try all integer values of x within the giv...
Title: Line Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: A line on the plane is described by an equation *Ax*<=+<=*By*<=+<=*C*<==<=0. You are to find any point on this line, whose coordinates are integer numbers from <=-<=5·1018 to 5·1018 inclusive, or to find out that such points do not ex...
```python # LUOGU_RID: 96773615 import math # Read A, B, and C from standard input A = int(input()) B = int(input()) C = int(input()) # Compute the least common multiple of A and B lcm = abs(A * B) // math.gcd(A, B) # Divide A and C by the least common multiple A //= lcm C //= lcm # Try all integer values of x with...
-1
257
B
Playing Cubes
PROGRAMMING
1,300
[ "games", "greedy", "implementation" ]
null
null
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa...
The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly.
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
[ "3 1\n", "2 4\n" ]
[ "2 1\n", "3 2\n" ]
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point. If Petya would choose the red cu...
500
[ { "input": "3 1", "output": "2 1" }, { "input": "2 4", "output": "3 2" }, { "input": "1 1", "output": "0 1" }, { "input": "2 1", "output": "1 1" }, { "input": "4 4", "output": "3 4" }, { "input": "10 7", "output": "9 7" }, { "input": "5 13"...
1,589,104,019
2,147,483,647
PyPy 3
OK
TESTS
40
280
20,172,800
n,m = map(int,input().split()) vasya = min(n,m) petya = n+m-1-vasya print('{} {}'.format(petya,vasya))
Title: Playing Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (...
```python n,m = map(int,input().split()) vasya = min(n,m) petya = n+m-1-vasya print('{} {}'.format(petya,vasya)) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got.
Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,694,421,939
2,147,483,647
Python 3
OK
TESTS
30
46
0
x,y=sorted(map(int,input().split()));print(x,(y-x)//2) #HI codeforces #
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python x,y=sorted(map(int,input().split()));print(x,(y-x)//2) #HI codeforces # ```
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,590,546,055
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
248
307,200
def integerize(arr): for i in range(len(arr)): arr[i] = int(arr[i]) return arr n = int(input()) arr = input().split() arr = integerize(arr) i = 0 while i < len(arr): if i == 0 and arr[i]%2 != arr[i+1]%2 and arr[i]%2 != arr[i+2]%2: print(1) elif i == len(arr)-1 and arr[i]%2 != arr[i-1]%2 and arr[i]%2 != arr[i-...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python def integerize(arr): for i in range(len(arr)): arr[i] = int(arr[i]) return arr n = int(input()) arr = input().split() arr = integerize(arr) i = 0 while i < len(arr): if i == 0 and arr[i]%2 != arr[i+1]%2 and arr[i]%2 != arr[i+2]%2: print(1) elif i == len(arr)-1 and arr[i]%2 != arr[i-1]%2 and arr[i]%2...
-1
494
A
Treasure
PROGRAMMING
1,500
[ "greedy" ]
null
null
Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that th...
The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character.
If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them.
[ "(((#)((#)\n", "()((#((#(#()\n", "#\n", "(#)\n" ]
[ "1\n2\n", "2\n2\n1", "-1\n", "-1\n" ]
|*s*| denotes the length of the string *s*.
500
[ { "input": "(((#)((#)", "output": "1\n2" }, { "input": "()((#((#(#()", "output": "1\n1\n3" }, { "input": "#", "output": "-1" }, { "input": "(#)", "output": "-1" }, { "input": "(((((#(#(#(#()", "output": "1\n1\n1\n5" }, { "input": "#))))", "output":...
1,419,788,936
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
t = input() n = t.count('#') - 1 k = t.rfind('#') - n t = t.replace('#', '') a = b = 0 for i in t[k: ]: b -= 2 * ord(i) - 81 if b > 0: print(-1) exit() for i in t[: k]: a += 2 * ord(i) - 81 if a > 0: print(-1) exit() print('0\n' * n + str(b - a))
Title: Treasure Time Limit: None seconds Memory Limit: None megabytes Problem Description: Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open...
```python t = input() n = t.count('#') - 1 k = t.rfind('#') - n t = t.replace('#', '') a = b = 0 for i in t[k: ]: b -= 2 * ord(i) - 81 if b > 0: print(-1) exit() for i in t[: k]: a += 2 * ord(i) - 81 if a > 0: print(-1) exit() print('0\n' * n + str(b - ...
0
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,627,968,672
2,147,483,647
PyPy 3
OK
TESTS
27
186
20,172,800
from math import sqrt m,n,o = map(int, input().split()) ans = 4*(sqrt((o*n)/m)+sqrt((n*m)/o) + sqrt((m*o)/n)) print(int(ans))
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 from math import sqrt m,n,o = map(int, input().split()) ans = 4*(sqrt((o*n)/m)+sqrt((n*m)/o) + sqrt((m*o)/n)) print(int(ans)) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do...
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,672,165,526
2,147,483,647
Python 3
OK
TESTS
102
46
0
x=input() y=input() res=''.join([str(int(i)^int(j)) for i ,j in zip(x,y)]) print(res)
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 x=input() y=input() res=''.join([str(int(i)^int(j)) for i ,j in zip(x,y)]) print(res) ```
3.9885
144
A
Arrival of the General
PROGRAMMING
800
[ "implementation" ]
null
null
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their...
The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin...
Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like.
[ "4\n33 44 11 22\n", "7\n10 10 58 31 63 40 76\n" ]
[ "2\n", "10\n" ]
In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11). In the second sample the colonel may swap the soldiers in the following sequence: 1. (10, 10, 58, 31, 63, 40, 76)...
500
[ { "input": "4\n33 44 11 22", "output": "2" }, { "input": "7\n10 10 58 31 63 40 76", "output": "10" }, { "input": "2\n88 89", "output": "1" }, { "input": "5\n100 95 100 100 88", "output": "0" }, { "input": "7\n48 48 48 48 45 45 45", "output": "0" }, { "...
1,695,921,141
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
x= int(input()) h = list(map(int, input().split())) max = h.index(max(h)) min = h.index(min(h)) if max < min: s = max+ (x - 1 - min) else: s = max + (x - 1 - min) - 1 print(s)
Title: Arrival of the General Time Limit: None seconds Memory Limit: None megabytes Problem Description: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t...
```python x= int(input()) h = list(map(int, input().split())) max = h.index(max(h)) min = h.index(min(h)) if max < min: s = max+ (x - 1 - min) else: s = max + (x - 1 - min) - 1 print(s) ```
0
579
A
Raising Bacteria
PROGRAMMING
1,000
[ "bitmasks" ]
null
null
You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the mini...
The only line containing one integer *x* (1<=≤<=*x*<=≤<=109).
The only line containing one integer: the answer.
[ "5\n", "8\n" ]
[ "2\n", "1\n" ]
For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2. For the second sample, we can put one in the first morning and in the 4-th ...
250
[ { "input": "5", "output": "2" }, { "input": "8", "output": "1" }, { "input": "536870911", "output": "29" }, { "input": "1", "output": "1" }, { "input": "343000816", "output": "14" }, { "input": "559980448", "output": "12" }, { "input": "697...
1,685,527,496
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
15
0
##a=input() ##b=input() ##c=str(int(a)+int(b)) ####print('c ',type(c), c) ##m=c.replace('0','') ##k=a.replace('0','') ##l=b.replace('0','') ####print('m ',type(m), m) ##if int(k)+int(l)==int(m): ## print('YES') ##else: ## print('NO') a=int(input()) b=int(input()) c=a+b numbers=[a,b,c] i=0 while i...
Title: Raising Bacteria Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split...
```python ##a=input() ##b=input() ##c=str(int(a)+int(b)) ####print('c ',type(c), c) ##m=c.replace('0','') ##k=a.replace('0','') ##l=b.replace('0','') ####print('m ',type(m), m) ##if int(k)+int(l)==int(m): ## print('YES') ##else: ## print('NO') a=int(input()) b=int(input()) c=a+b numbers=[a,b,c] i=...
-1
166
E
Tetrahedron
PROGRAMMING
1,500
[ "dp", "math", "matrices" ]
null
null
You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each moment of time he makes a step from one vertex to another one along some edge of the tetrahedron. ...
The first line contains the only integer *n* (1<=≤<=*n*<=≤<=107) — the required length of the cyclic path.
Print the only integer — the required number of ways modulo 1000000007 (109<=+<=7).
[ "2\n", "4\n" ]
[ "3\n", "21\n" ]
The required paths in the first sample are: - *D* - *A* - *D* - *D* - *B* - *D* - *D* - *C* - *D*
1,000
[ { "input": "2", "output": "3" }, { "input": "4", "output": "21" }, { "input": "1", "output": "0" }, { "input": "3", "output": "6" }, { "input": "5", "output": "60" }, { "input": "6", "output": "183" }, { "input": "7", "output": "546" ...
1,673,689,891
2,147,483,647
PyPy 3-64
OK
TESTS
36
124
0
n=int(input()) MOD=int(1e9+7) print(int(((pow(3, n, 4*MOD)+3*pow(-1,n))/4))%MOD)
Title: Tetrahedron Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a tetrahedron. Let's mark its vertices with letters *A*, *B*, *C* and *D* correspondingly. An ant is standing in the vertex *D* of the tetrahedron. The ant is quite active and he wouldn't stay idle. At each m...
```python n=int(input()) MOD=int(1e9+7) print(int(((pow(3, n, 4*MOD)+3*pow(-1,n))/4))%MOD) ```
3
989
A
A Blend of Springtime
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic. The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o...
The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively.
Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise. You can print each letter in any case (upper or lower).
[ ".BAC.\n", "AA..CB\n" ]
[ "Yes\n", "No\n" ]
In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it. In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell.
500
[ { "input": ".BAC.", "output": "Yes" }, { "input": "AA..CB", "output": "No" }, { "input": ".", "output": "No" }, { "input": "ACB.AAAAAA", "output": "Yes" }, { "input": "B.BC.BBBCA", "output": "Yes" }, { "input": "BA..CAB..B", "output": "Yes" }, ...
1,582,834,448
2,147,483,647
Python 3
OK
TESTS
37
109
0
n = input() print('YES' if 'ABC' in n or 'ACB' in n or 'BCA' in n or 'BAC' in n or 'CAB' in n or 'CBA' in n else 'NO')
Title: A Blend of Springtime Time Limit: None seconds Memory Limit: None megabytes Problem Description: "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone." "But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti...
```python n = input() print('YES' if 'ABC' in n or 'ACB' in n or 'BCA' in n or 'BAC' in n or 'CAB' in n or 'CBA' in n else 'NO') ```
3
344
A
Magnets
PROGRAMMING
800
[ "implementation" ]
null
null
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" posit...
On the single line of the output print the number of groups of magnets.
[ "6\n10\n10\n10\n01\n10\n10\n", "4\n01\n01\n10\n10\n" ]
[ "3\n", "2\n" ]
The first testcase corresponds to the figure. The testcase has three groups consisting of three, one and two magnets. The second testcase has two groups, each consisting of two magnets.
500
[ { "input": "6\n10\n10\n10\n01\n10\n10", "output": "3" }, { "input": "4\n01\n01\n10\n10", "output": "2" }, { "input": "1\n10", "output": "1" }, { "input": "2\n01\n10", "output": "2" }, { "input": "2\n10\n10", "output": "1" }, { "input": "3\n10\n01\n10",...
1,695,414,574
2,147,483,647
Python 3
OK
TESTS
31
248
0
n=int(input()) groups=1 last=0 for i in range(n): x=int(input()) if i==0: last=x else: if x==last: groups=groups+0 else: groups=groups+1 last=x print(groups)
Title: Magnets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets...
```python n=int(input()) groups=1 last=0 for i in range(n): x=int(input()) if i==0: last=x else: if x==last: groups=groups+0 else: groups=groups+1 last=x print(groups) ```
3
612
B
HDD is Outdated Technology
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the problems of HDD hard drives is the following: the magnetic head should move from one sector to another to read s...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of fragments. The second line contains *n* different integers *f**i* (1<=≤<=*f**i*<=≤<=*n*) — the number of the fragment written in the *i*-th sector.
Print the only integer — the number of time units needed to read the file.
[ "3\n3 1 2\n", "5\n1 3 5 4 2\n" ]
[ "3\n", "10\n" ]
In the second example the head moves in the following way: - 1-&gt;2 means movement from the sector 1 to the sector 5, i.e. it takes 4 time units - 2-&gt;3 means movement from the sector 5 to the sector 2, i.e. it takes 3 time units - 3-&gt;4 means movement from the sector 2 to the sector 4, i.e. it takes 2 time un...
0
[ { "input": "3\n3 1 2", "output": "3" }, { "input": "5\n1 3 5 4 2", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "40" ...
1,585,314,056
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
17
1,000
10,547,200
n=int(input());a=list(map(int,input().split()));p=0 i=a.index(n) while n>1: j=a.index(n-1) p=p+abs(i-j) i=j n-=1 print(p)
Title: HDD is Outdated Technology Time Limit: None seconds Memory Limit: None megabytes Problem Description: HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order. One of the ...
```python n=int(input());a=list(map(int,input().split()));p=0 i=a.index(n) while n>1: j=a.index(n-1) p=p+abs(i-j) i=j n-=1 print(p) ```
0
21
A
Jabber ID
PROGRAMMING
1,900
[ "implementation", "strings" ]
A. Jabber ID
0
256
Jabber ID on the national Berland service «Babber» has a form &lt;username&gt;@&lt;hostname&gt;[/resource], where - &lt;username&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of &lt;username&gt; is between 1 and 16, inclusive. - &lt;hostname&gt; — is...
The input contains of a single line. The line has the length between 1 and 100 characters, inclusive. Each characters has ASCII-code between 33 and 127, inclusive.
Print YES or NO.
[ "[email protected]\n", "[email protected]/contest.icpc/12\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "mike@codeforces.com", "output": "YES" }, { "input": "john.smith@codeforces.ru/contest.icpc/12", "output": "NO" }, { "input": "test@test.ri/abacaba", "output": "YES" }, { "input": "@ops", "output": "NO" }, { "input": "this-is-the-test", "output": "N...
1,526,635,801
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
109
409,600
import re def get_ans(s): new = re.split(r'[@/]', s) n = len(new) if n > 3 or n < 2: return "NO" username = new[0] hostname = new[1] resource = '' if len(new) == 3: resource = new[2] count = 0 for i in username: if not ((i >= 'a' and i <= 'z')...
Title: Jabber ID Time Limit: 0 seconds Memory Limit: 256 megabytes Problem Description: Jabber ID on the national Berland service «Babber» has a form &lt;username&gt;@&lt;hostname&gt;[/resource], where - &lt;username&gt; — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «...
```python import re def get_ans(s): new = re.split(r'[@/]', s) n = len(new) if n > 3 or n < 2: return "NO" username = new[0] hostname = new[1] resource = '' if len(new) == 3: resource = new[2] count = 0 for i in username: if not ((i >= 'a' and...
0
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer — the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,697,571,798
2,147,483,647
PyPy 3-64
OK
TESTS
27
62
0
def accnumlist(): return list(map(int, input().split())) def accnums(): return map(int, input().split()) def accstr(): return input() def accnum(): return int(input()) n = accnum() ans = 0 for i in range(n): x, y = accnums() if y - x > 1: ans += 1 print(ans)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python def accnumlist(): return list(map(int, input().split())) def accnums(): return map(int, input().split()) def accstr(): return input() def accnum(): return int(input()) n = accnum() ans = 0 for i in range(n): x, y = accnums() if y - x > 1: ans += 1 print(ans) `...
3
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" ...
1,661,348,485
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
2
2,000
11,264,000
n = int(input()) shows = [] t1 = [] t2 = [] for i in range(n): left, right = [int(x) for x in input().split()] shows.append((left, right)) for i in range(n - 1): for j in range(i + 1, n): if shows[i][0] > shows[j][1]: aux = shows[i] shows[i] = shows[j] shows[j...
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He ...
```python n = int(input()) shows = [] t1 = [] t2 = [] for i in range(n): left, right = [int(x) for x in input().split()] shows.append((left, right)) for i in range(n - 1): for j in range(i + 1, n): if shows[i][0] > shows[j][1]: aux = shows[i] shows[i] = shows[j] ...
0
955
A
Feed the cat
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are...
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening. The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n" ]
[ "25200.0000\n", "1365.0000\n" ]
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15...
500
[ { "input": "19 00\n255 1 100 1", "output": "25200.0000" }, { "input": "17 41\n1000 6 15 11", "output": "1365.0000" }, { "input": "16 34\n61066 14 50 59", "output": "43360.0000" }, { "input": "18 18\n23331 86 87 41", "output": "49590.0000" }, { "input": "10 48\n684...
1,521,829,475
6,575
Python 3
OK
TESTS
34
93
7,065,600
# Standard Input import sys def main(): file = sys.stdin # we can read the input from this file line1 = file.readline() line2 = file.readline() # get the two lines hour, minute = line1.split() H, D, C, N = line2.split() hour, minute = int(hour), int(minute) H, D, C, N = in...
Title: Feed the cat Time Limit: None seconds Memory Limit: None megabytes Problem Description: After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without foo...
```python # Standard Input import sys def main(): file = sys.stdin # we can read the input from this file line1 = file.readline() line2 = file.readline() # get the two lines hour, minute = line1.split() H, D, C, N = line2.split() hour, minute = int(hour), int(minute) H, D,...
3
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "64009798...
1,547,106,821
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
0
from math import gcd l, r = list(map(int, input().rstrip().split())) d = {} for i in range(l, r): for j in range(i, r + 1): if gcd(i, j) == 1: d[i] = j for i, j in d.items(): if j in d: if gcd(i, d[j]) != 1: print(i, j, d[j]) exit() print(-1)
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different st...
```python from math import gcd l, r = list(map(int, input().rstrip().split())) d = {} for i in range(l, r): for j in range(i, r + 1): if gcd(i, j) == 1: d[i] = j for i, j in d.items(): if j in d: if gcd(i, d[j]) != 1: print(i, j, d[j]) exit() print...
0
488
A
Giga Tower
PROGRAMMING
1,100
[ "brute force" ]
null
null
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it ...
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Print the minimum *b* in a line.
[ "179\n", "-1\n", "18\n" ]
[ "1\n", "9\n", "10\n" ]
For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
500
[ { "input": "179", "output": "1" }, { "input": "-1", "output": "9" }, { "input": "18", "output": "10" }, { "input": "-410058385", "output": "1" }, { "input": "-586825624", "output": "1" }, { "input": "852318890", "output": "1" }, { "input": ...
1,636,014,858
2,147,483,647
Python 3
OK
TESTS
35
46
4,300,800
a = str(int(input())+1) i = 1 while "8" not in a: a = str(int(a)+1) i += 1 print(i)
Title: Giga Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever...
```python a = str(int(input())+1) i = 1 while "8" not in a: a = str(int(a)+1) i += 1 print(i) ```
3
998
A
Balloons
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $n$ packets with inflatable balloons, where $i$-th of them has exactly $a_i$ balloons insi...
The first line of input contains a single integer $n$ ($1 \le n \le 10$) — the number of packets with balloons. The second line contains $n$ integers: $a_1$, $a_2$, $\ldots$, $a_n$ ($1 \le a_i \le 1000$) — the number of balloons inside the corresponding packet.
If it's impossible to divide the balloons satisfying the conditions above, print $-1$. Otherwise, print an integer $k$ — the number of packets to give to Grigory followed by $k$ distinct integers from $1$ to $n$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons...
[ "3\n1 2 1\n", "2\n5 5\n", "1\n10\n" ]
[ "2\n1 2\n", "-1\n", "-1\n" ]
In the first test Grigory gets $3$ balloons in total while Andrey gets $1$. In the second test there's only one way to divide the packets which leads to equal numbers of balloons. In the third test one of the boys won't get a packet at all.
500
[ { "input": "3\n1 2 1", "output": "1\n1" }, { "input": "2\n5 5", "output": "-1" }, { "input": "1\n10", "output": "-1" }, { "input": "1\n1", "output": "-1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "1\n1" }, { "input": "10\n1 1 1 1 1 1 1 1 1 9",...
1,590,958,330
2,147,483,647
Python 3
OK
TESTS
49
108
0
#F nbpackets = int(input()) n = input() rock = 1 liste2 = [int(x) for x in n.split()] if nbpackets<=1 or (nbpackets<=2 and liste2.count(liste2[0])==len(liste2)): print("-1") else: print(1) print(liste2.index(min(liste2))+1)
Title: Balloons Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens. Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bou...
```python #F nbpackets = int(input()) n = input() rock = 1 liste2 = [int(x) for x in n.split()] if nbpackets<=1 or (nbpackets<=2 and liste2.count(liste2[0])==len(liste2)): print("-1") else: print(1) print(liste2.index(min(liste2))+1) ```
3
411
A
Password Check
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_".
If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes).
[ "abacaba\n", "X12345\n", "CONTEST_is_STARTED!!11\n" ]
[ "Too weak\n", "Too weak\n", "Correct\n" ]
none
0
[ { "input": "abacaba", "output": "Too weak" }, { "input": "X12345", "output": "Too weak" }, { "input": "CONTEST_is_STARTED!!11", "output": "Correct" }, { "input": "1zA__", "output": "Correct" }, { "input": "1zA_", "output": "Too weak" }, { "input": "zA_...
1,630,101,564
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
6,963,200
passwd = input() upperC = 0 lowerC = 0 digitC = 0 specialC = 0 for s in passwd: if s.isdigit(): digitC += 1 elif s.isupper(): upperC += 1 elif s.islower(): lowerC += 1 elif s == '!' or s == '?' or s == '.' or s == ',' or s == '_': specialC += 1 if len(passwd) >= 5 and ...
Title: Password Check Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password...
```python passwd = input() upperC = 0 lowerC = 0 digitC = 0 specialC = 0 for s in passwd: if s.isdigit(): digitC += 1 elif s.isupper(): upperC += 1 elif s.islower(): lowerC += 1 elif s == '!' or s == '?' or s == '.' or s == ',' or s == '_': specialC += 1 if len(passwd)...
0
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,690,847,568
2,147,483,647
Python 3
OK
TESTS
71
92
0
n = int(input()) capacity = [0] for _ in range(n): information = input().split() exiting = int(information[0]) entering = int(information[1]) new_capacity = capacity[-1] - exiting + entering capacity.append(new_capacity) print(max(capacity))
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python n = int(input()) capacity = [0] for _ in range(n): information = input().split() exiting = int(information[0]) entering = int(information[1]) new_capacity = capacity[-1] - exiting + entering capacity.append(new_capacity) print(max(capacity)) ```
3
306
A
Candies
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such *a**i*, where *a**i* is the number of candies in the *...
The single line of the input contains a pair of space-separated positive integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100;*n*<=≥<=*m*) — the number of candies and the number of Polycarpus's friends.
Print the required sequence *a*1,<=*a*2,<=...,<=*a**m*, where *a**i* is the number of candies in the *i*-th friend's present. All numbers *a**i* must be positive integers, total up to *n*, the maximum one should differ from the minimum one by the smallest possible value.
[ "12 3\n", "15 4\n", "18 7\n" ]
[ "4 4 4 ", "3 4 4 4 ", "2 2 2 3 3 3 3 " ]
Print *a*<sub class="lower-index">*i*</sub> in any order, separate the numbers by spaces.
500
[ { "input": "12 4", "output": "3 3 3 3 " }, { "input": "15 6", "output": "2 2 2 3 3 3 " }, { "input": "18 8", "output": "2 2 2 2 2 2 3 3 " }, { "input": "1 1", "output": "1 " }, { "input": "2 1", "output": "2 " }, { "input": "100 1", "output": "100 ...
1,639,401,476
2,147,483,647
Python 3
OK
TESTS
20
92
0
import math nums = list(map(int, input().split(" "))) n=math.ceil(nums[0]/nums[1]) l=[] for i in range(nums[1]): l.append(n) m=nums[1]*n-nums[0] if m!=0: for i in range(m): l[i]=l[i]-1 print(*l, sep = " ")
Title: Candies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has got *n* candies and *m* friends (*n*<=≥<=*m*). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most ...
```python import math nums = list(map(int, input().split(" "))) n=math.ceil(nums[0]/nums[1]) l=[] for i in range(nums[1]): l.append(n) m=nums[1]*n-nums[0] if m!=0: for i in range(m): l[i]=l[i]-1 print(*l, sep = " ") ```
3
313
B
Ilya and Queries
PROGRAMMING
1,100
[ "dp", "implementation" ]
null
null
Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting only of characters "." and "#" and *m* queries. Each query is described by a pair of integers *l**i*,<...
The first line contains string *s* of length *n* (2<=≤<=*n*<=≤<=105). It is guaranteed that the given string only consists of characters "." and "#". The next line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. Each of the next *m* lines contains the description of the corresponding query. The *i*-t...
Print *m* integers — the answers to the queries in the order in which they are given in the input.
[ "......\n4\n3 4\n2 3\n1 6\n2 6\n", "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4\n" ]
[ "1\n1\n5\n4\n", "1\n1\n2\n2\n0\n" ]
none
1,000
[ { "input": "......\n4\n3 4\n2 3\n1 6\n2 6", "output": "1\n1\n5\n4" }, { "input": "#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "output": "1\n1\n2\n2\n0" }, { "input": ".#...#..\n6\n1 5\n2 3\n6 7\n2 4\n2 5\n1 3", "output": "2\n0\n0\n1\n2\n0" }, { "input": "#.#.#..\n5\n3 4\n4 5\n5 7\n5...
1,689,970,236
2,147,483,647
Python 3
OK
TESTS
37
1,526
6,860,800
s = input() q = int(input()) eq = [] for i in range(len(s)-1): if s[i]==s[i+1]: eq.append(1) else: eq.append(0) ps = [0] for x in eq: ps.append(ps[-1] + x) for _ in range(q): a,b = map(int, input().split()) print(ps[b-1] - ps[a-1])
Title: Ilya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ilya the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string *s*<==<=*s*1*s*2... *s**n* (*n* is the length of the string), consisting ...
```python s = input() q = int(input()) eq = [] for i in range(len(s)-1): if s[i]==s[i+1]: eq.append(1) else: eq.append(0) ps = [0] for x in eq: ps.append(ps[-1] + x) for _ in range(q): a,b = map(int, input().split()) print(ps[b-1] - ps[a-1]) ```
3
2
A
Winner
PROGRAMMING
1,500
[ "hashing", "implementation" ]
A. Winner
1
64
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla...
The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ...
Print the name of the winner.
[ "3\nmike 3\nandrew 5\nmike 2\n", "3\nandrew 3\nandrew 2\nmike 5\n" ]
[ "andrew\n", "andrew\n" ]
none
0
[ { "input": "3\nmike 3\nandrew 5\nmike 2", "output": "andrew" }, { "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew" }, { "input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303", "output": "kaxqybeultn" },...
1,622,654,991
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
216
0
d={} l=[] for _ in range(int(input())): name,score = input().split() score=int(score) d[name]=d.get(name,0) + score l.append([name,d[name]]) m=max(d.values()) for name,score in l: if d[name]==m : print(name) break
Title: Winner Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes...
```python d={} l=[] for _ in range(int(input())): name,score = input().split() score=int(score) d[name]=d.get(name,0) + score l.append([name,d[name]]) m=max(d.values()) for name,score in l: if d[name]==m : print(name) break ```
0
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and m...
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact...
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......
1,673,456,411
2,147,483,647
Python 3
OK
TESTS
36
92
0
n,m=map(int,input().split()) L=[] for i in range(n): L.append(str(input())) Cor=[] for p in range(n): for q in range(m): if L[p][q]=='*': Cor.append([p+1,q+1]) l=0 c=0 A=Cor[0] B=Cor[1] C=Cor[2] def dist(E,F): return((E[0]-F[0])**2+(E[1]-F[1])**2) if dist(B,C)==dist(B,A)+...
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the ma...
```python n,m=map(int,input().split()) L=[] for i in range(n): L.append(str(input())) Cor=[] for p in range(n): for q in range(m): if L[p][q]=='*': Cor.append([p+1,q+1]) l=0 c=0 A=Cor[0] B=Cor[1] C=Cor[2] def dist(E,F): return((E[0]-F[0])**2+(E[1]-F[1])**2) if dist(B,C)==...
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,694,932,014
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
31
0
m=int(input()) n=int(input()) o=int(input()) if m==1 and o==1: print(m+n+o) elif n!=1 and(m==1 or o==1): print((1+n)*max(m,o)) else: print(m*n*o)
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ...
```python m=int(input()) n=int(input()) o=int(input()) if m==1 and o==1: print(m+n+o) elif n!=1 and(m==1 or o==1): print((1+n)*max(m,o)) else: print(m*n*o) ```
0
769
A
Year of University Entrance
PROGRAMMING
800
[ "*special", "implementation", "sortings" ]
null
null
There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups f...
The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed tha...
Print the year of Igor's university entrance.
[ "3\n2014 2016 2015\n", "1\n2050\n" ]
[ "2015\n", "2050\n" ]
In the first test the value *x* = 1. Igor entered the university in 2015. So he joined groups members of which are students who entered the university in 2014, 2015 and 2016. In the second test the value *x* = 0. Igor entered only the group which corresponds to the year of his university entrance.
500
[ { "input": "3\n2014 2016 2015", "output": "2015" }, { "input": "1\n2050", "output": "2050" }, { "input": "1\n2010", "output": "2010" }, { "input": "1\n2011", "output": "2011" }, { "input": "3\n2010 2011 2012", "output": "2011" }, { "input": "3\n2049 20...
1,488,651,777
22,977
Python 3
OK
TESTS
45
62
4,608,000
def main(): groups = int(input()) years = [int(x) for x in input().split()] years.sort() if groups == 1: print(years[0]) elif groups == 3: print(years[1]) elif groups == 5: print(years[2]) if __name__ == "__main__": main()
Title: Year of University Entrance Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of correspond...
```python def main(): groups = int(input()) years = [int(x) for x in input().split()] years.sort() if groups == 1: print(years[0]) elif groups == 3: print(years[1]) elif groups == 5: print(years[2]) if __name__ == "__main__": main() ```
3
6
A
Triangle
PROGRAMMING
900
[ "brute force", "geometry" ]
A. Triangle
2
64
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo...
The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks.
Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s...
[ "4 2 1 3\n", "7 2 2 4\n", "3 5 9 1\n" ]
[ "TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n" ]
none
0
[ { "input": "4 2 1 3", "output": "TRIANGLE" }, { "input": "7 2 2 4", "output": "SEGMENT" }, { "input": "3 5 9 1", "output": "IMPOSSIBLE" }, { "input": "3 1 5 1", "output": "IMPOSSIBLE" }, { "input": "10 10 10 10", "output": "TRIANGLE" }, { "input": "11 ...
1,608,025,216
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
186
307,200
a = [int(i) for i in input().split()] imax = 0 maxa = a[0] for i in range(1, len(a)): if a[i] > maxa: maxa = a[i] imax = i a[imax] = 0 r = [] for i in a: if maxa + i < sum(a) - i: r.append(1) elif maxa + i == sum(a) - i: r.append(2) else: r.append(0) if 1 in a: print('TRIANGLE') elif 2 in a: print('SEGME...
Title: Triangle Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o...
```python a = [int(i) for i in input().split()] imax = 0 maxa = a[0] for i in range(1, len(a)): if a[i] > maxa: maxa = a[i] imax = i a[imax] = 0 r = [] for i in a: if maxa + i < sum(a) - i: r.append(1) elif maxa + i == sum(a) - i: r.append(2) else: r.append(0) if 1 in a: print('TRIANGLE') elif 2 in a: pr...
0
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,672,770,346
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
t = (int(input())) while t>0: n = (input()) if len(n) <10: print(n) else: print(n[0] + str(len(n) - 2) + n[len(n)-1]) t = t-1
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python t = (int(input())) while t>0: n = (input()) if len(n) <10: print(n) else: print(n[0] + str(len(n) - 2) + n[len(n)-1]) t = t-1 ```
0
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,596,745,549
2,147,483,647
Python 3
OK
TESTS
81
218
6,963,200
n=int(input()) l=[] for i in range(n): il=[] for q in map(int,input().split()): il.append(q) l.append(il) x=0 y=0 z=0 for j in range(n): x+=l[j][0] y+=l[j][1] z+=l[j][2] if(x==0 and y==0 and 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()) l=[] for i in range(n): il=[] for q in map(int,input().split()): il.append(q) l.append(il) x=0 y=0 z=0 for j in range(n): x+=l[j][0] y+=l[j][1] z+=l[j][2] if(x==0 and y==0 and z==0): print("YES") else: print("NO") ```
3.93253
912
B
New Year's Eve
PROGRAMMING
1,300
[ "bitmasks", "constructive algorithms", "number theory" ]
null
null
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. The choice of candies has a d...
The sole string contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1018).
Output one number — the largest possible xor-sum.
[ "4 3\n", "6 6\n" ]
[ "7\n", "7\n" ]
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
1,000
[ { "input": "4 3", "output": "7" }, { "input": "6 6", "output": "7" }, { "input": "2 2", "output": "3" }, { "input": "1022 10", "output": "1023" }, { "input": "415853337373441 52", "output": "562949953421311" }, { "input": "75 12", "output": "127" ...
1,590,143,308
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
47
156
0
from math import log2, floor n, k = input().split() n = int(n) k = int(k) if k == 1: print(n) else: print(int(2**(floor(log2(n))+1)-1))
Title: New Year's Eve Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co...
```python from math import log2, floor n, k = input().split() n = int(n) k = int(k) if k == 1: print(n) else: print(int(2**(floor(log2(n))+1)-1)) ```
0
935
B
Fafa and the Gates
PROGRAMMING
900
[ "implementation" ]
null
null
Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The world can be represented by the first quadrant of a plane and the wall is built along the identity line (...
The first line of the input contains single integer *n* (1<=≤<=*n*<=≤<=105) — the number of moves in the walking sequence. The second line contains a string *S* of length *n* consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence *S* in order from left to right.
On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence *S*.
[ "1\nU\n", "6\nRURUUR\n", "7\nURRRUUU\n" ]
[ "0\n", "1\n", "2\n" ]
The figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.
750
[ { "input": "1\nU", "output": "0" }, { "input": "6\nRURUUR", "output": "1" }, { "input": "7\nURRRUUU", "output": "2" }, { "input": "100\nRUURUURRUURUUUUURRUUURRRRUURRURRURRRRUUUUUURRUURRRRURUUURUURURRRRRURUURRUURUURRUUURUUUUUURRUUUURUUUR", "output": "3" }, { "input...
1,654,169,827
2,147,483,647
PyPy 3-64
OK
TESTS
24
77
3,379,200
# =========== IMPORTS ============# # =========== GLOBAL =============# # =========== FUNCTIONS ========= # if __name__ == '__main__': n = int(input()) s = input() state = None # 'N' at the North kingdom - 'S' at the south kingdom pos = [0, 0] coins = 0 for move in s: ...
Title: Fafa and the Gates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The w...
```python # =========== IMPORTS ============# # =========== GLOBAL =============# # =========== FUNCTIONS ========= # if __name__ == '__main__': n = int(input()) s = input() state = None # 'N' at the North kingdom - 'S' at the south kingdom pos = [0, 0] coins = 0 for move...
3
400
C
Inna and Huge Candy Matrix
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as...
The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Tw...
For each of the *p* candies, print on a single line its space-separated new coordinates.
[ "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n" ]
[ "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n" ]
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
1,500
[ { "input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1" }, { "input": "5 5 0 0 0 1\n1 4", "output": "1 4" }, { "input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n1...
1,561,534,068
2,147,483,647
Python 3
OK
TESTS
60
545
11,980,800
h, w, x, y, z, p = map(int, input().split()) x, y, z = x % 4, y % 2, z % 4 def rotation(a, b): global h, w res = (b, h - a + 1) w, h = h, w return res def flip(a, b): return a, w - b + 1 res = [] for i in range(p): a, b = map(int, input().split()) ch, cw = h, w for i i...
Title: Inna and Huge Candy Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1...
```python h, w, x, y, z, p = map(int, input().split()) x, y, z = x % 4, y % 2, z % 4 def rotation(a, b): global h, w res = (b, h - a + 1) w, h = h, w return res def flip(a, b): return a, w - b + 1 res = [] for i in range(p): a, b = map(int, input().split()) ch, cw = h, w ...
3
514
A
Chewbaсca and Number
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits....
The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
[ "27\n", "4545\n" ]
[ "22\n", "4444\n" ]
none
500
[ { "input": "27", "output": "22" }, { "input": "4545", "output": "4444" }, { "input": "1", "output": "1" }, { "input": "9", "output": "9" }, { "input": "8772", "output": "1222" }, { "input": "81", "output": "11" }, { "input": "71723447", ...
1,682,330,388
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
a = input() w = [] w.extend(a) q = 9999999999999999999999999 for _ in range(len(w)): w[_] = int(w[_]) for i in range(len(w)): if w[i] < q and w[i] != 0: q = w[i] for k in range(len(w)): if w[k] != q: w[k] = 9 - w[k] for l in range(len(w)): w[l] = str(w[l]) print (''.join(w...
Title: Chewbaсca and Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform...
```python a = input() w = [] w.extend(a) q = 9999999999999999999999999 for _ in range(len(w)): w[_] = int(w[_]) for i in range(len(w)): if w[i] < q and w[i] != 0: q = w[i] for k in range(len(w)): if w[k] != q: w[k] = 9 - w[k] for l in range(len(w)): w[l] = str(w[l]) print ...
0
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,679,467,442
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n, a, b, c = map(int, input().split()) d = [a,b,c] ribbon = n // min(d) print(ribbon)
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the...
```python n, a, b, c = map(int, input().split()) d = [a,b,c] ribbon = n // min(d) print(ribbon) ```
0
771
A
Bear and Friendship Condition
PROGRAMMING
1,500
[ "dfs and similar", "dsu", "graphs" ]
null
null
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through *n*. *m* pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that...
The first line of the input contain two integers *n* and *m* (3<=≤<=*n*<=≤<=150<=000, ) — the number of members and the number of pairs of members that are friends. The *i*-th of the next *m* lines contains two distinct integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*). Members *a**i* and ...
If the given network is reasonable, print "YES" in a single line (without the quotes). Otherwise, print "NO" in a single line (without the quotes).
[ "4 3\n1 3\n3 4\n1 4\n", "4 4\n3 1\n2 3\n3 4\n1 2\n", "10 4\n4 3\n5 10\n8 9\n1 2\n", "3 2\n1 2\n2 3\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n" ]
The drawings below show the situation in the first sample (on the left) and in the second sample (on the right). Each edge represents two members that are friends. The answer is "NO" in the second sample because members (2, 3) are friends and members (3, 4) are friends, while members (2, 4) are not.
250
[ { "input": "4 3\n1 3\n3 4\n1 4", "output": "YES" }, { "input": "4 4\n3 1\n2 3\n3 4\n1 2", "output": "NO" }, { "input": "10 4\n4 3\n5 10\n8 9\n1 2", "output": "YES" }, { "input": "3 2\n1 2\n2 3", "output": "NO" }, { "input": "3 0", "output": "YES" }, { ...
1,597,349,911
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
31,334,400
from collections import defaultdict n,m=map(int,input().split()) adj=defaultdict(set) vis=[False]*(n+1) for i in range(m): u,v=map(int,input().split()) adj[u].add(v) adj[v].add(u) for x in adj: adj[x].add(x) for i in range(1,n+1): if not vis[i]: for j in adj[i]: vis[...
Title: Bear and Friendship Condition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are *n* members, numbered 1 through...
```python from collections import defaultdict n,m=map(int,input().split()) adj=defaultdict(set) vis=[False]*(n+1) for i in range(m): u,v=map(int,input().split()) adj[u].add(v) adj[v].add(u) for x in adj: adj[x].add(x) for i in range(1,n+1): if not vis[i]: for j in adj[i]: ...
0
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin...
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coord...
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,590,562,058
2,147,483,647
Python 3
OK
TESTS
45
109
307,200
n,d=map(int,input().split()) list=[int(i) for i in input().split()] output=1 if(n==1): print("2") exit() if((list[0]+d)<=(list[1]-d)): output+=1 for i in range(1,n-1): if((list[i]+d)<=(list[i+1]-d)): output+=1 if((list[i]-d)>(list[i-1]+d)): output+=1 if((list[n-1]-d)>(...
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer c...
```python n,d=map(int,input().split()) list=[int(i) for i in input().split()] output=1 if(n==1): print("2") exit() if((list[0]+d)<=(list[1]-d)): output+=1 for i in range(1,n-1): if((list[i]+d)<=(list[i+1]-d)): output+=1 if((list[i]-d)>(list[i-1]+d)): output+=1 if((list...
3
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentall...
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { ...
1,698,244,892
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
46
0
a=input() if a[1::]==a[1::].upper(): print(a[0].upper()+a[1::].lower()) elif a==a.upper(): print(a.lower()) else: print(a)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th...
```python a=input() if a[1::]==a[1::].upper(): print(a[0].upper()+a[1::].lower()) elif a==a.upper(): print(a.lower()) else: print(a) ```
0
682
A
Alyona and Numbers
PROGRAMMING
1,100
[ "constructive algorithms", "math", "number theory" ]
null
null
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first...
The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000).
Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5.
[ "6 12\n", "11 14\n", "1 5\n", "3 8\n", "5 7\n", "21 21\n" ]
[ "14\n", "31\n", "1\n", "5\n", "7\n", "88\n" ]
Following pairs are suitable in the first sample case: - for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9. Only th...
500
[ { "input": "6 12", "output": "14" }, { "input": "11 14", "output": "31" }, { "input": "1 5", "output": "1" }, { "input": "3 8", "output": "5" }, { "input": "5 7", "output": "7" }, { "input": "21 21", "output": "88" }, { "input": "10 15", ...
1,493,746,129
2,147,483,647
Python 3
OK
TESTS
128
93
5,632,000
#in the name of god #Mr_Rubik #''.join(sorted(a)) sort string a,b=map(int,input().split()) sum=0 sum+=a*int(b/5) sum+=int(a/5)* (b % 5) if a%5+b%5>=5: sum+=(a%5+b%5)%5+1 print(sum)
Title: Alyona and Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ...
```python #in the name of god #Mr_Rubik #''.join(sorted(a)) sort string a,b=map(int,input().split()) sum=0 sum+=a*int(b/5) sum+=int(a/5)* (b % 5) if a%5+b%5>=5: sum+=(a%5+b%5)%5+1 print(sum) ```
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,512,793,089
429
Python 3
OK
TESTS
32
61
5,529,600
import math a, b, c = [int(i) for i in input().split()] gdf = a * b // math.gcd(a, b) ans = 0 for i in range(1, c + 1): if i % gdf == 0: ans += 1 print(ans)
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 import math a, b, c = [int(i) for i in input().split()] gdf = a * b // math.gcd(a, b) ans = 0 for i in range(1, c + 1): if i % gdf == 0: ans += 1 print(ans) ```
3
617
A
Elephant
PROGRAMMING
800
[ "math" ]
null
null
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ...
The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house.
Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*.
[ "5\n", "12\n" ]
[ "1\n", "3\n" ]
In the first sample the elephant needs to make one step of length 5 to reach the point *x*. In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves.
500
[ { "input": "5", "output": "1" }, { "input": "12", "output": "3" }, { "input": "999999", "output": "200000" }, { "input": "41", "output": "9" }, { "input": "1000000", "output": "200000" }, { "input": "1", "output": "1" }, { "input": "2", ...
1,699,853,340
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
x = int(input()) y = x/5 + 1 print(y)
Title: Elephant Time Limit: None seconds Memory Limit: None megabytes Problem Description: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2...
```python x = int(input()) y = x/5 + 1 print(y) ```
0
121
A
Lucky Sum
PROGRAMMING
1,100
[ "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested ...
The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits.
In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "2 7\n", "7 7\n" ]
[ "33\n", "7\n" ]
In the first sample: *next*(2) + *next*(3) + *next*(4) + *next*(5) + *next*(6) + *next*(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33 In the second sample: *next*(7) = 7
500
[ { "input": "2 7", "output": "33" }, { "input": "7 7", "output": "7" }, { "input": "1 9", "output": "125" }, { "input": "4 7", "output": "25" }, { "input": "12 47", "output": "1593" }, { "input": "6 77", "output": "4012" }, { "input": "1 100...
1,592,835,592
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
307,200
l,r = map(int,input().split()) arr =[4,7] sumi=0 k=0 for i in range(0,9): for j in range(k,k+2**(i+1)): arr.append(arr[j]*10+4) arr.append(arr[j]*10+7) k=2**(i+1) while(l<=r): c=-1 if (l<=4): c=4 else: for i in range(1,len(arr)): print(i,arr[i],sep=" ") if (l<=arr[i] and l>arr[i-1]): ...
Title: Lucky Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let *...
```python l,r = map(int,input().split()) arr =[4,7] sumi=0 k=0 for i in range(0,9): for j in range(k,k+2**(i+1)): arr.append(arr[j]*10+4) arr.append(arr[j]*10+7) k=2**(i+1) while(l<=r): c=-1 if (l<=4): c=4 else: for i in range(1,len(arr)): print(i,arr[i],sep=" ") if (l<=arr[i] and l>a...
0
294
A
Shaass and Oskols
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*...
The first line of the input contains an integer *n*, (1<=≤<=*n*<=≤<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=≤<=*a**i*<=≤<=100). The third line contains an integer *m*, (0<=≤<=*m*<=≤<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i...
On the *i*-th line of the output print the number of birds on the *i*-th wire.
[ "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n", "3\n2 4 1\n1\n2 2\n" ]
[ "0\n12\n5\n0\n16\n", "3\n0\n3\n" ]
none
500
[ { "input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6", "output": "0\n12\n5\n0\n16" }, { "input": "3\n2 4 1\n1\n2 2", "output": "3\n0\n3" }, { "input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43", "output": "0\n66\n57\n7\n0" }, { "input": "10\n48 53 10 28 91 56 8...
1,572,769,979
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
26
280
307,200
def cal(x,y,l2): if x == 1: l2[x - 1] = l2[x - 1][y:] l2[x] = l2[x] + l2[x - 1] l2[x - 1] = [] elif x == len(l2): l2[x - 1] = l2[x - 1][:y - 1] l2[x - 2] = l2[x - 2] + l2[x - 1] l2[x - 1] = [] else: l2[x - 2] = l2[x - 2] + l2[x - 1][:y - 1] ...
Title: Shaass and Oskols Time Limit: None seconds Memory Limit: None megabytes Problem Description: Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each...
```python def cal(x,y,l2): if x == 1: l2[x - 1] = l2[x - 1][y:] l2[x] = l2[x] + l2[x - 1] l2[x - 1] = [] elif x == len(l2): l2[x - 1] = l2[x - 1][:y - 1] l2[x - 2] = l2[x - 2] + l2[x - 1] l2[x - 1] = [] else: l2[x - 2] = l2[x - 2] + l2[x - 1]...
-1
251
A
Points on Line
PROGRAMMING
1,300
[ "binary search", "combinatorics", "two pointers" ]
null
null
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*. Note that the order of the points inside the group of three chosen...
The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input stri...
Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "4 3\n1 2 3 4\n", "4 2\n-3 -2 -1 0\n", "5 19\n1 10 20 30 50\n" ]
[ "4\n", "2\n", "1\n" ]
In the first sample any group of three points meets our conditions. In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}. In the third sample only one group does: {1, 10, 20}.
500
[ { "input": "4 3\n1 2 3 4", "output": "4" }, { "input": "4 2\n-3 -2 -1 0", "output": "2" }, { "input": "5 19\n1 10 20 30 50", "output": "1" }, { "input": "10 5\n31 36 43 47 48 50 56 69 71 86", "output": "2" }, { "input": "10 50\n1 4 20 27 65 79 82 83 99 100", "...
1,565,360,750
2,147,483,647
Python 3
OK
TESTS
39
498
8,806,400
n , d = map(int , input().split(' ')) l = list(map(int ,input().split(' '))) ans = 0 i = 0 j = 0 while n>i : while l[i]-l[j] > d: # when the condition is not working make a step j +=1 ans += ((i-j)*(i-j-1))//2 i +=1 print(ans)
Title: Points on Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart...
```python n , d = map(int , input().split(' ')) l = list(map(int ,input().split(' '))) ans = 0 i = 0 j = 0 while n>i : while l[i]-l[j] > d: # when the condition is not working make a step j +=1 ans += ((i-j)*(i-j-1))//2 i +=1 print(ans) ```
3
982
C
Cut 'em all!
PROGRAMMING
1,500
[ "dfs and similar", "dp", "graphs", "greedy", "trees" ]
null
null
You're given a tree with $n$ vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size.
The first line contains an integer $n$ ($1 \le n \le 10^5$) denoting the size of the tree. The next $n - 1$ lines contain two integers $u$, $v$ ($1 \le u, v \le n$) each, describing the vertices connected by the $i$-th edge. It's guaranteed that the given edges form a tree.
Output a single integer $k$ — the maximum number of edges that can be removed to leave all connected components with even size, or $-1$ if it is impossible to remove edges in order to satisfy this property.
[ "4\n2 4\n4 1\n3 1\n", "3\n1 2\n1 3\n", "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5\n", "2\n1 2\n" ]
[ "1", "-1", "4", "0" ]
In the first example you can remove the edge between vertices $1$ and $4$. The graph after that will have two connected components with two vertices in each. In the second example you can't remove edges in such a way that all components have even number of vertices, so the answer is $-1$.
1,500
[ { "input": "4\n2 4\n4 1\n3 1", "output": "1" }, { "input": "3\n1 2\n1 3", "output": "-1" }, { "input": "10\n7 1\n8 4\n8 10\n4 7\n6 5\n9 3\n3 5\n2 10\n2 5", "output": "4" }, { "input": "2\n1 2", "output": "0" }, { "input": "1", "output": "-1" }, { "inpu...
1,551,171,480
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
from sys import stdin n = int(input()) g = [[] for _ in range(n)] def dfs(v, p=-1): res = 1 for to in g[v]: if to != p: res += dfs(to, v) return res for line in stdin: if line == '': break u, v = (int(x)-1 for x in line.split()) g[v].append(u) g[u].appe...
Title: Cut 'em all! Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a tree with $n$ vertices. Your task is to determine the maximum possible number of edges that can be removed in such a way that all the remaining connected components will have even size. Input Specification...
```python from sys import stdin n = int(input()) g = [[] for _ in range(n)] def dfs(v, p=-1): res = 1 for to in g[v]: if to != p: res += dfs(to, v) return res for line in stdin: if line == '': break u, v = (int(x)-1 for x in line.split()) g[v].append(u) ...
0
1,005
A
Tanya and Stairways
PROGRAMMING
800
[ "implementation" ]
null
null
Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For example, if she climbs two stairways, the first of which contains $3$ steps, and the second contains $4$ ...
The first line contains $n$ ($1 \le n \le 1000$) — the total number of numbers pronounced by Tanya. The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1000$) — all the numbers Tanya pronounced while climbing the stairs, in order from the first to the last pronounced number. Passing a stairway wit...
In the first line, output $t$ — the number of stairways that Tanya climbed. In the second line, output $t$ numbers — the number of steps in each stairway she climbed. Write the numbers in the correct order of passage of the stairways.
[ "7\n1 2 3 1 2 3 4\n", "4\n1 1 1 1\n", "5\n1 2 3 4 5\n", "5\n1 2 1 2 1\n" ]
[ "2\n3 4 ", "4\n1 1 1 1 ", "1\n5 ", "3\n2 2 1 " ]
none
0
[ { "input": "7\n1 2 3 1 2 3 4", "output": "2\n3 4 " }, { "input": "4\n1 1 1 1", "output": "4\n1 1 1 1 " }, { "input": "5\n1 2 3 4 5", "output": "1\n5 " }, { "input": "5\n1 2 1 2 1", "output": "3\n2 2 1 " }, { "input": "1\n1", "output": "1\n1 " }, { "inp...
1,645,714,263
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
46
0
n, a = int(input()), map(int, input().split()) li = [i for i, val in enumerate(a) if val == 1] print(len(li)) li += [7] print(*[y-x for x, y in zip(li, li[1:])])
Title: Tanya and Stairways Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Tanya climbs the stairs inside a multi-storey building. Every time Tanya climbs a stairway, she starts counting steps from $1$ to the number of steps in this stairway. She speaks every number aloud. For ...
```python n, a = int(input()), map(int, input().split()) li = [i for i, val in enumerate(a) if val == 1] print(len(li)) li += [7] print(*[y-x for x, y in zip(li, li[1:])]) ```
0
488
A
Giga Tower
PROGRAMMING
1,100
[ "brute force" ]
null
null
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it ...
The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109).
Print the minimum *b* in a line.
[ "179\n", "-1\n", "18\n" ]
[ "1\n", "9\n", "10\n" ]
For the first sample, he has to arrive at the floor numbered 180. For the second sample, he will arrive at 8. Note that *b* should be positive, so the answer for the third sample is 10, not 0.
500
[ { "input": "179", "output": "1" }, { "input": "-1", "output": "9" }, { "input": "18", "output": "10" }, { "input": "-410058385", "output": "1" }, { "input": "-586825624", "output": "1" }, { "input": "852318890", "output": "1" }, { "input": ...
1,630,497,244
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
61
6,963,200
x=float(input()) if x>=0: for i in range(1,11): c=i+x a=[] while (c>0): a.append(c%10) c=c//10 if 8 in a: print(i) break if x<0: x=(-1)*x for i in range(1, 11): c = x-i a = [] while (c>0):...
Title: Giga Tower Time Limit: None seconds Memory Limit: None megabytes Problem Description: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever...
```python x=float(input()) if x>=0: for i in range(1,11): c=i+x a=[] while (c>0): a.append(c%10) c=c//10 if 8 in a: print(i) break if x<0: x=(-1)*x for i in range(1, 11): c = x-i a = [] wh...
0
245
C
Game with Coins
PROGRAMMING
1,700
[ "greedy" ]
null
null
Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move a player is allowed to choose a positive integer *x* (2·*x...
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of chests with coins. The second line contains a sequence of space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the number of coins in the chest number *i* at the beginning of the game.
Print a single integer — the minimum number of moves needed to finish the game. If no sequence of turns leads to finishing the game, print -1.
[ "1\n1\n", "3\n1 2 3\n" ]
[ "-1\n", "3\n" ]
In the first test case there isn't a single move that can be made. That's why the players won't be able to empty the chests. In the second sample there is only one possible move *x* = 1. This move should be repeated at least 3 times to empty the third chest.
0
[ { "input": "1\n1", "output": "-1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "100\n269 608 534 956 993 409 297 735 258 451 468 422 125 407 580 769 857 383 419 67 377 230 842 113 169 427 287 75 372 133 456 450 644 303 638 40 217 445 427 730 168 341 371 633 237 951 142 596 528 5...
1,550,479,360
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
154
0
n=int(input()) l=[int(i) for i in input().split()] if max(l)<=2: print(-1) exit() l.sort() print(max(l))
Title: Game with Coins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two pirates Polycarpus and Vasily play a very interesting game. They have *n* chests with coins, the chests are numbered with integers from 1 to *n*. Chest number *i* has *a**i* coins. Polycarpus and Vasily move in tu...
```python n=int(input()) l=[int(i) for i in input().split()] if max(l)<=2: print(-1) exit() l.sort() print(max(l)) ```
0
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercise...
The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos...
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 ...
1,655,309,994
2,147,483,647
PyPy 3-64
OK
TESTS
61
1,028
22,425,600
#F - Greg`s Workout #https://vjudge.net/contest/499284#problem/F #Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times...
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ...
```python #F - Greg`s Workout #https://vjudge.net/contest/499284#problem/F #Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercis...
3
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. No...
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s...
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "outp...
1,589,428,657
2,147,483,647
PyPy 3
OK
TESTS
49
140
22,016,000
n,k=map(int,input().split()) if(k>0): l=list(map(int,input().split())) l.sort() c=0 if(k==0): print("YES") elif(l[0]==1 or l[-1]==n): print("NO") else: for i in range(2,k): if (l[i]-l[i-1]==1 and l[i-1]-l[i-2]==1): c=1 break if(c==0): print(...
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o...
```python n,k=map(int,input().split()) if(k>0): l=list(map(int,input().split())) l.sort() c=0 if(k==0): print("YES") elif(l[0]==1 or l[-1]==n): print("NO") else: for i in range(2,k): if (l[i]-l[i-1]==1 and l[i-1]-l[i-2]==1): c=1 break if(c==0): ...
3
169
A
Chores
PROGRAMMING
800
[ "sortings" ]
null
null
Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexit...
The first input line contains three integers *n*,<=*a* and *b* (2<=≤<=*n*<=≤<=2000; *a*,<=*b*<=≥<=1; *a*<=+<=*b*<==<=*n*) — the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=109), *h**i* ...
Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0.
[ "5 2 3\n6 2 3 100 1\n", "7 3 4\n1 1 9 1 1 1 1\n" ]
[ "3\n", "0\n" ]
In the first sample the possible values of *x* are 3, 4 or 5. In the second sample it is impossible to find such *x*, that Petya got 3 chores and Vasya got 4.
500
[ { "input": "5 2 3\n6 2 3 100 1", "output": "3" }, { "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0" }, { "input": "2 1 1\n10 2", "output": "8" }, { "input": "2 1 1\n7 7", "output": "0" }, { "input": "2 1 1\n1 1000000000", "output": "999999999" }, { "inp...
1,592,465,618
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
n,a,b=map(int,input().split()) l=list(map(int,input().split())) l=l.sort() a=a-1 i=l[a] j=l[a+1] if i==j: print(0) else: print(i-(j+1)+1)
Title: Chores Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter — its complexity. The complexity of th...
```python n,a,b=map(int,input().split()) l=list(map(int,input().split())) l=l.sort() a=a-1 i=l[a] j=l[a+1] if i==j: print(0) else: print(i-(j+1)+1) ```
-1
262
B
Roma and Changing Signs
PROGRAMMING
1,200
[ "greedy" ]
null
null
Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s...
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made. The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104). The numbers in the lines are separated by single spaces...
In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes.
[ "3 2\n-1 -1 1\n", "3 1\n-1 -1 1\n" ]
[ "3\n", "1\n" ]
In the first sample we can get sequence [1, 1, 1], thus the total income equals 3. In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1.
1,000
[ { "input": "3 2\n-1 -1 1", "output": "3" }, { "input": "3 1\n-1 -1 1", "output": "1" }, { "input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343", "output": "81852" }, { "input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89...
1,687,736,568
2,147,483,647
PyPy 3-64
OK
TESTS
56
186
13,721,600
n,k=map(int,input().split()) ll=list(map(int,input().split())) i,r=0,0 first=[] while i<n and k>0: if ll[i]<0: first.append(-ll[i]) i+=1 k-=1 else: break second=ll[i:] if k>0 and k&1: if first and second: t=first[-1] g=second[0] if t>g:...
Title: Roma and Changing Signs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ...
```python n,k=map(int,input().split()) ll=list(map(int,input().split())) i,r=0,0 first=[] while i<n and k>0: if ll[i]<0: first.append(-ll[i]) i+=1 k-=1 else: break second=ll[i:] if k>0 and k&1: if first and second: t=first[-1] g=second[0] ...
3
810
A
Straight <<A>>
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, wh...
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack.
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*.
[ "2 10\n8 9\n", "3 5\n4 4 4\n" ]
[ "4", "3" ]
Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc...
500
[ { "input": "2 10\n8 9", "output": "4" }, { "input": "3 5\n4 4 4", "output": "3" }, { "input": "3 10\n10 8 9", "output": "3" }, { "input": "2 23\n21 23", "output": "2" }, { "input": "5 10\n5 10 10 9 10", "output": "7" }, { "input": "12 50\n18 10 26 22 2...
1,583,659,458
2,147,483,647
Python 3
OK
TESTS
106
124
307,200
def check(m): return (s + k * m) * 2 >= (2 * k - 1) * (n + m) n, k = map(int,input().split()) a = list(map(int, input().split())) s = sum(a) l = -1 r = 10 ** 6 while l < r - 1: m = (l + r) // 2 if check(m): r = m else: l = m print(r)
Title: Straight <<A>> Time Limit: None seconds Memory Limit: None megabytes Problem Description: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. ...
```python def check(m): return (s + k * m) * 2 >= (2 * k - 1) * (n + m) n, k = map(int,input().split()) a = list(map(int, input().split())) s = sum(a) l = -1 r = 10 ** 6 while l < r - 1: m = (l + r) // 2 if check(m): r = m else: l = m print(r) ```
3
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and ...
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO"...
1,689,362,370
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
w = int(input("whats the weight?")) print("YES") if w%2 == 0 else print("NO")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python w = int(input("whats the weight?")) print("YES") if w%2 == 0 else print("NO") ```
0
735
B
Urbanization
PROGRAMMING
1,100
[ "greedy", "number theory", "sortings" ]
null
null
Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* of them is equal to *a**i*. Authorities plan to build two cities, first for *n*1 people and second ...
The first line of the input contains three integers *n*, *n*1 and *n*2 (1<=≤<=*n*,<=*n*1,<=*n*2<=≤<=100<=000, *n*1<=+<=*n*2<=≤<=*n*) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line conta...
Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your ...
[ "2 1 1\n1 5\n", "4 2 1\n1 4 2 3\n" ]
[ "6.00000000\n", "6.50000000\n" ]
In the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second. In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (*a*<sub class="lower-index">3</sub> + *a*<sub class=...
1,000
[ { "input": "2 1 1\n1 5", "output": "6.00000000" }, { "input": "4 2 1\n1 4 2 3", "output": "6.50000000" }, { "input": "3 1 2\n1 2 3", "output": "4.50000000" }, { "input": "10 4 6\n3 5 7 9 12 25 67 69 83 96", "output": "88.91666667" }, { "input": "19 7 12\n1 2 4 8 1...
1,658,310,507
2,147,483,647
PyPy 3-64
OK
TESTS
37
93
13,721,600
n,n1,n2=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() n1,n2=min(n1,n2),max(n1,n2) ans=0 res=0 for i in range(n1): ans+=arr.pop() ans=ans/n1 for j in range(n2): res+=arr.pop() res=res/n2 print(ans+res)
Title: Urbanization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are *n* people who plan to move to the cities. The wealth of the *i* o...
```python n,n1,n2=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() n1,n2=min(n1,n2),max(n1,n2) ans=0 res=0 for i in range(n1): ans+=arr.pop() ans=ans/n1 for j in range(n2): res+=arr.pop() res=res/n2 print(ans+res) ```
3
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s...
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi...
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGB...
1,599,866,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
154
0
n = int(input()) seq = 'ROYGBIV' se = 'OYGBI' r = n % 7 i = n // 7 result = '' for j in range(i): result+=seq result+=seq[:r] if result[0] == result[-1]: result = result[:-2] + se[(r+1)%5] print(result)
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: -...
```python n = int(input()) seq = 'ROYGBIV' se = 'OYGBI' r = n % 7 i = n // 7 result = '' for j in range(i): result+=seq result+=seq[:r] if result[0] == result[-1]: result = result[:-2] + se[(r+1)%5] print(result) ```
0
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ...
The first line contains string *a*, and the second line — string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd...
1,678,725,762
2,147,483,647
Python 3
OK
TESTS
73
46
102,400
n = input() m = input() ans = -1 if n == m else max(len(n), len(m)) print(ans)
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two ...
```python n = input() m = input() ans = -1 if n == m else max(len(n), len(m)) print(ans) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo...
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,640,792,197
2,147,483,647
PyPy 3-64
OK
TESTS
59
109
0
def fact(t): if(t==0): return 1 else: return t*fact(t-1) a,b=map(int,input().split()) print(fact(min(a,b)))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi...
```python def fact(t): if(t==0): return 1 else: return t*fact(t-1) a,b=map(int,input().split()) print(fact(min(a,b))) ```
3
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se...
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,689,593,934
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
x = int(input()) hate = "I hate" love = "I love" sep = 'that' end = 'it' result = [] for i in range(x): if i%2 == 0: result.append(love) else: result.append(hate) print(sep.join(result)+end)
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and...
```python x = int(input()) hate = "I hate" love = "I love" sep = 'that' end = 'it' result = [] for i in range(x): if i%2 == 0: result.append(love) else: result.append(hate) print(sep.join(result)+end) ```
0
629
D
Babaei and Birthday Cake
PROGRAMMING
2,000
[ "data structures", "dp" ]
null
null
As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake. Simple cake is a cylinder of some radius and height. The volume of the simple cake is equal to the volume of corresponding cylinder. Babaei has *n* simple cakes and he is going to make a special ...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of simple cakes Babaei has. Each of the following *n* lines contains two integers *r**i* and *h**i* (1<=≤<=*r**i*,<=*h**i*<=≤<=10<=000), giving the radius and height of the *i*-th cake.
Print the maximum volume of the cake that Babaei can make. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "2\n100 30\n40 10\n", "4\n1 1\n9 7\n1 4\n10 7\n" ]
[ "942477.796077000\n", "3983.539484752\n" ]
In first sample, the optimal way is to choose the cake number 1. In second sample, the way to get the maximum volume is to use cakes with indices 1, 2 and 4.
2,000
[ { "input": "2\n100 30\n40 10", "output": "942477.796077000" }, { "input": "4\n1 1\n9 7\n1 4\n10 7", "output": "3983.539484752" }, { "input": "3\n2 2\n1 1\n3 3", "output": "109.955742876" }, { "input": "3\n2 2\n3 3\n1 1", "output": "109.955742876" }, { "input": "3\...
1,456,629,632
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> #define LL long long #define mp make_pair #define pi 3.141592653589793 using namespace std; int n; set<pair<LL,LL>> s; int main() { cin>>n; s.insert(mp(0,0)); for(int i=1;i<=n;i++) { int x,y; cin>>x>>y; LL v = x*x*y; auto p=mp(v,0); auto next = s.upper_bound(p), prev...
Title: Babaei and Birthday Cake Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you know, every birthday party has a cake! This time, Babaei is going to prepare the very special birthday party's cake. Simple cake is a cylinder of some radius and height. The volume of the simple cake is...
```python #include <bits/stdc++.h> #define LL long long #define mp make_pair #define pi 3.141592653589793 using namespace std; int n; set<pair<LL,LL>> s; int main() { cin>>n; s.insert(mp(0,0)); for(int i=1;i<=n;i++) { int x,y; cin>>x>>y; LL v = x*x*y; auto p=mp(v,0); auto next = s.upper_boun...
-1