contestId
int64
0
1.01k
index
stringclasses
40 values
name
stringlengths
2
54
type
stringclasses
2 values
rating
int64
0
3.4k
tags
listlengths
0
7
title
stringclasses
393 values
time-limit
stringclasses
7 values
memory-limit
stringclasses
6 values
problem-description
stringlengths
0
2.97k
input-specification
stringlengths
4
1.87k
output-specification
stringlengths
4
1.12k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
3.5k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
1 value
testset
stringclasses
9 values
passedTestCount
int64
1
402
timeConsumedMillis
int64
15
8.06k
memoryConsumedBytes
int64
0
514M
code
stringlengths
11
61.4k
prompt
stringlengths
297
7.35k
response
stringlengths
25
61.4k
score
float64
2.82
3.99
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruitsΒ β€” ...
The first line contains the positive integer *a* (1<=≀<=*a*<=≀<=1000)Β β€” the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≀<=*b*<=≀<=1000)Β β€” the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≀<=*c*<=≀<=1000)Β β€” the number of pears Nikolay has...
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }...
1,642,993,767
2,147,483,647
PyPy 3-64
OK
TESTS
84
109
0
a=int(input()) b=int(input()) c=int(input()) maximumfactor=min(a, b//2, c//4) print(maximumfactor*7)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exa...
```python a=int(input()) b=int(input()) c=int(input()) maximumfactor=min(a, b//2, c//4) print(maximumfactor*7) ```
3
63
A
Sinking Ship
PROGRAMMING
900
[ "implementation", "sortings", "strings" ]
A. Sinking Ship
2
256
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri...
The first line contains an integer *n*, which is the number of people in the crew (1<=≀<=*n*<=≀<=100). Then follow *n* lines. The *i*-th of those lines contains two words β€” the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa...
Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship.
[ "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n" ]
[ "Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n" ]
none
500
[ { "input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack" }, { "input": "1\nA captain", "output": "A" }, { "input": "1\nAbcdefjhij captain", "output": "Abcdefjhij" }, { "input": "5\nA captain...
1,661,835,410
2,147,483,647
PyPy 3-64
OK
TESTS
26
124
0
t = int(input()) dct = {} for i in range(t): inp = input().split() dct[inp[0]] = inp[1] for k in dct.keys(): if(dct[k] == "rat"): print(k) for k in dct.keys(): if(dct[k] == "woman" or dct[k] == "child"): print(k) for k in dct.keys(): if(dct[k] == "man"): ...
Title: Sinking Ship Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ...
```python t = int(input()) dct = {} for i in range(t): inp = input().split() dct[inp[0]] = inp[1] for k in dct.keys(): if(dct[k] == "rat"): print(k) for k in dct.keys(): if(dct[k] == "woman" or dct[k] == "child"): print(k) for k in dct.keys(): if(dct[k] == "man...
3.969
0
none
none
none
0
[ "none" ]
null
null
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters.
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
[ "7\naogogob\n", "13\nogogmgogogogo\n", "9\nogoogoogo\n" ]
[ "a***b\n", "***gmg***\n", "*********\n" ]
The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
0
[ { "input": "7\naogogob", "output": "a***b" }, { "input": "13\nogogmgogogogo", "output": "***gmg***" }, { "input": "9\nogoogoogo", "output": "*********" }, { "input": "32\nabcdefogoghijklmnogoopqrstuvwxyz", "output": "abcdef***ghijklmn***opqrstuvwxyz" }, { "input":...
1,504,854,610
2,147,483,647
Python 3
OK
TESTS
48
62
0
##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) n = int(input()) s = input() res = '' i = 0 while i < n: update = False if i+2 < n: ss = s[i:i+3] if ss == 'ogo': j = i+3 while j+1 < n: sss = s[j:j...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo i...
```python ##n = int(input()) ##a = list(map(int, input().split())) ##print(" ".join(map(str, res))) n = int(input()) s = input() res = '' i = 0 while i < n: update = False if i+2 < n: ss = s[i:i+3] if ss == 'ogo': j = i+3 while j+1 < n: s...
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,687,277,602
2,147,483,647
Python 3
OK
TESTS
40
62
0
''' Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. ''' t=input() t2=input() re=t[::-1]...
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 ''' Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. ''' t=input() t2=input() ...
3.9845
698
A
Vacations
PROGRAMMING
1,400
[ "dp" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is close...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co...
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya ca...
500
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,546,159,913
2,147,483,647
Python 3
OK
TESTS
88
109
0
n = int(input()) line = [int(x) for x in input().split()] d = [0]*3 for i in line: d_1 = d[:] d[0] = min(d_1) + 1 if i == 1: d[1] = min(d_1[0], d_1[2]) d[2] = 10**6 elif i == 2: d[2] = min(d_1[0], d_1[1]) d[1] = 10**6 elif i == 3: d[1] = min(d_1[0...
Title: Vacations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int...
```python n = int(input()) line = [int(x) for x in input().split()] d = [0]*3 for i in line: d_1 = d[:] d[0] = min(d_1) + 1 if i == 1: d[1] = min(d_1[0], d_1[2]) d[2] = 10**6 elif i == 2: d[2] = min(d_1[0], d_1[1]) d[1] = 10**6 elif i == 3: d[1] =...
3
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of disks on the combination lock. The second line contains a string of *n* digitsΒ β€” the original state of the disks. The third line contains a string of *n* digitsΒ β€” Scrooge McDuck's combination that opens the lock.
Print a single integerΒ β€” the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32...
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { ...
1,607,078,014
2,147,483,647
Python 3
OK
TESTS
43
109
0
#540A n = int(input()) os = input() psswd = input() moves = 0 for i in range(n): x = abs(int(os[i])-int(psswd[i])) if x>=5: x = 10 - x moves+=x print(moves)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is ...
```python #540A n = int(input()) os = input() psswd = input() moves = 0 for i in range(n): x = abs(int(os[i])-int(psswd[i])) if x>=5: x = 10 - x moves+=x print(moves) ```
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,679,419,349
2,147,483,647
Python 3
OK
TESTS
40
92
0
s=input() t=input() y="" for i in range(len(s)): if s[i]==t[len(t)-1-i]: y+="YES" else: y+="NO" if "NO" in y: print("NO") else: print("YES")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python s=input() t=input() y="" for i in range(len(s)): if s[i]==t[len(t)-1-i]: y+="YES" else: y+="NO" if "NO" in y: print("NO") else: print("YES") ```
3.977
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f...
The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input...
1,692,399,961
2,147,483,647
PyPy 3-64
OK
TESTS
80
124
2,355,200
n=int(input()) listy=list(map(int,input().split())) counter=0 maxer=0 for i in range(len(listy)): counter = 0 if(i==0): for j in range(i,n-1): if(listy[j]>=listy[j+1]): counter += 1 else : break else: for j in range(i,n...
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *...
```python n=int(input()) listy=list(map(int,input().split())) counter=0 maxer=0 for i in range(len(listy)): counter = 0 if(i==0): for j in range(i,n-1): if(listy[j]>=listy[j+1]): counter += 1 else : break else: for j in...
3.964613
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i*Β β€” the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one numberΒ β€” the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,688,398,509
2,147,483,647
PyPy 3-64
OK
TESTS
30
1,107
9,318,400
n=int(input()) c=0 for i in range(n): a=str(input()).lower() if(a=="tetrahedron"): c+=4 elif(a=="cube"): c+=6 elif(a=="octahedron"): c+=8 elif(a=="dodecahedron"): c+=12 elif(a=="icosahedron"): c+=20 print(c)
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python n=int(input()) c=0 for i in range(n): a=str(input()).lower() if(a=="tetrahedron"): c+=4 elif(a=="cube"): c+=6 elif(a=="octahedron"): c+=8 elif(a=="dodecahedron"): c+=12 elif(a=="icosahedron"): c+=20 print(c) ```
3
600
B
Queries about less or equal elements
PROGRAMMING
1,300
[ "binary search", "data structures", "sortings", "two pointers" ]
null
null
You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*.
The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109).
Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*.
[ "5 4\n1 3 5 7 9\n6 4 2 8\n", "5 5\n1 2 1 2 5\n3 1 4 1 5\n" ]
[ "3 2 1 4\n", "4 2 4 2 5\n" ]
none
0
[ { "input": "5 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4" }, { "input": "5 5\n1 2 1 2 5\n3 1 4 1 5", "output": "4 2 4 2 5" }, { "input": "1 1\n-1\n-2", "output": "0" }, { "input": "1 1\n-80890826\n686519510", "output": "1" }, { "input": "11 11\n237468511 -77918754...
1,628,093,617
2,147,483,647
Python 3
OK
TESTS
60
733
26,726,400
import bisect a,b=map(int,input().split()) l1=[int(i) for i in input().split()] l2=[int(i) for i in input().split()] l1.sort() f=0 ans=[] low=0 high=a-1 mid=(low+high)//2 for i in l2: print(bisect.bisect_right(l1,i,0,a),end=" ")
Title: Queries about less or equal elements Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. In...
```python import bisect a,b=map(int,input().split()) l1=[int(i) for i in input().split()] l2=[int(i) for i in input().split()] l1.sort() f=0 ans=[] low=0 high=a-1 mid=(low+high)//2 for i in l2: print(bisect.bisect_right(l1,i,0,a),end=" ") ```
3
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=108). The second line contains a single integer *m* (1<=≀<=*m*<=≀<=108).
Output a single integerΒ β€” the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,699,494,063
2,147,483,647
Python 3
OK
TESTS
49
545
47,001,600
n= int(input()) m= int(input()) result = m % (2**n) print(result)
Title: Modular Exponentiation Time Limit: None seconds Memory Limit: None megabytes Problem Description: The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" prob...
```python n= int(input()) m= int(input()) result = m % (2**n) print(result) ```
3
1,009
A
Game Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy ...
The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the inp...
Print a single integer β€” the number of games Maxim will buy.
[ "5 4\n2 4 5 2 4\n5 3 4 6\n", "5 2\n20 40 50 20 40\n19 20\n", "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n" ]
[ "3\n", "0\n", "4\n" ]
The first example is described in the problem statement. In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop. In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter unti...
0
[ { "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3" }, { "input": "5 2\n20 40 50 20 40\n19 20", "output": "0" }, { "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4" }, { "input": "5 1\n1 1 1 1 1\n5", "output": "1" }, { "input": "5 1\n10 1 1 1 1\n...
1,534,425,046
346
Python 3
OK
TESTS
19
109
0
n , m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) bill = 0 ans = 0 for i in range(len(c)): if bill < len(a) and c[i] <= a[bill]: ans += 1 bill += 1 print(ans)
Title: Game Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the ...
```python n , m = map(int, input().split()) c = list(map(int, input().split())) a = list(map(int, input().split())) bill = 0 ans = 0 for i in range(len(c)): if bill < len(a) and c[i] <= a[bill]: ans += 1 bill += 1 print(ans) ```
3
859
A
Declined Finalists
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to travel to the office, though. Initially the top 25 contestants are invited to come onsite. Each eligible ...
The first line of input contains *K* (1<=≀<=*K*<=≀<=25), the number of onsite finalists you know. The second line of input contains *r*1,<=*r*2,<=...,<=*r**K* (1<=≀<=*r**i*<=≀<=106), the qualifying ranks of the finalists you know. All these ranks are distinct.
Print the minimum possible number of contestants that declined the invitation to compete onsite.
[ "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28\n", "5\n16 23 8 15 4\n", "3\n14 15 92\n" ]
[ "3\n", "0\n", "67\n" ]
In the first example, you know all 25 onsite finalists. The contestants who ranked 1-st, 13-th, and 27-th must have declined, so the answer is 3.
500
[ { "input": "25\n2 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 28", "output": "3" }, { "input": "5\n16 23 8 15 4", "output": "0" }, { "input": "3\n14 15 92", "output": "67" }, { "input": "1\n1000000", "output": "999975" }, { "input": "25\n1000000 ...
1,564,254,940
2,147,483,647
Python 3
OK
TESTS
25
109
0
int(input()) li = list(map(int, input().split())) a = max(li) b = a-25 if b < 0: print(0) else: print(b)
Title: Declined Finalists Time Limit: None seconds Memory Limit: None megabytes Problem Description: This year, as in previous years, MemSQL is inviting the top 25 competitors from the Start[c]up qualification round to compete onsite for the final round. Not everyone who is eligible to compete onsite can afford to t...
```python int(input()) li = list(map(int, input().split())) a = max(li) b = a-25 if b < 0: print(0) else: print(b) ```
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≀<=*n*<=≀<=100, 2<=≀<=*t*<=≀<=10) β€” the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, β€” the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,690,154,124
2,147,483,647
Python 3
OK
TESTS
65
46
0
n, t = list(map(int, input().split())) start = '1' + '0' * (n - 1) start = int(start) start_2 = start while True: if start % t == 0: print(start) break else: start += 1 if start == start_2 * 10: print(-1) break
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python n, t = list(map(int, input().split())) start = '1' + '0' * (n - 1) start = int(start) start_2 = start while True: if start % t == 0: print(start) break else: start += 1 if start == start_2 * 10: print(-1) break ```
3
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ...
The first line of input will be a single string *s* (1<=≀<=|*s*|<=≀<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,584,978,012
2,147,483,647
Python 3
OK
TESTS
28
108
0
s=input() l=[] l.append(s) j=0 while(j<len(s)-1): y="" y=s[len(s)-1] i=1 while(i<len(s)): y=y+s[i-1] i=i+1 if y not in l: l.append(y) s=y j=j+1 print(len(l))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to m...
```python s=input() l=[] l.append(s) j=0 while(j<len(s)-1): y="" y=s[len(s)-1] i=1 while(i<len(s)): y=y+s[i-1] i=i+1 if y not in l: l.append(y) s=y j=j+1 print(len(l)) ```
3
816
B
Karen and Coffee
PROGRAMMING
1,400
[ "binary search", "data structures", "implementation" ]
null
null
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee ...
The first line of input contains three integers, *n*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=200000), and *q* (1<=≀<=*q*<=≀<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe ...
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
[ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ]
[ "3\n3\n0\n4\n", "0\n" ]
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperatur...
1,000
[ { "input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4" }, { "input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0" }, { "input": "1 1 1\n1 1\n1 1", "output": "1" }, { "input": "1 1 1\n200000 200000\n200000 200000", "output": "1" ...
1,609,257,741
2,147,483,647
Python 3
OK
TESTS
45
779
18,739,200
import sys from itertools import accumulate def main(): itr=iter(sys.stdin) n,s,q=map(int,next(itr).split()) prefix_ranges=[0]*200002 for i in range(n): x,y=map(int,next(itr).split()) prefix_ranges[x]+=1 prefix_ranges[y+1]-=1 prefix_ranges=list(accumulate(prefix_ran...
Title: Karen and Coffee Time Limit: None seconds Memory Limit: None megabytes Problem Description: To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading seve...
```python import sys from itertools import accumulate def main(): itr=iter(sys.stdin) n,s,q=map(int,next(itr).split()) prefix_ranges=[0]*200002 for i in range(n): x,y=map(int,next(itr).split()) prefix_ranges[x]+=1 prefix_ranges[y+1]-=1 prefix_ranges=list(accumulate(...
3
96
A
Football
PROGRAMMING
900
[ "implementation", "strings" ]
A. Football
2
256
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If...
The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field.
Print "YES" if the situation is dangerous. Otherwise, print "NO".
[ "001001\n", "1000000001\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "001001", "output": "NO" }, { "input": "1000000001", "output": "YES" }, { "input": "00100110111111101", "output": "YES" }, { "input": "11110111111111111", "output": "YES" }, { "input": "01", "output": "NO" }, { "input": "10100101", "outp...
1,669,233,040
2,147,483,647
Python 3
OK
TESTS
44
92
0
x = input() last = x[0] counter = 0 for char in x: if char == last: counter += 1 if counter >= 7: break else: counter = 1 last = char if counter >= 7: print("YES") else: print("NO")
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A...
```python x = input() last = x[0] counter = 0 for char in x: if char == last: counter += 1 if counter >= 7: break else: counter = 1 last = char if counter >= 7: print("YES") else: print("NO") ```
3.977
639
A
Bear and Displayed Friends
PROGRAMMING
1,200
[ "implementation" ]
null
null
Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this value is, the better the friendship is. No two friends have the same value *t**i*. Spring is starting and the Wint...
The first line contains three integers *n*, *k* and *q* (1<=≀<=*n*,<=*q*<=≀<=150<=000,<=1<=≀<=*k*<=≀<=*min*(6,<=*n*))Β β€” the number of friends, the maximum number of displayed online friends and the number of queries, respectively. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=109) ...
For each query of the second type print one line with the answerΒ β€” "YES" (without quotes) if the given friend is displayed and "NO" (without quotes) otherwise.
[ "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3\n", "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3\n" ]
[ "NO\nYES\nNO\nYES\nYES\n", "NO\nYES\nNO\nYES\n" ]
In the first sample, Limak has 4 friends who all sleep initially. At first, the system displays nobody because nobody is online. There are the following 8 queries: 1. "1 3"Β β€” Friend 3 becomes online. 1. "2 4"Β β€” We should check if friend 4 is displayed. He isn't even online and thus we print "NO". 1. "2 3"Β β€” We shou...
500
[ { "input": "4 2 8\n300 950 500 200\n1 3\n2 4\n2 3\n1 1\n1 2\n2 1\n2 2\n2 3", "output": "NO\nYES\nNO\nYES\nYES" }, { "input": "6 3 9\n50 20 51 17 99 24\n1 3\n1 4\n1 5\n1 2\n2 4\n2 2\n1 1\n2 4\n2 3", "output": "NO\nYES\nNO\nYES" }, { "input": "6 3 10\n62417580 78150524 410053501 582708235 ...
1,599,657,586
2,147,483,647
PyPy 3
OK
TESTS
44
1,871
14,643,200
n,k,q = map(int,input().split()) t = list(map(int,input().split())) f=[] for i in range(q): a,b= map(int,input().split()) if a==1: if len(f)<k: f.append(t[b-1]) else: f.append(t[b-1]) f.sort() f=f[::-1][:k] ...
Title: Bear and Displayed Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He loves connecting with other bears via social networks. He has *n* friends and his relation with the *i*-th of them is described by a unique integer *t**i*. The bigger this val...
```python n,k,q = map(int,input().split()) t = list(map(int,input().split())) f=[] for i in range(q): a,b= map(int,input().split()) if a==1: if len(f)<k: f.append(t[b-1]) else: f.append(t[b-1]) f.sort() f=f[...
3
708
A
Letters Cyclic Shift
PROGRAMMING
1,200
[ "constructive algorithms", "greedy", "implementation", "strings" ]
null
null
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is ...
The only line of the input contains the string *s* (1<=≀<=|*s*|<=≀<=100<=000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
[ "codeforces\n", "abacaba\n" ]
[ "bncdenqbdr\n", "aaacaba\n" ]
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≀ *i* ≀ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i*...
500
[ { "input": "codeforces", "output": "bncdenqbdr" }, { "input": "abacaba", "output": "aaacaba" }, { "input": "babbbabaababbaa", "output": "aabbbabaababbaa" }, { "input": "bcbacaabcababaccccaaaabacbbcbbaa", "output": "abaacaabcababaccccaaaabacbbcbbaa" }, { "input": "...
1,592,472,282
2,147,483,647
Python 3
OK
TESTS
54
155
512,000
s=input() f=0 start=0 ans = '' for l in s: if l!='a' and f==0: ans+=chr(ord(l)-1) start=1 else: if l=='a' and start==1: f=1 ans += l if ans != s: print(ans) else: print(s[:-1]+'z')
Title: Letters Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each cha...
```python s=input() f=0 start=0 ans = '' for l in s: if l!='a' and f==0: ans+=chr(ord(l)-1) start=1 else: if l=='a' and start==1: f=1 ans += l if ans != s: print(ans) else: print(s[:-1]+'z') ```
3
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,...
The first line contains the single integer *n* (1<=≀<=*n*<=≀<=100). The second line contains *n* space-separated integers *r**i* (1<=≀<=*r**i*<=≀<=1000) β€” the circles' radii. It is guaranteed that all circles are different.
Print the single real number β€” total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the secon...
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output"...
1,620,056,730
2,147,483,647
PyPy 3
OK
TESTS
44
186
0
from math import pi n = int(input()) r = sorted(list(map(int,input().split()))) s = r[::-1] a=0 if n%2==0: for i in range(0,n-1,2): a+=s[i]**2-s[i+1]**2 else: a+=r[0]**2 for i in range(2,n,2): a+=r[i]**2-r[i-1]**2 print(pi*a)
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall in...
```python from math import pi n = int(input()) r = sorted(list(map(int,input().split()))) s = r[::-1] a=0 if n%2==0: for i in range(0,n-1,2): a+=s[i]**2-s[i+1]**2 else: a+=r[0]**2 for i in range(2,n,2): a+=r[i]**2-r[i-1]**2 print(pi*a) ```
3
177
D2
Encrypting Messages
PROGRAMMING
1,500
[ "data structures" ]
null
null
The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A message is a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Encryption uses a key which is a sequence ...
The first input line contains three integers *n*, *m* and *c*, separated by single spaces. The second input line contains *n* integers *a**i* (0<=≀<=*a**i*<=&lt;<=*c*), separated by single spaces β€” the original message. The third input line contains *m* integers *b**i* (0<=≀<=*b**i*<=&lt;<=*c*), separated by single...
Print *n* space-separated integers β€” the result of encrypting the original message.
[ "4 3 2\n1 1 1 1\n1 1 1\n", "3 1 5\n1 2 3\n4\n" ]
[ "0 1 1 0\n", "0 1 2\n" ]
In the first sample the encryption is performed in two steps: after the first step *a* = (0, 0, 0, 1) (remember that the calculations are performed modulo 2), after the second step *a* = (0, 1, 1, 0), and that is the answer.
70
[ { "input": "4 3 2\n1 1 1 1\n1 1 1", "output": "0 1 1 0" }, { "input": "3 1 5\n1 2 3\n4", "output": "0 1 2" }, { "input": "5 2 7\n0 0 1 2 4\n3 5", "output": "3 1 2 3 2" }, { "input": "20 15 17\n4 9 14 11 15 16 15 4 0 10 7 12 10 1 8 6 7 14 1 13\n6 3 14 8 8 11 16 4 5 9 2 13 6 14...
1,666,008,087
2,147,483,647
Python 3
OK
TESTS2
22
654
9,216,000
from email import message msgSize, keySize, modSize = map(int, input().split()) msg = list(map(int, input().split())) key = list(map(int, input().split())) prefix = [0 for _ in range(msgSize)] for i in range(keySize): prefix[i] += key[i] if (i + 1 < keySize): prefix[msgSize - keySize...
Title: Encrypting Messages Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Smart Beaver from ABBYY invented a new message encryption method and now wants to check its performance. Checking it manually is long and tiresome, so he decided to ask the ABBYY Cup contestants for help. A mes...
```python from email import message msgSize, keySize, modSize = map(int, input().split()) msg = list(map(int, input().split())) key = list(map(int, input().split())) prefix = [0 for _ in range(msgSize)] for i in range(keySize): prefix[i] += key[i] if (i + 1 < keySize): prefix[msgSize...
3
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≀<=*n*<=≀<=100,<=0<=≀<=*P*1,<=*P*2,<=*P*3<=≀<=100,<=1<=≀<=*T*1,<=*T*2<=≀<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≀<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,686,234,963
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
n, p1, p2, p3, t1, t2 = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] total = p1 * (a[0][1] - a[0][0]) for i in range(1, n): total += p1 * (a[i][1] - a[i][0]) delta = a[i][0] - a[i - 1][1] total += p1 * min(delta, t1) delta -= t1 total += max(0, min(delta,...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python n, p1, p2, p3, t1, t2 = map(int, input().split()) a = [list(map(int, input().split())) for i in range(n)] total = p1 * (a[0][1] - a[0][0]) for i in range(1, n): total += p1 * (a[i][1] - a[i][0]) delta = a[i][0] - a[i - 1][1] total += p1 * min(delta, t1) delta -= t1 total += max(0, ...
3.938
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≀<=*n*<=≀<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,574,447,189
2,147,483,647
PyPy 3
OK
TESTS
33
140
0
entrada = str(input()) digitos = len(entrada) possibilidades = int(2**digitos) limiteInferior = possibilidades - 1 limiteSuperior = limiteInferior*2 for d in entrada: #print(d, digitos, possibilidades, limiteInferior, limiteSuperior) if (possibilidades != 2): possibilidades = possibilidades//2 ...
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python entrada = str(input()) digitos = len(entrada) possibilidades = int(2**digitos) limiteInferior = possibilidades - 1 limiteSuperior = limiteInferior*2 for d in entrada: #print(d, digitos, possibilidades, limiteInferior, limiteSuperior) if (possibilidades != 2): possibilidades = possibilidades//...
3
835
B
The number on the board
PROGRAMMING
1,100
[ "greedy" ]
null
null
Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that the length of the number didn't change. You have to find the minimum number of digits in which these two numbe...
The first line contains integer *k* (1<=≀<=*k*<=≀<=109). The second line contains integer *n* (1<=≀<=*n*<=&lt;<=10100000). There are no leading zeros in *n*. It's guaranteed that this situation is possible.
Print the minimum number of digits in which the initial number and *n* can differ.
[ "3\n11\n", "3\n99\n" ]
[ "1\n", "0\n" ]
In the first example, the initial number could be 12. In the second example the sum of the digits of *n* is not less than *k*. The initial number could be equal to *n*.
750
[ { "input": "3\n11", "output": "1" }, { "input": "3\n99", "output": "0" }, { "input": "10\n5205602270", "output": "0" }, { "input": "70\n3326631213", "output": "6" }, { "input": "200\n100000001000000000000000000001000000000000000100000100000000000000000000000000000...
1,651,123,341
2,147,483,647
Python 3
OK
TESTS
48
78
102,400
K = int(input()) x = [0] * 10 for i in input(): i = int(i) K -= i x[i] += 1 t = 0 it = 0 while K > 0 and it != 9: i = min(K // (9 - it) + (1 if K % (9 - it) != 0 else 0), x[it]) K -= i * (9 - it) it += 1 t += i print(t)
Title: The number on the board Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some natural number was written on the board. Its sum of digits was not less than *k*. But you were distracted a bit, and someone changed this number to *n*, replacing some digits with others. It's known that th...
```python K = int(input()) x = [0] * 10 for i in input(): i = int(i) K -= i x[i] += 1 t = 0 it = 0 while K > 0 and it != 9: i = min(K // (9 - it) + (1 if K % (9 - it) != 0 else 0), x[it]) K -= i * (9 - it) it += 1 t += i print(t) ```
3
218
B
Airport
PROGRAMMING
1,100
[ "implementation" ]
null
null
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=&gt;<=0) empty seats at the given moment, then the ticket for such a plane ...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=1000) β€” the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≀<=*a**i*<=≀<=1000) β€” *a**i* stands for the number of empty seats in the *i*-th...
Print two integers β€” the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly.
[ "4 3\n2 1 1\n", "4 3\n2 2 2\n" ]
[ "5 5\n", "7 6\n" ]
In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum. In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person β€” to the 2-nd pl...
500
[ { "input": "4 3\n2 1 1", "output": "5 5" }, { "input": "4 3\n2 2 2", "output": "7 6" }, { "input": "10 5\n10 3 3 1 2", "output": "58 26" }, { "input": "10 1\n10", "output": "55 55" }, { "input": "10 1\n100", "output": "955 955" }, { "input": "10 2\n4 7...
1,452,431,112
2,147,483,647
Python 3
OK
TESTS
33
186
1,228,800
import queue; q = queue.PriorityQueue(); k, n = map(int, input().split()) a = sorted(list(map(int, input().split()))) q = queue.PriorityQueue(); for x in a: q.put(-x) mx = 0; mn = 0; for i in range(0, k): x = -q.get(); #print(q.qsize()) mx += x; q.put(-(x - 1)); cur = 0; for i in range(0, k):...
Title: Airport Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows: - it is up to a passenger to choose a plane to fly on; - if the chosen pl...
```python import queue; q = queue.PriorityQueue(); k, n = map(int, input().split()) a = sorted(list(map(int, input().split()))) q = queue.PriorityQueue(); for x in a: q.put(-x) mx = 0; mn = 0; for i in range(0, k): x = -q.get(); #print(q.qsize()) mx += x; q.put(-(x - 1)); cur = 0; for i in ra...
3
0
none
none
none
0
[ "none" ]
null
null
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the ...
First line of input contains single integer number *n* (2<=≀<=*n*<=≀<=100<=000) Β β€” number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≀<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence r...
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
[ "3\n1 1\n", "5\n1 2 2 2\n", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n" ]
[ "1\n", "3\n", "4\n" ]
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initial...
0
[ { "input": "3\n1 1", "output": "1" }, { "input": "5\n1 2 2 2", "output": "3" }, { "input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "output": "4" }, { "input": "2\n1", "output": "2" }, { "input": "3\n1 2", "output": "3" }, { "input": "20\n1 1 1 1 1 ...
1,566,116,345
3,185
Python 3
OK
TESTS
90
327
24,371,200
n = int(input()) P = [0, 0] + list(map(int, input().split())) deep = [0] * (n + 1) sons = [] for _ in range(n + 1): sons.append(set()) for i in range(2, n + 1): sons[P[i]].add(i) cnt = 1 s1 = {1} s2 = set() while s1: for v in s1: for u in sons[v]: s2.add(u) deep[u] = cnt ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near b...
```python n = int(input()) P = [0, 0] + list(map(int, input().split())) deep = [0] * (n + 1) sons = [] for _ in range(n + 1): sons.append(set()) for i in range(2, n + 1): sons[P[i]].add(i) cnt = 1 s1 = {1} s2 = set() while s1: for v in s1: for u in sons[v]: s2.add(u) deep[u] ...
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i*Β β€” the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one numberΒ β€” the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,674,664,206
2,147,483,647
Python 3
OK
TESTS
30
280
0
n=int(input()) c=0 for i in range(n): f=input() if(f=="Tetrahedron"): c=c+4 elif(f=="Cube"): c=c+6 elif(f=="Octahedron"): c=c+8 elif(f=="Dodecahedron"): c=c+12 ...
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python n=int(input()) c=0 for i in range(n): f=input() if(f=="Tetrahedron"): c=c+4 elif(f=="Cube"): c=c+6 elif(f=="Octahedron"): c=c+8 elif(f=="Dodecahedron"): c=c+12 ...
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (...
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }...
1,690,566,887
2,147,483,647
PyPy 3-64
OK
TESTS
106
93
20,275,200
n=int(input()) ll=list(map(int,input().split())) k=sum(ll)/2 c=0 for i in range(n): c+=ll[i] if c>=k: print(i+1) exit()
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve...
```python n=int(input()) ll=list(map(int,input().split())) k=sum(ll)/2 c=0 for i in range(n): c+=ll[i] if c>=k: print(i+1) exit() ```
3
466
A
Cheap Travel
PROGRAMMING
1,200
[ "implementation" ]
null
null
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu...
The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≀<=*n*,<=*m*,<=*a*,<=*b*<=≀<=1000) β€” the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket.
Print a single integer β€” the minimum sum in rubles that Ann will need to spend.
[ "6 2 1 2\n", "5 2 2 3\n" ]
[ "6\n", "8\n" ]
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets.
500
[ { "input": "6 2 1 2", "output": "6" }, { "input": "5 2 2 3", "output": "8" }, { "input": "10 3 5 1", "output": "4" }, { "input": "1000 1 1000 1000", "output": "1000000" }, { "input": "1000 3 1000 1000", "output": "334000" }, { "input": "1 1 1 1", "...
1,687,877,572
2,147,483,647
PyPy 3-64
OK
TESTS
19
46
0
n, m, a, b = map(int, input().split()) s = [] s.append(n * a) if n % m != 0: s.append((n // m + 1) * b ) s.append((n // m) * b + (n % m) * a) elif n % m == 0: s.append((n // m) * b ) print(min(s))
Title: Cheap Travel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl...
```python n, m, a, b = map(int, input().split()) s = [] s.append(n * a) if n % m != 0: s.append((n // m + 1) * b ) s.append((n // m) * b + (n % m) * a) elif n % m == 0: s.append((n // m) * b ) print(min(s)) ```
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,587,810,613
2,147,483,647
Python 3
OK
TESTS
102
109
307,200
n1=input() n2=input() n3='' a=len(n1) for i in range(a): if n1[i]=='0' and n2[i]=='0': n3=n3+'0' elif n1[i]=='0' and n2[i]=='1': n3=n3+'1' elif n1[i]=='1' an...
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 n1=input() n2=input() n3='' a=len(n1) for i in range(a): if n1[i]=='0' and n2[i]=='0': n3=n3+'0' elif n1[i]=='0' and n2[i]=='1': n3=n3+'1' elif n1[...
3.972178
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,689,161,546
2,147,483,647
Python 3
OK
TESTS
30
92
0
s=input() n=len(s)//2 d=s.upper() l=0 for i in range(len(s)): if d[i]<s[i] : l=l+1 if len(s)%2==0 : if l<(len(s)//2) : s=s.upper() else : s=s.lower() else : if l<=(len(s)//2) : s=s.upper() else : s=s.lower() print(s)
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() n=len(s)//2 d=s.upper() l=0 for i in range(len(s)): if d[i]<s[i] : l=l+1 if len(s)%2==0 : if l<(len(s)//2) : s=s.upper() else : s=s.lower() else : if l<=(len(s)//2) : s=s.upper() else : s=s.lower() print(s) ...
3.977
172
A
Phone Code
PROGRAMMING
800
[ "*special", "brute force", "implementation" ]
null
null
Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the...
The first line of the input contains an integer *n* (2<=≀<=*n*<=≀<=3Β·104) β€” the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* β€” the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, ...
Print the number of digits in the city phone code.
[ "4\n00209\n00219\n00999\n00909\n", "2\n1\n2\n", "3\n77012345678999999999\n77012345678901234567\n77012345678998765432\n" ]
[ "2\n", "0\n", "12\n" ]
A prefix of string *t* is a string that is obtained by deleting zero or more digits from the end of string *t*. For example, string "00209" has 6 prefixes: "" (an empty prefix), "0", "00", "002", "0020", "00209". In the first sample the city phone code is string "00". In the second sample the city phone code is an em...
1,000
[ { "input": "4\n00209\n00219\n00999\n00909", "output": "2" }, { "input": "2\n1\n2", "output": "0" }, { "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12" }, { "input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", ...
1,633,205,889
2,147,483,647
PyPy 3
OK
TESTS
28
624
25,497,600
n=int(input()) l=input() for i in range(n-1): a=input() for i in range(len(l)): if a[i]!=l[i]: l=a[:i] break print(len(l))
Title: Phone Code Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus...
```python n=int(input()) l=input() for i in range(n-1): a=input() for i in range(len(l)): if a[i]!=l[i]: l=a[:i] break print(len(l)) ```
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,595,760,255
2,147,483,647
Python 3
OK
TESTS
32
186
6,656,000
n=int(input()) l=list(map(int,input().split())) le=[i for i in l if i%2==0] lo=[i for i in l if i not in le] if len(le)==1: print(l.index(le[0])+1) else: print(l.index(lo[0])+1)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” t...
```python n=int(input()) l=list(map(int,input().split())) le=[i for i in l if i%2==0] lo=[i for i in l if i not in le] if len(le)==1: print(l.index(le[0])+1) else: print(l.index(lo[0])+1) ```
3.941102
560
B
Gerald is into Art
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
null
null
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an *a*1<=Γ—<=*b*1 rectangle, the paintings have shape of a *a*2<=Γ—<=*b*2 and *a*3<=Γ—<=*b*3 rec...
The first line contains two space-separated numbers *a*1 and *b*1 β€” the sides of the board. Next two lines contain numbers *a*2,<=*b*2,<=*a*3 and *b*3 β€” the sides of the paintings. All numbers *a**i*,<=*b**i* in the input are integers and fit into the range from 1 to 1000.
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
[ "3 2\n1 3\n2 1\n", "5 5\n3 3\n3 3\n", "4 2\n2 3\n1 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
That's how we can place the pictures in the first test: <img class="tex-graphics" src="https://espresso.codeforces.com/b41bf40c649073c6d3dd62eb7ae7adfc4bd131bd.png" style="max-width: 100.0%;max-height: 100.0%;"/> And that's how we can do it in the third one. <img class="tex-graphics" src="https://espresso.codeforces...
1,000
[ { "input": "3 2\n1 3\n2 1", "output": "YES" }, { "input": "5 5\n3 3\n3 3", "output": "NO" }, { "input": "4 2\n2 3\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 1", "output": "YES" }, { "input": "1000 1000\n999 999\n1 1000", "output": "YES" }, { "in...
1,437,576,248
2,648
Python 3
OK
TESTS
101
62
0
x, y = map(int, input().split(" ")) a2, b2 = map(int, input().split(" ")) a3, b3 = map(int, input().split(" ")) if (x>= a2+a3 and y >= b2 and y>= b3) or (x>= b2+b3 and y>= a2 and y>= a3) or (x >= a2+b3 and y >= a3 and y>= b2) or (x>=a3+b2 and y >= a2 and y >= b3) or (y>= a2+a3 and x >= b2 and x>= b3) or (y>= b2+b3...
Title: Gerald is into Art Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board ha...
```python x, y = map(int, input().split(" ")) a2, b2 = map(int, input().split(" ")) a3, b3 = map(int, input().split(" ")) if (x>= a2+a3 and y >= b2 and y>= b3) or (x>= b2+b3 and y>= a2 and y>= a3) or (x >= a2+b3 and y >= a3 and y>= b2) or (x>=a3+b2 and y >= a2 and y >= b3) or (y>= a2+a3 and x >= b2 and x>= b3) or ...
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,687,924,428
2,147,483,647
Python 3
OK
TESTS
43
46
0
n=list(map(int,list(input().strip()))) ans=0 if n[0]<9 and n[0]>4: ans=ans*10+(9-n[0]) else: ans=ans*10+n[0] for i in range(1,len(n)): if n[i]>4: ans=ans*10+(9-n[i]) else: ans=ans*10+n[i] print(ans)
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 n=list(map(int,list(input().strip()))) ans=0 if n[0]<9 and n[0]>4: ans=ans*10+(9-n[0]) else: ans=ans*10+n[0] for i in range(1,len(n)): if n[i]>4: ans=ans*10+(9-n[i]) else: ans=ans*10+n[i] print(ans) ```
3
799
C
Fountains
PROGRAMMING
1,800
[ "binary search", "data structures", "implementation" ]
null
null
Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can be either in coins or diamonds. No money changes between the types are all...
The first line contains three integers *n*, *c* and *d* (2<=≀<=*n*<=≀<=100<=000, 0<=≀<=*c*,<=*d*<=≀<=100<=000)Β β€” the number of fountains, the number of coins and diamonds Arkady has. The next *n* lines describe fountains. Each of these lines contain two integers *b**i* and *p**i* (1<=≀<=*b**i*,<=*p**i*<=≀<=100<=000)Β β€”...
Print the maximum total beauty of exactly two fountains Arkady can build. If he can't build two fountains, print 0.
[ "3 7 6\n10 8 C\n4 3 C\n5 6 D\n", "2 4 5\n2 5 C\n2 1 D\n", "3 10 10\n5 5 C\n5 5 C\n10 11 D\n" ]
[ "9\n", "0\n", "10\n" ]
In the first example Arkady should build the second fountain with beauty 4, which costs 3 coins. The first fountain he can't build because he don't have enough coins. Also Arkady should build the third fountain with beauty 5 which costs 6 diamonds. Thus the total beauty of built fountains is 9. In the second example t...
1,500
[ { "input": "3 7 6\n10 8 C\n4 3 C\n5 6 D", "output": "9" }, { "input": "2 4 5\n2 5 C\n2 1 D", "output": "0" }, { "input": "3 10 10\n5 5 C\n5 5 C\n10 11 D", "output": "10" }, { "input": "6 68 40\n1 18 D\n6 16 D\n11 16 D\n7 23 D\n16 30 D\n2 20 D", "output": "18" }, { ...
1,635,423,803
2,147,483,647
Python 3
OK
TESTS
79
233
16,793,600
import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') n, g, d = map(int, f.readline().split()) items = list() for _ in range(n): power, money, type_ = f.readline().strip().split() items.append(...
Title: Fountains Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are *n* available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so ea...
```python import sys def read_input(input_path=None): if input_path is None: f = sys.stdin else: f = open(input_path, 'r') n, g, d = map(int, f.readline().split()) items = list() for _ in range(n): power, money, type_ = f.readline().strip().split() ite...
3
298
B
Sail
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (*x*,<=*y*). - If the wind blows to the east, the boat will ...
The first line contains five integers *t*,<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y* (1<=≀<=*t*<=≀<=105,<=<=-<=109<=≀<=*s**x*,<=*s**y*,<=*e**x*,<=*e**y*<=≀<=109). The starting location and the ending location will be different. The second line contains *t* characters, the *i*-th character is the wind blowing direction at the...
If they can reach (*e**x*,<=*e**y*) within *t* seconds, print the earliest time they can achieve it. Otherwise, print "-1" (without quotes).
[ "5 0 0 1 1\nSESNW\n", "10 5 3 3 6\nNENSWESNEE\n" ]
[ "4\n", "-1\n" ]
In the first sample, they can stay at seconds 1, 3, and move at seconds 2, 4. In the second sample, they cannot sail to the destination.
500
[ { "input": "5 0 0 1 1\nSESNW", "output": "4" }, { "input": "10 5 3 3 6\nNENSWESNEE", "output": "-1" }, { "input": "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS", "output": "13" }, { "input": "39 -1000000000 -1000000000 -999999997 -1000000000\nENEENWSWSS...
1,545,858,713
2,147,483,647
Python 3
OK
TESTS
43
280
204,800
l,a,b,c,d=map(int, input().split()) s=input() t=0 for i in s: if i=='E' and a < c: a+=1 elif i=='W' and a > c: a-=1 elif i=='S' and b > d: b-=1 elif i == 'N' and b < d: b+=1 elif a==c and b==d: break t+=1 if a==c and b==d: print(t) else: print(-1) ...
Title: Sail Time Limit: None seconds Memory Limit: None megabytes Problem Description: The polar bears are going fishing. They plan to sail from (*s**x*,<=*s**y*) to (*e**x*,<=*e**y*). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assu...
```python l,a,b,c,d=map(int, input().split()) s=input() t=0 for i in s: if i=='E' and a < c: a+=1 elif i=='W' and a > c: a-=1 elif i=='S' and b > d: b-=1 elif i == 'N' and b < d: b+=1 elif a==c and b==d: break t+=1 if a==c and b==d: print(t) else: ...
3
883
F
Lost in Transliteration
PROGRAMMING
1,300
[ "implementation" ]
null
null
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
The first line contains integer number *n* (2<=≀<=*n*<=≀<=400) β€” number of the words in the list. The following *n* lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
[ "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "2\nalex\nalex\n" ]
[ "4\n", "5\n", "1\n" ]
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 1. "oolyana", "ulyana" 1. "kooooper", "koouper" 1. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "...
0
[ { "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4" }, { "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5" }, { "input": "2\nalex\nalex", "output": "1" }, { "input": ...
1,508,576,566
3,466
PyPy 3
OK
TESTS1
36
156
25,907,200
n = input() #print(n) names = set() for i in range(0, int(n)): s = input() while "kh" in s: s = s.replace("kh", "h") while "u" in s: s = s.replace("u", "oo") #print("->", s) #print(i) names.add(s) print(len(names))
Title: Lost in Transliteration Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For thi...
```python n = input() #print(n) names = set() for i in range(0, int(n)): s = input() while "kh" in s: s = s.replace("kh", "h") while "u" in s: s = s.replace("u", "oo") #print("->", s) #print(i) names.add(s) print(len(names)) ```
3
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n*Β (1<=≀<=*n*<=≀<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,685,822,642
2,147,483,647
Python 3
OK
TESTS
63
61
10,547,200
n = int(input()) events = list(map(int, input().split())) off, crim = 0, 0 for event in events: if event > 0: off += event else: if off > 0: off -= 1 else: crim += 1 print(crim)
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python n = int(input()) events = list(map(int, input().split())) off, crim = 0, 0 for event in events: if event > 0: off += event else: if off > 0: off -= 1 else: crim += 1 print(crim) ```
3
699
A
Launch of Collider
PROGRAMMING
1,000
[ "implementation" ]
null
null
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis...
The first line contains the positive integer *n* (1<=≀<=*n*<=≀<=200<=000)Β β€” the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right....
In the first line print the only integerΒ β€” the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
[ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n" ]
[ "1\n", "-1\n" ]
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
500
[ { "input": "4\nRLRL\n2 4 6 10", "output": "1" }, { "input": "3\nLLR\n40 50 60", "output": "-1" }, { "input": "4\nRLLR\n46 230 264 470", "output": "92" }, { "input": "6\nLLRLLL\n446 492 650 844 930 970", "output": "97" }, { "input": "8\nRRLLLLLL\n338 478 512 574 59...
1,536,559,080
2,147,483,647
Python 3
OK
TESTS
85
249
17,305,600
n=int(input()) p=list(input()) nop=list(map(int,input().split())) ro=[] for x in range(n-1): if p[x]=="R": if p[x+1]=="L": ro.append(nop[x+1]-nop[x]) else: pass else: pass if ro==list(): print(-1) else: print(min(ro)//2)
Title: Launch of Collider Time Limit: None seconds Memory Limit: None megabytes Problem Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be...
```python n=int(input()) p=list(input()) nop=list(map(int,input().split())) ro=[] for x in range(n-1): if p[x]=="R": if p[x+1]=="L": ro.append(nop[x+1]-nop[x]) else: pass else: pass if ro==list(): print(-1) else: print(min(ro)//2) ```
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,693,433,840
2,147,483,647
Python 3
OK
TESTS
20
62
0
# Read the weight of the watermelon w = int(input()) # Check if it's possible to divide it as per the conditions # Both parts should be even and positive if w > 2 and w % 2 == 0: print("YES") else: print("NO")
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin...
```python # Read the weight of the watermelon w = int(input()) # Check if it's possible to divide it as per the conditions # Both parts should be even and positive if w > 2 and w % 2 == 0: print("YES") else: print("NO") ```
3.969
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,633,941,678
2,147,483,647
PyPy 3
OK
TESTS
81
216
20,172,800
n=int(input()) net_x,net_y,net_z=0,0,0 for i in range(n): x,y,z=map(int,input().split()) net_x+=x net_y+=y net_z+=z if net_x==0 and net_y==0 and net_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()) net_x,net_y,net_z=0,0,0 for i in range(n): x,y,z=map(int,input().split()) net_x+=x net_y+=y net_z+=z if net_x==0 and net_y==0 and net_z==0: print("YES") else: print("NO") ```
3.908425
26
A
Almost Prime
PROGRAMMING
900
[ "number theory" ]
A. Almost Prime
2
256
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive.
Input contains one integer number *n* (1<=≀<=*n*<=≀<=3000).
Output the amount of almost prime numbers between 1 and *n*, inclusive.
[ "10\n", "21\n" ]
[ "2\n", "8\n" ]
none
500
[ { "input": "10", "output": "2" }, { "input": "21", "output": "8" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "4", "output": "0" }, { "input": "3", "output": "0" }, { "input": "8", "output": "1" }, ...
1,381,151,782
2,147,483,647
Python 3
OK
TESTS
23
592
0
def readln(inp=None): return tuple(map(int, (inp or input()).split())) n, = readln() def check(d): i = 2 while i * i <= d: if d % i == 0: return False i += 1 return True simple = [i for i in range(2, n + 1) if check(i)] ans = 0 for i in range(len(simple)): for j in range(i ...
Title: Almost Prime Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in...
```python def readln(inp=None): return tuple(map(int, (inp or input()).split())) n, = readln() def check(d): i = 2 while i * i <= d: if d % i == 0: return False i += 1 return True simple = [i for i in range(2, n + 1) if check(i)] ans = 0 for i in range(len(simple)): for j i...
3.852
897
A
Scarborough Fair
PROGRAMMING
800
[ "implementation" ]
null
null
Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get there. Willem asks his friend, Grick for directions, Grick helped them, and gave them a task. Althou...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). The second line contains a string *s* of length *n*, consisting of lowercase English letters. Each of the next *m* lines contains four parameters *l*,<=*r*,<=*c*1,<=*c*2 (1<=≀<=*l*<=≀<=*r*<=≀<=*n*, *c*1,<=*c*2 are lowercase English letters), ...
Output string *s* after performing *m* operations described above.
[ "3 1\nioi\n1 1 i n\n", "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g\n" ]
[ "noi", "gaaak" ]
For the second example: After the first operation, the string is wxxak. After the second operation, the string is waaak. After the third operation, the string is gaaak.
500
[ { "input": "3 1\nioi\n1 1 i n", "output": "noi" }, { "input": "5 3\nwxhak\n3 3 h x\n1 5 x a\n1 3 w g", "output": "gaaak" }, { "input": "9 51\nbhfbdcgff\n2 3 b b\n2 8 e f\n3 8 g f\n5 7 d a\n1 5 e b\n3 4 g b\n6 7 c d\n3 6 e g\n3 6 e h\n5 6 a e\n7 9 a c\n4 9 a h\n3 7 c b\n6 9 b g\n1 7 h b\n...
1,632,831,671
2,147,483,647
Python 3
OK
TESTS
47
77
6,758,400
m,t = map(int,input().split()) a = input() for i in range(t): b,c,d,e = input().split() b = int(b) c = int(c) a = a[:b-1]+(a[b-1:c]).replace(d,e)+a[c:] print(a)
Title: Scarborough Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Parsley, sage, rosemary and thyme. Remember me to one who lives there. He once was the true love of mine. Willem is taking the girl to the highest building in island No.28, however, neither of them knows how to get ...
```python m,t = map(int,input().split()) a = input() for i in range(t): b,c,d,e = input().split() b = int(b) c = int(c) a = a[:b-1]+(a[b-1:c]).replace(d,e)+a[c:] print(a) ```
3
496
C
Removing Columns
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You are given an *n*<=Γ—<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the table Β  we obtain the table: Β  A table is called...
The first line contains two integers Β β€” *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Next *n* lines contain *m* small English letters eachΒ β€” the characters of the table.
Print a single numberΒ β€” the minimum number of columns that you need to remove in order to make the table good.
[ "1 10\ncodeforces\n", "4 4\ncase\ncare\ntest\ncode\n", "5 4\ncode\nforc\nesco\ndefo\nrces\n" ]
[ "0\n", "2\n", "4\n" ]
In the first sample the table is already good. In the second sample you may remove the first and third column. In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition). Let strings *s* and *t* have equal length. Then, *s* is lexicographica...
1,750
[ { "input": "1 10\ncodeforces", "output": "0" }, { "input": "4 4\ncase\ncare\ntest\ncode", "output": "2" }, { "input": "5 4\ncode\nforc\nesco\ndefo\nrces", "output": "4" }, { "input": "2 2\nfb\nye", "output": "0" }, { "input": "5 5\nrzrzh\nrzrzh\nrzrzh\nrzrzh\nrzrz...
1,614,004,664
2,147,483,647
PyPy 3
OK
TESTS
49
124
1,843,200
import sys from collections import deque import math input_ = lambda: sys.stdin.readline().strip("\r\n") ii = lambda : int(input_()) il = lambda : list(map(int, input_().split())) ilf = lambda : list(map(float, input_().split())) ip = lambda : input_() fi = lambda : float(input_()) li = lambda : list(input_())...
Title: Removing Columns Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an *n*<=Γ—<=*m* rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For e...
```python import sys from collections import deque import math input_ = lambda: sys.stdin.readline().strip("\r\n") ii = lambda : int(input_()) il = lambda : list(map(int, input_().split())) ilf = lambda : list(map(float, input_().split())) ip = lambda : input_() fi = lambda : float(input_()) li = lambda : list...
3
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≀<=*i*<=≀<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment o...
The first line contains integer *n* (1<=≀<=*n*<=≀<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≀<=*a**i*<=≀<=109).
Print a single integer β€” the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,691,361,608
2,147,483,647
Python 3
OK
TESTS
28
93
14,233,600
from sys import stdin n = int(stdin.readline()) b = list(map(int,stdin.readline().split())) aCum = 1 z = 0 for i in range(1,n): if b[i-1]<= b[i]:aCum += 1 elif z < aCum: z = aCum;aCum = 1 else:aCum = 1 if aCum>z: print(aCum) else: print(z)
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≀<=*i*<=≀<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the l...
```python from sys import stdin n = int(stdin.readline()) b = list(map(int,stdin.readline().split())) aCum = 1 z = 0 for i in range(1,n): if b[i-1]<= b[i]:aCum += 1 elif z < aCum: z = aCum;aCum = 1 else:aCum = 1 if aCum>z: print(aCum) else: print(z) ```
3
14
A
Letter
PROGRAMMING
800
[ "implementation" ]
A. Letter
1
64
A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the w...
The first line of the input data contains numbers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=50), *n* β€” amount of lines, and *m* β€” amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character Β«.Β» stands for a non-shaded square on the sheet, and Β«*Β» β€” for a shaded square. It is guaranteed that ...
Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better.
[ "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..\n", "3 3\n***\n*.*\n***\n" ]
[ "***\n*..\n***\n*..\n***\n", "***\n*.*\n***\n" ]
none
0
[ { "input": "6 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "output": "***\n*..\n***\n*..\n***" }, { "input": "3 3\n***\n*.*\n***", "output": "***\n*.*\n***" }, { "input": "1 1\n*", "output": "*" }, { "input": "2 1\n*\n*", "output": "*\n*" }, { "input"...
1,663,291,632
2,147,483,647
Python 3
OK
TESTS
30
92
0
n, m = (int(i) for i in input().split()) s = [[c for c in input()] for _ in range(n)] min_r, max_r, min_c, max_c = n, -1, m, -1 for r in range(n): for c in range(m): if s[r][c] == "*": min_r, max_r = min(min_r, r), max(max_r, r) min_c, max_c = min(min_c, c), max(max_c, c) res = "\n"....
Title: Letter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brothe...
```python n, m = (int(i) for i in input().split()) s = [[c for c in input()] for _ in range(n)] min_r, max_r, min_c, max_c = n, -1, m, -1 for r in range(n): for c in range(m): if s[r][c] == "*": min_r, max_r = min(min_r, r), max(max_r, r) min_c, max_c = min(min_c, c), max(max_c, c) r...
3.954
894
A
QAQ
PROGRAMMING
800
[ "brute force", "dp" ]
null
null
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!). Bort wants to know how many subsequences "QAQ" are...
The only line contains a string of length *n* (1<=≀<=*n*<=≀<=100). It's guaranteed that the string only contains uppercase English letters.
Print a single integerΒ β€” the number of subsequences "QAQ" in the string.
[ "QAQAQYSYIOIWIN\n", "QAQQQZZYNOIWIN\n" ]
[ "4\n", "3\n" ]
In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".
500
[ { "input": "QAQAQYSYIOIWIN", "output": "4" }, { "input": "QAQQQZZYNOIWIN", "output": "3" }, { "input": "QA", "output": "0" }, { "input": "IAQVAQZLQBQVQFTQQQADAQJA", "output": "24" }, { "input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ", "output": "378" }, { ...
1,599,416,240
2,147,483,647
Python 3
OK
TESTS
43
124
0
s = input() ps = [0] * 105 for i in range(len(s)): ps[i + 1] = ps[i] if (s[i] == 'Q'): ps[i + 1] += 1 ans = 0 for i in range(len(s)): if (s[i] == 'A'): ans += ps[i] * (ps[len(s)] - ps[i]) print (ans)
Title: QAQ Time Limit: None seconds Memory Limit: None megabytes Problem Description: "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth. Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"...
```python s = input() ps = [0] * 105 for i in range(len(s)): ps[i + 1] = ps[i] if (s[i] == 'Q'): ps[i + 1] += 1 ans = 0 for i in range(len(s)): if (s[i] == 'A'): ans += ps[i] * (ps[len(s)] - ps[i]) print (ans) ```
3
84
A
Toy Army
PROGRAMMING
900
[ "math", "number theory" ]
A. Toy Army
2
256
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe...
The input data consist of a single integer *n* (2<=≀<=*n*<=≀<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields.
Print a single number β€” a maximum total number of soldiers that could be killed in the course of the game in three turns.
[ "2\n", "4\n" ]
[ "3\n", "6\n" ]
The first sample test: 1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1. 2) Arcady's soldier 2 shoots at Valera's soldier 1. 3) Valera's soldier 1 shoots at Arcady's soldier 2. There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2.
500
[ { "input": "2", "output": "3" }, { "input": "4", "output": "6" }, { "input": "6", "output": "9" }, { "input": "8", "output": "12" }, { "input": "10", "output": "15" }, { "input": "140", "output": "210" }, { "input": "500", "output": "75...
1,566,073,337
2,147,483,647
PyPy 3
OK
TESTS
23
310
0
def main(): n=int(input()) print(2*n-n//2) main()
Title: Toy Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows. There are two armies on t...
```python def main(): n=int(input()) print(2*n-n//2) main() ```
3.9225
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a progra...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=1000) β€” the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers β€” the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≀<=*t**i*<=≀<=2;Β *x...
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to t...
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1...
1,646,917,568
2,147,483,647
Python 3
OK
TESTS
13
62
0
a=b=0; for _ in [0]*int(input()): l,x,y=map(int,input().split()) if l==1:a+=x-y else:b+=x-y print('DLEIAVDE'[a>=0::2]) print('DLEIAVDE'[b>=0::2])
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping co...
```python a=b=0; for _ in [0]*int(input()): l,x,y=map(int,input().split()) if l==1:a+=x-y else:b+=x-y print('DLEIAVDE'[a>=0::2]) print('DLEIAVDE'[b>=0::2]) ```
3
911
D
Inversion Counting
PROGRAMMING
1,800
[ "brute force", "math" ]
null
null
A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* and *a**i*<=&lt;<=*a**j*. For example, a permutation [4,<=1,<=3,<=2] contains 4 inversions: (2,<=1), (3,<=...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=1500) β€” the size of the permutation. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=*n*) β€” the elements of the permutation. These integers are pairwise distinct. The third line contains one integer *m* (1<=≀<=*m*<=≀<=2Β·105) β€” the...
Print *m* lines. *i*-th of them must be equal to odd if the number of inversions in the permutation after *i*-th query is odd, and even otherwise.
[ "3\n1 2 3\n2\n1 2\n2 3\n", "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3\n" ]
[ "odd\neven\n", "odd\nodd\nodd\neven\n" ]
The first example: 1. after the first query *a* = [2, 1, 3], inversion: (2, 1); 1. after the second query *a* = [2, 3, 1], inversions: (3, 1), (3, 2). The second example: 1. *a* = [1, 2, 4, 3], inversion: (4, 3); 1. *a* = [3, 4, 2, 1], inversions: (3, 1), (4, 1), (3, 2), (4, 2), (4, 3); 1. *a* = [1, 2, 4, 3], i...
0
[ { "input": "3\n1 2 3\n2\n1 2\n2 3", "output": "odd\neven" }, { "input": "4\n1 2 4 3\n4\n1 1\n1 4\n1 4\n2 3", "output": "odd\nodd\nodd\neven" }, { "input": "7\n2 6 1 7 4 5 3\n5\n4 5\n7 7\n5 6\n4 5\n4 5", "output": "odd\nodd\neven\nodd\neven" }, { "input": "3\n2 1 3\n3\n2 3\n1 ...
1,584,735,958
2,147,483,647
PyPy 3
OK
TESTS
23
514
13,004,800
def arr_inp(): return [int(x) for x in stdin.readline().split()] def nCr(n, r): f, m = factorial, 1 for i in range(n, n - r, -1): m *= i return int(m // f(r)) from math import factorial from sys import stdin n, a, ans, tem = int(input()), arr_inp(), [], 0 mem = [0] * (n + 1) ...
Title: Inversion Counting Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of size *n* is an array of size *n* such that each integer from 1 to *n* occurs exactly once in this array. An inversion in a permutation *p* is a pair of indices (*i*,<=*j*) such that *i*<=&gt;<=*j* an...
```python def arr_inp(): return [int(x) for x in stdin.readline().split()] def nCr(n, r): f, m = factorial, 1 for i in range(n, n - r, -1): m *= i return int(m // f(r)) from math import factorial from sys import stdin n, a, ans, tem = int(input()), arr_inp(), [], 0 mem = [0] ...
3
984
A
Game
PROGRAMMING
800
[ "sortings" ]
null
null
Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i.Β e. $n - 1$ turns are made. The first player makes the first move, then players ...
The first line contains one integer $n$ ($1 \le n \le 1000$)Β β€” the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$).
Print one number that will be left on the board.
[ "3\n2 1 3\n", "3\n2 2 2\n" ]
[ "2", "2" ]
In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board. In the second sample, $2$ is left on the board regardless of the actions of the players.
500
[ { "input": "3\n2 1 3", "output": "2" }, { "input": "3\n2 2 2", "output": "2" }, { "input": "9\n44 53 51 80 5 27 74 79 94", "output": "53" }, { "input": "10\n38 82 23 37 96 4 81 60 67 86", "output": "60" }, { "input": "10\n58 26 77 15 53 81 68 48 22 65", "outpu...
1,601,379,137
2,147,483,647
Python 3
OK
TESTS
35
109
307,200
probs = int(input()) numbers = list(map(int, input().split(' '))) numbers.sort() out = 0 length = len(numbers) if length % 2 == 0: out = numbers[(length//2)-1] else: out = numbers[(length//2)] print(out)
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the...
```python probs = int(input()) numbers = list(map(int, input().split(' '))) numbers.sort() out = 0 length = len(numbers) if length % 2 == 0: out = numbers[(length//2)-1] else: out = numbers[(length//2)] print(out) ```
3
760
A
Petr and a calendar
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to ...
The only line contain two integers *m* and *d* (1<=≀<=*m*<=≀<=12, 1<=≀<=*d*<=≀<=7)Β β€” the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
[ "1 7\n", "1 1\n", "11 6\n" ]
[ "6\n", "5\n", "5\n" ]
The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
500
[ { "input": "1 7", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "2 1", "output": "4" }, { "input": "8 6", "output": "6" }, { "input": "1 1", "output...
1,606,388,827
2,147,483,647
PyPy 3
OK
TESTS
104
155
0
month, ref = [int(j) for j in input().split()] days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] count, day = 1, 1 while day < days[month - 1]: day += 1 ref += 1 if ref == 8: ref = 1 count += 1 print(count)
Title: Petr and a calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells...
```python month, ref = [int(j) for j in input().split()] days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] count, day = 1, 1 while day < days[month - 1]: day += 1 ref += 1 if ref == 8: ref = 1 count += 1 print(count) ```
3
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β€” the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,692,694,599
2,147,483,647
Python 3
OK
TESTS
101
92
0
n = int(input()) permutation = list(map(int, input().split())) inverse_permutation = [0] * n for i in range(n): inverse_permutation[permutation[i] - 1] = i + 1 print(" ".join(map(str, inverse_permutation)))
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n = int(input()) permutation = list(map(int, input().split())) inverse_permutation = [0] * n for i in range(n): inverse_permutation[permutation[i] - 1] = i + 1 print(" ".join(map(str, inverse_permutation))) ```
3
839
A
Arya and Bran
PROGRAMMING
900
[ "implementation" ]
null
null
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ...
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=100, 1<=≀<=*k*<=≀<=10000). The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100).
If it is impossible for Arya to give Bran *k* candies within *n* days, print -1. Otherwise print a single integerΒ β€” the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day.
[ "2 3\n1 2\n", "3 17\n10 10 10\n", "1 9\n10\n" ]
[ "2", "3", "-1" ]
In the first sample, Arya can give Bran 3 candies in 2 days. In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day. In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with...
500
[ { "input": "2 3\n1 2", "output": "2" }, { "input": "3 17\n10 10 10", "output": "3" }, { "input": "1 9\n10", "output": "-1" }, { "input": "10 70\n6 5 2 3 3 2 1 4 3 2", "output": "-1" }, { "input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",...
1,591,505,280
2,147,483,647
Python 3
OK
TESTS
60
109
307,200
n,k = input().split() n = int(n) k = int(k) a = input().split() a.insert(0,0) tuiA = 0 tuiB = 0 dainchua = 0 for i in range(1,n+1,1): tuiA+=int(a[i]) if k-tuiB >=8 and tuiA>=8: tuiA-=8 tuiB+=8 elif k-tuiB >=8 and tuiA<8: tuiB+=tuiA tuiA = 0 elif k-tuiB<8 a...
Title: Arya and Bran Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies. At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**...
```python n,k = input().split() n = int(n) k = int(k) a = input().split() a.insert(0,0) tuiA = 0 tuiB = 0 dainchua = 0 for i in range(1,n+1,1): tuiA+=int(a[i]) if k-tuiB >=8 and tuiA>=8: tuiA-=8 tuiB+=8 elif k-tuiB >=8 and tuiA<8: tuiB+=tuiA tuiA = 0 elif ...
3
454
A
Little Pony and Crystal Mine
PROGRAMMING
800
[ "implementation" ]
null
null
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=Γ—<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot...
The only line contains an integer *n* (3<=≀<=*n*<=≀<=101; *n* is odd).
Output a crystal of size *n*.
[ "3\n", "5\n", "7\n" ]
[ "*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n" ]
none
500
[ { "input": "3", "output": "*D*\nDDD\n*D*" }, { "input": "5", "output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**" }, { "input": "7", "output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***" }, { "input": "11", "output": "*****D*****\n****DDD****\n***DDDDD***\n**...
1,618,813,007
2,147,483,647
PyPy 3
OK
TESTS
12
171
9,318,400
# author: violist # created: 19.04.2021 07:52:27 import sys input = sys.stdin.readline n = int(input()) for i in range(1, n + 1): for j in range(1, n + 1): if (abs(i - (n // 2 + 1)) + abs(j - (n // 2 + 1)) <= n // 2): print("D", end = "") else: print("*", end = "") p...
Title: Little Pony and Crystal Mine Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=Γ—<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You ...
```python # author: violist # created: 19.04.2021 07:52:27 import sys input = sys.stdin.readline n = int(input()) for i in range(1, n + 1): for j in range(1, n + 1): if (abs(i - (n // 2 + 1)) + abs(j - (n // 2 + 1)) <= n // 2): print("D", end = "") else: print("*", end =...
3
0
none
none
none
0
[ "none" ]
null
null
You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replaced with the previous character of English alphabet and 'a' is replaced with 'z'. What is ...
The only line of the input contains the string *s* (1<=≀<=|*s*|<=≀<=100<=000) consisting of lowercase English letters.
Print the lexicographically minimum string that can be obtained from *s* by shifting letters of exactly one non-empty substring.
[ "codeforces\n", "abacaba\n" ]
[ "bncdenqbdr\n", "aaacaba\n" ]
String *s* is lexicographically smaller than some other string *t* of the same length if there exists some 1 ≀ *i* ≀ |*s*|, such that *s*<sub class="lower-index">1</sub> = *t*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub> = *t*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*i*...
0
[ { "input": "codeforces", "output": "bncdenqbdr" }, { "input": "abacaba", "output": "aaacaba" }, { "input": "babbbabaababbaa", "output": "aabbbabaababbaa" }, { "input": "bcbacaabcababaccccaaaabacbbcbbaa", "output": "abaacaabcababaccccaaaabacbbcbbaa" }, { "input": "...
1,654,213,700
2,147,483,647
Python 3
OK
TESTS
54
124
1,331,200
s = input() splited = [] first = 0 last = 0 fpos = 0 lpos = 0 for i in s: splited.append(i) for x in range(len(splited)): if splited[x] != "a" and first == 0: fpos = x first = 1 elif splited[x] == "a" and first == 1 and last == 0: last = 1 lpos = x break if first ==...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a non-empty string *s* consisting of lowercase English letters. You have to pick exactly one non-empty substring of *s* and shift all its letters 'z' 'y' 'x' 'b' 'a' 'z'. In other words, each character is replac...
```python s = input() splited = [] first = 0 last = 0 fpos = 0 lpos = 0 for i in s: splited.append(i) for x in range(len(splited)): if splited[x] != "a" and first == 0: fpos = x first = 1 elif splited[x] == "a" and first == 1 and last == 0: last = 1 lpos = x break i...
3
433
B
Kuriyama Mirai's Stones
PROGRAMMING
1,200
[ "dp", "implementation", "sortings" ]
null
null
Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r*Β (1<=≀<=*l*<=≀<=*r*...
The first line contains an integer *n*Β (1<=≀<=*n*<=≀<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n*Β (1<=≀<=*v**i*<=≀<=109) β€” costs of the stones. The third line contains an integer *m*Β (1<=≀<=*m*<=≀<=105) β€” the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains t...
Print *m* lines. Each line must contain an integer β€” the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input.
[ "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2\n" ]
[ "24\n9\n28\n", "10\n15\n5\n15\n5\n5\n2\n12\n3\n5\n" ]
Please note that the answers to the questions may overflow 32-bit integer type.
1,500
[ { "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28" }, { "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5" }, { "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1...
1,699,193,214
2,147,483,647
Python 3
OK
TESTS
46
483
24,371,200
if __name__ == '__main__': n = int(input()) arr = [int(i) for i in input().split()] m = int(input()) sorted_arr = sorted(arr) prefix_arr = [arr[0],] for i in range(n - 1): prefix_arr.append(prefix_arr[i] + arr[i+1]) prefix_sorted_arr = [sorted_arr[0],] for i in range(n - 1):...
Title: Kuriyama Mirai's Stones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones s...
```python if __name__ == '__main__': n = int(input()) arr = [int(i) for i in input().split()] m = int(input()) sorted_arr = sorted(arr) prefix_arr = [arr[0],] for i in range(n - 1): prefix_arr.append(prefix_arr[i] + arr[i+1]) prefix_sorted_arr = [sorted_arr[0],] for i in ran...
3
507
B
Amr and Pins
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b...
Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≀<=*r*<=≀<=105, <=-<=105<=≀<=*x*,<=*y*,<=*x*',<=*y*'<=≀<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.
Output a single integer β€” minimum number of steps required to move the center of the circle to the destination point.
[ "2 0 0 0 4\n", "1 1 1 4 4\n", "4 5 6 5 6\n" ]
[ "1\n", "3\n", "0\n" ]
In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter). <img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "2 0 0 0 4", "output": "1" }, { "input": "1 1 1 4 4", "output": "3" }, { "input": "4 5 6 5 6", "output": "0" }, { "input": "10 20 0 40 0", "output": "1" }, { "input": "9 20 0 40 0", "output": "2" }, { "input": "5 -1 -6 -5 1", "output": "...
1,650,903,597
2,147,483,647
PyPy 3-64
OK
TESTS
37
62
0
import math from sys import stdin, stdout input, print = stdin.readline, stdout.write def main(): r, x1, y1, x2, y2 = map(int, input().split()) dist = math.sqrt(abs(x2-x1)**2+abs(y2-y1)**2) ans = math.ceil(dist/(2*r)) print(str(ans) + "\n") if __name__ == "__main__": main()
Title: Amr and Pins Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*'). In one step Amr can ...
```python import math from sys import stdin, stdout input, print = stdin.readline, stdout.write def main(): r, x1, y1, x2, y2 = map(int, input().split()) dist = math.sqrt(abs(x2-x1)**2+abs(y2-y1)**2) ans = math.ceil(dist/(2*r)) print(str(ans) + "\n") if __name__ == "__main__": main(...
3
0
none
none
none
0
[ "none" ]
null
null
A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycleΒ β€” a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands *n* and 1. The center of each island contains an identical pedestal, and all but...
The first line contains a single integer *n* (2<=≀<=*n*<=≀<=200<=000)Β β€” the total number of islands. The second line contains *n* space-separated integers *a**i* (0<=≀<=*a**i*<=≀<=*n*<=-<=1)Β β€” the statue currently placed on the *i*-th island. If *a**i*<==<=0, then the island has no statue. It is guaranteed that the *a...
Print "YES" (without quotes) if the rearrangement can be done in the existing network, and "NO" otherwise.
[ "3\n1 0 2\n2 0 1\n", "2\n1 0\n0 1\n", "4\n1 2 3 0\n0 3 2 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
In the first sample, the islanders can first move statue 1 from island 1 to island 2, then move statue 2 from island 3 to island 1, and finally move statue 1 from island 2 to island 3. In the second sample, the islanders can simply move statue 1 from island 1 to island 2. In the third sample, no sequence of movements...
0
[ { "input": "3\n1 0 2\n2 0 1", "output": "YES" }, { "input": "2\n1 0\n0 1", "output": "YES" }, { "input": "4\n1 2 3 0\n0 3 2 1", "output": "NO" }, { "input": "9\n3 8 4 6 7 1 5 2 0\n6 4 8 5 3 1 2 0 7", "output": "NO" }, { "input": "4\n2 3 1 0\n2 0 1 3", "output"...
1,456,689,034
6,034
Python 3
OK
TESTS
61
327
18,739,200
#!/usr/bin/env python3 n = int(input()) a = [int(x) for x in input().split() if x != '0'] b = [int(x) for x in input().split() if x != '0'] # print(repr(a)) # print(repr(b)) for i in range(0, len(b)): if b[i] == a[0]: break # print('i == {0}'.format(i)) result = True k = 0 for j in range(i, len(b)): ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycleΒ β€” a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connect...
```python #!/usr/bin/env python3 n = int(input()) a = [int(x) for x in input().split() if x != '0'] b = [int(x) for x in input().split() if x != '0'] # print(repr(a)) # print(repr(b)) for i in range(0, len(b)): if b[i] == a[0]: break # print('i == {0}'.format(i)) result = True k = 0 for j in range(i, l...
3
591
A
Wizards' Duel
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and...
The first line of the input contains a single integer *l* (1<=≀<=*l*<=≀<=1<=000)Β β€” the length of the corridor where the fight takes place. The second line contains integer *p*, the third line contains integer *q* (1<=≀<=*p*,<=*q*<=≀<=500)Β β€” the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ...
Print a single real numberΒ β€” the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4. Namely: let's assume that your answer equals *a*, and the answer ...
[ "100\n50\n50\n", "199\n60\n40\n" ]
[ "50\n", "119.4\n" ]
In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor.
500
[ { "input": "100\n50\n50", "output": "50" }, { "input": "199\n60\n40", "output": "119.4" }, { "input": "1\n1\n1", "output": "0.5" }, { "input": "1\n1\n500", "output": "0.001996007984" }, { "input": "1\n500\n1", "output": "0.998003992" }, { "input": "1\n...
1,508,387,498
2,147,483,647
Python 3
OK
TESTS
45
62
5,529,600
l=int(input()) p=int(input()) q=int(input()) ans=(p*l)/(p+q) print(ans)
Title: Wizards' Duel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en...
```python l=int(input()) p=int(input()) q=int(input()) ans=(p*l)/(p+q) print(ans) ```
3
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,592,253,216
2,147,483,647
Python 3
OK
TESTS
35
124
0
n = int(input()) ans =1 n+=1 while(True): if('8' in str(n)): break n+=1 ans+=1 print(ans)
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 n = int(input()) ans =1 n+=1 while(True): if('8' in str(n)): break n+=1 ans+=1 print(ans) ```
3
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t...
The first and only input line contains two positive integers β€” *n* and *m* (2<=≀<=*n*<=&lt;<=*m*<=≀<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≀<=*n*<=&lt;<=*m*<=≀<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,592,732,191
2,147,483,647
Python 3
OK
TESTS
45
218
307,200
def sakurajima(n): if n < 9: return [0, 1, 1, 0, 1, 0, 1, 0] l = [1] * n for i in range(2, int(n ** 0.5) + 1): if l[i - 1] == 1: for j in range(i ** 2, n + 1, i): if j % i == 0: l[j - 1] = 0 l[0] = 0 return l def azusagawa(...
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater t...
```python def sakurajima(n): if n < 9: return [0, 1, 1, 0, 1, 0, 1, 0] l = [1] * n for i in range(2, int(n ** 0.5) + 1): if l[i - 1] == 1: for j in range(i ** 2, n + 1, i): if j % i == 0: l[j - 1] = 0 l[0] = 0 return l def ...
3.944928
574
A
Bear and Elections
PROGRAMMING
1,200
[ "greedy", "implementation" ]
null
null
Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elect...
The first line contains single integer *n* (2<=≀<=*n*<=≀<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate ...
Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate.
[ "5\n5 1 11 2 8\n", "4\n1 8 8 8\n", "2\n7 6\n" ]
[ "4\n", "6\n", "0\n" ]
In the first sample Limak has 5 votes. One of the ways to achieve victory is to bribe 4 citizens who want to vote for the third candidate. Then numbers of votes would be 9, 1, 7, 2, 8 (Limak would have 9 votes). Alternatively, Limak could steal only 3 votes from the third candidate and 1 vote from the second candidate ...
500
[ { "input": "5\n5 1 11 2 8", "output": "4" }, { "input": "4\n1 8 8 8", "output": "6" }, { "input": "2\n7 6", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "10\n100 200 57 99 1 1000 200 200 200 500", "output": "451" }, { "input": "16\...
1,448,739,579
2,147,483,647
Python 3
OK
TESTS
35
155
0
a=int(input()) b=input().split() for i in range(a): b[i]=int(b[i]) bribes=0 while b[0]!=max(b): for i in range(1,len(b)): if b[i]==max(b): b[i]-=1 b[0]+=1 bribes+=1 break true = False for i in range(1,len(b)): if b[i]==max(b): tr...
Title: Bear and Elections Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for e...
```python a=int(input()) b=input().split() for i in range(a): b[i]=int(b[i]) bribes=0 while b[0]!=max(b): for i in range(1,len(b)): if b[i]==max(b): b[i]-=1 b[0]+=1 bribes+=1 break true = False for i in range(1,len(b)): if b[i]==max(b): ...
3
327
A
Flipping Game
PROGRAMMING
1,200
[ "brute force", "dp", "implementation" ]
null
null
Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≀<=*i*<=≀<=*j*<=≀<=*n*) and flips all values *a**k* for which their positions are in...
The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1.
Print an integer β€” the maximal number of 1s that can be obtained after exactly one move.
[ "5\n1 0 0 1 0\n", "4\n1 0 0 1\n" ]
[ "4\n", "4\n" ]
In the first case, flip the segment from 2 to 5 (*i* = 2, *j* = 5). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1]. In the second case, flipping only the second and the third element (*i* = 2, *j* = 3) will turn all nu...
500
[ { "input": "5\n1 0 0 1 0", "output": "4" }, { "input": "4\n1 0 0 1", "output": "4" }, { "input": "1\n1", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "8\n1 0 0 0 1 0 0 0", "output": "7" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,696,360,291
2,147,483,647
PyPy 3-64
OK
TESTS
21
248
2,048,000
#JAI MATA DI ##### binary and decimal ##### # way to convert number to binary -------> bin(Number)[2:] # way to convert binary to number -------> int(n,2) ######################### #to get permutations of a string from itertools import permutations def allPermutations(str): permList = permutations(str) ...
Title: Flipping Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *...
```python #JAI MATA DI ##### binary and decimal ##### # way to convert number to binary -------> bin(Number)[2:] # way to convert binary to number -------> int(n,2) ######################### #to get permutations of a string from itertools import permutations def allPermutations(str): permList = permutat...
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≀<=<=*k*,<=*w*<=<=≀<=<=1000, 0<=≀<=*n*<=≀<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer β€” the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }...
1,698,683,451
2,147,483,647
Python 3
OK
TESTS
15
46
0
k,n,w=map(int,input().split()) x=0 for i in range(1,w+1,1): x+=k*i if n>=x: print(0) else: print(x-n)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana). He h...
```python k,n,w=map(int,input().split()) x=0 for i in range(1,w+1,1): x+=k*i if n>=x: print(0) else: print(x-n) ```
3
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya wi...
The first line contains a single integer $n$ ($1\leq n\leq 10^5$)Β β€” the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$)Β β€” the numbers in a row.
Print one numberΒ β€” the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,530,880,153
2,147,483,647
Python 3
OK
TESTS
42
374
10,240,000
n=int(input()) nums = list(map(int, input().split())) left = {} from collections import Counter left=Counter(nums) count = 0 done = set() for i in nums: left[i] -= 1 if left[i] == 0: del left[i] if i not in done: count += len(left.keys()) done.add(i) print(count)
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot ...
```python n=int(input()) nums = list(map(int, input().split())) left = {} from collections import Counter left=Counter(nums) count = 0 done = set() for i in nums: left[i] -= 1 if left[i] == 0: del left[i] if i not in done: count += len(left.keys()) done.add(i) print(c...
3
90
B
African Crossword
PROGRAMMING
1,100
[ "implementation", "strings" ]
B. African Crossword
2
256
An African crossword is a rectangular table *n*<=Γ—<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To solve the crossword you should cross out all repeated letters in rows and columns. In other words, a...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). Next *n* lines contain *m* lowercase Latin letters each. That is the crossword grid.
Print the encrypted word on a single line. It is guaranteed that the answer consists of at least one letter.
[ "3 3\ncba\nbcd\ncbc\n", "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf\n" ]
[ "abcd", "codeforces" ]
none
1,000
[ { "input": "3 3\ncba\nbcd\ncbc", "output": "abcd" }, { "input": "5 5\nfcofd\nooedo\nafaoa\nrdcdf\neofsf", "output": "codeforces" }, { "input": "4 4\nusah\nusha\nhasu\nsuha", "output": "ahhasusu" }, { "input": "7 5\naabcd\neffgh\niijkk\nlmnoo\npqqrs\nttuvw\nxxyyz", "output...
1,673,979,616
2,147,483,647
PyPy 3
OK
TESTS
43
216
2,969,600
from collections import Counter, defaultdict m, n = tuple(map(int, input().split())) mat = [] for i in range(m): mat.append(input()) row_count = {} for i in range(m): row_count[i] = Counter(mat[i]) col_count = {} for j in range(n): curr_count = defaultdict(int) for i in range(m): ...
Title: African Crossword Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: An African crossword is a rectangular table *n*<=Γ—<=*m* in size. Each cell of the table contains exactly one letter. This table (it is also referred to as grid) contains some encrypted word that needs to be decoded. To s...
```python from collections import Counter, defaultdict m, n = tuple(map(int, input().split())) mat = [] for i in range(m): mat.append(input()) row_count = {} for i in range(m): row_count[i] = Counter(mat[i]) col_count = {} for j in range(n): curr_count = defaultdict(int) for i in ra...
3.940469
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,650,391,659
2,147,483,647
Python 3
OK
TESTS
37
46
0
n,k=map(int,input().split()) a=n%k ans=n+k-a print(ans)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *...
```python n,k=map(int,input().split()) a=n%k ans=n+k-a print(ans) ```
3
513
A
Game
PROGRAMMING
800
[ "constructive algorithms", "math" ]
null
null
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2...
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output "First" if the first player wins and "Second" otherwise.
[ "2 2 1 2\n", "2 1 1 1\n" ]
[ "Second\n", "First\n" ]
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
3
[ { "input": "2 2 1 2", "output": "Second" }, { "input": "2 1 1 1", "output": "First" }, { "input": "5 7 4 1", "output": "Second" }, { "input": "5 7 1 4", "output": "Second" }, { "input": "5 7 10 10", "output": "Second" }, { "input": "5 7 1 10", "out...
1,511,362,833
2,147,483,647
Python 3
OK
TESTS
20
77
409,600
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/11/22 22:59 """ n1, n2, k1, k2 = map(int, input().split()) if n1 <= n2: print("Second") else: print("First")
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 ba...
```python # -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/11/22 22:59 """ n1, n2, k1, k2 = map(int, input().split()) if n1 <= n2: print("Second") else: print("First") `...
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,694,664,868
2,147,483,647
PyPy 3-64
OK
TESTS
20
46
0
n, m, a = map(int, input().split()) if round(m/a) < (m/a): height = round(m/a)+1 else: height = round(m/a) if round(n/a) < (n/a): width = round(n/a)+1 else: width = round(n/a) num_flagstones = width * height print(num_flagstones)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ—<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ...
```python n, m, a = map(int, input().split()) if round(m/a) < (m/a): height = round(m/a)+1 else: height = round(m/a) if round(n/a) < (n/a): width = round(n/a)+1 else: width = round(n/a) num_flagstones = width * height print(num_flagstones) ```
3.977
292
B
Network Topology
PROGRAMMING
1,200
[ "graphs", "implementation" ]
null
null
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them...
The first line contains two space-separated integers *n* and *m* (4<=≀<=*n*<=≀<=105;Β 3<=≀<=*m*<=≀<=105) β€” the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≀<=*x**i*,<=*...
In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo...
[ "4 3\n1 2\n2 3\n3 4\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "4 3\n1 2\n1 3\n1 4\n", "4 4\n1 2\n2 3\n3 1\n1 4\n" ]
[ "bus topology\n", "ring topology\n", "star topology\n", "unknown topology\n" ]
none
1,000
[ { "input": "4 3\n1 2\n2 3\n3 4", "output": "bus topology" }, { "input": "4 4\n1 2\n2 3\n3 4\n4 1", "output": "ring topology" }, { "input": "4 3\n1 2\n1 3\n1 4", "output": "star topology" }, { "input": "4 4\n1 2\n2 3\n3 1\n1 4", "output": "unknown topology" }, { "i...
1,697,898,833
2,147,483,647
PyPy 3-64
OK
TESTS
45
248
5,734,400
import sys input = lambda : sys.stdin.readline().rstrip() n, m = map(int, input().split()) deg = [0] * n for _ in range(m): u, v = [int(i) - 1 for i in input().split()] deg[u] += 1 deg[v] += 1 if deg.count(2) == n: print("ring topology") elif deg.count(1) == n - 1: print("star topology") ...
Title: Network Topology Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution. Polycarpus continues working as a system administrator in...
```python import sys input = lambda : sys.stdin.readline().rstrip() n, m = map(int, input().split()) deg = [0] * n for _ in range(m): u, v = [int(i) - 1 for i in input().split()] deg[u] += 1 deg[v] += 1 if deg.count(2) == n: print("ring topology") elif deg.count(1) == n - 1: print("star t...
3
248
A
Cupboards
PROGRAMMING
800
[ "implementation" ]
null
null
One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* woode...
The first input line contains a single integer *n* β€” the number of cupboards in the kitchen (2<=≀<=*n*<=≀<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≀<=*l**i*,<=*r**i*<=≀<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equal...
In the only output line print a single integer *t* β€” the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs.
[ "5\n0 1\n1 0\n0 1\n1 1\n0 1\n" ]
[ "3\n" ]
none
500
[ { "input": "5\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3" }, { "input": "2\n0 0\n0 0", "output": "0" }, { "input": "3\n0 1\n1 1\n1 1", "output": "1" }, { "input": "8\n0 1\n1 0\n0 1\n1 1\n0 1\n1 0\n0 1\n1 0", "output": "7" }, { "input": "8\n1 0\n1 0\n1 0\n0 1\n0 1\n1 ...
1,590,857,977
2,147,483,647
Python 3
OK
TESTS
57
248
1,024,000
n = int(input()) arr = [] count = 0 for i in range(n): arr.append(list(map(int, input().split()))) arr = list(zip(*arr)) for j in range(2): if sum(arr[j]) > n//2: count += n-sum(arr[j]) else: count += sum(arr[j]) print(count)
Title: Cupboards Time Limit: None seconds Memory Limit: None megabytes Problem Description: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any long...
```python n = int(input()) arr = [] count = 0 for i in range(n): arr.append(list(map(int, input().split()))) arr = list(zip(*arr)) for j in range(2): if sum(arr[j]) > n//2: count += n-sum(arr[j]) else: count += sum(arr[j]) print(count) ```
3
553
A
Kyoya and Colored Balls
PROGRAMMING
1,500
[ "combinatorics", "dp", "math" ]
null
null
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of...
The first line of input will have one integer *k* (1<=≀<=*k*<=≀<=1000) the number of colors. Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≀<=*c**i*<=≀<=1000). The total number of balls doesn't exceed 1000.
A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007.
[ "3\n2\n2\n1\n", "4\n1\n2\n3\n4\n" ]
[ "3\n", "1680\n" ]
In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are:
250
[ { "input": "3\n2\n2\n1", "output": "3" }, { "input": "4\n1\n2\n3\n4", "output": "1680" }, { "input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100", "output": "12520708" }, { "input": "5\n10\n10\n10\n10\n10", "output": "425711769" }, { "input": "11\n291\n3...
1,643,037,218
2,147,483,647
Python 3
OK
TESTS
27
46
0
k=int(input()) #number of colors c=[] for i in range(0,k): c.append(int(input())) #Ci m=1000000007 import math total=0 sum=1 for i in range(0,k): total=total+c[i] sum=sum*math.comb(total-1,c[i]-1) % m print(sum)
Title: Kyoya and Colored Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by o...
```python k=int(input()) #number of colors c=[] for i in range(0,k): c.append(int(input())) #Ci m=1000000007 import math total=0 sum=1 for i in range(0,k): total=total+c[i] sum=sum*math.comb(total-1,c[i]-1) % m print(sum) ```
3
746
D
Green and Black Tea
PROGRAMMING
1,500
[ "constructive algorithms", "greedy", "math" ]
null
null
Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black. Innokentiy doesn't like to drink the same tea (green or black) more than *k* times in a row. Your task is to determine the order ...
The first line contains four integers *n*, *k*, *a* and *b* (1<=≀<=*k*<=≀<=*n*<=≀<=105, 0<=≀<=*a*,<=*b*<=≀<=*n*)Β β€” the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that *a*<=+<=*b*<==<=*n*.
If it is impossible to drink *n* cups of tea, print "NO" (without quotes). Otherwise, print the string of the length *n*, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be ...
[ "5 1 3 2\n", "7 2 2 5\n", "4 3 4 0\n" ]
[ "GBGBG\n", "BBGBGBB", "NO\n" ]
none
2,000
[ { "input": "5 1 3 2", "output": "GBGBG" }, { "input": "7 2 2 5", "output": "BBGBBGB" }, { "input": "4 3 4 0", "output": "NO" }, { "input": "2 2 0 2", "output": "BB" }, { "input": "3 2 0 3", "output": "NO" }, { "input": "1 1 0 1", "output": "B" },...
1,624,378,617
2,147,483,647
PyPy 3
OK
TESTS
50
904
10,547,200
n,k,a,b=map(int,input().split()) x=min(a,b) y=max(a,b) if x==a: L='G' H='B' else: H='G' L='B' if y>(x+1)*k: print("NO") else: q=y//(x+1) w=y%(x+1) g=H*q ans="" i=0 while(i<n): ans+=g i+=q if(w): ans+=H w-=1 i+=1 ans+=L i+=1 print(ans[:n])
Title: Green and Black Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy likes tea very much and today he wants to drink exactly *n* cups of tea. He would be happy to drink more but he had exactly *n* tea bags, *a* of them are green and *b* are black. Innokentiy doesn't like ...
```python n,k,a,b=map(int,input().split()) x=min(a,b) y=max(a,b) if x==a: L='G' H='B' else: H='G' L='B' if y>(x+1)*k: print("NO") else: q=y//(x+1) w=y%(x+1) g=H*q ans="" i=0 while(i<n): ans+=g i+=q if(w): ans+=H w-=1 i+=1 ans+=L i+=1 print(ans[:n]) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
The first line contains a word *s* β€” it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,638,592,264
2,147,483,647
Python 3
OK
TESTS
30
92
0
s=input() k=len(s) l_count=0 u_count=0 for i in range(k): if s[i].islower(): l_count=l_count+1 else: u_count=u_count+1 if u_count>l_count: print(s.upper()) elif l_count>=u_count: print(s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei...
```python s=input() k=len(s) l_count=0 u_count=0 for i in range(k): if s[i].islower(): l_count=l_count+1 else: u_count=u_count+1 if u_count>l_count: print(s.upper()) elif l_count>=u_count: print(s.lower()) ```
3.977
353
A
Domino
PROGRAMMING
1,200
[ "implementation", "math" ]
null
null
Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do...
The first line contains integer *n* (1<=≀<=*n*<=≀<=100), denoting the number of dominoes Valera has. Next *n* lines contain two space-separated integers *x**i*,<=*y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=6). Number *x**i* is initially written on the upper half of the *i*-th domino, *y**i* is initially written on the lower half...
Print a single number β€” the minimum required number of seconds. If Valera can't do the task in any time, print <=-<=1.
[ "2\n4 2\n6 4\n", "1\n2 3\n", "3\n1 4\n2 3\n4 4\n" ]
[ "0\n", "-1\n", "1\n" ]
In the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything. In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the...
500
[ { "input": "2\n4 2\n6 4", "output": "0" }, { "input": "1\n2 3", "output": "-1" }, { "input": "3\n1 4\n2 3\n4 4", "output": "1" }, { "input": "5\n5 4\n5 4\n1 5\n5 5\n3 3", "output": "1" }, { "input": "20\n1 3\n5 2\n5 2\n2 6\n2 4\n1 1\n1 3\n1 4\n2 6\n4 2\n5 6\n2 2\n...
1,589,631,887
2,147,483,647
PyPy 3
OK
TESTS
59
312
20,172,800
n = int(input()) numOfDiff = 0 sumX = 0 sumY = 0 for i in range(n): x, y = map(int, input().split()) if (x % 2 == 0 and y % 2 != 0) or (x % 2 != 0 and y % 2 == 0): numOfDiff += 1 sumX += x sumY += y if sumX % 2 == 0 and sumY % 2 == 0: print(0) elif (sumX % 2 == 0 and sumY % 2 != 0) or (sumX ...
Title: Domino Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera has got *n* domino pieces in a row. Each piece consists of two halves β€” the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the n...
```python n = int(input()) numOfDiff = 0 sumX = 0 sumY = 0 for i in range(n): x, y = map(int, input().split()) if (x % 2 == 0 and y % 2 != 0) or (x % 2 != 0 and y % 2 == 0): numOfDiff += 1 sumX += x sumY += y if sumX % 2 == 0 and sumY % 2 == 0: print(0) elif (sumX % 2 == 0 and sumY % 2 != 0)...
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,688,635,932
2,147,483,647
Python 3
OK
TESTS
59
46
0
import math a,b = map(int, input().split()) v = min(a,b) print(math.factorial(v)) # Thu Jul 06 2023 12:32:12 GMT+0300 (Moscow Standard Time)
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 import math a,b = map(int, input().split()) v = min(a,b) print(math.factorial(v)) # Thu Jul 06 2023 12:32:12 GMT+0300 (Moscow Standard Time) ```
3
171
G
Mysterious numbers - 2
PROGRAMMING
1,600
[ "*special" ]
null
null
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≀<=*a*1,<=*a*2,<=*a*3<=≀<=20), separated by spaces. Output a single integer.
The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≀<=*a*1,<=*a*2,<=*a*3<=≀<=20), separated by spaces.
Output a single integer.
[ "2 3 2\n", "13 14 1\n", "14 5 9\n", "17 18 3\n" ]
[ "5\n", "14\n", "464\n", "53\n" ]
none
0
[ { "input": "2 3 2", "output": "5" }, { "input": "13 14 1", "output": "14" }, { "input": "14 5 9", "output": "464" }, { "input": "17 18 3", "output": "53" }, { "input": "1 1 1", "output": "1" }, { "input": "4 6 7", "output": "110" }, { "inpu...
1,691,982,452
2,147,483,647
PyPy 3-64
OK
TESTS
15
124
0
from sys import stdin,stdout # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations,islice # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(int(1e5)) ...
Title: Mysterious numbers - 2 Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only line of input contains three integers *a*1,<=*a*2,<=*a*3 (1<=≀<=*a*1,<=*a*2,<=*a*3<=≀<=20), separated by spaces. Output a single integer. Input Specification: The only line of input contains three inte...
```python from sys import stdin,stdout # from bisect import bisect_left,bisect # from heapq import heapify,heappop,heappush # from sys import setrecursionlimit # from collections import defaultdict,Counter # from itertools import permutations,islice # from math import gcd,ceil,sqrt,factorial # setrecursionlimit(...
3
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ...
The first line of the input contains a positive integer *n* (1<=≀<=*n*<=≀<=2Β·109) β€” the length of Pasha's stick.
The output should contain a single integerΒ β€” the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "4...
1,451,674,389
4,389
Python 3
OK
TESTS
76
62
0
n = int(input()) answer = 0 k = n // 2 if k*2 == n: answer = (k-1) // 2 print(answer)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv...
```python n = int(input()) answer = 0 k = n // 2 if k*2 == n: answer = (k-1) // 2 print(answer) ```
3
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=Γ—<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and m...
The first line contains two space-separated integers *n* and *m* (2<=≀<=*n*,<=*m*<=≀<=100) β€” the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters β€” the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A charact...
Print two integers β€” the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......
1,453,488,969
2,147,483,647
Python 3
OK
TESTS
36
124
0
n, m = tuple(map(int, input().strip().split(" "))) arr = [] minX = 1000 minY = 1000 maxX = -1 maxY = -1 for _ in range(n): for j, ch in enumerate(input().strip()): if ch == "*": minX = min(minX, _) minY = min(minY, j) maxX = max(maxX, _) maxY...
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 = tuple(map(int, input().strip().split(" "))) arr = [] minX = 1000 minY = 1000 maxX = -1 maxY = -1 for _ in range(n): for j, ch in enumerate(input().strip()): if ch == "*": minX = min(minX, _) minY = min(minY, j) maxX = max(maxX, _) ...
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,651,953,293
2,147,483,647
Python 3
OK
TESTS
32
92
0
n = int(input()) a = input().split() a = [int(i) for i in a] f = 0 l = 0 for i in a: if i % 2 == 0: f += 1 else: l += 1 if f > l: for i in range(len(a)): if a[i] % 2 != 0: print(i + 1) else: for i in range(len(a)): if a[i] % 2 == 0: ...
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β€” t...
```python n = int(input()) a = input().split() a = [int(i) for i in a] f = 0 l = 0 for i in a: if i % 2 == 0: f += 1 else: l += 1 if f > l: for i in range(len(a)): if a[i] % 2 != 0: print(i + 1) else: for i in range(len(a)): if a[i] % 2 == 0: ...
3.977
496
A
Minimum Difficulty
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,...
The first line contains a single integer *n* (3<=≀<=*n*<=≀<=100)Β β€” the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≀<=*a**i*<=≀<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict...
Print a single number β€” the minimum difficulty of the track after removing a single hold.
[ "3\n1 4 6\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n" ]
[ "5\n", "2\n", "4\n" ]
In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5. In the second test after removing every hold the difficulty equals 2. In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic...
500
[ { "input": "3\n1 4 6", "output": "5" }, { "input": "5\n1 2 3 4 5", "output": "2" }, { "input": "5\n1 2 3 7 8", "output": "4" }, { "input": "3\n1 500 1000", "output": "999" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2" }, { "input": "10\n1 4 9...
1,660,895,278
2,147,483,647
Python 3
OK
TESTS
19
46
0
n = int(input()) a = list(map(int, input().split())) b = list() diff = 0 for i in range(1, len(a)-1): diff = a[i+1] - a[i-1] b.append(diff) id = b.index(min(b)) a.remove(a[id+1]) d = list() for j in range(1, len(a)): diff = a[j]-a[j-1] d.append(diff) print(max(d))
Title: Minimum Difficulty Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 fo...
```python n = int(input()) a = list(map(int, input().split())) b = list() diff = 0 for i in range(1, len(a)-1): diff = a[i+1] - a[i-1] b.append(diff) id = b.index(min(b)) a.remove(a[id+1]) d = list() for j in range(1, len(a)): diff = a[j]-a[j-1] d.append(diff) print(max(d)) ```
3
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,648,539,686
2,147,483,647
PyPy 3
OK
TESTS
24
93
1,945,600
n = int(input()) arr = input() coord = [0,0] ans= 0 if arr[0] == "U": kingdom = 2 else: kingdom = 1 for i in range(n-1): if arr[i] == "U": coord[1]+= 1 else: coord[0]+= 1 if coord[0] == coord[1]: if kingdom == 2 and arr[i+1] == "R": ...
Title: Fafa and the Gates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin. The w...
```python n = int(input()) arr = input() coord = [0,0] ans= 0 if arr[0] == "U": kingdom = 2 else: kingdom = 1 for i in range(n-1): if arr[i] == "U": coord[1]+= 1 else: coord[0]+= 1 if coord[0] == coord[1]: if kingdom == 2 and arr[i+1] == "R": ...
3
750
A
New Year and Hurry
PROGRAMMING
800
[ "binary search", "brute force", "implementation", "math" ]
null
null
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5Β·*i* minutes to solve th...
The only line of the input contains two integers *n* and *k* (1<=≀<=*n*<=≀<=10, 1<=≀<=*k*<=≀<=240)Β β€” the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house.
Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.
[ "3 222\n", "4 190\n", "7 1\n" ]
[ "2\n", "4\n", "7\n" ]
In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar...
500
[ { "input": "3 222", "output": "2" }, { "input": "4 190", "output": "4" }, { "input": "7 1", "output": "7" }, { "input": "10 135", "output": "6" }, { "input": "10 136", "output": "5" }, { "input": "1 1", "output": "1" }, { "input": "1 240", ...
1,676,652,038
2,147,483,647
PyPy 3-64
OK
TESTS
52
62
0
from math import floor, sqrt def solution(): n, k = map(int, input().split(' ')) time = 4 * 60 - k ans = floor((sqrt(1 + 8 / 5 * time) - 1 )/ 2) return floor(ans) if ans < n else n print(solution())
Title: New Year and Hurry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem...
```python from math import floor, sqrt def solution(): n, k = map(int, input().split(' ')) time = 4 * 60 - k ans = floor((sqrt(1 + 8 / 5 * time) - 1 )/ 2) return floor(ans) if ans < n else n print(solution()) ```
3
12
B
Correct Solution?
PROGRAMMING
1,100
[ "implementation", "sortings" ]
B. Correct Solution?
2
256
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: β€”Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroe...
The first line contains one integer *n* (0<=≀<=*n*<=≀<=109) without leading zeroes. The second lines contains one integer *m* (0<=≀<=*m*<=≀<=109) β€” Bob's answer, possibly with leading zeroes.
Print OK if Bob's answer is correct and WRONG_ANSWER otherwise.
[ "3310\n1033\n", "4\n5\n" ]
[ "OK\n", "WRONG_ANSWER\n" ]
none
0
[ { "input": "3310\n1033", "output": "OK" }, { "input": "4\n5", "output": "WRONG_ANSWER" }, { "input": "40\n04", "output": "WRONG_ANSWER" }, { "input": "12\n12", "output": "OK" }, { "input": "432\n234", "output": "OK" }, { "input": "17109\n01179", "o...
1,673,725,541
2,147,483,647
PyPy 3-64
OK
TESTS
32
124
0
n = list(input()) m = input() n.sort() if len(n)>1 and n[0]=='0': n[0],n[1] = n[1],n[0] n = ''.join(n) print("OK") if m==n else print("WRONG_ANSWER")
Title: Correct Solution? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number *n* to Bob and said: β€”Shuf...
```python n = list(input()) m = input() n.sort() if len(n)>1 and n[0]=='0': n[0],n[1] = n[1],n[0] n = ''.join(n) print("OK") if m==n else print("WRONG_ANSWER") ```
3.969
27
A
Next Test
PROGRAMMING
1,200
[ "implementation", "sortings" ]
A. Next Test
2
256
Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ...
The first line contains one integer *n* (1<=≀<=*n*<=≀<=3000) β€” the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=3000) β€” indexes of these tests.
Output the required default value for the next test index.
[ "3\n1 7 2\n" ]
[ "3\n" ]
none
500
[ { "input": "1\n1", "output": "2" }, { "input": "2\n2 1", "output": "3" }, { "input": "3\n3 4 1", "output": "2" }, { "input": "4\n6 4 3 5", "output": "1" }, { "input": "5\n3 2 1 7 4", "output": "5" }, { "input": "6\n4 1 2 5 3 7", "output": "6" }, ...
1,570,734,826
2,147,483,647
PyPy 3
OK
TESTS
30
280
1,433,600
n = int(input()) a = list(map(int,input().split())) a = sorted(a) k = 1 ok = False for i in range(n): if k!=a[i]: ok = True print(k) break k+=1 if ok==False: print(k)
Title: Next Test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Β«PolygonΒ» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the...
```python n = int(input()) a = list(map(int,input().split())) a = sorted(a) k = 1 ok = False for i in range(n): if k!=a[i]: ok = True print(k) break k+=1 if ok==False: print(k) ```
3.92733
870
A
Search for Pretty Integers
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=9) β€” the lengths of the first and the second lists, respectively. The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=9) β€” the elements of the first list. The third line contains *m* distinct digits *b*1,<=*b*2...
Print the smallest pretty integer.
[ "2 3\n4 2\n5 7 6\n", "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n" ]
[ "25\n", "1\n" ]
In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list. In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t...
500
[ { "input": "2 3\n4 2\n5 7 6", "output": "25" }, { "input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1", "output": "1" }, { "input": "1 1\n9\n1", "output": "19" }, { "input": "9 1\n5 4 2 3 6 1 7 9 8\n9", "output": "9" }, { "input": "5 3\n7 2 5 8 6\n3 1 9", "output"...
1,668,812,406
2,147,483,647
PyPy 3-64
OK
TESTS
52
109
0
# AA Iniciante 2022.1 - Lista 01: Ad-Hoc 1 # K. Search for Pretty Integers # author: uncoded def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) inters = set(a) & set(b) if inters: print(min(inters)) else: min_a = ...
Title: Search for Pretty Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two lists of non-zero digits. Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the sm...
```python # AA Iniciante 2022.1 - Lista 01: Ad-Hoc 1 # K. Search for Pretty Integers # author: uncoded def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) inters = set(a) & set(b) if inters: print(min(inters)) else: ...
3
761
C
Dasha and Password
PROGRAMMING
1,500
[ "brute force", "dp", "implementation" ]
null
null
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one digit in the string, - There is at least one lowercase (small) letter of the Latin alphabet in the string,...
The first line contains two integers *n*, *m* (3<=≀<=*n*<=≀<=50,<=1<=≀<=*m*<=≀<=50) β€” the length of the password and the length of strings which are assigned to password symbols. Each of the next *n* lines contains the string which is assigned to the *i*-th symbol of the password string. Its length is *m*, it consist...
Print one integer β€” the minimum number of operations which is necessary to make the string, which is displayed on the screen, a valid password.
[ "3 4\n1**2\na3*0\nc4**\n", "5 5\n#*&amp;#*\n*a1c&amp;\n&amp;q2w*\n#a3c#\n*&amp;#*&amp;\n" ]
[ "1\n", "3\n" ]
In the first test it is necessary to move the pointer of the third string to one left to get the optimal answer. In the second test one of possible algorithms will be: - to move the pointer of the second symbol once to the right. - to move the pointer of the third symbol twice to the right.
1,500
[ { "input": "3 4\n1**2\na3*0\nc4**", "output": "1" }, { "input": "5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&", "output": "3" }, { "input": "5 2\n&l\n*0\n*9\n*#\n#o", "output": "2" }, { "input": "25 16\nvza**ooxkmd#*ywa\ndip#*#&ef&z&&&pv\nwggob&&72#*&&nku\nrsb##*&jm&#u**te\nzif#lu#...
1,485,885,391
2,147,483,647
Python 3
OK
TESTS
52
280
11,366,400
import math, itertools n, m = map(int, input().split()) strings = [] for _ in range(n): strings.append(input()) # print(strings) trans = str.maketrans('0123456789qwertyuiopasdfghjklzxcvbnm#*&', '000000000011111111111111111111111111222') for i in range(n): strings[i] = strings[i].translate(trans) # print(strings...
Title: Dasha and Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length *n* which satisfies the following requirements: - There is at least one dig...
```python import math, itertools n, m = map(int, input().split()) strings = [] for _ in range(n): strings.append(input()) # print(strings) trans = str.maketrans('0123456789qwertyuiopasdfghjklzxcvbnm#*&', '000000000011111111111111111111111111222') for i in range(n): strings[i] = strings[i].translate(trans) # pri...
3
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,645,896,752
2,147,483,647
Python 3
OK
TESTS
37
46
0
import math n, k = map(int, input().split()) if n % k == 0: print(n+k) else: print(math.ceil(n / k) * k)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *...
```python import math n, k = map(int, input().split()) if n % k == 0: print(n+k) else: print(math.ceil(n / k) * k) ```
3
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers ...
In a single line you are given two integers *M* and *N* β€” board sizes in squares (1<=≀<=*M*<=≀<=*N*<=≀<=16).
Output one number β€” the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,636,433,650
2,147,483,647
Python 3
OK
TESTS
35
92
4,300,800
def main(): n, m = map(int, input().split()) area_of_domino = 2 area_of_board = n * m print(area_of_board // area_of_domino) main()
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=Γ—<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ—<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p...
```python def main(): n, m = map(int, input().split()) area_of_domino = 2 area_of_board = n * m print(area_of_board // area_of_domino) main() ```
3.968989
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Ini...
The input contains two lines. The first line contains the string *s* (1<=≀<=|*s*|<=≀<=50). The second line contains the string *t* (1<=≀<=|*t*|<=≀<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,664,224,528
2,147,483,647
Python 3
OK
TESTS
19
62
0
ch1=input() ch2=input() j=0 for i in range(len(ch2)): if ch2[i]==ch1[j]: j=j+1 print(j+1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st...
```python ch1=input() ch2=input() j=0 for i in range(len(ch2)): if ch2[i]==ch1[j]: j=j+1 print(j+1) ```
3
63
D
Dividing Island
PROGRAMMING
1,900
[ "constructive algorithms" ]
D. Dividing Island
2
256
A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolution. However, they can't divide the island. The island can be conventionally represented as two ...
The first line contains 5 space-separated integers β€” *a*, *b*, *c*, *d* and *n* (1<=≀<=*a*,<=*b*,<=*c*,<=*d*<=≀<=50, *b*<=β‰ <=*d*, 1<=≀<=*n*<=≀<=26). The second line contains *n* space-separated numbers. The *i*-th of them is equal to number *x**i* (1<=≀<=*x**i*<=≀<=*a*<=Γ—<=*b*<=+<=*c*<=Γ—<=*d*). It is guaranteed that .
If dividing the island between parties in the required manner is impossible, print "NO" (without the quotes). Otherwise, print "YES" (also without the quotes) and, starting from the next line, print *max*(*b*,<=*d*) lines each containing *a*<=+<=*c* characters. To mark what square should belong to what party, use lower...
[ "3 4 2 2 3\n5 8 3\n", "3 2 1 4 4\n1 2 3 4\n" ]
[ "YES\naaabb\naabbb\ncbb..\nccb..\n", "YES\nabbd\ncccd\n...d\n...d\n" ]
none
2,000
[ { "input": "3 4 2 2 3\n5 8 3", "output": "YES\nbbbbc\nbbbcc\naab..\naaa.." }, { "input": "3 2 1 4 4\n1 2 3 4", "output": "YES\ncccd\nbbad\n...d\n...d" }, { "input": "1 2 1 1 1\n3", "output": "YES\naa\na." }, { "input": "1 2 1 3 2\n3 2", "output": "YES\naa\nab\n.b" }, ...
1,665,099,227
2,147,483,647
Python 3
OK
TESTS
44
92
0
def solve(x0, y0, dx, X): for i, x in enumerate(X): while x > 0: x-=1 m[y0][x0] = i x0 += dx if x == 0 and i == len(X)-1: break if x0 == -1: y0 += 1 x0 = 0 dx...
Title: Dividing Island Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A revolution took place on the Buka Island. New government replaced the old one. The new government includes *n* parties and each of them is entitled to some part of the island according to their contribution to the revolut...
```python def solve(x0, y0, dx, X): for i, x in enumerate(X): while x > 0: x-=1 m[y0][x0] = i x0 += dx if x == 0 and i == len(X)-1: break if x0 == -1: y0 += 1 x0 = 0 ...
3.977
909
B
Segments
PROGRAMMING
1,300
[ "constructive algorithms", "math" ]
null
null
You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoin...
The only input line contains a single integer *N* (1<=≀<=*N*<=≀<=100).
Output a single integer - the minimal number of layers required to draw the segments for the given *N*.
[ "2\n", "3\n", "4\n" ]
[ "2\n", "4\n", "6\n" ]
As an example, here are the segments and their optimal arrangement into layers for *N* = 4.
1,000
[ { "input": "2", "output": "2" }, { "input": "3", "output": "4" }, { "input": "4", "output": "6" }, { "input": "21", "output": "121" }, { "input": "100", "output": "2550" }, { "input": "1", "output": "1" }, { "input": "5", "output": "9" ...
1,619,334,529
2,147,483,647
PyPy 3
OK
TESTS
102
93
0
import math n=int(input()) print((math.floor(n/2)+1)*math.ceil(n/2))
Title: Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *N*. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and *N*, inclusive; there will be of them. You want to draw these segments in se...
```python import math n=int(input()) print((math.floor(n/2)+1)*math.ceil(n/2)) ```
3
552
A
Vanya and Table
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur mu...
The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rectangles. Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≀<=*x*1<=≀<=*x*2<=≀<=100, 1<=≀<=*y*1<=≀<=*y*2<=≀<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *...
In a single line print the sum of all values in the cells of the table.
[ "2\n1 1 2 3\n2 2 3 3\n", "2\n1 1 3 3\n1 1 3 3\n" ]
[ "10\n", "18\n" ]
Note to the first sample test: Values of the table in the first three rows and columns will be as follows: 121 121 110 So, the sum of values will be equal to 10. Note to the second sample test: Values of the table in the first three rows and columns will be as follows: 222 222 222 So, the sum of values will ...
500
[ { "input": "2\n1 1 2 3\n2 2 3 3", "output": "10" }, { "input": "2\n1 1 3 3\n1 1 3 3", "output": "18" }, { "input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13", "output": "510" }, { "input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11", "o...
1,633,454,504
2,147,483,647
Python 3
OK
TESTS
26
61
6,758,400
area = 0 for _ in range(int(input())): a, b, x, y = [int(inp) for inp in input().split(" ")] area += (abs(x-a+1)*abs(y-b+1)) print(area)
Title: Vanya and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vany...
```python area = 0 for _ in range(int(input())): a, b, x, y = [int(inp) for inp in input().split(" ")] area += (abs(x-a+1)*abs(y-b+1)) print(area) ```
3
687
A
NP-Hard Problem
PROGRAMMING
1,500
[ "dfs and similar", "graphs" ]
null
null
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot...
The first line of the input contains two integers *n* and *m* (2<=≀<=*n*<=≀<=100<=000, 1<=≀<=*m*<=≀<=100<=000)Β β€” the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≀<=<=*u**i*,<=<=*v**i*<=<=≀<=<=*n*), denoting ...
If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ...
[ "4 2\n1 2\n2 3\n", "3 3\n1 2\n2 3\n1 3\n" ]
[ "1\n2 \n2\n1 3 \n", "-1\n" ]
In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish). In the second sample, there is no way to satisfy both Pari and Arya.
500
[ { "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 " }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "-1" }, { "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1" }, { "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1" ...
1,680,715,894
2,147,483,647
Python 3
OK
TESTS
56
545
16,384,000
n, m = map(int, input().split()) graph = [[] for _ in range(n)] for i in range(m): u, v = map(int, input().split()) graph[u-1].append(v-1) graph[v-1].append(u-1) colors = [-1] * n def bfs(start): to_visit = [start] colors[start] = 0 while to_visit: node = to_visit.pop(...
Title: NP-Hard Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ...
```python n, m = map(int, input().split()) graph = [[] for _ in range(n)] for i in range(m): u, v = map(int, input().split()) graph[u-1].append(v-1) graph[v-1].append(u-1) colors = [-1] * n def bfs(start): to_visit = [start] colors[start] = 0 while to_visit: node = to_...
3
439
A
Devu, the Singer and Churu, the Joker
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited. Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s...
The first line contains two space separated integers *n*, *d* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*d*<=≀<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=100).
If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.
[ "3 30\n2 2 1\n", "3 20\n2 1 1\n" ]
[ "5\n", "-1\n" ]
Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: - First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch...
500
[ { "input": "3 30\n2 2 1", "output": "5" }, { "input": "3 20\n2 1 1", "output": "-1" }, { "input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1", "output": "1943" }, { "input": "50 10000\n4 7 15 9 11 12 ...
1,690,903,582
2,147,483,647
Python 3
OK
TESTS
26
46
0
n, d = [int(i) for i in input().split()] t = [int(i) for i in input().split()] remain = (d - sum(t)) // 5 if (((len(t)-1) * 10) + sum(t)) > d: print(-1) else: print(remain)
Title: Devu, the Singer and Churu, the Joker Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit...
```python n, d = [int(i) for i in input().split()] t = [int(i) for i in input().split()] remain = (d - sum(t)) // 5 if (((len(t)-1) * 10) + sum(t)) > d: print(-1) else: print(remain) ```
3
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything ...
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≀<=*d*,<=*h*,<=*v*,<=*e*<=≀<=104), where: - *d* β€” the diameter of your cylindrical cup, - *h* β€” the initial level of water in the cup, - *v* β€” the speed of drinking process from the cup in milliliters per second, - *e* β€” the growth ...
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number β€” time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is...
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we ca...
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input...
1,471,015,796
2,147,483,647
Python 3
OK
TESTS
23
62
4,608,000
import math d,h,v,e=map(int,input().split()) s=math.pi*d*d/4 e*=s print('NO'if e>=v else'YES\n'+str(h*s/(v-e)))
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition β€” when it rains, you go on the street and stay silent for a moment, cont...
```python import math d,h,v,e=map(int,input().split()) s=math.pi*d*d/4 e*=s print('NO'if e>=v else'YES\n'+str(h*s/(v-e))) ```
3
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,699,858,709
2,147,483,647
Python 3
OK
TESTS
50
92
0
shuru=list(map(int,input().split(' '))) n=shuru[0] k=shuru[1] queue=list(map(int,input().split(' '))) jianduandian=queue[k-1] c=0 for i in range(n): if queue[i]>=jianduandian and queue[i]>0: c+=1 print(c)
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 shuru=list(map(int,input().split(' '))) n=shuru[0] k=shuru[1] queue=list(map(int,input().split(' '))) jianduandian=queue[k-1] c=0 for i in range(n): if queue[i]>=jianduandian and queue[i]>0: c+=1 print(c) ```
3
381
A
Sereja and Dima
PROGRAMMING
800
[ "greedy", "implementation", "two pointers" ]
null
null
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000.
On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game.
[ "4\n4 1 2 10\n", "7\n1 2 3 4 5 6 7\n" ]
[ "12 5\n", "16 12\n" ]
In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5.
500
[ { "input": "4\n4 1 2 10", "output": "12 5" }, { "input": "7\n1 2 3 4 5 6 7", "output": "16 12" }, { "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418" }, { "input": "43\n32 ...
1,682,209,088
2,147,483,647
Python 3
OK
TESTS
34
62
0
n = int(input()) a = list(map(int,input().split())) sereja = [] dima = [] for i in range(len(a)): if len(a) == 0: break sereja.append(max(a[0],a[-1])) a.pop(a.index(max(a[0],a[-1]))) if len(a) == 0: break dima.append(max(a[0],a[-1])) a.pop(a.index(max(a[0],a[-1]))) p...
Title: Sereja and Dima Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du...
```python n = int(input()) a = list(map(int,input().split())) sereja = [] dima = [] for i in range(len(a)): if len(a) == 0: break sereja.append(max(a[0],a[-1])) a.pop(a.index(max(a[0],a[-1]))) if len(a) == 0: break dima.append(max(a[0],a[-1])) a.pop(a.index(max(a[0],a...
3