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
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider t...
Print the answer on a single line β€” the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β€” 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling t...
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { ...
1,623,928,363
2,147,483,647
Python 3
OK
TESTS
45
218
8,192,000
n=int(input()) a=list(map(int,input().split())) m=min(a) print("Still Rozdil" if a.count(m)>1 else a.index(m)+1)
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha...
```python n=int(input()) a=list(map(int,input().split())) m=min(a) print("Still Rozdil" if a.count(m)>1 else a.index(m)+1) ```
3
617
C
Watering Flowers
PROGRAMMING
1,600
[ "implementation" ]
null
null
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values *r*1(*r*1<=β‰₯<=0) and *r*2(*r*2<=β‰₯<=0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such *r*1 and *r*2 that all the flowers are watered, that is, fo...
The first line of the input contains integers *n*, *x*1, *y*1, *x*2, *y*2 (1<=≀<=*n*<=≀<=2000, <=-<=107<=≀<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≀<=107)Β β€” the number of flowers, the coordinates of the first and the second fountain. Next follow *n* lines. The *i*-th of these lines contains integers *x**i* and *y**i* (<=-<=107<=≀...
Print the minimum possible value *r*12<=+<=*r*22. Note, that in this problem optimal answer is always integer.
[ "2 -1 0 5 3\n0 2\n5 2\n", "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4\n" ]
[ "6\n", "33\n" ]
The first sample is (*r*<sub class="lower-index">1</sub><sup class="upper-index">2</sup> = 5, *r*<sub class="lower-index">2</sub><sup class="upper-index">2</sup> = 1): <img class="tex-graphics" src="https://espresso.codeforces.com/15e780f508832a19b14698dd8eb54b4c0dd131bf.png" style="max-width: 100.0%;max-height: 100.0%...
1,250
[ { "input": "2 -1 0 5 3\n0 2\n5 2", "output": "6" }, { "input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33" }, { "input": "5 -6 -4 0 10\n-7 6\n-9 7\n-5 -1\n-2 1\n-8 10", "output": "100" }, { "input": "10 -68 10 87 22\n30 89\n82 -97\n-52 25\n76 -22\n-20 95\n21 25\n2 -3\n45...
1,698,952,193
2,147,483,647
PyPy 3
OK
TESTS
31
124
2,457,600
import sys input=sys.stdin.readline n,x1,y1,x2,y2=map(int,input().split()) l=[] for _ in range(n): x,y=map(int,input().split()) l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2]) l.sort(reverse=True) s=10**18 q=0 for u,v in l: s=min(s,u+q) q=max(q,v) print(min(s,q))
Title: Watering Flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values *r*1(*r*1<=β‰₯<=0) and *r*2(*r*2<=β‰₯<=0), giving the distances at which the water is spread from the first and second f...
```python import sys input=sys.stdin.readline n,x1,y1,x2,y2=map(int,input().split()) l=[] for _ in range(n): x,y=map(int,input().split()) l.append([(x-x1)**2+(y-y1)**2,(x-x2)**2+(y-y2)**2]) l.sort(reverse=True) s=10**18 q=0 for u,v in l: s=min(s,u+q) q=max(q,v) print(min(s,q)) ```
3
75
A
Life Without Zeros
PROGRAMMING
1,000
[ "implementation" ]
A. Life Without Zeros
2
256
Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*...
The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≀<=*a*,<=*b*<=≀<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*.
The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise.
[ "101\n102\n", "105\n106\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "101\n102", "output": "YES" }, { "input": "105\n106", "output": "NO" }, { "input": "544\n397", "output": "YES" }, { "input": "822\n280", "output": "NO" }, { "input": "101\n413", "output": "NO" }, { "input": "309\n139", "output": "NO" }...
1,595,439,627
2,147,483,647
Python 3
OK
TESTS
43
218
6,963,200
a = input() b = input() c = int(a) + int(b) na = "" nb = "" nc = "" for i in a: if i != "0": na += i for i in b: if i != "0": nb += i for i in str(c): if i!="0": nc += i if str(int(na)+int(nb)) == nc: print("YES") else: print("NO")
Title: Life Without Zeros Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Can you imagine our life if we removed all zeros from it? For sure we will have many problems. In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu...
```python a = input() b = input() c = int(a) + int(b) na = "" nb = "" nc = "" for i in a: if i != "0": na += i for i in b: if i != "0": nb += i for i in str(c): if i!="0": nc += i if str(int(na)+int(nb)) == nc: print("YES") else: print("NO") ...
3.93253
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,673,115,945
2,147,483,647
Python 3
OK
TESTS
43
46
0
x=input() ans='' for i in range(len(x)): if i==0 and 4<int(x[i])<9 or i!=0 and int(x[i])>4: ans+=str(9-int(x[i])) else: ans+=x[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 x=input() ans='' for i in range(len(x)): if i==0 and 4<int(x[i])<9 or i!=0 and int(x[i])>4: ans+=str(9-int(x[i])) else: ans+=x[i] print(ans) ```
3
756
B
Travel Card
PROGRAMMING
1,600
[ "binary search", "dp" ]
null
null
A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in the following manner. There are three types of tickets: 1. a tick...
The first line of input contains integer number *n* (1<=≀<=*n*<=≀<=105)Β β€” the number of trips made by passenger. Each of the following *n* lines contains the time of trip *t**i* (0<=≀<=*t**i*<=≀<=109), measured in minutes from the time of starting the system. All *t**i* are different, given in ascending order, i.Β e. *...
Output *n* integers. For each trip, print the sum the passenger is charged after it.
[ "3\n10\n20\n30\n", "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516\n" ]
[ "20\n20\n10\n", "20\n20\n10\n0\n20\n0\n0\n20\n20\n10\n" ]
In the first example, the system works as follows: for the first and second trips it is cheaper to pay for two one-trip tickets, so each time 20 rubles is charged, after the third trip the system understands that it would be cheaper to buy a ticket for 90 minutes. This ticket costs 50 rubles, and the passenger had alre...
1,000
[ { "input": "3\n10\n20\n30", "output": "20\n20\n10" }, { "input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10" }, { "input": "7\n100\n138\n279\n308\n396\n412\n821", "output": "20\n20\n20\n20\n20\n20\n0" }, { "input": "8\n0...
1,601,661,115
2,147,483,647
PyPy 3
OK
TESTS
31
904
13,107,200
n = int(input()) dp = [0] t = [0] i,j = 1,1 for _ in range(n): x = int(input()) t.append(x) while x-t[i]>89: i+=1 while x-t[j]>1439: j+=1 try: y = min(dp[-1]+20, dp[i-1]+50, dp[j-1]+120) dp.append(y) except: print(i,j) ans = [] for i in ...
Title: Travel Card Time Limit: None seconds Memory Limit: None megabytes Problem Description: A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare....
```python n = int(input()) dp = [0] t = [0] i,j = 1,1 for _ in range(n): x = int(input()) t.append(x) while x-t[i]>89: i+=1 while x-t[j]>1439: j+=1 try: y = min(dp[-1]+20, dp[i-1]+50, dp[j-1]+120) dp.append(y) except: print(i,j) 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,684,328,292
2,147,483,647
Python 3
OK
TESTS
45
124
0
def f(a): if a<2: return False k = 0 for i in range(2, a // 2+1): if (a % i == 0): k = k+1 if (k <= 0): return True return False x, y=map(int, input().split()) c=0 if f(x) and f(y): for i in range(x+1, y): if f(i): c+=1 if c==0: print("YES") el...
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 f(a): if a<2: return False k = 0 for i in range(2, a // 2+1): if (a % i == 0): k = k+1 if (k <= 0): return True return False x, y=map(int, input().split()) c=0 if f(x) and f(y): for i in range(x+1, y): if f(i): c+=1 if c==0: print("YES...
3.969
551
A
GukiZ and Contest
PROGRAMMING
800
[ "brute force", "implementation", "sortings" ]
null
null
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote...
The first line contains integer *n* (1<=≀<=*n*<=≀<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≀<=*a**i*<=≀<=2000) where *a**i* is the rating of *i*-th student (1<=≀<=*i*<=≀<=*n*).
In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input.
[ "3\n1 3 3\n", "1\n1\n", "5\n3 5 3 4 5\n" ]
[ "3 1 1\n", "1\n", "4 1 4 3 1\n" ]
In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating. In the second sample, first student is the only one on the contest. In the third sample, students 2 and 5 share the first positi...
500
[ { "input": "3\n1 3 3", "output": "3 1 1" }, { "input": "1\n1", "output": "1" }, { "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1" }, { "input": "7\n1 3 5 4 2 2 1", "output": "6 3 1 2 4 4 6" }, { "input": "11\n5 6 4 2 9 7 6 6 6 6 7", "output": "9 4 10 11 1 2 4 4...
1,524,931,215
2,147,483,647
Python 3
OK
TESTS
36
1,497
7,475,200
n = int(input()) arr = list(map(int, input().split())) answer = [] for i in range(n): counter = 0 for j in range(n): if (j != i): if (arr[i] < arr[j]): counter += 1 answer.append(counter + 1) print(*answer)
Title: GukiZ and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the star...
```python n = int(input()) arr = list(map(int, input().split())) answer = [] for i in range(n): counter = 0 for j in range(n): if (j != i): if (arr[i] < arr[j]): counter += 1 answer.append(counter + 1) print(*answer) ```
3
200
B
Drinks
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent. One day Vasya decided to make himself an orange cocktail. He took equal proportio...
The first input line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≀<=*p**i*<=≀<=100) β€” the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space.
Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4.
[ "3\n50 50 100\n", "4\n0 25 50 75\n" ]
[ "66.666666666667\n", "37.500000000000\n" ]
Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ...
500
[ { "input": "3\n50 50 100", "output": "66.666666666667" }, { "input": "4\n0 25 50 75", "output": "37.500000000000" }, { "input": "3\n0 1 8", "output": "3.000000000000" }, { "input": "5\n96 89 93 95 70", "output": "88.600000000000" }, { "input": "7\n62 41 78 4 38 39...
1,683,607,250
2,147,483,647
Python 3
OK
TESTS
31
92
0
x=int(input()) s=list(map(int,input().split())) lis=[] for i in range(x): lis.append(s[i]/100) print((sum(lis)/x)*100)
Title: Drinks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*...
```python x=int(input()) s=list(map(int,input().split())) lis=[] for i in range(x): lis.append(s[i]/100) print((sum(lis)/x)*100) ```
3
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regular, while Β«)(Β», Β«(()Β» and Β«(()))(Β» are not. One day Johnny got bracket sequence. He decided to remove some...
Input consists of a single line with non-empty string of Β«(Β» and Β«)Β» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()((...
1,633,018,158
2,147,483,647
Python 3
OK
TESTS
38
842
9,932,800
s = input() x = len(s) c = 0 for i in range(x): if(s[i]=='('): c+=1 elif(s[i]==')'): c-=1 if(c<0): x-=1 c = 0 print(x-c)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regula...
```python s = input() x = len(s) c = 0 for i in range(x): if(s[i]=='('): c+=1 elif(s[i]==')'): c-=1 if(c<0): x-=1 c = 0 print(x-c) ```
3.897299
592
A
PawnChess
PROGRAMMING
1,200
[ "implementation" ]
null
null
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed...
The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the ...
Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board.
[ "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n" ]
[ "A\n", "B\n" ]
In the first sample player A is able to complete his goal in 3 steps by always moving a pawn initially located at (4, 5). Player B needs at least 5 steps for any of his pawns to reach the row 8. Hence, player A will be the winner.
500
[ { "input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.", "output": "B" }, { "input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.", "output": "A" }, { "input": "BB..BB..\nBW.W.W.B\n..B.....\n.....BB.\n.B..B..B\n.........
1,499,197,423
2,147,483,647
Python 3
OK
TESTS
56
62
5,529,600
# Description of the problem can be found at http://codeforces.com/problemset/problem/592/A l_w = [9] * 8 l_b = [9] * 8 for y in range(8): i = 0 for c in input(): if c == "W": if l_b[i] == 9 and l_w[i] == 9: l_w[i] = y l_b[i] = 10 elif c == "B": ...
Title: PawnChess Time Limit: None seconds Memory Limit: None megabytes Problem Description: Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of ...
```python # Description of the problem can be found at http://codeforces.com/problemset/problem/592/A l_w = [9] * 8 l_b = [9] * 8 for y in range(8): i = 0 for c in input(): if c == "W": if l_b[i] == 9 and l_w[i] == 9: l_w[i] = y l_b[i] = 10 elif c == "B"...
3
509
A
Maximum in Table
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ...
The only line of input contains a positive integer *n* (1<=≀<=*n*<=≀<=10) β€” the number of rows and columns of the table.
Print a single line containing a positive integer *m* β€” the maximum value in the table.
[ "1\n", "5\n" ]
[ "1", "70" ]
In the second test the rows of the table look as follows:
0
[ { "input": "1", "output": "1" }, { "input": "5", "output": "70" }, { "input": "2", "output": "2" }, { "input": "3", "output": "6" }, { "input": "4", "output": "20" }, { "input": "6", "output": "252" }, { "input": "7", "output": "924" ...
1,613,179,563
2,147,483,647
Python 3
OK
TESTS
10
77
0
def solve(n): if n ==1 : return 1 arr = [[1]*n] for i in range(1,n): row = [1] for col in range(1,n): row.append(row[col-1]+arr[i-1][col]) if i == n-1: return row[-1] arr.append(row) def main(): print(solve(int(input()))) main()
Title: Maximum in Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: An *n*<=Γ—<=*n* table *a* is defined as follows: - The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t...
```python def solve(n): if n ==1 : return 1 arr = [[1]*n] for i in range(1,n): row = [1] for col in range(1,n): row.append(row[col-1]+arr[i-1][col]) if i == n-1: return row[-1] arr.append(row) def main(): print(solve(int(input()))) main() ```
3
156
C
Cipher
PROGRAMMING
2,000
[ "combinatorics", "dp" ]
null
null
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of somethin...
The input data contains several tests. The first line contains the only integer *t* (1<=≀<=*t*<=≀<=104) β€” the number of tests. Next *t* lines contain the words, one per line. Each word consists of lowercase Latin letters and has length from 1 to 100, inclusive. Lengths of words can differ.
For each word you should print the number of different other words that coincide with it in their meaning β€” not from the words listed in the input data, but from all possible words. As the sought number can be very large, print its value modulo 1000000007 (109<=+<=7).
[ "1\nab\n", "1\naaaaaaaaaaa\n", "2\nya\nklmbfxzb\n" ]
[ "1\n", "0\n", "24\n320092793\n" ]
Some explanations about the operation: - Note that for each letter, we can clearly define the letter that follows it. Letter "b" alphabetically follows letter "a", letter "c" follows letter "b", ..., "z" follows letter "y". - Preceding letters are defined in the similar manner: letter "y" precedes letter "z", ..., "...
1,500
[ { "input": "1\nab", "output": "1" }, { "input": "1\naaaaaaaaaaa", "output": "0" }, { "input": "2\nya\nklmbfxzb", "output": "24\n320092793" }, { "input": "1\na", "output": "0" }, { "input": "1\nz", "output": "0" }, { "input": "1\naaaaaaaaaaaaaaaaaaaaaaa...
1,647,882,454
2,147,483,647
PyPy 3-64
OK
TESTS
42
748
11,059,200
MOD = int(1e9 + 7) dp = [[0 for j in range(2501)] for i in range(101)] dp[0][0] = 1 for i in range(100): for j in range(i * 25 + 1): for k in range(26): dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j]) % MOD for tc in range(int(input())): S = input() s = sum([ ord(c) - ord('a') for c in S ]) print((d...
Title: Cipher Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence...
```python MOD = int(1e9 + 7) dp = [[0 for j in range(2501)] for i in range(101)] dp[0][0] = 1 for i in range(100): for j in range(i * 25 + 1): for k in range(26): dp[i + 1][j + k] = (dp[i + 1][j + k] + dp[i][j]) % MOD for tc in range(int(input())): S = input() s = sum([ ord(c) - ord('a') for c in S ]) ...
3
765
B
Code obfuscation
PROGRAMMING
1,100
[ "greedy", "implementation", "strings" ]
null
null
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and rep...
In the only line of input there is a string *S* of lowercase English letters (1<=≀<=|*S*|<=≀<=500)Β β€” the identifiers of a program with removed whitespace characters.
If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".
[ "abacaba\n", "jinotega\n" ]
[ "YES\n", "NO\n" ]
In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: - replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result...
1,000
[ { "input": "abacaba", "output": "YES" }, { "input": "jinotega", "output": "NO" }, { "input": "aaaaaaaaaaa", "output": "YES" }, { "input": "aba", "output": "YES" }, { "input": "bab", "output": "NO" }, { "input": "a", "output": "YES" }, { "in...
1,679,997,358
2,147,483,647
Python 3
OK
TESTS
59
46
0
s=input() st=sorted(set(s),key=s.index) for i in range(len(st)): if st[i]!=chr(97+i):exit(print('NO')) print('YES')
Title: Code obfuscation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont...
```python s=input() st=sorted(set(s),key=s.index) for i in range(len(st)): if st[i]!=chr(97+i):exit(print('NO')) print('YES') ```
3
78
A
Haiku
PROGRAMMING
800
[ "implementation", "strings" ]
A. Haiku
2
256
Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll...
The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin...
Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes).
[ "on codeforces \nbeta round is running\n a rustling of keys \n", "how many gallons\nof edo s rain did you drink\n cuckoo\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES" }, { "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO" }, { "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", ...
1,632,616,663
2,147,483,647
PyPy 3
OK
TESTS
40
216
21,401,600
dem, a, b, c = 0, input(), input(), input() for x in a: if x in ['u', 'e', 'o', 'a', 'i']: dem += 1 if dem != 5: print("NO") else: for x in b: if x in ['u', 'e', 'o', 'a', 'i']: dem += 1 if dem != 12: print("NO") else: for x in c: if x in ['u', 'e', 'o', 'a', 'i']: ...
Title: Haiku Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase...
```python dem, a, b, c = 0, input(), input(), input() for x in a: if x in ['u', 'e', 'o', 'a', 'i']: dem += 1 if dem != 5: print("NO") else: for x in b: if x in ['u', 'e', 'o', 'a', 'i']: dem += 1 if dem != 12: print("NO") else: for x in c: if x in ['u', 'e', 'o', '...
3.906136
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=6)Β β€” the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,630,472,816
2,147,483,647
Python 3
OK
TESTS
38
92
6,963,200
n,m = map(int,input().split()) count = 0 sount = 0 Dount = 0 for i in range(1,7): G = abs(n-i) H = abs(m-i) if G<H: count = count + 1 elif H<G: sount = sount + 1 else : Dount = Dount + 1 if n>m or m>n: print(count,Dount,sount) else: print(count,Dount...
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python n,m = map(int,input().split()) count = 0 sount = 0 Dount = 0 for i in range(1,7): G = abs(n-i) H = abs(m-i) if G<H: count = count + 1 elif H<G: sount = sount + 1 else : Dount = Dount + 1 if n>m or m>n: print(count,Dount,sount) else: print(c...
3
841
B
Godsend
PROGRAMMING
1,100
[ "games", "math" ]
null
null
Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts...
First line of input data contains single integer *n* (1<=≀<=*n*<=≀<=106) β€” length of the array. Next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=109).
Output answer in single line. "First", if first player wins, and "Second" otherwise (without quotes).
[ "4\n1 3 2 3\n", "2\n2 2\n" ]
[ "First\n", "Second\n" ]
In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
1,000
[ { "input": "4\n1 3 2 3", "output": "First" }, { "input": "2\n2 2", "output": "Second" }, { "input": "4\n2 4 6 8", "output": "Second" }, { "input": "5\n1 1 1 1 1", "output": "First" }, { "input": "4\n720074544 345031254 849487632 80870826", "output": "Second" ...
1,503,780,222
2,147,483,647
Python 3
OK
TESTS
88
561
78,540,800
def main(): n = int(input()) L = [int(x) for x in input().split()] print(solver(L)) def solver(L): for x in L: if x % 2 == 1: return 'First' return 'Second' main() #print(solver([2, 2]))
Title: Godsend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Leha somehow found an array consisting of *n* integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero l...
```python def main(): n = int(input()) L = [int(x) for x in input().split()] print(solver(L)) def solver(L): for x in L: if x % 2 == 1: return 'First' return 'Second' main() #print(solver([2, 2])) ```
3
749
A
Bachgold Problem
PROGRAMMING
800
[ "greedy", "implementation", "math", "number theory" ]
null
null
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ...
The only line of the input contains a single integer *n* (2<=≀<=*n*<=≀<=100<=000).
The first line of the output contains a single integer *k*Β β€” maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them.
[ "5\n", "6\n" ]
[ "2\n2 3\n", "3\n2 2 2\n" ]
none
500
[ { "input": "5", "output": "2\n2 3" }, { "input": "6", "output": "3\n2 2 2" }, { "input": "2", "output": "1\n2" }, { "input": "3", "output": "1\n3" }, { "input": "99999", "output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
1,657,878,516
2,147,483,647
PyPy 3
OK
TESTS
41
92
614,400
# A. Bachgold Problem n = int(input()) if n % 2 == 0: d = int(n / 2) print(d) print(str("2 ") * d) else: d = n - 3 print(int((d / 2) + 1)) print(str("2 ") * int((d /2)) ,"3")
Title: Bachgold Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. ...
```python # A. Bachgold Problem n = int(input()) if n % 2 == 0: d = int(n / 2) print(d) print(str("2 ") * d) else: d = n - 3 print(int((d / 2) + 1)) print(str("2 ") * int((d /2)) ,"3") ```
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,692,723,703
2,147,483,647
Python 3
OK
TESTS
20
31
0
n, m, a = map(int, input().split()) # Calculate the number of flagstones needed for width and length flagstones_width = (n + a - 1) // a # Ceiling division to account for remainder flagstones_length = (m + a - 1) // a # Calculate the total number of flagstones needed total_flagstones = flagstones_width * flag...
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()) # Calculate the number of flagstones needed for width and length flagstones_width = (n + a - 1) // a # Ceiling division to account for remainder flagstones_length = (m + a - 1) // a # Calculate the total number of flagstones needed total_flagstones = flagstones_wi...
3.9845
804
A
Find Amir
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "math" ]
null
null
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* an...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105)Β β€” the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
[ "2\n", "10\n" ]
[ "0\n", "4\n" ]
In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "2", "output": "0" }, { "input": "10", "output": "4" }, { "input": "43670", "output": "21834" }, { "input": "4217", "output": "2108" }, { "input": "17879", "output": "8939" }, { "input": "31809", "output": "15904" }, { "input": "...
1,493,991,412
2,147,483,647
Python 3
OK
TESTS
31
62
0
n = input() n = int(n) if (n % 2) != 0: print (n // 2) else: print ((n // 2) -1)
Title: Find Amir Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel b...
```python n = input() n = int(n) if (n % 2) != 0: print (n // 2) else: print ((n // 2) -1) ```
3
192
B
Walking in the Rain
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start walking on the tile number 1 and the finish on the tile number *n*. During the walk it is allowed to move...
The first line contains integer *n* (1<=≀<=*n*<=≀<=103) β€” the boulevard's length in tiles. The second line contains *n* space-separated integers *a**i* β€” the number of days after which the *i*-th tile gets destroyed (1<=≀<=*a**i*<=≀<=103).
Print a single number β€” the sought number of days.
[ "4\n10 3 5 10\n", "5\n10 2 8 3 5\n" ]
[ "5\n", "5\n" ]
In the first sample the second tile gets destroyed after day three, and the only path left is 1 → 3 → 4. After day five there is a two-tile gap between the first and the last tile, you can't jump over it. In the second sample path 1 → 3 → 5 is available up to day five, inclusive. On day six the last tile is destroyed ...
1,000
[ { "input": "4\n10 3 5 10", "output": "5" }, { "input": "5\n10 2 8 3 5", "output": "5" }, { "input": "10\n10 3 1 6 7 1 3 3 8 1", "output": "1" }, { "input": "10\n26 72 10 52 2 5 61 2 39 64", "output": "5" }, { "input": "100\n8 2 1 2 8 3 5 8 5 1 9 3 4 1 5 6 4 2 9 10...
1,696,788,816
2,147,483,647
PyPy 3-64
OK
TESTS
85
124
1,740,800
n = int(input()) a = list(map(int, input().split())) res = 0 while True: if a[0] == 0 or a[-1] == 0: print(res) break j = 0 while j < n: if j == n - 1: break if j + 2 < n and a[j + 2] > 0: j += 2 elif j + 1 < n and a[...
Title: Walking in the Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland the opposition is going to arrange mass walking on the boulevard. The boulevard consists of *n* tiles that are lain in a row and are numbered from 1 to *n* from right to left. The opposition should start ...
```python n = int(input()) a = list(map(int, input().split())) res = 0 while True: if a[0] == 0 or a[-1] == 0: print(res) break j = 0 while j < n: if j == n - 1: break if j + 2 < n and a[j + 2] > 0: j += 2 elif j + 1 ...
3
584
B
Kolya and Tanya
PROGRAMMING
1,500
[ "combinatorics" ]
null
null
Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3*n* gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the ...
A single line contains number *n* (1<=≀<=*n*<=≀<=105) β€” the number of the gnomes divided by three.
Print a single number β€” the remainder of the number of variants of distributing coins that satisfy Tanya modulo 109<=+<=7.
[ "1\n", "2\n" ]
[ "20", "680" ]
20 ways for *n* = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex): <img class="tex-graphics" src="https://espresso.codeforces.com/64df38b85ccb482cf88d02dc52e348e33313f9da.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "1", "output": "20" }, { "input": "2", "output": "680" }, { "input": "3", "output": "19340" }, { "input": "4", "output": "529040" }, { "input": "5", "output": "14332100" }, { "input": "7", "output": "459529590" }, { "input": "10"...
1,677,467,333
2,147,483,647
Python 3
OK
TESTS
42
46
0
# LUOGU_RID: 103165456 n, m = int(input()), 1000000007 print((pow(27, n, m) - pow(7, n, m)) % m)
Title: Kolya and Tanya Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle. More formally, there are 3*n* gnomes sitting in a ...
```python # LUOGU_RID: 103165456 n, m = int(input()), 1000000007 print((pow(27, n, m) - pow(7, n, m)) % m) ```
3
928
A
Login Verification
PROGRAMMING
1,200
[ "*special", "strings" ]
null
null
When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols (Β«_Β»). However, in order to decrease the number of frauds ...
The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols (Β«_Β») with length not exceeding 50 Β β€” the login itself. The second line contains a single integer *n* (1<=≀<=*n*<=≀<=1<=000)Β β€” the number of existing logins. The next *n* lines describe the exi...
Print Β«YesΒ» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print Β«NoΒ» (without quotes).
[ "1_wat\n2\n2_wat\nwat_1\n", "000\n3\n00\nooA\noOo\n", "_i_\n3\n__i_\n_1_\nI\n", "La0\n3\n2a0\nLa1\n1a0\n", "abc\n1\naBc\n", "0Lil\n2\nLIL0\n0Ril\n" ]
[ "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n" ]
In the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing. In the third sample case the new login is similar with the second one.
500
[ { "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes" }, { "input": "000\n3\n00\nooA\noOo", "output": "No" }, { "input": "_i_\n3\n__i_\n_1_\nI", "output": "No" }, { "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No" }, { "input": "abc\n1\naBc", "output": "No" }...
1,519,487,710
1,210
Python 3
OK
TESTS
73
77
5,632,000
def unify_login(login): login = login.lower() login = login.replace('0', 'o') login = login.replace('l', '1') login = login.replace('i', '1') return login s = unify_login(input()) n = int(input()) logins = set() for i in range(n): logins.add(unify_login(input())) if s in logins: print('...
Title: Login Verification Time Limit: None seconds Memory Limit: None megabytes Problem Description: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercas...
```python def unify_login(login): login = login.lower() login = login.replace('0', 'o') login = login.replace('l', '1') login = login.replace('i', '1') return login s = unify_login(input()) n = int(input()) logins = set() for i in range(n): logins.add(unify_login(input())) if s in logins: ...
3
217
A
Ice Skating
PROGRAMMING
1,200
[ "brute force", "dfs and similar", "dsu", "graphs" ]
null
null
Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves...
The first line of input contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=1000) β€” the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* ...
Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.
[ "2\n2 1\n1 2\n", "2\n2 1\n4 1\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "2\n2 1\n1 2", "output": "1" }, { "input": "2\n2 1\n4 1", "output": "0" }, { "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182...
1,597,069,516
2,147,483,647
Python 3
OK
TESTS
76
218
6,963,200
from sys import stdin def dfs(visited, l, i): visited[i]= True for j in range(n): if not visited[j]: if l[j][0]==l[i][0] or l[j][1]==l[i][1]: dfs(visited,l,j) n = int(stdin.readline().rstrip()) l = list() for _ in range(n): a, b = map(int, stdin.readli...
Title: Ice Skating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed tha...
```python from sys import stdin def dfs(visited, l, i): visited[i]= True for j in range(n): if not visited[j]: if l[j][0]==l[i][0] or l[j][1]==l[i][1]: dfs(visited,l,j) n = int(stdin.readline().rstrip()) l = list() for _ in range(n): a, b = map(int, st...
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=1015, 1<=≀<=*k*<=≀<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "ou...
1,613,801,132
2,147,483,647
PyPy 3
OK
TESTS
96
1,356
3,276,800
def div(x): i=1;ans=[] while i*i<=n: if x%i==0 and i!=x//i:ans.append(i);ans.append(x//i) elif x%i==0:ans.append(i) i+=1 return ans n,k=map(int,input().split()) ans=div(n) if len(ans)<k:print(-1) else:ans=sorted(ans);print(ans[k-1])
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specificatio...
```python def div(x): i=1;ans=[] while i*i<=n: if x%i==0 and i!=x//i:ans.append(i);ans.append(x//i) elif x%i==0:ans.append(i) i+=1 return ans n,k=map(int,input().split()) ans=div(n) if len(ans)<k:print(-1) else:ans=sorted(ans);print(ans[k-1]) ```
3
913
A
Modular Exponentiation
PROGRAMMING
900
[ "implementation", "math" ]
null
null
The following problem is well-known: given integers *n* and *m*, calculate where 2*n*<==<=2Β·2Β·...Β·2 (*n* factors), and denotes the remainder of division of *x* by *y*. You are asked to solve the "reverse" problem. Given integers *n* and *m*, calculate
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=108). The second line contains a single integer *m* (1<=≀<=*m*<=≀<=108).
Output a single integerΒ β€” the value of .
[ "4\n42\n", "1\n58\n", "98765432\n23456789\n" ]
[ "10\n", "0\n", "23456789\n" ]
In the first example, the remainder of division of 42 by 2<sup class="upper-index">4</sup> = 16 is equal to 10. In the second example, 58 is divisible by 2<sup class="upper-index">1</sup> = 2 without remainder, and the answer is 0.
500
[ { "input": "4\n42", "output": "10" }, { "input": "1\n58", "output": "0" }, { "input": "98765432\n23456789", "output": "23456789" }, { "input": "8\n88127381", "output": "149" }, { "input": "32\n92831989", "output": "92831989" }, { "input": "92831989\n25...
1,628,020,496
2,147,483,647
PyPy 3
OK
TESTS
49
109
33,177,600
n=int(input()) m=int(input()) x=pow(m,1,2**n) print(x)
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()) x=pow(m,1,2**n) print(x) ```
3
915
A
Garden
PROGRAMMING
900
[ "implementation" ]
null
null
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat...
The first line of input contains two integer numbers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the length of the segment that can be watered by the *i*-th bucket in one ...
Print one integer number β€” the minimum number of hours required to water the garden.
[ "3 6\n2 3 5\n", "6 7\n1 2 3 4 5 6\n" ]
[ "2\n", "7\n" ]
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 1.
0
[ { "input": "3 6\n2 3 5", "output": "2" }, { "input": "6 7\n1 2 3 4 5 6", "output": "7" }, { "input": "5 97\n1 10 50 97 2", "output": "1" }, { "input": "5 97\n1 10 50 100 2", "output": "97" }, { "input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5...
1,522,376,648
2,147,483,647
Python 3
OK
TESTS
83
93
7,065,600
#http://codeforces.com/problemset/problem/915/A numBuckets, garLen = map(int, input().split()) buckets = list(map(int,input().split())) biggest = 0 for x in buckets: if(garLen%x == 0 and x > biggest): biggest = x else: pass print(int(garLen/biggest))
Title: Garden Time Limit: None seconds Memory Limit: None megabytes Problem Description: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ...
```python #http://codeforces.com/problemset/problem/915/A numBuckets, garLen = map(int, input().split()) buckets = list(map(int,input().split())) biggest = 0 for x in buckets: if(garLen%x == 0 and x > biggest): biggest = x else: pass print(int(garLen/biggest)) ```
3
192
A
Funky Numbers
PROGRAMMING
1,300
[ "binary search", "brute force", "implementation" ]
null
null
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and c...
The first input line contains an integer *n* (1<=≀<=*n*<=≀<=109).
Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).
[ "256\n", "512\n" ]
[ "YES\n", "NO\n" ]
In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample number 512 can not be represented as a sum of two triangular numbers.
500
[ { "input": "256", "output": "YES" }, { "input": "512", "output": "NO" }, { "input": "80", "output": "NO" }, { "input": "828", "output": "YES" }, { "input": "6035", "output": "NO" }, { "input": "39210", "output": "YES" }, { "input": "79712",...
1,663,850,195
2,147,483,647
Python 3
OK
TESTS
71
156
2,457,600
a = set([i*(i+1)//2 for i in range(1,50000)]) n = int(input()) print("YES" if any(n-t in a for t in a) else "NO")
Title: Funky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent...
```python a = set([i*(i+1)//2 for i in range(1,50000)]) n = int(input()) print("YES" if any(n-t in a for t in a) else "NO") ```
3
740
B
Alyona and flowers
PROGRAMMING
1,200
[ "constructive algorithms" ]
null
null
Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarray as a segment of consecutive flowers. The mother suggested some set of subarrays. Alyona wants to choos...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of flowers and the number of subarrays suggested by the mother. The second line contains the flowers moodsΒ β€” *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=100<=≀<=*a**i*<=≀<=100). The next *m* lines contain the description of the ...
Print single integerΒ β€” the maximum possible value added to the Alyona's happiness.
[ "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4\n", "4 3\n1 2 3 4\n1 3\n2 4\n1 1\n", "2 2\n-1 -2\n1 1\n1 2\n" ]
[ "7\n", "16\n", "0\n" ]
The first example is the situation described in the statements. In the second example Alyona should choose all subarrays. The third example has answer 0 because Alyona can choose none of the subarrays.
1,000
[ { "input": "5 4\n1 -2 1 3 -4\n1 2\n4 5\n3 4\n1 4", "output": "7" }, { "input": "4 3\n1 2 3 4\n1 3\n2 4\n1 1", "output": "16" }, { "input": "2 2\n-1 -2\n1 1\n1 2", "output": "0" }, { "input": "5 6\n1 1 1 -1 0\n2 4\n1 3\n4 5\n1 5\n1 4\n4 5", "output": "8" }, { "inpu...
1,479,921,043
2,143
Python 3
OK
TESTS
53
93
0
n, m = map(int, input().split()) a = [int(i) for i in input().split()] ans = 0 for i in range(m): s, e = map(int, input().split()) t = sum(a[s-1:e]) if t > 0: ans += t print(ans)
Title: Alyona and flowers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Alyona is celebrating Happy Birthday! Her mother has an array of *n* flowers. Each flower has some mood, the mood of *i*-th flower is *a**i*. The mood can be positive, zero or negative. Let's define a subarra...
```python n, m = map(int, input().split()) a = [int(i) for i in input().split()] ans = 0 for i in range(m): s, e = map(int, input().split()) t = sum(a[s-1:e]) if t > 0: ans += t print(ans) ```
3
469
A
I Wanna Be the Guy
PROGRAMMING
800
[ "greedy", "implementation" ]
null
null
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can...
The first line contains a single integer *n* (1<=≀<=<=*n*<=≀<=100). The next line contains an integer *p* (0<=≀<=*p*<=≀<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≀<=*a**i*<=≀<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels...
If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).
[ "4\n3 1 2 3\n2 2 4\n", "4\n3 1 2 3\n2 2 3\n" ]
[ "I become the guy.\n", "Oh, my keyboard!\n" ]
In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both. In the second sample, no one can pass level 4.
500
[ { "input": "4\n3 1 2 3\n2 2 4", "output": "I become the guy." }, { "input": "4\n3 1 2 3\n2 2 3", "output": "Oh, my keyboard!" }, { "input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6", "output": "Oh, my keyboard!" }, { "input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8", "output":...
1,694,079,944
2,147,483,647
Python 3
OK
TESTS
29
46
0
# Input the total number of levels n = int(input()) # Input levels Little X can pass p, *x_levels = map(int, input().split()) # Input levels Little Y can pass q, *y_levels = map(int, input().split()) # Create a set of levels that Little X can pass x_set = set(x_levels) # Create a set of levels that Litt...
Title: I Wanna Be the Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game. Little X can pass only *p* levels of the g...
```python # Input the total number of levels n = int(input()) # Input levels Little X can pass p, *x_levels = map(int, input().split()) # Input levels Little Y can pass q, *y_levels = map(int, input().split()) # Create a set of levels that Little X can pass x_set = set(x_levels) # Create a set of levels...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,652,422,159
2,147,483,647
PyPy 3-64
OK
TESTS
40
62
0
hello = ["h", "e", "l", "l", "o"] test = input() index = -1 for letter in hello: try: index = test.index(letter, index + 1) except ValueError: print("NO") exit(0) print("YES")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python hello = ["h", "e", "l", "l", "o"] test = input() index = -1 for letter in hello: try: index = test.index(letter, index + 1) except ValueError: print("NO") exit(0) print("YES") ```
3.969
146
A
Lucky Ticket
PROGRAMMING
800
[ "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It...
The first line contains an even integer *n* (2<=≀<=*n*<=≀<=50) β€” the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* β€” the ticket number. The number may contain leading zeros.
On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).
[ "2\n47\n", "4\n4738\n", "4\n4774\n" ]
[ "NO\n", "NO\n", "YES\n" ]
In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7). In the second sample the ticket number is not the lucky number.
500
[ { "input": "2\n47", "output": "NO" }, { "input": "4\n4738", "output": "NO" }, { "input": "4\n4774", "output": "YES" }, { "input": "4\n4570", "output": "NO" }, { "input": "6\n477477", "output": "YES" }, { "input": "6\n777777", "output": "YES" }, ...
1,694,067,982
2,147,483,647
Python 3
OK
TESTS
46
92
0
n = int(input()) tnum = input() counter = 0 for i in range(len(tnum)): if tnum[i] == '7' or tnum[i] == '4': continue else: counter +=1 if counter == 0: s1 = 0 s2 = 0 for i in range(n//2): s1 += int(tnum[i]) for i in range(n//2,n): s2 += int(tnum[i]) ...
Title: Lucky Ticket Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python n = int(input()) tnum = input() counter = 0 for i in range(len(tnum)): if tnum[i] == '7' or tnum[i] == '4': continue else: counter +=1 if counter == 0: s1 = 0 s2 = 0 for i in range(n//2): s1 += int(tnum[i]) for i in range(n//2,n): s2 += int...
3
439
B
Devu, the Dumb Guy
PROGRAMMING
1,200
[ "implementation", "sortings" ]
null
null
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously. Let us say that his initial per chapter learning power of a subject is *x* hours. In other ...
The first line will contain two space separated integers *n*, *x* (1<=≀<=*n*,<=*x*<=≀<=105). The next line will contain *n* space separated integers: *c*1,<=*c*2,<=...,<=*c**n* (1<=≀<=*c**i*<=≀<=105).
Output a single integer representing the answer to the problem.
[ "2 3\n4 1\n", "4 2\n5 1 2 1\n", "3 3\n1 1 1\n" ]
[ "11\n", "10\n", "6\n" ]
Look at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 ...
1,000
[ { "input": "2 3\n4 1", "output": "11" }, { "input": "4 2\n5 1 2 1", "output": "10" }, { "input": "3 3\n1 1 1", "output": "6" }, { "input": "20 4\n1 1 3 5 5 1 3 4 2 5 2 4 3 1 3 3 3 3 4 3", "output": "65" }, { "input": "20 10\n6 6 1 2 6 4 5 3 6 5 4 5 6 5 4 6 6 2 3 3...
1,524,197,719
2,147,483,647
Python 3
OK
TESTS
31
187
14,438,400
n, x = map(int, input().split()) c = sorted(map(int, input().split())) p = x result = 0 for ci in c: result += p * ci if p > 1: p -= 1 print(result)
Title: Devu, the Dumb Guy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him *n* subjects, the *i**th* subject has *c**i* chapters. When you teach him, you are supposed to teach all the chapters of a subject co...
```python n, x = map(int, input().split()) c = sorted(map(int, input().split())) p = x result = 0 for ci in c: result += p * ci if p > 1: p -= 1 print(result) ```
3
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho...
The first line of input will be a single string *s* (1<=≀<=|*s*|<=≀<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "i...
1,606,794,189
2,147,483,647
Python 3
OK
TESTS
33
139
0
s=input() print(26*(len(s)+1)-len(s))
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b...
```python s=input() print(26*(len(s)+1)-len(s)) ```
3
400
A
Inna and Choose Options
PROGRAMMING
1,000
[ "implementation" ]
null
null
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X"...
The first line of the input contains integer *t* (1<=≀<=*t*<=≀<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The ...
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line b...
[ "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n" ]
[ "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n" ]
none
500
[ { "input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0" }, { "input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX", "output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1" }, { "input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\n...
1,557,757,538
2,147,483,647
Python 3
OK
TESTS
44
140
0
def is_possible(request, a): b = 12 // a for i in range(b): if 'O' not in [request[i + j * b] for j in range(a)]: return True return False def solve(request): possible_ways = [1, 2, 3, 4, 6, 12] count_ways = 0 ways = [] for i in possible_ways: if is_possible...
Title: Inna and Choose Options Time Limit: None seconds Memory Limit: None megabytes Problem Description: There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game....
```python def is_possible(request, a): b = 12 // a for i in range(b): if 'O' not in [request[i + j * b] for j in range(a)]: return True return False def solve(request): possible_ways = [1, 2, 3, 4, 6, 12] count_ways = 0 ways = [] for i in possible_ways: if i...
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,501,729,216
2,147,483,647
Python 3
OK
TESTS
45
77
4,608,000
n = int(input()) p = int(input()) q = int(input()) print(n/(p+q)*p)
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 n = int(input()) p = int(input()) q = int(input()) print(n/(p+q)*p) ```
3
858
D
Polycarp's phone book
PROGRAMMING
1,600
[ "data structures", "implementation", "sortings" ]
null
null
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for w...
The first line contains single integer *n* (1<=≀<=*n*<=≀<=70000) β€” the total number of phone contacts in Polycarp's contacts. The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct.
Print exactly *n* lines: the *i*-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the *i*-th number from the contacts. If there are several such sequences, print any of them.
[ "3\n123456789\n100000000\n100123456\n", "4\n123456789\n193456789\n134567819\n934567891\n" ]
[ "9\n000\n01\n", "2\n193\n81\n91\n" ]
none
2,000
[ { "input": "3\n123456789\n100000000\n100123456", "output": "9\n000\n01" }, { "input": "4\n123456789\n193456789\n134567819\n934567891", "output": "2\n193\n81\n91" }, { "input": "1\n167038488", "output": "4" }, { "input": "5\n115830748\n403459907\n556271610\n430358099\n41396141...
1,588,244,130
2,147,483,647
PyPy 3
OK
TESTS
53
2,839
85,708,800
n=int(input()) a=[] d={} for _ in range(n): s=input() g=set() for i in range(len(s)): for k in range(i,len(s)): st=s[i:k+1] if st in g: continue else: g.add(st) if st in d: d[st]+=1 ...
Title: Polycarp's phone book Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS ...
```python n=int(input()) a=[] d={} for _ in range(n): s=input() g=set() for i in range(len(s)): for k in range(i,len(s)): st=s[i:k+1] if st in g: continue else: g.add(st) if st in d: d[st]...
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "1000022...
1,659,706,035
2,147,483,647
PyPy 3
OK
TESTS
30
156
0
t = input() str1 = "" i=0 while True: try: if t[i]=='.': str1 +='0' else: if(t[i+1]=='.'): str1+='1' i = i+1 else: str1+='2' i = i+1 i+=1 except: break print(str...
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as Β«.Β», 1 as Β«-.Β» and 2 as Β«--Β». You are to decode the Borze code, i.e. to find out the ternary ...
```python t = input() str1 = "" i=0 while True: try: if t[i]=='.': str1 +='0' else: if(t[i+1]=='.'): str1+='1' i = i+1 else: str1+='2' i = i+1 i+=1 except: break ...
3.961
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ...
The first line of the input contains a positive integer *n* (2<=≀<=*n*<=≀<=105)Β β€”Β the number of rooms in the house. The second line of the input contains string *s* of length 2Β·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain ...
Print the only integer β€” the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg...
1,427,387,753
353
PyPy 3
OK
TESTS
46
124
2,150,400
n=int(input()) a=[0 for i in range(26)] s=input().strip() ans=0 for i in range(n-1): a[ord(s[2*i])-97]+=1 if a[ord(s[2*i+1])-65]>0: a[ord(s[2*i+1])-65]-=1 else: ans+=1 print(ans)
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from...
```python n=int(input()) a=[0 for i in range(26)] s=input().strip() ans=0 for i in range(n-1): a[ord(s[2*i])-97]+=1 if a[ord(s[2*i+1])-65]>0: a[ord(s[2*i+1])-65]-=1 else: ans+=1 print(ans) ```
3
116
A
Tram
PROGRAMMING
800
[ "implementation" ]
null
null
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex...
The first line contains a single number *n* (2<=≀<=*n*<=≀<=1000) β€” the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≀<=*a**i*,<=*b**i*<=≀<=1000) β€” the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at...
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).
[ "4\n0 3\n2 5\n4 2\n4 0\n" ]
[ "6\n" ]
For the first example, a capacity of 6 is sufficient: - At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ...
500
[ { "input": "4\n0 3\n2 5\n4 2\n4 0", "output": "6" }, { "input": "5\n0 4\n4 6\n6 5\n5 4\n4 0", "output": "6" }, { "input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0", "output": "18" }, { "input": "3\n0 1\n1 1\n1 0", "output": "1" }, { "input": "4\n0 1...
1,691,416,158
2,147,483,647
Python 3
OK
TESTS
71
92
0
# N,M = map(int,input().split()) # N = int(input()) # A = list(map(int,input().split())) N = int(input()) res = 0 cur = 0 for _ in range(N): a,b = map(int,input().split()) cur -= a cur += b res = max(res, cur) print(res)
Title: Tram Time Limit: None seconds Memory Limit: None megabytes Problem Description: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ...
```python # N,M = map(int,input().split()) # N = int(input()) # A = list(map(int,input().split())) N = int(input()) res = 0 cur = 0 for _ in range(N): a,b = map(int,input().split()) cur -= a cur += b res = max(res, cur) print(res) ```
3
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ...
The first line contains an integer *N* (1<=≀<=*N*<=≀<=1000) β€” the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* β€” the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers β€” the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20...
1,533,569,880
2,147,483,647
Python 3
OK
TESTS
61
248
0
n = int(input()) max_len = 1 cur_len = 1 unique = 1 seq = sorted(list(map(int, input().split()))) for i in range(n - 1): if seq[i] == seq[i + 1]: cur_len += 1 if cur_len > max_len: max_len = cur_len else: unique += 1 cur_len = 1 print(max_len, unique)
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct...
```python n = int(input()) max_len = 1 cur_len = 1 unique = 1 seq = sorted(list(map(int, input().split()))) for i in range(n - 1): if seq[i] == seq[i + 1]: cur_len += 1 if cur_len > max_len: max_len = cur_len else: unique += 1 cur_len = 1 print(max_len, u...
3.938
129
A
Cookies
PROGRAMMING
900
[ "implementation" ]
null
null
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan...
The first line contains the only integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the number of cookies in the *i*-th bag.
Print in the only line the only number β€” the sought number of ways. If there are no such ways print 0.
[ "1\n1\n", "10\n1 2 2 3 4 4 4 2 2 2\n", "11\n2 2 2 2 2 2 2 2 2 2 99\n" ]
[ "1\n", "8\n", "1\n" ]
In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies. In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β€” 5 + 3 = 8 ways in total. In the third sample, no matter which bag with two cookies Olga chooses, t...
500
[ { "input": "1\n1", "output": "1" }, { "input": "10\n1 2 2 3 4 4 4 2 2 2", "output": "8" }, { "input": "11\n2 2 2 2 2 2 2 2 2 2 99", "output": "1" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n2 2", "output": "2" }, { "input": "2\n1 2", "o...
1,644,289,268
2,147,483,647
PyPy 3
OK
TESTS
52
154
0
n=int(input()) a=list(map(int,input().split())) b=sum(a);ans=0 if b%2==0: for x in a: if x%2==0:ans+=1 else: for x in a: if x%2==1:ans+=1 print(ans)
Title: Cookies Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan...
```python n=int(input()) a=list(map(int,input().split())) b=sum(a);ans=0 if b%2==0: for x in a: if x%2==0:ans+=1 else: for x in a: if x%2==1:ans+=1 print(ans) ```
3
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≀<=*p**i*<=≀<=*q**i*<=≀<=100) β€” the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer β€” the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,691,669,235
2,147,483,647
Python 3
OK
TESTS
27
46
0
a=int(input()) k=0 for i in range(a): c=input() c=c.split(" ") x,y=int(c[0]),int(c[1]) if y-x>=2: k+=1 else: continue print(k)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python a=int(input()) k=0 for i in range(a): c=input() c=c.split(" ") x,y=int(c[0]),int(c[1]) if y-x>=2: k+=1 else: continue print(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,618,471,106
2,147,483,647
Python 3
OK
TESTS
35
124
0
a,b=map(int,input().split()) x=(a*b)/2 print(int(x))
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 a,b=map(int,input().split()) x=(a*b)/2 print(int(x)) ```
3.969
864
C
Bus
PROGRAMMING
1,500
[ "greedy", "implementation", "math" ]
null
null
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ...
The first line contains four integers *a*, *b*, *f*, *k* (0<=&lt;<=*f*<=&lt;<=*a*<=≀<=106, 1<=≀<=*b*<=≀<=109, 1<=≀<=*k*<=≀<=104) β€” the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1.
[ "6 9 2 4\n", "6 10 2 4\n", "6 5 4 3\n" ]
[ "4\n", "2\n", "-1\n" ]
In the first example the bus needs to refuel during each journey. In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin...
1,500
[ { "input": "6 9 2 4", "output": "4" }, { "input": "6 10 2 4", "output": "2" }, { "input": "6 5 4 3", "output": "-1" }, { "input": "2 2 1 1", "output": "0" }, { "input": "10 4 6 10", "output": "-1" }, { "input": "3 1 1 1", "output": "-1" }, { ...
1,615,510,104
2,147,483,647
Python 3
OK
TESTS
48
62
307,200
a, b, f, k = map(int, input().split()) start = True tank = b refuels = 0 possible = True while k > 0 and possible: if k == 1: # can reach end if tank >= a: k -= 1 continue if start: # need to refuel # can reach fuel gas station, and can go from gas station to end if tank >= f and b >= (a - f): ...
Title: Bus Time Limit: None seconds Memory Limit: None megabytes Problem Description: A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ...
```python a, b, f, k = map(int, input().split()) start = True tank = b refuels = 0 possible = True while k > 0 and possible: if k == 1: # can reach end if tank >= a: k -= 1 continue if start: # need to refuel # can reach fuel gas station, and can go from gas station to end if tank >= f and b >=...
3
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i...
The single line contains two positive space-separated integers *l*, *r* (1<=≀<=*l*<=≀<=*r*<=≀<=1018; *r*<=-<=*l*<=≀<=50).
Print three positive space-separated integers *a*, *b*, *c*Β β€” three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "64009798...
1,597,487,859
2,147,483,647
Python 3
OK
TESTS
42
109
307,200
a, b = map(int, input().split()) superbreak = 0 for i in range(a, b+1): for j in range(i+1, b+1): for k in range(j+1, b+1): j2, i2, k2 = j, i, k lst = sorted([j, i, k]) while j > 0: i, j = j, i%j if i == 1: while k > 0...
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different st...
```python a, b = map(int, input().split()) superbreak = 0 for i in range(a, b+1): for j in range(i+1, b+1): for k in range(j+1, b+1): j2, i2, k2 = j, i, k lst = sorted([j, i, k]) while j > 0: i, j = j, i%j if i == 1: w...
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,653,909,933
2,147,483,647
Python 3
OK
TESTS
43
218
204,800
inputs = [int(num) for num in input().split()] t = inputs[0] sx = inputs[1] sy = inputs[2] ex = inputs[3] ey = inputs[4] s = input() if(ex>=sx): right = abs(ex-sx) left=0 else: left = abs(sx-ex) right=0 if(ey>=sy): up = abs(ey-sy) down =0 else: up=0 down = abs(ey-sy) t...
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 inputs = [int(num) for num in input().split()] t = inputs[0] sx = inputs[1] sy = inputs[2] ex = inputs[3] ey = inputs[4] s = input() if(ex>=sx): right = abs(ex-sx) left=0 else: left = abs(sx-ex) right=0 if(ey>=sy): up = abs(ey-sy) down =0 else: up=0 down = abs...
3
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many w...
The single line contains two integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=6)Β β€” the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,659,316,307
2,147,483,647
Python 3
OK
TESTS
38
46
0
a, b = list(map(int,input().split(" "))) w, d, l = 0, 0, 0 for i in range(1,7): t1, t2 = abs(i - a), abs(i - b) if(t1 < t2): w += 1 elif(t1 == t2): d += 1 else: l += 1 print(w,d,l)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff...
```python a, b = list(map(int,input().split(" "))) w, d, l = 0, 0, 0 for i in range(1,7): t1, t2 = abs(i - a), abs(i - b) if(t1 < t2): w += 1 elif(t1 == t2): d += 1 else: l += 1 print(w,d,l) ```
3
557
B
Pasha and Tea
PROGRAMMING
1,500
[ "constructive algorithms", "implementation", "math", "sortings" ]
null
null
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most *a**i* milliliters of water. It turned out that among Pasha's friends there are exactly *n* boys a...
The first line of the input contains two integers, *n* and *w* (1<=≀<=*n*<=≀<=105, 1<=≀<=*w*<=≀<=109)Β β€” the number of Pasha's friends that are boys (equal to the number of Pasha's friends that are girls) and the capacity of Pasha's teapot in milliliters. The second line of the input contains the sequence of integers *...
Print a single real number β€” the maximum total amount of water in milliliters that Pasha can pour to his friends without violating the given conditions. Your answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=6.
[ "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "1 5\n2 3\n" ]
[ "3", "18", "4.5" ]
Pasha also has candies that he is going to give to girls but that is another task...
1,000
[ { "input": "2 4\n1 1 1 1", "output": "3.0000000000" }, { "input": "3 18\n4 4 4 2 2 2", "output": "18.0000000000" }, { "input": "1 5\n2 3", "output": "4.5000000000" }, { "input": "1 1\n1000000000 1000000000", "output": "1.0000000000" }, { "input": "4 1000000000\n1 ...
1,441,197,166
1,066
Python 3
OK
TESTS
50
233
16,896,000
def main(): n, w = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] a = sorted(a) x = w / (3*n) if (x <= a[0] and 2*x <= a[n]): print(w) else: print(3*min(a[0], a[n]/2)*n) if __name__ == "__main__": main()
Title: Pasha and Tea Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of *w* milliliters and 2*n* tea cups, each cup is for one of Pasha's friends. The *i*-th cup can hold at most ...
```python def main(): n, w = [int(i) for i in input().split(" ")] a = [int(i) for i in input().split(" ")] a = sorted(a) x = w / (3*n) if (x <= a[0] and 2*x <= a[n]): print(w) else: print(3*min(a[0], a[n]/2)*n) if __name__ == "__main__": main() ```
3
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times...
The first line contains two integers *l* and *r* (2<=≀<=*l*<=≀<=*r*<=≀<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {...
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95",...
1,640,972,947
2,147,483,647
PyPy 3-64
OK
TESTS
93
109
0
Homura = [int(i) for i in input().split()] l = Homura[0] r = Homura[1] if l == r: print(l) else: print(2)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the...
```python Homura = [int(i) for i in input().split()] l = Homura[0] r = Homura[1] if l == r: print(l) else: print(2) ```
3
8
B
Obsession with Robots
PROGRAMMING
1,400
[ "constructive algorithms", "graphs", "implementation" ]
B. Obsession with Robots
2
64
The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a ...
The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100.
In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist).
[ "LLUUUR\n", "RRUULLDD\n" ]
[ "OK\n", "BUG\n" ]
none
0
[ { "input": "LLUUUR", "output": "OK" }, { "input": "RRUULLDD", "output": "BUG" }, { "input": "L", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "R", "output": "OK" }, { "input": "RR", "output": "OK" }, { "input": "DL", "...
1,585,464,962
2,147,483,647
Python 3
OK
TESTS
60
218
307,200
# maa chudaaye duniya d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]] path = input() vis = [] cur = [0, 0] f = True for p in path: prev = cur if p == 'L': index = 0 elif p == 'R' : index = 1 elif p == 'U' : index = 2 else: index = 3 cur = [cur[0] + d[index][0], cur[1] + d[index][1]] if cur in vis:...
Title: Obsession with Robots Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path fr...
```python # maa chudaaye duniya d = [[0,1], [0, -1], [1, 0], [-1, 0], [0, 0]] path = input() vis = [] cur = [0, 0] f = True for p in path: prev = cur if p == 'L': index = 0 elif p == 'R' : index = 1 elif p == 'U' : index = 2 else: index = 3 cur = [cur[0] + d[index][0], cur[1] + d[index][1]] if c...
3.943211
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,664,377,900
2,147,483,647
Python 3
OK
TESTS
36
92
0
y,w=map(int,input().split()) mx=max(y,w) a,b=0,0 mx=6-mx+1 if(mx==0): a=0 b=1 elif(mx==1): a=1 b=6 elif(mx==2): a=1 b=3 elif(mx==3): a=1 b=2 elif(mx==4): a=2 b=3 elif(mx==5): a=5 b=6 else: a,b=1,1 print(a,end='') print( '/' , end='') print(b) ...
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python y,w=map(int,input().split()) mx=max(y,w) a,b=0,0 mx=6-mx+1 if(mx==0): a=0 b=1 elif(mx==1): a=1 b=6 elif(mx==2): a=1 b=3 elif(mx==3): a=1 b=2 elif(mx==4): a=2 b=3 elif(mx==5): a=5 b=6 else: a,b=1,1 print(a,end='') print( '/' , end='') print(b) ...
3.954
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10...
1,650,130,299
2,147,483,647
PyPy 3-64
OK
TESTS
35
264
4,096,000
import time h=[] f=int(input()) t=time.time() for i in range(10,10**8//9,9): u=sum(map(int, str(i))) if u==10: h.append(i) print(h[f-1]) #print(time.time()-t)
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A singl...
```python import time h=[] f=int(input()) t=time.time() for i in range(10,10**8//9,9): u=sum(map(int, str(i))) if u==10: h.append(i) print(h[f-1]) #print(time.time()-t) ```
3
673
A
Bear and Game
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=......
The first line of the input contains one integer *n* (1<=≀<=*n*<=≀<=90)Β β€” the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≀<=90), given in the increasing order.
Print the number of minutes Limak will watch the game.
[ "3\n7 20 88\n", "9\n16 20 30 40 50 60 70 80 90\n", "9\n15 20 30 40 50 60 70 80 90\n" ]
[ "35\n", "15\n", "90\n" ]
In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w...
500
[ { "input": "3\n7 20 88", "output": "35" }, { "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15" }, { "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90" }, { "input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88", ...
1,540,440,077
2,147,483,647
Python 3
OK
TESTS
34
109
0
n = int(input()) moment = list(map(int, input().split())) def stupid_bear (a): for i in range (len(a)): if i == 0: if a[i] > 15: ans = 15 return ans else: if a[i]- a[i-1] > 15: ans = a[i-1]+15 return ans if a[i]- a[i-1] <= 15 and i == len(a)-1: ...
Title: Bear and Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim...
```python n = int(input()) moment = list(map(int, input().split())) def stupid_bear (a): for i in range (len(a)): if i == 0: if a[i] > 15: ans = 15 return ans else: if a[i]- a[i-1] > 15: ans = a[i-1]+15 return ans if a[i]- a[i-1] <= 15 and i == l...
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,680,020,263
2,147,483,647
PyPy 3-64
OK
TESTS
44
124
0
# https://codeforces.com/contest/96/problem/A s = input() print('YES' if '1' * 7 in s or '0' * 7 in s else '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 # https://codeforces.com/contest/96/problem/A s = input() print('YES' if '1' * 7 in s or '0' * 7 in s else 'NO') ```
3.969
205
A
Little Elephant and Rozdil
PROGRAMMING
900
[ "brute force", "implementation" ]
null
null
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider t...
Print the answer on a single line β€” the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes).
[ "2\n7 4\n", "7\n7 4 47 100 4 9 12\n" ]
[ "2\n", "Still Rozdil\n" ]
In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β€” 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2. In the second sample the closest cities are cities two and five, the travelling t...
500
[ { "input": "2\n7 4", "output": "2" }, { "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil" }, { "input": "1\n47", "output": "1" }, { "input": "2\n1000000000 1000000000", "output": "Still Rozdil" }, { "input": "7\n7 6 5 4 3 2 1", "output": "7" }, { ...
1,560,230,753
2,147,483,647
Python 3
OK
TESTS
45
310
8,396,800
import sys n = int(input()) a = list(map(int, input().split())) mi = sys.maxsize c = 0 j = 0 for i in range(n): if mi > a[i]: mi = a[i] c = 1 j = i elif mi == a[i]: c += 1 if c > 1: print("Still Rozdil") else: print(j + 1)
Title: Little Elephant and Rozdil Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha...
```python import sys n = int(input()) a = list(map(int, input().split())) mi = sys.maxsize c = 0 j = 0 for i in range(n): if mi > a[i]: mi = a[i] c = 1 j = i elif mi == a[i]: c += 1 if c > 1: print("Still Rozdil") else: print(j + 1) ```
3
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,682,459,133
2,147,483,647
Python 3
OK
TESTS
23
342
0
n=int(input()); primes=[2]; ans=0; for i in range(3,n+1): prime_divisor_count=0; x=i; for j in primes: if x%j==0: prime_divisor_count+=1; if prime_divisor_count<3: while x%j==0: x//=j; if prime_divisor_count==0: primes.appe...
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 n=int(input()); primes=[2]; ans=0; for i in range(3,n+1): prime_divisor_count=0; x=i; for j in primes: if x%j==0: prime_divisor_count+=1; if prime_divisor_count<3: while x%j==0: x//=j; if prime_divisor_count==0: p...
3.9145
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≀<=*p**i*<=≀<=*q**i*<=≀<=100) β€” the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer β€” the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,697,106,091
2,147,483,647
Python 3
OK
TESTS
27
46
0
import sys user_input = int(sys.stdin.readline().strip()) counter = 0 for i in range(user_input): a, b = map(int, sys.stdin.readline().strip().split()) if (b - a) >= 2: counter += 1 print(counter)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python import sys user_input = int(sys.stdin.readline().strip()) counter = 0 for i in range(user_input): a, b = map(int, sys.stdin.readline().strip().split()) if (b - a) >= 2: counter += 1 print(counter) ```
3
224
A
Parallelepiped
PROGRAMMING
1,100
[ "brute force", "geometry", "math" ]
null
null
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
The first and the single line contains three space-separated integers β€” the areas of the parallelepiped's faces. The area's values are positive (<=&gt;<=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement.
Print a single number β€” the sum of all edges of the parallelepiped.
[ "1 1 1\n", "4 6 6\n" ]
[ "12\n", "28\n" ]
In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second oneΒ β€” 2 × 2 × 3.
500
[ { "input": "1 1 1", "output": "12" }, { "input": "4 6 6", "output": "28" }, { "input": "20 10 50", "output": "68" }, { "input": "9 4 36", "output": "56" }, { "input": "324 9 36", "output": "184" }, { "input": "1333 93 129", "output": "308" }, {...
1,607,711,524
2,147,483,647
Python 3
OK
TESTS
27
216
0
import sys import math f1,f2,f3=map(int,input().split()) c=math.sqrt(f3/(f1/f2)) b=f2/c a=f3/c print(int(4*(a+b+c)))
Title: Parallelepiped Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. Input S...
```python import sys import math f1,f2,f3=map(int,input().split()) c=math.sqrt(f3/(f1/f2)) b=f2/c a=f3/c print(int(4*(a+b+c))) ```
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,670,592,131
2,147,483,647
Python 3
OK
TESTS
20
46
0
n,m,a=map(int , input().split()) total1=0 total2=0 if(n%a==0): total1=total1+n//a else: total1=total1+n//a+1 if(m%a==0): total2=total2+m//a else: total2=total2+m//a+1 print(total1*total2)
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()) total1=0 total2=0 if(n%a==0): total1=total1+n//a else: total1=total1+n//a+1 if(m%a==0): total2=total2+m//a else: total2=total2+m//a+1 print(total1*total2) ```
3.977
1,003
A
Polycarp's Pockets
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i...
The first line of the input contains one integer $n$ ($1 \le n \le 100$) β€” the number of coins. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) β€” values of coins.
Print only one integer β€” the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
[ "6\n1 2 4 3 3 2\n", "1\n100\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "6\n1 2 4 3 3 2", "output": "2" }, { "input": "1\n100", "output": "1" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
1,697,005,260
2,147,483,647
Python 3
OK
TESTS
37
46
307,200
from collections import defaultdict if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) mp = defaultdict(int) for num in a: mp[num] += 1 mx = max(mp.values()) print(mx)
Title: Polycarp's Pockets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Po...
```python from collections import defaultdict if __name__ == "__main__": n = int(input()) a = list(map(int, input().split())) mp = defaultdict(int) for num in a: mp[num] += 1 mx = max(mp.values()) print(mx) ```
3
168
A
Wizards and Demonstration
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city...
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≀<=*n*,<=*x*,<=*y*<=≀<=104,<=*x*<=≀<=*n*) β€” the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to...
Print a single integer β€” the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
[ "10 1 14\n", "20 10 50\n", "1000 352 146\n" ]
[ "1\n", "0\n", "1108\n" ]
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 1...
500
[ { "input": "10 1 14", "output": "1" }, { "input": "20 10 50", "output": "0" }, { "input": "1000 352 146", "output": "1108" }, { "input": "68 65 20", "output": "0" }, { "input": "78 28 27", "output": "0" }, { "input": "78 73 58", "output": "0" }, ...
1,594,465,542
2,147,483,647
PyPy 3
OK
TESTS
43
624
29,900,800
import decimal D = decimal.Decimal l1 = [int(x) for x in input().split()] n,x,y = l1[0],l1[1],l1[2] need = n*y have = x*100 extra = 0 i=0 while need-have>extra: extra+=100 i+=1 print(i)
Title: Wizards and Demonstration Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n...
```python import decimal D = decimal.Decimal l1 = [int(x) for x in input().split()] n,x,y = l1[0],l1[1],l1[2] need = n*y have = x*100 extra = 0 i=0 while need-have>extra: extra+=100 i+=1 print(i) ```
3
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a di...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=600)Β β€” participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integerΒ β€” the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero sco...
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { ...
1,637,753,599
2,147,483,647
Python 3
OK
TESTS
21
62
307,200
a=int(input()) n=[] count=0 n=input().split(" ") b=[0]*100000 n=[int(i) for i in n] for i in range(a): if n[i]>0: p=n[i] b[p]=b[p]+1 for i in range(100000): if b[i]>0: count=count+1 print(count)
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with ...
```python a=int(input()) n=[] count=0 n=input().split(" ") b=[0]*100000 n=[int(i) for i in n] for i in range(a): if n[i]>0: p=n[i] b[p]=b[p]+1 for i in range(100000): if b[i]>0: count=count+1 print(count) ```
3
581
A
Vasya the Hipster
PROGRAMMING
800
[ "implementation", "math" ]
null
null
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning ...
The single line of the input contains two positive integers *a* and *b* (1<=≀<=*a*,<=*b*<=≀<=100) β€” the number of red and blue socks that Vasya's got.
Print two space-separated integers β€” the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he'...
[ "3 1\n", "2 3\n", "7 3\n" ]
[ "1 1\n", "2 0\n", "3 2\n" ]
In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day.
500
[ { "input": "3 1", "output": "1 1" }, { "input": "2 3", "output": "2 0" }, { "input": "7 3", "output": "3 2" }, { "input": "100 100", "output": "100 0" }, { "input": "4 10", "output": "4 3" }, { "input": "6 10", "output": "6 2" }, { "input":...
1,698,343,025
2,147,483,647
Python 3
OK
TESTS
30
46
0
r,b = list(map(int,input().split())) d = min(r,b) s = (max(r,b)-d)//2 print(d,s)
Title: Vasya the Hipster Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red...
```python r,b = list(map(int,input().split())) d = min(r,b) s = (max(r,b)-d)//2 print(d,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,593,862,511
2,147,483,647
Python 3
OK
TESTS
102
124
0
s1 = input() s2 = input() s3 = str(int(s1) + int(s2)) s3 = s3.replace('2', '0') print(s3.zfill(len(s1)))
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 s1 = input() s2 = input() s3 = str(int(s1) + int(s2)) s3 = s3.replace('2', '0') print(s3.zfill(len(s1))) ```
3.969
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse...
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen...
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $...
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,642,761,874
2,147,483,647
PyPy 3-64
OK
TESTS
31
93
0
#!/usr/bin/env python # coding: utf-8 # In[18]: n, m = map(int,input().split()) x = list(map(int,input().strip().split()))[:n] y = list(map(int,input().strip().split()))[:m] a = [] for i in x: for j in y: if i == j: a.append(j) print(*a) # In[ ]:
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keyp...
```python #!/usr/bin/env python # coding: utf-8 # In[18]: n, m = map(int,input().split()) x = list(map(int,input().strip().split()))[:n] y = list(map(int,input().strip().split()))[:m] a = [] for i in x: for j in y: if i == j: a.append(j) print(*a) # In[ ]: ```
3
467
A
George and Accommodation
PROGRAMMING
800
[ "implementation" ]
null
null
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* peopl...
The first line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≀<=*p**i*<=≀<=*q**i*<=≀<=100) β€” the number of people who already live in the *i*-th room and the room's capacity.
Print a single integer β€” the number of rooms where George and Alex can move in.
[ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n" ]
[ "0\n", "2\n" ]
none
500
[ { "input": "3\n1 1\n2 2\n3 3", "output": "0" }, { "input": "3\n1 10\n0 10\n10 10", "output": "2" }, { "input": "2\n36 67\n61 69", "output": "2" }, { "input": "3\n21 71\n10 88\n43 62", "output": "3" }, { "input": "3\n1 2\n2 3\n3 4", "output": "0" }, { "...
1,691,935,300
2,147,483,647
PyPy 3-64
OK
TESTS
27
62
0
ct =0 n = int(input()) for i in range(n): p,q = map(int,input().split()) if(p+2 <=q): ct = ct +1 print(ct)
Title: George and Accommodation Time Limit: None seconds Memory Limit: None megabytes Problem Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want ...
```python ct =0 n = int(input()) for i in range(n): p,q = map(int,input().split()) if(p+2 <=q): ct = ct +1 print(ct) ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=1015, 1<=≀<=*k*<=≀<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "ou...
1,595,050,802
2,147,483,647
PyPy 3
OK
TESTS
96
1,700
23,449,600
import math as m n,k = map(int,input().split()) f = [] s = [] for x in range(1,int(m.sqrt(n))+1): if n%x == 0: f.append(x) if n//x not in f: s.append(n//x) c = f+s[::-1] try: print(c[k-1]) except: print(-1)
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specificatio...
```python import math as m n,k = map(int,input().split()) f = [] s = [] for x in range(1,int(m.sqrt(n))+1): if n%x == 0: f.append(x) if n//x not in f: s.append(n//x) c = f+s[::-1] try: print(c[k-1]) except: print(-1) ```
3
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to in...
The first line contains a single string *s*Β (1<=≀<=|*s*|<=≀<=103). The second line contains a single integer *k*Β (0<=≀<=*k*<=≀<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer β€” the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1Β·1 + 2Β·2 + 3Β·2 + 4Β·2 + 5Β·2 + 6Β·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetyw...
1,621,027,115
2,147,483,647
PyPy 3
OK
TESTS
24
93
1,331,200
s=input() k=int(input()) l=list(map(int,input().split())) t=[chr(x) for x in range(ord('a'), ord('z') + 1)] d={} for i in range(26): if t[i] not in d: d[t[i]]=l[i] m=max(l) i=l.index(m) s=s+t[i]*k r=0 for i in range(len(s)): r=r+((i+1)*d[s[i]]) print(r)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str...
```python s=input() k=int(input()) l=list(map(int,input().split())) t=[chr(x) for x in range(ord('a'), ord('z') + 1)] d={} for i in range(26): if t[i] not in d: d[t[i]]=l[i] m=max(l) i=l.index(m) s=s+t[i]*k r=0 for i in range(len(s)): r=r+((i+1)*d[s[i]]) print(r) ```
3
712
B
Memory and Trident
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move...
The first and only line contains the string *s* (1<=≀<=|*s*|<=≀<=100<=000)Β β€” the instructions Memory is given.
If there is a string satisfying the conditions, output a single integerΒ β€” the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.
[ "RRU\n", "UDUR\n", "RUUR\n" ]
[ "-1\n", "1\n", "2\n" ]
In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk. In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses ...
1,000
[ { "input": "RRU", "output": "-1" }, { "input": "UDUR", "output": "1" }, { "input": "RUUR", "output": "2" }, { "input": "DDDD", "output": "2" }, { "input": "RRRR", "output": "2" }, { "input": "RRRUUD", "output": "2" }, { "input": "UDURLRDURL...
1,473,528,542
2,642
Python 3
OK
TESTS
75
77
307,200
#!/usr/bin/python3 s = input() if len(s) % 2 != 0: print(-1) else: dy = s.count('U') - s.count('D') dx = s.count('R') - s.count('L') print((abs(dx) + abs(dy)) // 2)
Title: Memory and Trident Time Limit: None seconds Memory Limit: None megabytes Problem Description: Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion: - An 'L' indicates he should move one unit left. - An 'R' indicates he shou...
```python #!/usr/bin/python3 s = input() if len(s) % 2 != 0: print(-1) else: dy = s.count('U') - s.count('D') dx = s.count('R') - s.count('L') print((abs(dx) + abs(dy)) // 2) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr...
The only line of the input file contains two natural numbers Y and W β€” the results of Yakko's and Wakko's die rolls.
Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β€” the numerator, and B β€” the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β».
[ "4 2\n" ]
[ "1/2\n" ]
Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
0
[ { "input": "4 2", "output": "1/2" }, { "input": "1 1", "output": "1/1" }, { "input": "1 2", "output": "5/6" }, { "input": "1 3", "output": "2/3" }, { "input": "1 4", "output": "1/2" }, { "input": "1 5", "output": "1/3" }, { "input": "1 6", ...
1,690,809,800
2,147,483,647
Python 3
OK
TESTS
36
92
0
''' t=int(input()) ans=[] for _ in range(t): a,b,c=map(int,input().split()) if c>b: d=2*(c-b)+b-1 else:d=b-1 a-=1 if a>d:ans.append(2) elif a==d:ans.append(3) else:ans.append(1) print(*ans,sep='\n')''' import math a=6-max(map(int,input().split()))+1 b=math.gcd(a,6) pr...
Title: Die Roll Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T...
```python ''' t=int(input()) ans=[] for _ in range(t): a,b,c=map(int,input().split()) if c>b: d=2*(c-b)+b-1 else:d=b-1 a-=1 if a>d:ans.append(2) elif a==d:ans.append(3) else:ans.append(1) print(*ans,sep='\n')''' import math a=6-max(map(int,input().split()))+1 b=math.gc...
3.954
709
A
Juicer
PROGRAMMING
900
[ "implementation" ]
null
null
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ...
The first line of the input contains three integers *n*, *b* and *d* (1<=≀<=*n*<=≀<=100<=000, 1<=≀<=*b*<=≀<=*d*<=≀<=1<=000<=000)Β β€” the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line co...
Print one integerΒ β€” the number of times Kolya will have to empty the waste section.
[ "2 7 10\n5 6\n", "1 5 10\n7\n", "3 10 10\n5 7 7\n", "1 1 1\n1\n" ]
[ "1\n", "0\n", "1\n", "0\n" ]
In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards. In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.
500
[ { "input": "2 7 10\n5 6", "output": "1" }, { "input": "1 5 10\n7", "output": "0" }, { "input": "3 10 10\n5 7 7", "output": "1" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 951637 951638\n44069 951637", "output": "1" }, { "input": "50 100 12...
1,687,494,331
2,147,483,647
Python 3
OK
TESTS
58
171
13,619,200
# -*- coding: utf-8 -*- """ Created on Fri Jun 23 06:20:28 2023 @author: RadmediX """ (n,b,d) = tuple(map(int, input().split())) oranges = list(map(int, input().split())) waste = 0 emptyNum = 0 for orange in oranges: waste += orange if orange <= b else 0 if waste > d: emp...
Title: Juicer Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b...
```python # -*- coding: utf-8 -*- """ Created on Fri Jun 23 06:20:28 2023 @author: RadmediX """ (n,b,d) = tuple(map(int, input().split())) oranges = list(map(int, input().split())) waste = 0 emptyNum = 0 for orange in oranges: waste += orange if orange <= b else 0 if waste > d: ...
3
467
B
Fedor and New Game
PROGRAMMING
1,100
[ "bitmasks", "brute force", "constructive algorithms", "implementation" ]
null
null
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game Β«Call of Soldiers 3Β». The game has (*m*<=+<=1) players and *n* types of soldiers in total. Players Β«Call of Soldiers 3Β» are numbered form 1 to (*m*<=+<=1). Types of soldiers are numbered from 0 to *n...
The first line contains three integers *n*, *m*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=20;Β 1<=≀<=*m*<=≀<=1000). The *i*-th of the next (*m*<=+<=1) lines contains a single integer *x**i* (1<=≀<=*x**i*<=≀<=2*n*<=-<=1), that describes the *i*-th player's army. We remind you that Fedor is the (*m*<=+<=1)-th player.
Print a single integer β€” the number of Fedor's potential friends.
[ "7 3 1\n8\n5\n111\n17\n", "3 3 3\n1\n2\n3\n4\n" ]
[ "0\n", "3\n" ]
none
1,000
[ { "input": "7 3 1\n8\n5\n111\n17", "output": "0" }, { "input": "3 3 3\n1\n2\n3\n4", "output": "3" }, { "input": "4 2 2\n5\n6\n7", "output": "2" }, { "input": "4 7 4\n9\n10\n5\n12\n4\n12\n7\n10", "output": "7" }, { "input": "2 7 2\n1\n1\n1\n1\n1\n1\n1\n1", "out...
1,687,167,007
2,147,483,647
PyPy 3
OK
TESTS
43
109
1,433,600
n, m, k = map(int,input().split()) x = [int(input()) for t in range (m + 1)] print(sum(bin(x[m]^y).count('1') <= k for y in x)-1)
Title: Fedor and New Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game Β«Call of Soldiers 3Β». The game has (*m*<=+<=1) players and *n* types of soldiers in total. Play...
```python n, m, k = map(int,input().split()) x = [int(input()) for t in range (m + 1)] print(sum(bin(x[m]^y).count('1') <= k for y in x)-1) ```
3
312
B
Archer
PROGRAMMING
1,300
[ "math", "probabilities" ]
null
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will...
A single line contains four integers .
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "1 2 1 2\n" ]
[ "0.666666666667" ]
none
1,000
[ { "input": "1 2 1 2", "output": "0.666666666667" }, { "input": "1 3 1 3", "output": "0.600000000000" }, { "input": "1 3 2 3", "output": "0.428571428571" }, { "input": "3 4 3 4", "output": "0.800000000000" }, { "input": "1 2 10 11", "output": "0.523809523810" ...
1,373,445,779
2,147,483,647
Python 3
OK
TESTS
31
78
102,400
a, b, c, d = map(int, input().split()) print("{0:.10f}".format(a / b / (1 - ((1 - a / b) * (1 - c / d)))))
Title: Archer Time Limit: None seconds Memory Limit: None megabytes Problem Description: SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w...
```python a, b, c, d = map(int, input().split()) print("{0:.10f}".format(a / b / (1 - ((1 - a / b) * (1 - c / d))))) ```
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,695,113,787
2,147,483,647
Python 3
OK
TESTS
35
92
0
n,m = map(int,input().split()) if m % 2 == 0: ans = int(m / 2) * n else: ans = int(m // 2) * n + int(n // 2) print(ans)
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 n,m = map(int,input().split()) if m % 2 == 0: ans = int(m / 2) * n else: ans = int(m // 2) * n + int(n // 2) print(ans) ```
3.977
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,663,072,842
2,147,483,647
Python 3
OK
TESTS
35
92
0
a,b = map(int,input().split()) s = a*b s = s//2 print(s)
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 a,b = map(int,input().split()) s = a*b s = s//2 print(s) ```
3.977
987
C
Three displays
PROGRAMMING
1,400
[ "brute force", "dp", "implementation" ]
null
null
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent ...
The first line contains a single integer $n$ ($3 \le n \le 3\,000$)Β β€” the number of displays. The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^9$)Β β€” the font sizes on the displays in the order they stand along the road. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \...
If there are no three displays that satisfy the criteria, print -1. Otherwise print a single integerΒ β€” the minimum total rent cost of three displays with indices $i &lt; j &lt; k$ such that $s_i &lt; s_j &lt; s_k$.
[ "5\n2 4 5 4 10\n40 30 20 10 40\n", "3\n100 101 100\n2 4 5\n", "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13\n" ]
[ "90\n", "-1\n", "33\n" ]
In the first example you can, for example, choose displays $1$, $4$ and $5$, because $s_1 &lt; s_4 &lt; s_5$ ($2 &lt; 4 &lt; 10$), and the rent cost is $40 + 10 + 40 = 90$. In the second example you can't select a valid triple of indices, so the answer is -1.
1,250
[ { "input": "5\n2 4 5 4 10\n40 30 20 10 40", "output": "90" }, { "input": "3\n100 101 100\n2 4 5", "output": "-1" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10\n10 13 11 14 15 12 13 13 18 13", "output": "33" }, { "input": "3\n1 2 3\n100000000 100000000 100000000", "output": "300...
1,617,620,424
2,147,483,647
PyPy 3
OK
TESTS
33
280
10,752,000
import bisect n=int(input()) s=list(map(int,input().split())) c=list(map(int,input().split())) ans=10**18 for mid in range(1,n-1): l1=[c[i] for i in range(mid) if s[i]<s[mid]]+[10**18] l2=[c[i] for i in range(mid+1,n) if s[i]>s[mid]]+[10**18] ans=min(ans,min(l1)+c[mid]+min(l2)) if ans>=10**18: print(-...
Title: Three displays Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem. There are $n$ displays placed along a road, ...
```python import bisect n=int(input()) s=list(map(int,input().split())) c=list(map(int,input().split())) ans=10**18 for mid in range(1,n-1): l1=[c[i] for i in range(mid) if s[i]<s[mid]]+[10**18] l2=[c[i] for i in range(mid+1,n) if s[i]>s[mid]]+[10**18] ans=min(ans,min(l1)+c[mid]+min(l2)) if ans>=10**18: ...
3
686
A
Free Ice Cream
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the...
The first line contains two space-separated integers *n* and *x* (1<=≀<=*n*<=≀<=1000, 0<=≀<=*x*<=≀<=109). Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≀<=*d**i*<=≀<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ...
Print two space-separated integersΒ β€” number of ice cream packs left after all operations, and number of kids that left the house in distress.
[ "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n", "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n" ]
[ "22 1\n", "3 2\n" ]
Consider the first sample. 1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1....
500
[ { "input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20", "output": "22 1" }, { "input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98", "output": "3 2" }, { "input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000", "output": "7000000000 0" }, { ...
1,628,326,693
2,147,483,647
Python 3
OK
TESTS
34
62
6,758,400
times,ice_cream = map(int,input().split()) sad_kids = 0 for x in range(times): sign,order = input().split() if sign in '+': ice_cream+= int(order) else: if ice_cream >= int(order): ice_cream -= int(order) else: sad_kids += 1 print(ice_cream,end=' ...
Title: Free Ice Cream Time Limit: None seconds Memory Limit: None megabytes Problem Description: After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer. At the start of the day they have *x* ice cream packs. Since the ice cream is free, p...
```python times,ice_cream = map(int,input().split()) sad_kids = 0 for x in range(times): sign,order = input().split() if sign in '+': ice_cream+= int(order) else: if ice_cream >= int(order): ice_cream -= int(order) else: sad_kids += 1 print(ice_cr...
3
357
A
Group of Students
PROGRAMMING
1,000
[ "brute force", "greedy", "implementation" ]
null
null
At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got ...
The first line contains integer *m* (2<=≀<=*m*<=≀<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≀<=*c**i*<=≀<=100). The third line contains two space-separated integers *x* and *y* (1<=≀<=*x*<=≀<=*y*<=≀<=10000). At least one *c**i* is greater than 0.
If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* β€” the passing rate you'd like to suggest. If there are multiple possible answers, print any of them.
[ "5\n3 4 3 2 1\n6 8\n", "5\n0 3 3 4 2\n3 10\n", "2\n2 5\n3 6\n" ]
[ "3\n", "4\n", "0\n" ]
In the first sample the beginner group has 7 students, the intermediate group has 6 of them. In the second sample another correct answer is 3.
500
[ { "input": "5\n3 4 3 2 1\n6 8", "output": "3" }, { "input": "5\n0 3 3 4 2\n3 10", "output": "4" }, { "input": "2\n2 5\n3 6", "output": "0" }, { "input": "3\n0 1 0\n2 10", "output": "0" }, { "input": "5\n2 2 2 2 2\n5 5", "output": "0" }, { "input": "10\...
1,623,216,855
2,147,483,647
Python 3
OK
TESTS
58
124
0
#%% r = int(input()) ins = (list(map(int, input().split(" ")))) low, high = list(map(int, input().split(" "))) for i in range(1, len(ins)): ins[i] += ins[i-1] if ins[-1] > (high * 2): print(0) else: for i in range(len(ins)): if low<= ins[i] <= high and low <= ins[-1] - ins[i] <= high: ...
Title: Group of Students Time Limit: None seconds Memory Limit: None megabytes Problem Description: At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According ...
```python #%% r = int(input()) ins = (list(map(int, input().split(" ")))) low, high = list(map(int, input().split(" "))) for i in range(1, len(ins)): ins[i] += ins[i-1] if ins[-1] > (high * 2): print(0) else: for i in range(len(ins)): if low<= ins[i] <= high and low <= ins[-1] - ins[i] ...
3
278
A
Circle Line
PROGRAMMING
800
[ "implementation" ]
null
null
The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd and the 3-rd station;...- *d**n*<=-<=1 is the distance between the *n*<=-<=1-th and the *n*-th ...
The first line contains integer *n* (3<=≀<=*n*<=≀<=100) β€” the number of stations on the circle line. The second line contains *n* integers *d*1,<=*d*2,<=...,<=*d**n* (1<=≀<=*d**i*<=≀<=100) β€” the distances between pairs of neighboring stations. The third line contains two integers *s* and *t* (1<=≀<=*s*,<=*t*<=≀<=*n*) β€”...
Print a single number β€” the length of the shortest path between stations number *s* and *t*.
[ "4\n2 3 4 9\n1 3\n", "4\n5 8 2 100\n4 1\n", "3\n1 1 1\n3 1\n", "3\n31 41 59\n1 1\n" ]
[ "5\n", "15\n", "1\n", "0\n" ]
In the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13. In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15. In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2. In the fourth sample the numbers of st...
500
[ { "input": "4\n2 3 4 9\n1 3", "output": "5" }, { "input": "4\n5 8 2 100\n4 1", "output": "15" }, { "input": "3\n1 1 1\n3 1", "output": "1" }, { "input": "3\n31 41 59\n1 1", "output": "0" }, { "input": "5\n16 13 10 30 15\n4 2", "output": "23" }, { "inpu...
1,547,936,241
2,147,483,647
Python 3
OK
TESTS
23
218
0
input() Stations = list(map(int, input().split())) First, Second = list(map(int, input().split())) Count1, Count2 = 0, 0 i = First - 1 while i != Second - 1: Count1 += Stations[i] i = (i + 1) % len(Stations) i = (First - 2 if First - 2 >= 0 else len(Stations) - 1) while i != Second - 1: Count2 += ...
Title: Circle Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The circle line of the Berland subway has *n* stations. We know the distances between all pairs of neighboring stations: - *d*1 is the distance between the 1-st and the 2-nd station;- *d*2 is the distance between the 2-nd...
```python input() Stations = list(map(int, input().split())) First, Second = list(map(int, input().split())) Count1, Count2 = 0, 0 i = First - 1 while i != Second - 1: Count1 += Stations[i] i = (i + 1) % len(Stations) i = (First - 2 if First - 2 >= 0 else len(Stations) - 1) while i != Second - 1: ...
3
978
A
Remove Duplicates
PROGRAMMING
800
[ "implementation" ]
null
null
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed.
The first line contains a single integer $n$ ($1 \le n \le 50$) β€” the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) β€” the Petya's array.
In the first line print integer $x$ β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left.
[ "6\n1 5 5 1 6 1\n", "5\n2 4 2 4 4\n", "5\n6 6 6 6 6\n" ]
[ "3\n5 6 1 \n", "2\n2 4 \n", "1\n6 \n" ]
In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the...
0
[ { "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 " }, { "input": "5\n2 4 2 4 4", "output": "2\n2 4 " }, { "input": "5\n6 6 6 6 6", "output": "1\n6 " }, { "input": "7\n1 2 3 4 2 2 3", "output": "4\n1 4 2 3 " }, { "input": "9\n100 100 100 99 99 99 100 100 100", ...
1,682,118,349
2,147,483,647
PyPy 3-64
OK
TESTS
28
62
0
n = int(input()) a = list(map(int, input().split())) c = set(a) li = [] for i in range(len(a)-1, -1, -1): if a[i] in li: continue else: li.append(a[i]) li.reverse() print(len(li)) print(*li)
Title: Remove Duplicates Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the re...
```python n = int(input()) a = list(map(int, input().split())) c = set(a) li = [] for i in range(len(a)-1, -1, -1): if a[i] in li: continue else: li.append(a[i]) li.reverse() print(len(li)) print(*li) ```
3
660
A
Co-prime Array
PROGRAMMING
1,200
[ "greedy", "implementation", "math", "number theory" ]
null
null
You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integ...
The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of elements in the given array. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=109) β€” the elements of the array *a*.
Print integer *k* on the first line β€” the least number of elements needed to add to the array *a* to make it co-prime. The second line should contain *n*<=+<=*k* integers *a**j* β€” the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values shoul...
[ "3\n2 7 28\n" ]
[ "1\n2 7 9 28\n" ]
none
0
[ { "input": "3\n2 7 28", "output": "1\n2 7 1 28" }, { "input": "1\n1", "output": "0\n1" }, { "input": "1\n548", "output": "0\n548" }, { "input": "1\n963837006", "output": "0\n963837006" }, { "input": "10\n1 1 1 1 1 1 1 1 1 1", "output": "0\n1 1 1 1 1 1 1 1 1 1"...
1,625,572,872
2,147,483,647
Python 3
OK
TESTS
93
109
1,331,200
from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf, log2, sqrt, log10 from bisect import bisect_right, bisect_left from statistics import mode from string import ascii_uppercase lists = {2, 3, 5, 7, 11, 13, 17, 19...
Title: Co-prime Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. A...
```python from collections import deque, defaultdict, Counter from itertools import product, groupby, permutations, combinations from math import gcd, floor, inf, log2, sqrt, log10 from bisect import bisect_right, bisect_left from statistics import mode from string import ascii_uppercase lists = {2, 3, 5, 7, 11, ...
3
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,674,701,445
2,147,483,647
Python 3
OK
TESTS
50
62
0
t=[] a=[int(x) for x in input().split()] x=0 for i in range(a[0]): t=input().split() x+=t.count('W')+t.count('B')+t.count('G') if x==a[0]*a[1]: print("#Black&White") else: print("#Color")
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python t=[] a=[int(x) for x in input().split()] x=0 for i in range(a[0]): t=input().split() x+=t.count('W')+t.count('B')+t.count('G') if x==a[0]*a[1]: print("#Black&White") else: print("#Color") ```
3
711
A
Bus to Udayland
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied. ZS and Chris a...
The first line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of rows of seats in the bus. Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t...
If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ...
[ "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n", "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n" ]
[ "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n", "NO\n", "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n" ]
Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair. O+|+X XO|XX OX|OO XX|OX OO|OO OO|XX
500
[ { "input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX", "output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX" }, { "input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX", "output": "NO" }, { "input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO", "output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO" ...
1,680,913,294
2,147,483,647
Python 3
OK
TESTS
71
46
0
n = input() rows = [] flag = False for i in range(int(n)): row = input() if not flag and 'OO' in row: row = row.replace('OO', '++', 1) flag = True rows.append(row) if flag: print("YES") for i in range(int(n)): print(rows[i]) else: print("NO")
Title: Bus to Udayland Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai...
```python n = input() rows = [] flag = False for i in range(int(n)): row = input() if not flag and 'OO' in row: row = row.replace('OO', '++', 1) flag = True rows.append(row) if flag: print("YES") for i in range(int(n)): print(rows[i]) else: print("NO") ...
3
766
A
Mahmoud and Longest Uncommon Subsequence
PROGRAMMING
1,000
[ "constructive algorithms", "strings" ]
null
null
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ...
The first line contains string *a*, and the second lineΒ β€” string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters.
If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*.
[ "abcd\ndefgh\n", "a\na\n" ]
[ "5\n", "-1\n" ]
In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*.
500
[ { "input": "abcd\ndefgh", "output": "5" }, { "input": "a\na", "output": "-1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd...
1,699,714,759
2,147,483,647
PyPy 3-64
OK
TESTS
73
62
307,200
a = input() b = input() print(max(len(a), len(b)) if a != b else -1)
Title: Mahmoud and Longest Uncommon Subsequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two ...
```python a = input() b = input() print(max(len(a), len(b)) if a != b else -1) ```
3
214
A
System of Equations
PROGRAMMING
800
[ "brute force" ]
null
null
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of int...
A single line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=1000) β€” the parameters of the system. The numbers on the line are separated by a space.
On a single line print the answer to the problem.
[ "9 3\n", "14 28\n", "4 20\n" ]
[ "1\n", "1\n", "0\n" ]
In the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.
500
[ { "input": "9 3", "output": "1" }, { "input": "14 28", "output": "1" }, { "input": "4 20", "output": "0" }, { "input": "18 198", "output": "1" }, { "input": "22 326", "output": "1" }, { "input": "26 104", "output": "1" }, { "input": "14 10"...
1,682,503,159
2,147,483,647
Python 3
OK
TESTS
54
122
0
def system_of_equations_a(): n,m = map(int, input().split()) a, c = 0, 0 while(a <= int(math.sqrt(n))): b = n - a*a if(a + b*b == m): c += 1 a += 1 print(c) if __name__ == '__main__': import math system_of_equations_a()
Title: System of Equations Time Limit: None seconds Memory Limit: None megabytes Problem Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immedi...
```python def system_of_equations_a(): n,m = map(int, input().split()) a, c = 0, 0 while(a <= int(math.sqrt(n))): b = n - a*a if(a + b*b == m): c += 1 a += 1 print(c) if __name__ == '__main__': import math system_of_equations_a() ```
3
255
A
Greg's Workout
PROGRAMMING
800
[ "implementation" ]
null
null
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercise...
The first line contains integer *n* (1<=≀<=*n*<=≀<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=25) β€” the number of times Greg repeats the exercises.
Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.
[ "2\n2 8\n", "3\n5 1 10\n", "7\n3 3 2 7 9 6 8\n" ]
[ "biceps\n", "back\n", "chest\n" ]
In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises. In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises. In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos...
500
[ { "input": "2\n2 8", "output": "biceps" }, { "input": "3\n5 1 10", "output": "back" }, { "input": "7\n3 3 2 7 9 6 8", "output": "chest" }, { "input": "4\n5 6 6 2", "output": "chest" }, { "input": "5\n8 2 2 6 3", "output": "chest" }, { "input": "6\n8 7 ...
1,584,802,471
2,147,483,647
Python 3
OK
TESTS
61
248
0
# Π”Π°Π½ΠΎ n ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ # КаТдоС ΡƒΠΏΡ€Π°ΠΆΠ΅Π½ΠΈΠ½Π΅ это A1.. A2.. A3...... # 1. Π“Ρ€ΡƒΠ΄ΡŒ # 2. БицСпс # 3. Π‘ΠΏΠΈΠ½Π° n = int(input()) # Кол-Π²ΠΎ ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ tren = list(map(int,input().split())) grud = 0 bic = 0 spin = 0 upr = 1 for i in tren: if upr == 1: grud += i elif upr == 2: bic += i ...
Title: Greg's Workout Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ...
```python # Π”Π°Π½ΠΎ n ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ # КаТдоС ΡƒΠΏΡ€Π°ΠΆΠ΅Π½ΠΈΠ½Π΅ это A1.. A2.. A3...... # 1. Π“Ρ€ΡƒΠ΄ΡŒ # 2. БицСпс # 3. Π‘ΠΏΠΈΠ½Π° n = int(input()) # Кол-Π²ΠΎ ΡƒΠΏΡ€Π°ΠΆΠ½Π΅Π½ΠΈΠΉ tren = list(map(int,input().split())) grud = 0 bic = 0 spin = 0 upr = 1 for i in tren: if upr == 1: grud += i elif upr == 2: bi...
3
608
B
Hamming Distance Sum
PROGRAMMING
1,500
[ "combinatorics", "strings" ]
null
null
Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is defined as , where *s**i* is the *i*-th character of *s* and *t**i* is the *i*-th character of *t*. For exam...
The first line of the input contains binary string *a* (1<=≀<=|*a*|<=≀<=200<=000). The second line of the input contains binary string *b* (|*a*|<=≀<=|*b*|<=≀<=200<=000). Both strings are guaranteed to consist of characters '0' and '1' only.
Print a single integerΒ β€” the sum of Hamming distances between *a* and all contiguous substrings of *b* of length |*a*|.
[ "01\n00111\n", "0011\n0110\n" ]
[ "3\n", "2\n" ]
For the first sample case, there are four contiguous substrings of *b* of length |*a*|: "00", "01", "11", and "11". The distance between "01" and "00" is |0 - 0| + |1 - 0| = 1. The distance between "01" and "01" is |0 - 0| + |1 - 1| = 0. The distance between "01" and "11" is |0 - 1| + |1 - 1| = 1. Last distance counts ...
1,000
[ { "input": "01\n00111", "output": "3" }, { "input": "0011\n0110", "output": "2" }, { "input": "0\n0", "output": "0" }, { "input": "1\n0", "output": "1" }, { "input": "0\n1", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "1...
1,451,131,398
2,147,483,647
Python 3
OK
TESTS
30
342
7,270,400
a,b,cum,total,ans=input(),input(),[0],0,0 for i in range(len(b)): total+=int(b[i]) cum.append(total) for i in range(len(a)): one = cum[len(b)-(len(a)-i)+1]- cum[i] zero = len(b)-len(a)+1-one if a[i]=='0': ans+=one else: ans+=zero # print("i:",i,"one:",one,"zero...
Title: Hamming Distance Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string *s* is denoted |*s*|. The Hamming distance between two strings *s* and *t* of equal length is de...
```python a,b,cum,total,ans=input(),input(),[0],0,0 for i in range(len(b)): total+=int(b[i]) cum.append(total) for i in range(len(a)): one = cum[len(b)-(len(a)-i)+1]- cum[i] zero = len(b)-len(a)+1-one if a[i]=='0': ans+=one else: ans+=zero # print("i:",i,"one:"...
3
707
A
Brain's Photos
PROGRAMMING
800
[ "implementation" ]
null
null
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a ...
The first line of the input contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100)Β β€” the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i...
Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line.
[ "2 2\nC M\nY Y\n", "3 2\nW W\nW W\nB B\n", "1 1\nW\n" ]
[ "#Color", "#Black&amp;White", "#Black&amp;White" ]
none
500
[ { "input": "2 2\nC M\nY Y", "output": "#Color" }, { "input": "3 2\nW W\nW W\nB B", "output": "#Black&White" }, { "input": "1 1\nW", "output": "#Black&White" }, { "input": "2 3\nW W W\nB G Y", "output": "#Color" }, { "input": "1 1\nW", "output": "#Black&White" ...
1,698,637,028
2,147,483,647
PyPy 3-64
OK
TESTS
50
62
1,740,800
user = str(input()) b = user.split() c = [int(x) for x in b] Black = 0 Colored = 0 for x in range(c[0]): user_put = str(input()) d = user_put.split() for x in d: if x == "W" or x == "B" or x == "G": Black = Black + 1 else: Colored = Colored + 1 if B...
Title: Brain's Photos Time Limit: None seconds Memory Limit: None megabytes Problem Description: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the...
```python user = str(input()) b = user.split() c = [int(x) for x in b] Black = 0 Colored = 0 for x in range(c[0]): user_put = str(input()) d = user_put.split() for x in d: if x == "W" or x == "B" or x == "G": Black = Black + 1 else: Colored = Colored +...
3
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take...
The only string contains space-separated integers *a*, *b* and *n* (1<=≀<=*a*,<=*b*,<=*n*<=≀<=100) β€” the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b...
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,639,812,421
2,147,483,647
Python 3
OK
TESTS
45
92
0
def nod(x, y): if x < y: x, y = y, x while y != 0: d = y y = x % y x = d return x a, b, n = map(int, input().split()) while n != 0: n = n - nod(a, n) if n == 0: r = '0' print(r) break n -= nod(b, n) if n == 0: r = '1' ...
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto...
```python def nod(x, y): if x < y: x, y = y, x while y != 0: d = y y = x % y x = d return x a, b, n = map(int, input().split()) while n != 0: n = n - nod(a, n) if n == 0: r = '0' print(r) break n -= nod(b, n) if n == 0: r = '1...
3
122
B
Lucky Substring
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya was delivered a string *s*, containing only digits. He needs to find a string that - ...
The single line contains a non-empty string *s* whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
[ "047\n", "16\n", "472747\n" ]
[ "4\n", "-1\n", "7\n" ]
The lexicographical comparison of strings is performed by the &lt; operator in the modern programming languages. String *x* is lexicographically less than string *y* either if *x* is a prefix of *y*, or exists such *i* (1 ≀ *i* ≀ *min*(|*x*|, |*y*|)), that *x*<sub class="lower-index">*i*</sub> &lt; *y*<sub class="lower...
1,000
[ { "input": "047", "output": "4" }, { "input": "16", "output": "-1" }, { "input": "472747", "output": "7" }, { "input": "1925", "output": "-1" }, { "input": "5486846414848445484", "output": "4" }, { "input": "516160414", "output": "4" }, { "...
1,691,150,669
2,147,483,647
Python 3
OK
TESTS
42
92
0
text = input() empat = 0 tujuh = 0 for dt in text: if dt == "4": empat = empat + 1 elif dt == "7": tujuh = tujuh + 1 if empat == 0 and tujuh == 0: print(-1) elif empat >= tujuh: print(4) else: print(7) quit()
Title: Lucky Substring Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. ...
```python text = input() empat = 0 tujuh = 0 for dt in text: if dt == "4": empat = empat + 1 elif dt == "7": tujuh = tujuh + 1 if empat == 0 and tujuh == 0: print(-1) elif empat >= tujuh: print(4) else: print(7) quit() ```
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,589,472,667
2,147,483,647
Python 3
OK
TESTS
102
109
6,656,000
n=input() m=input() res="" for i in range(len(n)): if n[i]!=m[i]: res+='1' else: res+='0' print(res)
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10...
```python n=input() m=input() res="" for i in range(len(n)): if n[i]!=m[i]: res+='1' else: res+='0' print(res) ```
3.960352
588
A
Duff and Meat
PROGRAMMING
900
[ "greedy" ]
null
null
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ...
The first line of input contains integer *n* (1<=≀<=*n*<=≀<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≀<=*a**i*,<=*p**i*<=≀<=100), the amount of meat Duff needs and the cost of meat in that day.
Print the minimum money needed to keep Duff happy for *n* days, in one line.
[ "3\n1 3\n2 2\n3 1\n", "3\n1 3\n2 1\n3 2\n" ]
[ "10\n", "8\n" ]
In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day. In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.
750
[ { "input": "3\n1 3\n2 2\n3 1", "output": "10" }, { "input": "3\n1 3\n2 1\n3 2", "output": "8" }, { "input": "1\n39 52", "output": "2028" }, { "input": "2\n25 56\n94 17", "output": "2998" }, { "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321" }...
1,621,110,657
2,147,483,647
PyPy 3
OK
TESTS
30
171
8,294,400
import sys def main(): inp = sys.stdin.read().strip().split('\n') m = None c = 0 for s in inp[1:]: a, p = map(int, s.split()) if m == None or m > p: m = p c += a*m return c print(main())
Title: Duff and Meat Time Limit: None seconds Memory Limit: None megabytes Problem Description: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her ...
```python import sys def main(): inp = sys.stdin.read().strip().split('\n') m = None c = 0 for s in inp[1:]: a, p = map(int, s.split()) if m == None or m > p: m = p c += a*m return c print(main()) ```
3
490
A
Team Olympiad
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at prog...
The first line contains integer *n* (1<=≀<=*n*<=≀<=5000) β€” the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t**i*<=≀<=3), where *t**i* describes the skill of the *i*-th child.
In the first line output integer *w* β€” the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to...
[ "7\n1 3 1 3 2 1 2\n", "4\n2 1 1 2\n" ]
[ "2\n3 5 2\n6 7 4\n", "0\n" ]
none
500
[ { "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4" }, { "input": "4\n2 1 1 2", "output": "0" }, { "input": "1\n2", "output": "0" }, { "input": "2\n3 1", "output": "0" }, { "input": "3\n2 1 2", "output": "0" }, { "input": "3\n1 2 3", "output...
1,689,689,070
2,147,483,647
Python 3
OK
TESTS
41
46
307,200
a = int(input()) n = list(map(int, input().split())) num1 = [] num2 = [] num3 = [] for i in range(0, a): if n[i] == 1: num1.append(i+1) elif n[i] == 2: num2.append(i+1) elif n[i] == 3: num3.append(i+1) p = min(n.count(1),n.count(2) ,n.count(3)) print(p) if p > 0: ...
Title: Team Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The School β„–0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)...
```python a = int(input()) n = list(map(int, input().split())) num1 = [] num2 = [] num3 = [] for i in range(0, a): if n[i] == 1: num1.append(i+1) elif n[i] == 2: num2.append(i+1) elif n[i] == 3: num3.append(i+1) p = min(n.count(1),n.count(2) ,n.count(3)) print(p) if ...
3
289
B
Polo the Penguin and Matrix
PROGRAMMING
1,400
[ "brute force", "dp", "implementation", "sortings", "ternary search" ]
null
null
Little penguin Polo has an *n*<=Γ—<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*. In one move the penguin can add ...
The first line contains three integers *n*, *m* and *d* (1<=≀<=*n*,<=*m*<=≀<=100,<=1<=≀<=*d*<=≀<=104) β€” the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≀<=*a**ij*<=≀<=104).
In a single line print a single integer β€” the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes).
[ "2 2 2\n2 4\n6 8\n", "1 2 7\n6 7\n" ]
[ "4\n", "-1\n" ]
none
1,000
[ { "input": "2 2 2\n2 4\n6 8", "output": "4" }, { "input": "1 2 7\n6 7", "output": "-1" }, { "input": "3 2 1\n5 7\n1 2\n5 100", "output": "104" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 2", "output": "12" }, { "input": "3 3 3\n5 8 5\n11 11 17\n14 5 3", "outpu...
1,594,832,091
2,147,483,647
Python 3
OK
TESTS
31
216
7,065,600
def solve(): n, m, d = map(int, input().split()) a = [] l = list(map(int, input().split())) thismod = l[0]%d for i in range(m): a.append(l[i]) if l[i]%d != thismod: return -1 for i in range(1,n): l = list(map(int, input().split())) for j in ...
Title: Polo the Penguin and Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little penguin Polo has an *n*<=Γ—<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe...
```python def solve(): n, m, d = map(int, input().split()) a = [] l = list(map(int, input().split())) thismod = l[0]%d for i in range(m): a.append(l[i]) if l[i]%d != thismod: return -1 for i in range(1,n): l = list(map(int, input().split())) ...
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ...
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "tymbzjyqhymeda...
1,604,341,933
2,147,483,647
Python 3
OK
TESTS
40
108
0
s = input() word = "hello" it = 0 for item in s: if item == word[it]: it += 1 if it == 5: break if it == 5: print("YES") else: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter...
```python s = input() word = "hello" it = 0 for item in s: if item == word[it]: it += 1 if it == 5: break if it == 5: print("YES") else: print("NO") ```
3.946
828
B
Black Square
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has a checkered sheet of paper of size *n*<=Γ—<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum pos...
The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the sizes of the sheet. The next *n* lines contain *m* letters 'B' or 'W' each β€” the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
[ "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "1 2\nBB\n", "3 3\nWWW\nWWW\nWWW\n" ]
[ "5\n", "-1\n", "1\n" ]
In the first example it is needed to paint 5 cells β€” (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third exampl...
750
[ { "input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW", "output": "5" }, { "input": "1 2\nBB", "output": "-1" }, { "input": "3 3\nWWW\nWWW\nWWW", "output": "1" }, { "input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n...
1,550,500,002
2,147,483,647
Python 3
OK
TESTS
128
124
307,200
while True: try: n,m=map(int,input().split()) a=[] x1=y1=11111111 x2=y2=z=0 for i in range(0, n): x=list(input()) a.append(x) for i in range(0,n): for j in range(0,m): if a[i][j]=='B': z+=1 ...
Title: Black Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has a checkered sheet of paper of size *n*<=Γ—<=*m*. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of w...
```python while True: try: n,m=map(int,input().split()) a=[] x1=y1=11111111 x2=y2=z=0 for i in range(0, n): x=list(input()) a.append(x) for i in range(0,n): for j in range(0,m): if a[i][j]=='B': z...
3
71
A
Way Too Long Words
PROGRAMMING
800
[ "strings" ]
A. Way Too Long Words
1
256
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation. This abbreviation is made lik...
The first line contains an integer *n* (1<=≀<=*n*<=≀<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters.
Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data.
[ "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n" ]
[ "word\nl10n\ni18n\np43s\n" ]
none
500
[ { "input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis", "output": "word\nl10n\ni18n\np43s" }, { "input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm", "output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m" }, { "input":...
1,679,511,174
2,147,483,647
PyPy 3-64
OK
TESTS
20
46
0
n = int(input()) words = [input() for _ in range(n)] new_words = [] for word in words: if len(word) > 10: curr = f"{word[0]}{len(word)-2}{word[-1]}" else: curr = word new_words.append(curr) [print(word) for word in new_words]
Title: Way Too Long Words Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome. Let's consider a word too long, if its length is strictly more than 10 character...
```python n = int(input()) words = [input() for _ in range(n)] new_words = [] for word in words: if len(word) > 10: curr = f"{word[0]}{len(word)-2}{word[-1]}" else: curr = word new_words.append(curr) [print(word) for word in new_words] ```
3.977
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≀<=*n*<=≀<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX"...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, ...
1,618,559,155
2,147,483,647
Python 3
OK
TESTS
23
62
0
n = int(input()) ha = str(input()) for _ in range(0,n): tl = str(input()) if n % 2 == 0: print('home') else: print('contest')
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei...
```python n = int(input()) ha = str(input()) for _ in range(0,n): tl = str(input()) if n % 2 == 0: print('home') else: print('contest') ```
3
233
A
Perfect Permutation
PROGRAMMING
800
[ "implementation", "math" ]
null
null
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He lik...
A single line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the permutation size.
If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* β€” permutation *p*, that is perfect. Separate printed numbers by whitespaces.
[ "1\n", "2\n", "4\n" ]
[ "-1\n", "2 1 \n", "2 1 4 3 \n" ]
none
500
[ { "input": "1", "output": "-1" }, { "input": "2", "output": "2 1 " }, { "input": "4", "output": "2 1 4 3 " }, { "input": "3", "output": "-1" }, { "input": "5", "output": "-1" }, { "input": "6", "output": "2 1 4 3 6 5 " }, { "input": "7", ...
1,688,279,790
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
n = int(input()) result = [] if n%2 == 0: for i in range(1,n+1): if i%2 != 0: result.append(str(i+1)) else: result.append(str(i-1)) print(" ".join(result)) else: print(-1)
Title: Perfect Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ...
```python n = int(input()) result = [] if n%2 == 0: for i in range(1,n+1): if i%2 != 0: result.append(str(i+1)) else: result.append(str(i-1)) print(" ".join(result)) else: print(-1) ```
3
68
A
Irrational problem
PROGRAMMING
1,100
[ "implementation", "number theory" ]
A. Irrational problem
2
256
Little Petya was given this problem for homework: You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*. It is a pity that Petya forgot the order in which the remainders should be taken and wr...
First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≀<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≀<=1000,<=0<=≀<=*a*<=≀<=*b*<=≀<=31415). It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct.
Output the number of integers in the given range that have the given property.
[ "2 7 1 8 2 8\n", "20 30 40 50 0 100\n", "31 41 59 26 17 43\n" ]
[ "0\n", "20\n", "9\n" ]
none
500
[ { "input": "2 7 1 8 2 8", "output": "0" }, { "input": "20 30 40 50 0 100", "output": "20" }, { "input": "31 41 59 26 17 43", "output": "9" }, { "input": "1 2 3 4 0 0", "output": "1" }, { "input": "1 2 3 4 1 1", "output": "0" }, { "input": "1 2 999 1000...
1,699,738,544
2,147,483,647
PyPy 3
OK
TESTS
41
218
1,638,400
from itertools import permutations as per p1, p2, p3, p4, a, b = map(int, input().split()) p = list(per([p1, p2, p3, p4], 4)) x = 0 for i in range(a, b + 1): c = 0 for j in p: if (((i % j[0]) % j[1]) % j[2]) % j[3] == i: c += 1 if c >= 7: x += 1 print(x)
Title: Irrational problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya was given this problem for homework: You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x...
```python from itertools import permutations as per p1, p2, p3, p4, a, b = map(int, input().split()) p = list(per([p1, p2, p3, p4], 4)) x = 0 for i in range(a, b + 1): c = 0 for j in p: if (((i % j[0]) % j[1]) % j[2]) % j[3] == i: c += 1 if c >= 7: x += 1 print(x) ```
3.942448