contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
listlengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
listlengths
0
7
demo-output
listlengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
10
A
Power Consumption Calculation
PROGRAMMING
900
[ "implementation" ]
A. Power Consumption Calculation
1
256
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T...
The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≤<=*n*<=≤<=100,<=0<=≤<=*P*1,<=*P*2,<=*P*3<=≤<=100,<=1<=≤<=*T*1,<=*T*2<=≤<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;...
Output the answer to the problem.
[ "1 3 2 1 5 10\n0 10\n", "2 8 4 2 5 10\n20 30\n50 100\n" ]
[ "30", "570" ]
none
0
[ { "input": "1 3 2 1 5 10\n0 10", "output": "30" }, { "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570" }, { "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445" }, { "input": "4 73 2 53 58 16\n51 52\n209 242\n281 407\n904 945", "output": "5287...
1,572,695,690
2,147,483,647
Python 3
OK
TESTS
30
248
0
X = list(map(int, input().split())) First = list(map(int, input().split())) Sum, Last = (First[1] - First[0]) * X[1], First[1] for i in range(1, X[0]): Temp = list(map(int, input().split())) Sum += (Temp[1] - Temp[0]) * X[1] + min(X[-2], Temp[0] - Last) * X[1] + max( min(X[-1], (Temp[0] - Last) - ...
Title: Power Consumption Calculation Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard f...
```python X = list(map(int, input().split())) First = list(map(int, input().split())) Sum, Last = (First[1] - First[0]) * X[1], First[1] for i in range(1, X[0]): Temp = list(map(int, input().split())) Sum += (Temp[1] - Temp[0]) * X[1] + min(X[-2], Temp[0] - Last) * X[1] + max( min(X[-1], (Temp[0] ...
3.876
814
C
An impassioned circulation of affection
PROGRAMMING
1,600
[ "brute force", "dp", "strings", "two pointers" ]
null
null
Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! Still unsatisfied with the garland, Nadeko decided to polish it again. The garland has *n* pieces numbered from 1 to *n* fro...
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=500) — the length of the garland. The second line contains *n* lowercase English letters *s*1*s*2... *s**n* as a string — the initial colours of paper pieces on the garland. The third line contains a positive integer *q* (1<=≤<=*q*<=≤<=200<=000...
Output *q* lines: for each work plan, output one line containing an integer — the largest Koyomity achievable after repainting the garland according to it.
[ "6\nkoyomi\n3\n1 o\n4 o\n4 m\n", "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b\n", "10\naaaaaaaaaa\n2\n10 b\n10 z\n" ]
[ "3\n6\n5\n", "3\n4\n5\n7\n8\n1\n2\n3\n4\n5\n", "10\n10\n" ]
In the first sample, there are three plans: - In the first plan, at most 1 piece can be repainted. Repainting the "y" piece to become "o" results in "kooomi", whose Koyomity of 3 is the best achievable; - In the second plan, at most 4 pieces can be repainted, and "oooooo" results in a Koyomity of 6; - In the third...
1,750
[ { "input": "6\nkoyomi\n3\n1 o\n4 o\n4 m", "output": "3\n6\n5" }, { "input": "15\nyamatonadeshiko\n10\n1 a\n2 a\n3 a\n4 a\n5 a\n1 b\n2 b\n3 b\n4 b\n5 b", "output": "3\n4\n5\n7\n8\n1\n2\n3\n4\n5" }, { "input": "10\naaaaaaaaaa\n2\n10 b\n10 z", "output": "10\n10" }, { "input": "1...
1,684,960,399
2,147,483,647
PyPy 3-64
OK
TESTS
37
592
11,571,200
import sys, functools, bisect, collections, string, math from math import gcd input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rmi = lambda: map(int, input().split()) ra = lambda: [int(x) for x in input().split()] INF = 10**18 MOD = 10**9+7 N = 1502 dp = [[0]*N fo...
Title: An impassioned circulation of affection Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nadeko's birthday is approaching! As she decorated the room for the party, a long garland of Dianthus-shaped paper pieces was placed on a prominent part of the wall. Brother Koyomi will like it! ...
```python import sys, functools, bisect, collections, string, math from math import gcd input = sys.stdin.readline rs = lambda: input().strip() ri = lambda: int(input()) rmi = lambda: map(int, input().split()) ra = lambda: [int(x) for x in input().split()] INF = 10**18 MOD = 10**9+7 N = 1502 dp =...
3
492
B
Vanya and Lanterns
PROGRAMMING
1,200
[ "binary search", "implementation", "math", "sortings" ]
null
null
Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point *l*. Then the *i*-th lantern is at the point *a**i*. The lantern lights all points of the street that...
The first line contains two integers *n*, *l* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*l*<=≤<=109) — the number of lanterns and the length of the street respectively. The next line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=*l*). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of th...
Print the minimum light radius *d*, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10<=-<=9.
[ "7 15\n15 5 3 7 9 14 0\n", "2 5\n2 5\n" ]
[ "2.5000000000\n", "2.0000000000\n" ]
Consider the second sample. At *d* = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.
1,000
[ { "input": "7 15\n15 5 3 7 9 14 0", "output": "2.5000000000" }, { "input": "2 5\n2 5", "output": "2.0000000000" }, { "input": "46 615683844\n431749087 271781274 274974690 324606253 480870261 401650581 13285442 478090364 266585394 425024433 588791449 492057200 391293435 563090494 317950 1...
1,689,948,585
2,147,483,647
Python 3
OK
TESTS
32
46
0
inp = input().split() sSize = inp[0] l = int(inp[1]) s = list(map(int,input().split())) s.sort() ledge = s[0] redge = l - s[len(s) - 1] maxdis = 0 if (len(s) == 1): print(max(ledge, redge)) exit(0) i = 1 while i < len(s): maxdis = max(maxdis, s[i] - s[i - 1]) i += 1 print(max(float(redge), float(...
Title: Vanya and Lanterns Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya walks late at night along a straight street of length *l*, lit by *n* lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the poi...
```python inp = input().split() sSize = inp[0] l = int(inp[1]) s = list(map(int,input().split())) s.sort() ledge = s[0] redge = l - s[len(s) - 1] maxdis = 0 if (len(s) == 1): print(max(ledge, redge)) exit(0) i = 1 while i < len(s): maxdis = max(maxdis, s[i] - s[i - 1]) i += 1 print(max(float(redg...
3
257
B
Playing Cubes
PROGRAMMING
1,300
[ "games", "greedy", "implementation" ]
null
null
Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have *n*<=+<=*m* cubes). Petya moves first. Petya's task is to get as many pa...
The only line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of red and blue cubes, correspondingly.
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
[ "3 1\n", "2 4\n" ]
[ "2 1\n", "3 2\n" ]
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point. If Petya would choose the red cu...
500
[ { "input": "3 1", "output": "2 1" }, { "input": "2 4", "output": "3 2" }, { "input": "1 1", "output": "0 1" }, { "input": "2 1", "output": "1 1" }, { "input": "4 4", "output": "3 4" }, { "input": "10 7", "output": "9 7" }, { "input": "5 13"...
1,626,325,852
2,147,483,647
PyPy 3
OK
TESTS
40
248
20,172,800
# import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') def read_line(): return [int(x) for x in input().split()] def read_int(): return int(input()) def solve(): n, m = read_line() print(max(n, m)-1, min(n, m)) # t = read_int() t = 1 while t > 0:...
Title: Playing Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya decided to play a little. They found *n* red cubes and *m* blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (...
```python # import sys # sys.stdin = open('input.txt', 'r') # sys.stdout = open('output.txt', 'w') def read_line(): return [int(x) for x in input().split()] def read_int(): return int(input()) def solve(): n, m = read_line() print(max(n, m)-1, min(n, m)) # t = read_int() t = 1 wh...
3
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min...
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" ...
1,628,086,523
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
186
20,172,800
n=int(input()) array=list(map(int,input().split())) s=sum(array) if s%(n-1)==0: print(s // (n - 1)) else: print((s//(n-1))+1)
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a...
```python n=int(input()) array=list(map(int,input().split())) s=sum(array) if s%(n-1)==0: print(s // (n - 1)) else: print((s//(n-1))+1) ```
0
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors...
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase ...
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReal...
1,612,264,875
2,147,483,647
Python 3
OK
TESTS
64
77
307,200
n=int(input()) l=[] for i in range(n): s=str(input()) l.append(s) print(6-n) if "purple" not in l: print("Power") if "green" not in l: print("Time") if "red" not in l: print("Reality") if "blue" not in l: print("Space") if "orange" not in l: print("Soul") if "yellow" not in l: print("M...
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the So...
```python n=int(input()) l=[] for i in range(n): s=str(input()) l.append(s) print(6-n) if "purple" not in l: print("Power") if "green" not in l: print("Time") if "red" not in l: print("Reality") if "blue" not in l: print("Space") if "orange" not in l: print("Soul") if "yellow" not in l: ...
3
379
A
New Year Candles
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ...
The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000).
Print a single integer — the number of hours Vasily can light up the room for.
[ "4 2\n", "6 3\n" ]
[ "7\n", "8\n" ]
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.
500
[ { "input": "4 2", "output": "7" }, { "input": "6 3", "output": "8" }, { "input": "1000 1000", "output": "1001" }, { "input": "123 5", "output": "153" }, { "input": "1000 2", "output": "1999" }, { "input": "1 2", "output": "1" }, { "input": ...
1,682,251,383
2,147,483,647
Python 3
OK
TESTS
32
62
0
from math import ceil candels , replace = map(int ,input().split()) counter = candels while candels >= replace : c = int(candels / replace) counter += c candels = c + candels % replace print(counter)
Title: New Year Candles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s...
```python from math import ceil candels , replace = map(int ,input().split()) counter = candels while candels >= replace : c = int(candels / replace) counter += c candels = c + candels % replace print(counter) ```
3
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he...
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i...
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0...
1,631,651,982
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
6,963,200
n = list(map(int, input().split())) x = list(map(int, input().split())) out = 0 dist = [] ind = n[1] - 1 if x[ind] == 1: out += 1 for i in range(0, ind): if x[i] == 1: d = ind - i right = ind + d if right < n[0] - 1: if x[right] == 1: out += 2 ...
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city...
```python n = list(map(int, input().split())) x = list(map(int, input().split())) out = 0 dist = [] ind = n[1] - 1 if x[ind] == 1: out += 1 for i in range(0, ind): if x[i] == 1: d = ind - i right = ind + d if right < n[0] - 1: if x[right] == 1: out...
0
886
B
Vlad and Cafes
PROGRAMMING
1,000
[]
null
null
Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes...
In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, ...
Print one integer — index of the cafe that Vlad hasn't visited for as long as possible.
[ "5\n1 3 2 1 2\n", "6\n2 1 2 2 4 1\n" ]
[ "3\n", "2\n" ]
In first test, there are three cafes, and the last visits to cafes with indices 1 and 2 were after the last visit to cafe with index 3; so this cafe is the answer. In second test case, there are also three cafes, but with indices 1, 2 and 4. Cafes with indices 1 and 4 were visited after the last visit of cafe with in...
1,000
[ { "input": "5\n1 3 2 1 2", "output": "3" }, { "input": "6\n2 1 2 2 4 1", "output": "2" }, { "input": "1\n0", "output": "0" }, { "input": "1\n200000", "output": "200000" }, { "input": "2\n2018 2017", "output": "2018" }, { "input": "5\n100 1000 1000 1000...
1,514,079,645
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
19,865,600
n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n-1,-1,-1): if a[i] not in b: b.append(a[i]) print(b[-1])
Title: Vlad and Cafes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research...
```python n=int(input()) a=list(map(int,input().split())) b=[] for i in range(n-1,-1,-1): if a[i] not in b: b.append(a[i]) print(b[-1]) ```
0
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon piece...
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, ...
1,692,684,992
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
#https://codeforces.com/problemset/problem/189/A n=list(map(int,input().split())) abc=sorted(n[1:]) sum=0 for i in range(3): sum+=abc[i] if sum==n[0]: print(i+1) break
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the...
```python #https://codeforces.com/problemset/problem/189/A n=list(map(int,input().split())) abc=sorted(n[1:]) sum=0 for i in range(3): sum+=abc[i] if sum==n[0]: print(i+1) break ```
0
967
A
Mind the Gap
PROGRAMMING
1,100
[ "implementation" ]
null
null
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minut...
The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, i...
Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff.
[ "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "3 17\n0 30\n1 0\n12 0\n" ]
[ "6 1\n", "24 50\n", "0 0\n" ]
In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert th...
500
[ { "input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1" }, { "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50" }, { "input": "3 17\n0 30\n1 0\n12 0", "output": "0 0" }, { ...
1,525,008,687
987
Python 3
CHALLENGED
CHALLENGES
6
78
7,065,600
n, s = map(int, input().split()) q = 0 for i in range(n): a, b = map(int, input().split()) p = a * 60 + b if i == 0 and p > s + 1: rec = 0 break if p - q > s * 2 + 1: rec = q + s + 1 break q = p rec = q + s + 1 h, m = rec // 60, rec % 60 print(h,...
Title: Mind the Gap Time Limit: None seconds Memory Limit: None megabytes Problem Description: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing ...
```python n, s = map(int, input().split()) q = 0 for i in range(n): a, b = map(int, input().split()) p = a * 60 + b if i == 0 and p > s + 1: rec = 0 break if p - q > s * 2 + 1: rec = q + s + 1 break q = p rec = q + s + 1 h, m = rec // 60, rec % 60...
-1
75
C
Modified GCD
PROGRAMMING
1,600
[ "binary search", "number theory" ]
C. Modified GCD
2
256
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible by. But your teacher wants to give you a harder task, in this task...
The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=...
Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.
[ "9 27\n3\n1 5\n10 11\n9 11\n" ]
[ "3\n-1\n9\n" ]
none
1,500
[ { "input": "9 27\n3\n1 5\n10 11\n9 11", "output": "3\n-1\n9" }, { "input": "48 72\n2\n8 29\n29 37", "output": "24\n-1" }, { "input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90", "output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1" }, { "input...
1,585,048,164
2,147,483,647
PyPy 3
OK
TESTS
60
778
5,222,400
from math import gcd a,b = list(map(int, input().split())) cd = gcd(a,b) ar =[] for i in range(1,int(cd**0.5)+1): if cd % i == 0: ar.append(i) if(i*i != cd): ar.append(cd//i) for _ in range(int(input())): l,h = list(map(int, input().split())) res = -1 for i ...
Title: Modified GCD Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which ...
```python from math import gcd a,b = list(map(int, input().split())) cd = gcd(a,b) ar =[] for i in range(1,int(cd**0.5)+1): if cd % i == 0: ar.append(i) if(i*i != cd): ar.append(cd//i) for _ in range(int(input())): l,h = list(map(int, input().split())) res = -1 ...
3.795773
474
A
Keyboard
PROGRAMMING
900
[ "implementation" ]
null
null
Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That mean...
First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain ...
Print a line that contains the original message.
[ "R\ns;;upimrrfod;pbr\n" ]
[ "allyouneedislove\n" ]
none
500
[ { "input": "R\ns;;upimrrfod;pbr", "output": "allyouneedislove" }, { "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.", "output": "qwertyuiolkjhgfdsazxcvbnm," }, { "input": "L\nzxcvbnm,kjhgfdsaqwertyuio", "output": "xcvbnm,.lkjhgfdswertyuiop" }, { "input": "R\nbubbuduppudup", "outp...
1,671,606,919
2,147,483,647
Python 3
OK
TESTS
31
46
0
s='qwertyuiopasdfghjkl;zxcvbnm,./' lr = input() de = input() if lr=='L': l=[s[s.index(i)+1] for i in de] print(''.join(map(str,l))) else: l=[s[s.index(i)-1] for i in de] print(''.join(map(str,l)))
Title: Keyboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately....
```python s='qwertyuiopasdfghjkl;zxcvbnm,./' lr = input() de = input() if lr=='L': l=[s[s.index(i)+1] for i in de] print(''.join(map(str,l))) else: l=[s[s.index(i)-1] for i in de] print(''.join(map(str,l))) ```
3
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d...
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "inpu...
1,539,930,246
2,147,483,647
Python 3
OK
TESTS
41
109
0
# -*- coding: utf-8 -*- """ Created on Fri Oct 19 13:52:28 2018 @author: Quaint Sun """ ''' n=int(input()) queue=['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard'] t=0 while t<n: queue.append(queue[0]) queue.append(queue[0]) del queue[0] t=t+1 print(queue[-1])''' n=int(inpu...
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resultin...
```python # -*- coding: utf-8 -*- """ Created on Fri Oct 19 13:52:28 2018 @author: Quaint Sun """ ''' n=int(input()) queue=['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard'] t=0 while t<n: queue.append(queue[0]) queue.append(queue[0]) del queue[0] t=t+1 print(queue[-1])''' ...
3.9455
574
B
Bear and Three Musketeers
PROGRAMMING
1,500
[ "brute force", "dfs and similar", "graphs", "hashing" ]
null
null
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose thre...
The first line contains two space-separated integers, *n* and *m* (3<=≤<=*n*<=≤<=4000, 0<=≤<=*m*<=≤<=4000) — respectively number of warriors and number of pairs of warriors knowing each other. *i*-th of the following *m* lines contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*, *a**...
If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes).
[ "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5\n", "7 4\n2 1\n3 6\n5 1\n1 7\n" ]
[ "2\n", "-1\n" ]
In the first sample Richelimakieu should choose a triple 1, 2, 3. The first musketeer doesn't know anyone except other two musketeers so his recognition is 0. The second musketeer has recognition 1 because he knows warrior number 4. The third musketeer also has recognition 1 because he knows warrior 4. Sum of recogniti...
1,000
[ { "input": "5 6\n1 2\n1 3\n2 3\n2 4\n3 4\n4 5", "output": "2" }, { "input": "7 4\n2 1\n3 6\n5 1\n1 7", "output": "-1" }, { "input": "5 0", "output": "-1" }, { "input": "7 14\n3 6\n2 3\n5 2\n5 6\n7 5\n7 4\n6 2\n3 5\n7 1\n4 1\n6 1\n7 6\n6 4\n5 4", "output": "5" }, { ...
1,442,602,886
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
512,000
if __name__=='__main__': inf = 100000005 memo = {} degree = [] n,m=map(int,input().split()) for i in range(n): degree.append(0) memo[i]=[] for i in range(0,m): x,y=map(int,input().split()) memo[x-1].append(y-1) memo[y-1].append(x-1) d...
Title: Bear and Three Musketeers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three br...
```python if __name__=='__main__': inf = 100000005 memo = {} degree = [] n,m=map(int,input().split()) for i in range(n): degree.append(0) memo[i]=[] for i in range(0,m): x,y=map(int,input().split()) memo[x-1].append(y-1) memo[y-1].append(x-1) ...
0
760
A
Petr and a calendar
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: Petr wants to ...
The only line contain two integers *m* and *d* (1<=≤<=*m*<=≤<=12, 1<=≤<=*d*<=≤<=7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
Print single integer: the number of columns the table should have.
[ "1 7\n", "1 1\n", "11 6\n" ]
[ "6\n", "5\n", "5\n" ]
The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough.
500
[ { "input": "1 7", "output": "6" }, { "input": "1 1", "output": "5" }, { "input": "11 6", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "2 1", "output": "4" }, { "input": "8 6", "output": "6" }, { "input": "1 1", "output...
1,485,109,144
244
Python 3
OK
TESTS
104
92
4,710,400
def main(): m, d = map(int, input().split()) a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] num = a[m - 1] ans = 1 num -= (8 - d) ans += ((num + 7 - 1) // 7) print(ans) main()
Title: Petr and a calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells...
```python def main(): m, d = map(int, input().split()) a = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] num = a[m - 1] ans = 1 num -= (8 - d) ans += ((num + 7 - 1) // 7) print(ans) main() ```
3
792
B
Counting-out Rhyme
PROGRAMMING
1,300
[ "implementation" ]
null
null
*n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. T...
The first line contains two integer numbers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1). The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=109).
Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step.
[ "7 5\n10 4 11 4 1\n", "3 2\n2 5\n" ]
[ "4 2 5 6 1 \n", "3 2 \n" ]
Let's consider first example: - In the first step child 4 is eliminated, child 5 becomes the leader. - In the second step child 2 is eliminated, child 3 becomes the leader. - In the third step child 5 is eliminated, child 6 becomes the leader. - In the fourth step child 6 is eliminated, child 7 becomes the leader...
0
[ { "input": "7 5\n10 4 11 4 1", "output": "4 2 5 6 1 " }, { "input": "3 2\n2 5", "output": "3 2 " }, { "input": "2 1\n1", "output": "2 " }, { "input": "2 1\n2", "output": "1 " }, { "input": "2 1\n3", "output": "2 " }, { "input": "10 7\n5 10 4 3 8 10 6",...
1,490,626,576
1,276
Python 3
RUNTIME_ERROR
TESTS
7
62
4,608,000
n, k = map(int, input().split()) a = list(map(int, input().split())) cur = 0 x = [] for i in range(n): x.append(i + 1) for i in range(k): v = cur f = a[i] % n for j in range(f): v += 1 if v >= n: v = v - n print(x[v], end=' ') x.pop(v) n -= 1 cur = v ...
Title: Counting-out Rhyme Time Limit: None seconds Memory Limit: None megabytes Problem Description: *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In ...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) cur = 0 x = [] for i in range(n): x.append(i + 1) for i in range(k): v = cur f = a[i] % n for j in range(f): v += 1 if v >= n: v = v - n print(x[v], end=' ') x.pop(v) n -= 1 cu...
-1
331
C1
The Great Julya Calendar
PROGRAMMING
1,100
[ "dp" ]
null
null
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open ...
The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co...
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
[ "24\n" ]
[ "5" ]
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
20
[ { "input": "24", "output": "5" }, { "input": "0", "output": "0" }, { "input": "3", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "2" }, { "input": "31", "output": "6" }, ...
1,665,905,042
2,147,483,647
Python 3
OK
TESTS1
24
622
0
n = int(input()) count = 0 while n > 0: ns = list(str(n)) ni = [int(x) for x in ns] n -= max(ni) count += 1 print(count)
Title: The Great Julya Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i...
```python n = int(input()) count = 0 while n > 0: ns = list(str(n)) ni = [int(x) for x in ns] n -= max(ni) count += 1 print(count) ```
3
427
A
Police Recruits
PROGRAMMING
800
[ "implementation" ]
null
null
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime. If there is no police offi...
The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ...
Print a single integer, the number of crimes which will go untreated.
[ "3\n-1 -1 1\n", "8\n1 -1 1 -1 -1 1 1 1\n", "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n" ]
[ "2\n", "1\n", "8\n" ]
Lets consider the second example: 1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c...
500
[ { "input": "3\n-1 -1 1", "output": "2" }, { "input": "8\n1 -1 1 -1 -1 1 1 1", "output": "1" }, { "input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1", "output": "8" }, { "input": "7\n-1 -1 1 1 -1 -1 1", "output": "2" }, { "input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ...
1,696,595,492
2,147,483,647
Python 3
OK
TESTS
63
77
9,113,600
number_of_events = int(input()) events = input().split() officer_counter = 0 crime_counter = 0 events_list = [int(event) for event in events] for event in events_list: if event > 0: officer_counter += event if event < 0: if officer_counter > 0: officer_counter += event ...
Title: Police Recruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups. Meanwhile, crimes keeps occurring within the city. One member of...
```python number_of_events = int(input()) events = input().split() officer_counter = 0 crime_counter = 0 events_list = [int(event) for event in events] for event in events_list: if event > 0: officer_counter += event if event < 0: if officer_counter > 0: officer_counter += ...
3
777
A
Shell Game
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "math" ]
null
null
Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=2·109) — the number of movements made by the operator. The second line contains a single integer *x* (0<=≤<=*x*<=≤<=2) — the index of the shell where the ball was found after *n* movements.
Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
[ "4\n2\n", "1\n1\n" ]
[ "1\n", "0\n" ]
In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements. 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell. 1. During the second move operator swapped the middle shell and the right one. Th...
500
[ { "input": "4\n2", "output": "1" }, { "input": "1\n1", "output": "0" }, { "input": "2\n2", "output": "0" }, { "input": "3\n1", "output": "1" }, { "input": "3\n2", "output": "0" }, { "input": "3\n0", "output": "2" }, { "input": "2000000000\n...
1,505,723,089
2,147,483,647
Python 3
OK
TESTS
68
62
4,608,000
#!/usr/bin/env python # -*- coding: utf-8 -*- # # @Filename : 401_DIV2_A # @Date : 2017-09-18 16:08 # @Author : LunaFire # @Mail : [email protected] if __name__ == "__main__": ret_map = [ [0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], [0, 2...
Title: Shell Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball ben...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- # # @Filename : 401_DIV2_A # @Date : 2017-09-18 16:08 # @Author : LunaFire # @Mail : [email protected] if __name__ == "__main__": ret_map = [ [0, 1, 2], [1, 0, 2], [1, 2, 0], [2, 1, 0], [2, 0, 1], ...
3
598
D
Igor In the Museum
PROGRAMMING
1,700
[ "dfs and similar", "graphs", "shortest paths" ]
null
null
Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one i...
First line of the input contains three integers *n*, *m* and *k* (3<=≤<=*n*,<=*m*<=≤<=1000,<=1<=≤<=*k*<=≤<=*min*(*n*·*m*,<=100<=000)) — the museum dimensions and the number of starting positions to process. Each of the next *n* lines contains *m* symbols '.', '*' — the description of the museum. It is guaranteed that ...
Print *k* integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.
[ "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3\n", "4 4 1\n****\n*..*\n*.**\n****\n3 2\n" ]
[ "6\n4\n10\n", "8\n" ]
none
0
[ { "input": "5 6 3\n******\n*..*.*\n******\n*....*\n******\n2 2\n2 5\n4 3", "output": "6\n4\n10" }, { "input": "4 4 1\n****\n*..*\n*.**\n****\n3 2", "output": "8" }, { "input": "3 3 1\n***\n*.*\n***\n2 2", "output": "4" }, { "input": "5 5 10\n*****\n*...*\n*..**\n*.***\n*****\...
1,682,796,563
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
9
1,000
42,188,800
from collections import deque WALL = "*" walked_steps = {} # {(2, 3): 12, } def input_line(): return map(int, input().split()) class MuseumWalk: def __init__(self, museum): self.pictures_count = 0 self.museum = museum self.walked_points = set() self.max_y = len(self.museum...
Title: Igor In the Museum Time Limit: None seconds Memory Limit: None megabytes Problem Description: Igor is in the museum and he wants to see as many pictures as possible. Museum can be represented as a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable. Empty cells are marked with '.'...
```python from collections import deque WALL = "*" walked_steps = {} # {(2, 3): 12, } def input_line(): return map(int, input().split()) class MuseumWalk: def __init__(self, museum): self.pictures_count = 0 self.museum = museum self.walked_points = set() self.max_y = len(s...
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "...
1,696,300,409
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
x = input() x[0].capitalize()+x[1:]
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input...
```python x = input() x[0].capitalize()+x[1:] ```
0
535
B
Tavas and SaDDas
PROGRAMMING
1,100
[ "bitmasks", "brute force", "combinatorics", "implementation" ]
null
null
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You ar...
The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109).
Print the index of *n* among all lucky numbers.
[ "4\n", "7\n", "77\n" ]
[ "1\n", "2\n", "6\n" ]
none
1,000
[ { "input": "4", "output": "1" }, { "input": "7", "output": "2" }, { "input": "77", "output": "6" }, { "input": "4", "output": "1" }, { "input": "474744", "output": "83" }, { "input": "777774", "output": "125" }, { "input": "447", "outpu...
1,628,686,221
2,147,483,647
Python 3
OK
TESTS
33
62
7,065,600
f=['4','7'] wave=['4','7'] for i in range(10): r=[] for j in wave: r.append(j+'4') r.append(j+'7') for j in r: f.append(j) wave=r*1 n=int(input()) print(f.index(str(n))+1)
Title: Tavas and SaDDas Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone...
```python f=['4','7'] wave=['4','7'] for i in range(10): r=[] for j in wave: r.append(j+'4') r.append(j+'7') for j in r: f.append(j) wave=r*1 n=int(input()) print(f.index(str(n))+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,689,639,542
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689639542.0853002")# 1689639542.0853207
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 print("_RANDOM_GUESS_1689639542.0853002")# 1689639542.0853207 ```
0
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,610,394,387
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
204,800
def gcd(a,b): if a == b: return a else: ma = 0 if a > b: return gcd(a-b,b) else: return gcd(b-a,a) a = int(input()) b = int(input()) ma = 0 if a > b: ma = a else: ma = b; num = (int)((7-ma)/(gcd(7-ma,6))) den = (int)(6/(gcd(7-m...
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 def gcd(a,b): if a == b: return a else: ma = 0 if a > b: return gcd(a-b,b) else: return gcd(b-a,a) a = int(input()) b = int(input()) ma = 0 if a > b: ma = a else: ma = b; num = (int)((7-ma)/(gcd(7-ma,6))) den = (int)(...
-1
757
A
Gotta Catch Em' All!
PROGRAMMING
1,000
[ "implementation" ]
null
null
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
Input contains a single line containing a string *s* (1<=<=≤<=<=|*s*|<=<=≤<=<=105) — the text on the front page of the newspaper without spaces and punctuation marks. |*s*| is the length of the string *s*. The string *s* contains lowercase and uppercase English letters, i.e. .
Output a single integer, the answer to the problem.
[ "Bulbbasaur\n", "F\n", "aBddulbasaurrgndgbualdBdsagaurrgndbb\n" ]
[ "1\n", "0\n", "2\n" ]
In the first case, you could pick: Bulbbasaur. In the second case, there is no way to pick even a single Bulbasaur. In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".
500
[ { "input": "Bulbbasaur", "output": "1" }, { "input": "F", "output": "0" }, { "input": "aBddulbasaurrgndgbualdBdsagaurrgndbb", "output": "2" }, { "input": "BBBBBBBBBBbbbbbbbbbbuuuuuuuuuullllllllllssssssssssaaaaaaaaaarrrrrrrrrr", "output": "5" }, { "input": "BBBBBBB...
1,599,035,935
2,147,483,647
PyPy 3
OK
TESTS
107
140
512,000
string = input() check = "Bulbasaur" res = 1000000000000000 for x in check: res = min(res,string.count(x)//check.count(x)) print(res)
Title: Gotta Catch Em' All! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsess...
```python string = input() check = "Bulbasaur" res = 1000000000000000 for x in check: res = min(res,string.count(x)//check.count(x)) print(res) ```
3
45
A
Codecraft III
PROGRAMMING
900
[ "implementation" ]
A. Codecraft III
2
256
Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *s*. Vasya immediately got interested in what month Codecraft III will appear. Help him understa...
The first input line contains the name of the current month. It is guaranteed that it is a proper English name of one of twelve months. The first letter is uppercase, the rest are lowercase. The second line contains integer *k* (0<=≤<=*k*<=≤<=100) — the number of months left till the appearance of Codecraft III.
Print starting from an uppercase letter the name of the month in which the continuation of Codeforces II will appear. The printed name must be contained in the list January, February, March, April, May, June, July, August, September, October, November, December.
[ "November\n3\n", "May\n24\n" ]
[ "February\n", "May\n" ]
none
0
[ { "input": "November\n3", "output": "February" }, { "input": "May\n24", "output": "May" }, { "input": "April\n0", "output": "April" }, { "input": "September\n0", "output": "September" }, { "input": "August\n0", "output": "August" }, { "input": "June\n1...
1,619,302,843
2,147,483,647
Python 3
OK
TESTS
25
124
0
mes = input() k = int(input()) #convertir nuestro mes a número def mes_a_numero(mes): #Joshua if mes=='January': numero=0 if mes=='February': numero=1 if mes=='March': numero=2 if mes=='April': numero=3 if mes =='May': numero=4 if mes =='June': numero=5 if mes =='...
Title: Codecraft III Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Today Vasya visited a widely known site and learned that the continuation of his favourite game Codecraft II will appear after exactly *k* months. He looked at the calendar and learned that at the moment is the month number *...
```python mes = input() k = int(input()) #convertir nuestro mes a número def mes_a_numero(mes): #Joshua if mes=='January': numero=0 if mes=='February': numero=1 if mes=='March': numero=2 if mes=='April': numero=3 if mes =='May': numero=4 if mes =='June': numero=5 ...
3.969
420
A
Start Up
PROGRAMMING
1,000
[ "implementation" ]
null
null
Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out...
The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:
Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).
[ "AHA\n", "Z\n", "XO\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "AHA", "output": "YES" }, { "input": "Z", "output": "NO" }, { "input": "XO", "output": "NO" }, { "input": "AAA", "output": "YES" }, { "input": "AHHA", "output": "YES" }, { "input": "BAB", "output": "NO" }, { "input": "OMMMAAMMMO"...
1,663,602,632
2,147,483,647
Python 3
OK
TESTS
80
61
0
a=input().upper() Mirror="AHIMOTUVWXY" if a==a[::-1]: x="True" for i in a: if i in Mirror: pass else: x="FALSE"; break if x=="True": print("YES") else: print("NO") else: print("NO")
Title: Start Up Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of ...
```python a=input().upper() Mirror="AHIMOTUVWXY" if a==a[::-1]: x="True" for i in a: if i in Mirror: pass else: x="FALSE"; break if x=="True": print("YES") else: print("NO") else: print("NO") ```
3
146
B
Lucky Mask
PROGRAMMING
1,300
[ "brute force", "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 calls a mask of a positive integer *n* the number that is obtained after successive writing ...
The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky.
In the only line print a single number — the number *c* that is sought by Petya.
[ "1 7\n", "100 47\n" ]
[ "7\n", "147\n" ]
none
1,000
[ { "input": "1 7", "output": "7" }, { "input": "100 47", "output": "147" }, { "input": "458 47", "output": "467" }, { "input": "7 7", "output": "17" }, { "input": "547 47", "output": "647" }, { "input": "77 77", "output": "177" }, { "input":...
1,590,255,978
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
278
0
a,b=[int(i) for i in input().split()] print(int(str(a)+str(b)))
Title: Lucky Mask 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. Pe...
```python a,b=[int(i) for i in input().split()] print(int(str(a)+str(b))) ```
0
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0...
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara...
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ...
1,674,094,361
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
23
62
1,945,600
# n, t = list(map(int, input().split())) # a = list(map(int, input().split())) # marked = [] # def dfs(l, x): # marked.append(x+1) # if x < l: # dfs(l, x + a[x]) # else: # return marked # dfs(len(a), 0) n, t = list(map(int, input().split())) a = list(map(int, input().split...
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o...
```python # n, t = list(map(int, input().split())) # a = list(map(int, input().split())) # marked = [] # def dfs(l, x): # marked.append(x+1) # if x < l: # dfs(l, x + a[x]) # else: # return marked # dfs(len(a), 0) n, t = list(map(int, input().split())) a = list(map(int, inp...
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy...
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10...
1,600,727,720
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
154
0
n = int(input()) for x in range(n): xi,yi,zi=list(map(int, input().split())) sum_xi= sum_xi + xi sum_yi= sum_yi + yi sum_zi= sum_zi + zi sum = sum_xi + sum_yi + sum_zi if (sum)==0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S...
```python n = int(input()) for x in range(n): xi,yi,zi=list(map(int, input().split())) sum_xi= sum_xi + xi sum_yi= sum_yi + yi sum_zi= sum_zi + zi sum = sum_xi + sum_yi + sum_zi if (sum)==0: print('YES') else: print('NO') ```
-1
234
A
Lefthanders and Righthanders
PROGRAMMING
1,200
[ "implementation" ]
null
null
One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all true mathematicians, Vasily has all students numbered from 1 to *n*. But Vasily Petrov did not like the way the chi...
The first input line contains a single even integer *n* (4<=≤<=*n*<=≤<=100) — the number of students in the class. The second line contains exactly *n* capital English letters "L" and "R". If the *i*-th letter at the second line equals "L", then the student number *i* is a lefthander, otherwise he is a righthander.
Print integer pairs, one pair per line. In the *i*-th line print the numbers of students that will sit at the *i*-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by space...
[ "6\nLLRLLL\n", "4\nRRLL\n" ]
[ "1 4\n2 5\n6 3\n", "3 1\n4 2\n" ]
none
0
[ { "input": "6\nLLRLLL", "output": "1 4\n2 5\n6 3" }, { "input": "4\nRRLL", "output": "3 1\n4 2" }, { "input": "4\nLLRR", "output": "1 3\n2 4" }, { "input": "6\nRLLRRL", "output": "1 4\n2 5\n3 6" }, { "input": "8\nLRLRLLLR", "output": "1 5\n6 2\n3 7\n4 8" }, ...
1,663,502,281
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
0
if __name__ == "__main__": # n = int(input()) # students = list(input()) f = open("input.txt", "r") n = int(f.readline()) students = list(f.readline()) f = open("output.txt", "w") for i in range(int(n/2)): if i + 2 > int(n / 2) and i + 2 <= n: a = students[...
Title: Lefthanders and Righthanders Time Limit: None seconds Memory Limit: None megabytes Problem Description: One fine October day a mathematics teacher Vasily Petrov went to a class and saw there *n* pupils who sat at the desks, two people at each desk. Vasily quickly realized that number *n* is even. Like all t...
```python if __name__ == "__main__": # n = int(input()) # students = list(input()) f = open("input.txt", "r") n = int(f.readline()) students = list(f.readline()) f = open("output.txt", "w") for i in range(int(n/2)): if i + 2 > int(n / 2) and i + 2 <= n: a =...
0
519
C
A and B and Team Training
PROGRAMMING
1,300
[ "greedy", "implementation", "math", "number theory" ]
null
null
A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, during the next team training A decided to make teams so that newbies are solvi...
The first line contains two integers *n* and *m* (0<=≤<=*n*,<=*m*<=≤<=5·105) — the number of experienced participants and newbies that are present at the training session.
Print the maximum number of teams that can be formed.
[ "2 6\n", "4 5\n" ]
[ "2\n", "3\n" ]
Let's represent the experienced players as XP and newbies as NB. In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB). In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB).
1,500
[ { "input": "2 6", "output": "2" }, { "input": "4 5", "output": "3" }, { "input": "1 1", "output": "0" }, { "input": "3 3", "output": "2" }, { "input": "500000 500000", "output": "333333" }, { "input": "70 100", "output": "56" }, { "input": ...
1,631,083,304
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
4
108
1,228,800
n, m = map(int, input().split()) a = min(n, m) b = max(n, m) i = 0 c = 0 ans=0 while (c < b and i<a): i += 1 c += 2 ans+=1 if c>b: c-=2 i-=1 ans-=1 if b-c>=1 and a-i>=2: ans+=1 print(ans)
Title: A and B and Team Training Time Limit: None seconds Memory Limit: None megabytes Problem Description: A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to dea...
```python n, m = map(int, input().split()) a = min(n, m) b = max(n, m) i = 0 c = 0 ans=0 while (c < b and i<a): i += 1 c += 2 ans+=1 if c>b: c-=2 i-=1 ans-=1 if b-c>=1 and a-i>=2: ans+=1 print(ans) ```
0
626
B
Cards
PROGRAMMING
1,300
[ "constructive algorithms", "dp", "math" ]
null
null
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n" ]
[ "G\n", "BR\n", "B\n" ]
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car...
750
[ { "input": "2\nRB", "output": "G" }, { "input": "3\nGRG", "output": "BR" }, { "input": "5\nBBBBB", "output": "B" }, { "input": "1\nR", "output": "R" }, { "input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB...
1,561,397,466
2,147,483,647
Python 3
OK
TESTS
46
109
307,200
# In this template you are not required to write code in main import sys inf = float("inf") #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd #from bisect ...
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors...
```python # In this template you are not required to write code in main import sys inf = float("inf") #from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace #from math import ceil,floor,log,sqrt,factorial,pow,pi,gcd #fr...
3
673
B
Problems for Round
PROGRAMMING
1,300
[ "greedy", "implementation" ]
null
null
There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems. Authors want to split problems between two division according to the following rules: - Problemset ...
The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 0<=≤<=*m*<=≤<=100<=000) — the number of problems prepared for the round and the number of pairs of similar problems, respectively. Each of the following *m* lines contains a pair of similar problems *u**i* and *v**i* (1<=≤<=*u**i*,<...
Print one integer — the number of ways to split problems in two divisions.
[ "5 2\n1 4\n5 2\n", "3 3\n1 2\n2 3\n1 3\n", "3 2\n3 1\n3 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first sample, problems 1 and 2 should be used in division 2, while problems 4 and 5 in division 1. Problem 3 may be used either in division 1 or in division 2. In the second sample, all pairs of problems are similar and there is no way to split problem between two divisions without breaking any rules. Third sa...
750
[ { "input": "5 2\n1 4\n5 2", "output": "2" }, { "input": "3 3\n1 2\n2 3\n1 3", "output": "0" }, { "input": "3 2\n3 1\n3 2", "output": "1" }, { "input": "2 0", "output": "1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "3 0", "output": "2" ...
1,464,143,437
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
3
62
4,608,000
nm=input().split() n=int(nm[0]) m=int(nm[1]) i=0 d1=[] d2=[] while i<m: uv=input().split() u=int(uv[0]) v=int(uv[1]) d1.append(max(u,v)) d2.append(min(u,v)) i+=1 x=min(d1) y=max(d2) if x<=y: print(0) else: print(x-y)
Title: Problems for Round Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are *m* pairs of similar problems...
```python nm=input().split() n=int(nm[0]) m=int(nm[1]) i=0 d1=[] d2=[] while i<m: uv=input().split() u=int(uv[0]) v=int(uv[1]) d1.append(max(u,v)) d2.append(min(u,v)) i+=1 x=min(d1) y=max(d2) if x<=y: print(0) else: print(x-y) ```
-1
236
A
Boy or Girl
PROGRAMMING
800
[ "brute force", "implementation", "strings" ]
null
null
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
[ "wjmzbmr\n", "xiaodao\n", "sevenkplus\n" ]
[ "CHAT WITH HER!\n", "IGNORE HIM!\n", "CHAT WITH HER!\n" ]
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
500
[ { "input": "wjmzbmr", "output": "CHAT WITH HER!" }, { "input": "xiaodao", "output": "IGNORE HIM!" }, { "input": "sevenkplus", "output": "CHAT WITH HER!" }, { "input": "pezu", "output": "CHAT WITH HER!" }, { "input": "wnemlgppy", "output": "CHAT WITH HER!" },...
1,695,190,333
2,147,483,647
Python 3
OK
TESTS
85
92
0
# Read the user name as a string user_name = input() # Count the number of distinct characters in the user name distinct_characters = set(user_name) # Check if the count is even or odd if len(distinct_characters) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!")
Title: Boy or Girl Time Limit: None seconds Memory Limit: None megabytes Problem Description: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he though...
```python # Read the user name as a string user_name = input() # Count the number of distinct characters in the user name distinct_characters = set(user_name) # Check if the count is even or odd if len(distinct_characters) % 2 == 0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
479
A
Expression
PROGRAMMING
1,000
[ "brute force", "math" ]
null
null
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul...
The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10).
Print the maximum value of the expression that you can obtain.
[ "1\n2\n3\n", "2\n10\n3\n" ]
[ "9\n", "60\n" ]
none
500
[ { "input": "1\n2\n3", "output": "9" }, { "input": "2\n10\n3", "output": "60" }, { "input": "1\n1\n1", "output": "3" }, { "input": "1\n2\n1", "output": "4" }, { "input": "10\n10\n10", "output": "1000" }, { "input": "5\n1\n3", "output": "20" }, {...
1,694,167,724
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
a,b,c = map(int,input().split()) x1 = a+b+c x2 = a*b*c x3 = (a+b)*c x4 = a+(b*c) x5 = a*b+c print(max(x1,x2,x3,x4,x5))
Title: Expression Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ...
```python a,b,c = map(int,input().split()) x1 = a+b+c x2 = a*b*c x3 = (a+b)*c x4 = a+(b*c) x5 = a*b+c print(max(x1,x2,x3,x4,x5)) ```
-1
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,559,282,925
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
109
0
# a = input() def is_a_in_b(a, b): if len(a) ==0: return True if len(b) ==1: if len(a) == 1: return a in b else: return False else: if b[0] == a[0]: return is_a_in_b(a[1:0],b[1:0]) else: ...
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 # a = input() def is_a_in_b(a, b): if len(a) ==0: return True if len(b) ==1: if len(a) == 1: return a in b else: return False else: if b[0] == a[0]: return is_a_in_b(a[1:0],b[1:0]) else: ...
0
118
A
String Task
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: - deletes all the vowels, - inserts a character "." before each consonant, - replaces ...
The first line represents input string of Petya's program. This string only consists of uppercase and lowercase Latin letters and its length is from 1 to 100, inclusive.
Print the resulting string. It is guaranteed that this string is not empty.
[ "tour\n", "Codeforces\n", "aBAcAba\n" ]
[ ".t.r\n", ".c.d.f.r.c.s\n", ".b.c.b\n" ]
none
500
[ { "input": "tour", "output": ".t.r" }, { "input": "Codeforces", "output": ".c.d.f.r.c.s" }, { "input": "aBAcAba", "output": ".b.c.b" }, { "input": "obn", "output": ".b.n" }, { "input": "wpwl", "output": ".w.p.w.l" }, { "input": "ggdvq", "output": "...
1,698,922,371
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
l=list(input().split()) k=[] for i in l : if l[i]==a or l[i]==e or l[i]==i or l[i]==o or l[i]== u or l[i]==A or l[i]==E or l[i]==I or l[i]==O or l[i]== U : l.pop[i] for j in range(len(l)): k.append(.) k.append(l[j]) for p in k: print(i,end="")
Title: String Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters...
```python l=list(input().split()) k=[] for i in l : if l[i]==a or l[i]==e or l[i]==i or l[i]==o or l[i]== u or l[i]==A or l[i]==E or l[i]==I or l[i]==O or l[i]== U : l.pop[i] for j in range(len(l)): k.append(.) k.append(l[j]) for p in k: print(i,end="") ```
-1
349
A
Cinema Line
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t...
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.
Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".
[ "4\n25 25 50 50\n", "2\n25 100\n", "4\n50 50 25 25\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "4\n25 25 50 50", "output": "YES" }, { "input": "2\n25 100", "output": "NO" }, { "input": "4\n50 50 25 25", "output": "NO" }, { "input": "3\n25 50 100", "output": "NO" }, { "input": "10\n25 25 25 25 25 25 25 25 25 25", "output": "YES" }, { "...
1,666,718,189
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
n = int(input()) tickets = list(map(int, input().split())) curr = 0 ticket_cost = 25 for ticket in tickets: if curr - (ticket - ticket_cost) < 0: print("NO") break curr += ticket else: print("YES")
Title: Cinema Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin...
```python n = int(input()) tickets = list(map(int, input().split())) curr = 0 ticket_cost = 25 for ticket in tickets: if curr - (ticket - ticket_cost) < 0: print("NO") break curr += ticket else: print("YES") ```
0
1,011
B
Planning The Expedition
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat t...
The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food pac...
Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.
[ "4 10\n1 5 2 1 1 1 2 5 7 2\n", "100 1\n1\n", "2 5\n5 4 3 2 1\n", "3 9\n42 42 42 42 42 42 42 42 42\n" ]
[ "2\n", "0\n", "1\n", "3\n" ]
In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of ty...
1,000
[ { "input": "4 10\n1 5 2 1 1 1 2 5 7 2", "output": "2" }, { "input": "100 1\n1", "output": "0" }, { "input": "2 5\n5 4 3 2 1", "output": "1" }, { "input": "3 9\n42 42 42 42 42 42 42 42 42", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "inp...
1,692,819,746
2,147,483,647
PyPy 3-64
OK
TESTS
31
77
2,662,400
import sys import math import collections from heapq import heappush, heappop input = sys.stdin.readline ints = lambda: list(map(int, input().split())) m, n = ints() a = ints() def check(x): cnt = 0 f = collections.defaultdict(int) for i in range(n): f[str(a[i])] += 1 for k...
Title: Planning The Expedition Time Limit: None seconds Memory Limit: None megabytes Problem Description: Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. E...
```python import sys import math import collections from heapq import heappush, heappop input = sys.stdin.readline ints = lambda: list(map(int, input().split())) m, n = ints() a = ints() def check(x): cnt = 0 f = collections.defaultdict(int) for i in range(n): f[str(a[i])] += 1 ...
3
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *...
Print "YES" (without the quotes), if you can choose *k* numbers in array *A* and *m* numbers in array *B* so that any number chosen in array *A* was strictly less than any number chosen in array *B*. Otherwise, print "NO" (without the quotes).
[ "3 3\n2 1\n1 2 3\n3 4 5\n", "3 3\n3 3\n1 2 3\n3 4 5\n", "5 2\n3 1\n1 1 1 1 1\n2 2\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test you can, for example, choose numbers 1 and 2 from array *A* and number 3 from array *B* (1 &lt; 3 and 2 &lt; 3). In the second sample test the only way to choose *k* elements in the first array and *m* elements in the second one is to choose all numbers in both arrays, but then not all the num...
500
[ { "input": "3 3\n2 1\n1 2 3\n3 4 5", "output": "YES" }, { "input": "3 3\n3 3\n1 2 3\n3 4 5", "output": "NO" }, { "input": "5 2\n3 1\n1 1 1 1 1\n2 2", "output": "YES" }, { "input": "3 5\n1 1\n5 5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n1 1\n1\n1", "ou...
1,531,134,946
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n_a, n_b = map(int, input().split()) k, l = map(int, input().split()) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) if (a_list[k-1] < b_list[l-1]): print('YES') else: print('NO')
Title: Arrays Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the fi...
```python n_a, n_b = map(int, input().split()) k, l = map(int, input().split()) a_list = list(map(int, input().split())) b_list = list(map(int, input().split())) if (a_list[k-1] < b_list[l-1]): print('YES') else: print('NO') ```
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,584,481,220
2,147,483,647
Python 3
OK
TESTS
32
280
0
n = int(input()) a = list(map(int, input().split())) count = a[0] % 2 + a[1] % 2 + a[2] % 2 even = True if count <= 1 else False for i in range(n): if even == True and a[i] % 2 != 0: print(i+1) break elif even == False and a[i] % 2 == 0: print(i+1) break
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n = int(input()) a = list(map(int, input().split())) count = a[0] % 2 + a[1] % 2 + a[2] % 2 even = True if count <= 1 else False for i in range(n): if even == True and a[i] % 2 != 0: print(i+1) break elif even == False and a[i] % 2 == 0: print(i+1) break ```
3.93
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-...
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input"...
1,675,704,168
2,147,483,647
Python 3
OK
TESTS
65
46
0
import math x = list(map(int,input().split())) if(x[0] ==1 and x[1] == 10): print(-1) exit() sol = x[1] while(True) : div = math.floor(sol/(math.pow(10,x[0]-1))) if (div < 10 and div > 0): print(sol) exit() sol *= 2 print(-1)
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larg...
```python import math x = list(map(int,input().split())) if(x[0] ==1 and x[1] == 10): print(-1) exit() sol = x[1] while(True) : div = math.floor(sol/(math.pow(10,x[0]-1))) if (div < 10 and div > 0): print(sol) exit() sol *= 2 print(-1) ```
3
620
B
Grandfather Dovlet’s calculator
PROGRAMMING
1,000
[ "implementation" ]
null
null
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)). Max starts to type all the values from *a* to *b*. After typi...
The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max.
Print the only integer *a* — the total number of printed segments.
[ "1 3\n", "10 15\n" ]
[ "12\n", "39\n" ]
none
0
[ { "input": "1 3", "output": "12" }, { "input": "10 15", "output": "39" }, { "input": "1 100", "output": "928" }, { "input": "100 10000", "output": "188446" }, { "input": "213 221442", "output": "5645356" }, { "input": "1 1000000", "output": "287333...
1,680,740,190
2,147,483,647
PyPy 3-64
OK
TESTS
11
109
2,150,400
def f(n): s=0 while n>9: s+= mp[n%10] n//=10 s+=mp[n] return s mp = [6,2,5,5,4,5,6,3,7,6] s = 0 a,b = map(int,input().split()) for i in range(a,b+1): s += f(i) print(s)
Title: Grandfather Dovlet’s calculator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](...
```python def f(n): s=0 while n>9: s+= mp[n%10] n//=10 s+=mp[n] return s mp = [6,2,5,5,4,5,6,3,7,6] s = 0 a,b = map(int,input().split()) for i in range(a,b+1): s += f(i) print(s) ```
3
605
B
Lazy Student
PROGRAMMING
1,700
[ "constructive algorithms", "data structures", "graphs" ]
null
null
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
The first line of the input contains two integers *n* and *m* () — the number of vertices and the number of edges in the graph. Each of the next *m* lines describes an edge of the graph and consists of two integers *a**j* and *b**j* (1<=≤<=*a**j*<=≤<=109,<=*b**j*<==<={0,<=1}). The first of these numbers is the weight ...
If Vladislav has made a mistake and such graph doesn't exist, print <=-<=1. Otherwise print *m* lines. On the *j*-th line print a pair of vertices (*u**j*,<=*v**j*) (1<=≤<=*u**j*,<=*v**j*<=≤<=*n*,<=*u**j*<=≠<=*v**j*), that should be connected by the *j*-th edge. The edges are numbered in the same order as in the input...
[ "4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n", "3 3\n1 0\n2 1\n3 1\n" ]
[ "2 4\n1 4\n3 4\n3 1\n3 2\n", "-1\n" ]
none
1,000
[ { "input": "4 5\n2 1\n3 1\n4 0\n1 1\n5 0", "output": "2 4\n1 4\n3 4\n3 1\n3 2" }, { "input": "3 3\n1 0\n2 1\n3 1", "output": "-1" }, { "input": "2 1\n7 1", "output": "1 2" }, { "input": "3 2\n8 1\n9 1", "output": "1 2\n1 3" }, { "input": "3 3\n4 1\n5 0\n7 1", ...
1,550,439,674
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
109
307,200
g = input().split(" ") Namount = int(g[0]) Eamount = int(g[1]) Array = [] Pointer1 = 1 # Pointer1 keeps the number of points currently active Pointer2 = 1 # Pointer2 keeps the smallest number for which we can add more edges (Location in Namount) NArray = [Pointer1] LArray = [] for j in range(Eamount): g ...
Title: Lazy Student Time Limit: None seconds Memory Limit: None megabytes Problem Description: Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sittin...
```python g = input().split(" ") Namount = int(g[0]) Eamount = int(g[1]) Array = [] Pointer1 = 1 # Pointer1 keeps the number of points currently active Pointer2 = 1 # Pointer2 keeps the smallest number for which we can add more edges (Location in Namount) NArray = [Pointer1] LArray = [] for j in range(Eamou...
0
408
A
Line to Cashier
PROGRAMMING
900
[ "implementation" ]
null
null
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ...
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier. The *i*-th of the next *n* lines contains *k**i*...
Print a single integer — the minimum number of seconds Vasya needs to get to the cashier.
[ "1\n1\n1\n", "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n" ]
[ "20\n", "100\n" ]
In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou...
500
[ { "input": "1\n1\n1", "output": "20" }, { "input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8", "output": "100" }, { "input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3", "output": "100" }, { "input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"...
1,607,162,817
2,147,483,647
PyPy 3
OK
TESTS
20
139
1,536,000
n = int(input()) k = list(map(int,input().split())) ans = [] for i in range(n): p = list(map(int,input().split())) q = sum(p)*5 + k[i]*15 ans.append(q) print(min(ans))
Title: Line to Cashier Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products. There are *n* c...
```python n = int(input()) k = list(map(int,input().split())) ans = [] for i in range(n): p = list(map(int,input().split())) q = sum(p)*5 + k[i]*15 ans.append(q) print(min(ans)) ```
3
785
A
Anton and Polyhedrons
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (withou...
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
[ "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n", "3\nDodecahedron\nOctahedron\nOctahedron\n" ]
[ "42\n", "28\n" ]
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
500
[ { "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42" }, { "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28" }, { "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa...
1,697,494,363
2,147,483,647
Python 3
OK
TESTS
30
264
16,076,800
n = int(input()) Tetrahedron = 4 Cube = 6 Octahedron =8 Dodecahedron = 12 Icosahedron = 20 face = 0 ls = [] for i in range(n): x = input() ls.append(x) for i in ls: if i == "Tetrahedron": face += Tetrahedron elif i == "Cube": face += Cube elif i == "Octahedro...
Title: Anton and Polyhedrons Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe...
```python n = int(input()) Tetrahedron = 4 Cube = 6 Octahedron =8 Dodecahedron = 12 Icosahedron = 20 face = 0 ls = [] for i in range(n): x = input() ls.append(x) for i in ls: if i == "Tetrahedron": face += Tetrahedron elif i == "Cube": face += Cube elif i == ...
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,694,707,261
2,147,483,647
PyPy 3-64
OK
TESTS
76
154
1,638,400
def dfs(i): sn[i] = 1 for j in g[i]: if sn[j] != 1: dfs(j) t = 1 comp = 0 N = 1010 g = [[] for _ in range(N)] gr = [] sn = [0] * N def solve(): global comp n = int(input()) for _ in range(n): a, b = map(int, input().split()) gr.append((a, b)) ...
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 def dfs(i): sn[i] = 1 for j in g[i]: if sn[j] != 1: dfs(j) t = 1 comp = 0 N = 1010 g = [[] for _ in range(N)] gr = [] sn = [0] * N def solve(): global comp n = int(input()) for _ in range(n): a, b = map(int, input().split()) gr.append...
3
0
none
none
none
0
[ "none" ]
null
null
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ...
The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the ...
Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).
[ "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first example the second square lies entirely within the first square, so they do intersect. In the second sample squares do not have any points in common. Here are images corresponding to the samples:
0
[ { "input": "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1", "output": "NO" }, { "input": "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7", "output": "YES" }, { "input": "0 0 6 0 6 6 0 6\n8 4 4 8 8 12 12 8", "output": "YES" }, ...
1,529,559,662
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
108
0
s1=list(map(int, input().split())) s2=list(map(int, input().split())) p1=[] p2=[] for i in range(0,8,2): p1.append([s1[i],s1[i+1]]) p2.append([s2[i],s2[i+1]]) # ������, ��� ����� ������� � ������: ru=p1[0] num=0 for i in range(1,4): if p1[i][0]>=ru[0] and p1[i][1]>=ru[1]: ru=p1[i] num=i for...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be pa...
```python s1=list(map(int, input().split())) s2=list(map(int, input().split())) p1=[] p2=[] for i in range(0,8,2): p1.append([s1[i],s1[i+1]]) p2.append([s2[i],s2[i+1]]) # ������, ��� ����� ������� � ������: ru=p1[0] num=0 for i in range(1,4): if p1[i][0]>=ru[0] and p1[i][1]>=ru[1]: ru=p1[i] ...
0
987
B
High School: Become Human
PROGRAMMING
1,100
[ "math" ]
null
null
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl...
On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$).
If $x^y &lt; y^x$, then print '&lt;' (without quotes). If $x^y &gt; y^x$, then print '&gt;' (without quotes). If $x^y = y^x$, then print '=' (without quotes).
[ "5 8\n", "10 3\n", "6 6\n" ]
[ "&gt;\n", "&lt;\n", "=\n" ]
In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '&gt;'. In the second example $10^3 = 1000 &lt; 3^{10} = 59049$. In the third example $6^6 = 46656 = 6^6$.
1,000
[ { "input": "5 8", "output": ">" }, { "input": "10 3", "output": "<" }, { "input": "6 6", "output": "=" }, { "input": "14 1", "output": ">" }, { "input": "2 4", "output": "=" }, { "input": "987654321 123456987", "output": "<" }, { "input": "...
1,625,486,127
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
25
1,000
1,945,600
a,b=map(int,input().split()) if len(str(a))>8 and len(str(b))>8: if b>a: print('>') elif b<a: print('<') else: print('=') elif (a**b)>(b**a): print('>') elif (a**b)<(b**a): print('<') else: print('=')
Title: High School: Become Human Time Limit: None seconds Memory Limit: None megabytes Problem Description: Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before. It turns out tha...
```python a,b=map(int,input().split()) if len(str(a))>8 and len(str(b))>8: if b>a: print('>') elif b<a: print('<') else: print('=') elif (a**b)>(b**a): print('>') elif (a**b)<(b**a): print('<') else: print('=') ```
0
556
A
Case of the Zeros and Ones
PROGRAMMING
900
[ "greedy" ]
null
null
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, an...
First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=2·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones.
Output the minimum length of the string that may remain after applying the described operations several times.
[ "4\n1100\n", "5\n01010\n", "8\n11101111\n" ]
[ "0\n", "1\n", "6\n" ]
In the first sample test it is possible to change the string like the following: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/10df55364c21c6e8d5da31b6ab6f6294c4fc26b3.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test it is possible to change the string like...
250
[ { "input": "4\n1100", "output": "0" }, { "input": "5\n01010", "output": "1" }, { "input": "8\n11101111", "output": "6" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "2" }, { "input"...
1,681,762,201
2,147,483,647
Python 3
OK
TESTS
49
124
716,800
#Complejidad O(n) n = int(input()) p = input() count = 0 aux = 0 if len(p)==n: for char in p: if char == "0": count += 1 elif char == "1": aux += 1 ans = abs(count - aux) #La funcion abs me devuelve el valor absoluto #De una resta print(ans) ...
Title: Case of the Zeros and Ones Time Limit: None seconds Memory Limit: None megabytes Problem Description: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Cons...
```python #Complejidad O(n) n = int(input()) p = input() count = 0 aux = 0 if len(p)==n: for char in p: if char == "0": count += 1 elif char == "1": aux += 1 ans = abs(count - aux) #La funcion abs me devuelve el valor absoluto #De una resta print(an...
3
0
none
none
none
0
[ "none" ]
null
null
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Print a single integer — the remainder of dividing the number of plants that will point "upwards" in *n* years by 1000000007 (109<=+<=7).
[ "1\n", "2\n" ]
[ "3\n", "10\n" ]
The first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.
0
[ { "input": "1", "output": "3" }, { "input": "2", "output": "10" }, { "input": "385599124", "output": "493875375" }, { "input": "989464295", "output": "31966163" }, { "input": "376367012", "output": "523204186" }, { "input": "529357306", "output": "...
1,667,475,279
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
8
218
9,420,800
from collections import defaultdict,Counter,deque import math import bisect from itertools import accumulate from math import ceil, log,gcd from functools import lru_cache from sys import stdin, stdout import atexit import io import sys def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = kwargs.get...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will poin...
```python from collections import defaultdict,Counter,deque import math import bisect from itertools import accumulate from math import ceil, log,gcd from functools import lru_cache from sys import stdin, stdout import atexit import io import sys def write(*args, **kwargs): sep = kwargs.get('sep', ' ') end = ...
-1
933
B
A Determined Cleanup
PROGRAMMING
2,000
[ "math" ]
null
null
In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doing this... Given two integers *p* and *k*, find a polynomial *f*(*x*) with non-negative integer coefficien...
The only line of input contains two space-separated integers *p* and *k* (1<=≤<=*p*<=≤<=1018, 2<=≤<=*k*<=≤<=2<=000).
If the polynomial does not exist, print a single integer -1, or output two lines otherwise. In the first line print a non-negative integer *d* — the number of coefficients in the polynomial. In the second line print *d* space-separated integers *a*0,<=*a*1,<=...,<=*a**d*<=-<=1, describing a polynomial fulfilling the...
[ "46 2\n", "2018 214\n" ]
[ "7\n0 1 0 0 1 1 1\n", "3\n92 205 1\n" ]
In the first example, *f*(*x*) = *x*<sup class="upper-index">6</sup> + *x*<sup class="upper-index">5</sup> + *x*<sup class="upper-index">4</sup> + *x* = (*x*<sup class="upper-index">5</sup> - *x*<sup class="upper-index">4</sup> + 3*x*<sup class="upper-index">3</sup> - 6*x*<sup class="upper-index">2</sup> + 12*x* - 23)·...
750
[ { "input": "46 2", "output": "7\n0 1 0 0 1 1 1" }, { "input": "2018 214", "output": "3\n92 205 1" }, { "input": "4 2", "output": "3\n0 0 1" }, { "input": "5 2", "output": "3\n1 0 1" }, { "input": "10 3", "output": "3\n1 0 1" }, { "input": "250 1958", ...
1,518,698,484
2,147,483,647
PyPy 3
OK
TESTS
40
77
19,968,000
p,k=input().strip().split(' ') flag=1 p=int(p) k=int(k) A=[] B=[] k=-k while p!=0: A.append(p%k) p//=k if A[-1]<0: p+=1 for i in A: if i<0: B.append(i-k); else: B.append(i); print(len(B)) for i in B: print(i,end=" ")
Title: A Determined Cleanup Time Limit: None seconds Memory Limit: None megabytes Problem Description: In order to put away old things and welcome a fresh new year, a thorough cleaning of the house is a must. Little Tommy finds an old polynomial and cleaned it up by taking it modulo another. But now he regrets doin...
```python p,k=input().strip().split(' ') flag=1 p=int(p) k=int(k) A=[] B=[] k=-k while p!=0: A.append(p%k) p//=k if A[-1]<0: p+=1 for i in A: if i<0: B.append(i-k); else: B.append(i); print(len(B)) for i in B: print(i,end=" ") ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ...
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "i...
1,688,562,430
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
0
122
2,867,200
""" inp1 = lambda: map(int,input().split()) inp2 = lambda: list(map(int,input().split())) """ """ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ """ mod = 10**9 + 7 inp1 = lambda: map(int,input().split()) inp2 = lambda: list(map(int,input().split())) def compute_gcd(x, y): while(y): x, y = y, x % ...
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entert...
```python """ inp1 = lambda: map(int,input().split()) inp2 = lambda: list(map(int,input().split())) """ """ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ """ mod = 10**9 + 7 inp1 = lambda: map(int,input().split()) inp2 = lambda: list(map(int,input().split())) def compute_gcd(x, y): while(y): x, y...
-1
920
B
Tea Queue
PROGRAMMING
1,200
[ "implementation" ]
null
null
Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea. *i*-th s...
The first line contains one integer *t* — the number of test cases to solve (1<=≤<=*t*<=≤<=1000). Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=≤<=*n*<=≤<=1000) — the number of students. Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=...
For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea.
[ "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n" ]
[ "1 2 \n1 0 2 \n" ]
The example contains 2 tests: 1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and ...
0
[ { "input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3", "output": "1 2 \n1 0 2 " }, { "input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2...
1,689,150,538
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
t=int(input()) for _ in range(t): n=int(input()) arr=[] d=1 for k in range(n): c,l=map(int,input().split()) if c<l: arr.append(max(c,d)) d+=1 else: arr.append(0) print(*arr)
Title: Tea Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently *n* students from city S moved to city P to attend a programming camp. They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use ...
```python t=int(input()) for _ in range(t): n=int(input()) arr=[] d=1 for k in range(n): c,l=map(int,input().split()) if c<l: arr.append(max(c,d)) d+=1 else: arr.append(0) print(*arr) ```
0
32
C
Flea
PROGRAMMING
1,700
[ "math" ]
C. Flea
2
256
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*m* centimeters (each cell is 1<=×<=1 centimeters). She can jump as she wishes for an a...
The first line contains three integers *n*, *m*, *s* (1<=≤<=*n*,<=*m*,<=*s*<=≤<=106) — length of the board, width of the board and length of the flea's jump.
Output the only integer — the number of the required starting positions of the flea.
[ "2 3 1000000\n", "3 3 2\n" ]
[ "6\n", "4\n" ]
none
1,500
[ { "input": "2 3 1000000", "output": "6" }, { "input": "3 3 2", "output": "4" }, { "input": "1 2 3", "output": "2" }, { "input": "4 5 6", "output": "20" }, { "input": "9 8 7", "output": "8" }, { "input": "1000 1000 1000", "output": "1000000" }, ...
1,639,230,882
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
16
186
0
n, m, s = map(int, input().split()) row_n = n // s + int(n > s and n % s != 0) row_m = m // s + int(m > s and m % s != 0) a = (row_n - 1) * s + 1 b = (row_m - 1) * s + 1 can_move_right = n - a can_move_down = m - b if row_m == 0 or row_n == 0: if row_m == 0 and row_n == 0: print(n * m) eli...
Title: Flea Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*...
```python n, m, s = map(int, input().split()) row_n = n // s + int(n > s and n % s != 0) row_m = m // s + int(m > s and m % s != 0) a = (row_n - 1) * s + 1 b = (row_m - 1) * s + 1 can_move_right = n - a can_move_down = m - b if row_m == 0 or row_n == 0: if row_m == 0 and row_n == 0: print(n * m...
0
405
A
Gravity Flip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column.
Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch.
[ "4\n3 2 1 2\n", "3\n2 3 8\n" ]
[ "1 2 2 3 \n", "2 3 8 \n" ]
The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not ...
500
[ { "input": "4\n3 2 1 2", "output": "1 2 2 3 " }, { "input": "3\n2 3 8", "output": "2 3 8 " }, { "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n4 3", "output": "3 4 " }, { "input": "6\n100 40 60 20...
1,687,101,090
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
num=input('') x=map(int,input('').split(' ')) arr=[] for k in x: arr.append(k) arr.sort() print(arr)
Title: Gravity Flip Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the bo...
```python num=input('') x=map(int,input('').split(' ')) arr=[] for k in x: arr.append(k) arr.sort() print(arr) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk...
1,666,855,637
2,147,483,647
PyPy 3-64
OK
TESTS
40
154
0
import math def reverse(string): string = "".join(reversed(string)) return string word1 = input("") word2 = input("") if word1 == reverse(word2): print("YES") else: print("NO")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron...
```python import math def reverse(string): string = "".join(reversed(string)) return string word1 = input("") word2 = input("") if word1 == reverse(word2): print("YES") else: print("NO") ```
3.9615
750
C
New Year and Rating
PROGRAMMING
1,600
[ "binary search", "greedy", "math" ]
null
null
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000). The *i*-th of next *n* lines contains two integers *c**i* and *d**i* (<=-<=100<=≤<=*c**i*<=≤<=100, 1<=≤<=*d**i*<=≤<=2), describing Limak's rating change after the *i*-th contest and his division during the *i*-th contest contest.
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the *n* contests.
[ "3\n-7 1\n5 2\n8 2\n", "2\n57 1\n22 2\n", "1\n-5 1\n", "4\n27 2\n13 1\n-50 1\n8 2\n" ]
[ "1907\n", "Impossible\n", "Infinity\n", "1897\n" ]
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: - Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. - With rating 1894 Limak is in the division 2. His rating increases by 5. - Limak has rati...
1,000
[ { "input": "3\n-7 1\n5 2\n8 2", "output": "1907" }, { "input": "2\n57 1\n22 2", "output": "Impossible" }, { "input": "1\n-5 1", "output": "Infinity" }, { "input": "4\n27 2\n13 1\n-50 1\n8 2", "output": "1897" }, { "input": "6\n8 1\n-22 1\n9 2\n-7 2\n85 2\n77 1", ...
1,690,591,017
2,147,483,647
PyPy 3-64
OK
TESTS
81
1,138
9,932,800
s, t = -10 ** 8, 10 ** 8 n = int(input()) for i in range(n): c, d = map(int, input().split()) if d == 1: s = max(s, 1900) if d == 2: t = min(t, 1899) if s > t: print('Impossible') exit() s = s + c t = t + c if (t > 4*10**7):print('Infinity') else: pr...
Title: New Year and Rating Time Limit: None seconds Memory Limit: None megabytes Problem Description: Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lo...
```python s, t = -10 ** 8, 10 ** 8 n = int(input()) for i in range(n): c, d = map(int, input().split()) if d == 1: s = max(s, 1900) if d == 2: t = min(t, 1899) if s > t: print('Impossible') exit() s = s + c t = t + c if (t > 4*10**7):print('Infinity')...
3
0
none
none
none
0
[ "none" ]
null
null
Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of t...
The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and the number of columns in the plan. The next *n* lines contain *m* integers, 0 or 1 each — the description of the plan. Integer 1, means there will be an actor in the corresponding cell, while 0 means the cell ...
Print one integer — the number of good positions for placing the spotlight.
[ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ]
[ "9\n", "20\n" ]
In the first example the following positions are good: 1. the (1, 1) cell and right direction; 1. the (1, 1) cell and down direction; 1. the (1, 3) cell and left direction; 1. the (1, 3) cell and down direction; 1. the (1, 4) cell and left direction; 1. the (2, 2) cell and left direction; 1. the (2, 2) cell and...
0
[ { "input": "2 4\n0 1 0 0\n1 0 1 0", "output": "9" }, { "input": "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0", "output": "20" }, { "input": "1 5\n1 1 0 0 0", "output": "3" }, { "input": "2 10\n0 0 0 0 0 0 0 1 0 0\n1 0 0 0 0 0 0 0 0 0", "output": "20" }, { "input": "3 ...
1,479,634,787
2,087
Python 3
TIME_LIMIT_EXCEEDED
TESTS
43
1,000
921,600
n,m = (int(x) for x in input().split()) ups = [-1]*m downs = [-1]*m upbools = [True]*m colcount = [0]*m totalcount = 0 for i in range(n): left = -1 right = -1 lbool = True rowcount = 0 l = [int(x) for x in input().split()] for j in range(m): x = l[j] if x == 1: rowcount += 1 colcount[j] ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Theater stage is a rectangular field of size *n*<=×<=*m*. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a ...
```python n,m = (int(x) for x in input().split()) ups = [-1]*m downs = [-1]*m upbools = [True]*m colcount = [0]*m totalcount = 0 for i in range(n): left = -1 right = -1 lbool = True rowcount = 0 l = [int(x) for x in input().split()] for j in range(m): x = l[j] if x == 1: rowcount += 1 co...
0
593
B
Anton and Lines
PROGRAMMING
1,600
[ "geometry", "sortings" ]
null
null
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of t...
The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=&lt;<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two ...
Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes).
[ "4\n1 2\n1 2\n1 0\n0 1\n0 2\n", "2\n1 3\n1 0\n-1 3\n", "2\n1 3\n1 0\n0 2\n", "2\n1 3\n1 0\n0 3\n" ]
[ "NO", "YES", "YES", "NO" ]
In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it.
1,000
[ { "input": "4\n1 2\n1 2\n1 0\n0 1\n0 2", "output": "NO" }, { "input": "2\n1 3\n1 0\n-1 3", "output": "YES" }, { "input": "2\n1 3\n1 0\n0 2", "output": "YES" }, { "input": "2\n1 3\n1 0\n0 3", "output": "NO" }, { "input": "2\n0 1\n-1000000 1000000\n1000000 -1000000"...
1,698,090,931
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
53
748
12,697,600
n = int(input()) x1, x2 = map(int, input().split()) segments = [] for i in range(n): k, b = map(int, input().split()) y1 = x1 * k + b y2 = x2 * k + b segments.append((y1, y2)) #let's just test if they intersect in this interval segments.sort(key= lambda t: t[0]) #print(segments) for i in rang...
Title: Anton and Lines Time Limit: None seconds Memory Limit: None megabytes Problem Description: The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*...
```python n = int(input()) x1, x2 = map(int, input().split()) segments = [] for i in range(n): k, b = map(int, input().split()) y1 = x1 * k + b y2 = x2 * k + b segments.append((y1, y2)) #let's just test if they intersect in this interval segments.sort(key= lambda t: t[0]) #print(segments) for...
0
335
B
Palindrome
PROGRAMMING
1,900
[ "constructive algorithms", "dp" ]
null
null
Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long as possible.
The only line of the input contains one string *s* of length *n* (1<=≤<=*n*<=≤<=5·104) containing only lowercase English letters.
If *s* contains a palindrome of length exactly 100 as a subsequence, print any palindrome of length 100 which is a subsequence of *s*. If *s* doesn't contain any palindromes of length exactly 100, print a palindrome that is a subsequence of *s* and is as long as possible. If there exists multiple answers, you are allo...
[ "bbbabcbbb\n", "rquwmzexectvnbanemsmdufrg\n" ]
[ "bbbcbbb\n", "rumenanemur\n" ]
A subsequence of a string is a string that can be derived from it by deleting some characters without changing the order of the remaining characters. A palindrome is a string that reads the same forward or backward.
1,000
[ { "input": "bbbabcbbb", "output": "bbbcbbb" }, { "input": "rquwmzexectvnbanemsmdufrg", "output": "rumenanemur" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
1,664,456,180
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
""" Question Link: """ from collections import Counter import sys # the setrecursionlimit function is # used to modify the default recursion # limit set by python. Using this, # we can increase the recursion limit # to satisfy our needs sys.setrecursionlimit(10**6) memo = {} text = "" def get100...
Title: Palindrome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Given a string *s*, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of *s* and is as long...
```python """ Question Link: """ from collections import Counter import sys # the setrecursionlimit function is # used to modify the default recursion # limit set by python. Using this, # we can increase the recursion limit # to satisfy our needs sys.setrecursionlimit(10**6) memo = {} text = "" ...
0
215
B
Olympic Medal
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/cm3. The second part is an inner disk with radius *r*2 cm, it is made of metal with density *p*2 g/...
The first input line contains an integer *n* and a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*. The second input line contains an integer *m* and a sequence of integers *y*1,<=*y*2,<=...,<=*y**m*. The third input line contains an integer *k* and a sequence of integers *z*1,<=*z*2,<=...,<=*z**k*. The last line conta...
Print a single real number — the sought value *r*2 with absolute or relative error of at most 10<=-<=6. It is guaranteed that the solution that meets the problem requirements exists.
[ "3 1 2 3\n1 2\n3 3 2 1\n1 2\n", "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1\n" ]
[ "2.683281573000\n", "2.267786838055\n" ]
In the first sample the jury should choose the following values: *r*<sub class="lower-index">1</sub> = 3, *p*<sub class="lower-index">1</sub> = 2, *p*<sub class="lower-index">2</sub> = 1.
500
[ { "input": "3 1 2 3\n1 2\n3 3 2 1\n1 2", "output": "2.683281573000" }, { "input": "4 2 3 6 4\n2 1 2\n3 10 6 8\n2 1", "output": "2.267786838055" }, { "input": "1 5\n1 3\n1 7\n515 892", "output": "3.263613058533" }, { "input": "2 3 2\n3 2 3 1\n2 2 1\n733 883", "output": "2....
1,620,970,652
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
6,963,200
import math R1 = input().split(" ") P1 = input().split(" ") P2 = input().split(" ") ab = input().split(" ") a = float(ab[0]) b = float(ab[1]) def maximum(lst): max = -1 for el in lst: if float(el) > max: max = float(el) return max def minimum(lst): min = flo...
Title: Olympic Medal Time Limit: None seconds Memory Limit: None megabytes Problem Description: The World Programming Olympics Medal is a metal disk, consisting of two parts: the first part is a ring with outer radius of *r*1 cm, inner radius of *r*2 cm, (0<=&lt;<=*r*2<=&lt;<=*r*1) made of metal with density *p*1 g/...
```python import math R1 = input().split(" ") P1 = input().split(" ") P2 = input().split(" ") ab = input().split(" ") a = float(ab[0]) b = float(ab[1]) def maximum(lst): max = -1 for el in lst: if float(el) > max: max = float(el) return max def minimum(lst): ...
0
195
A
Let's Watch Football
PROGRAMMING
1,000
[ "binary search", "brute force", "math" ]
null
null
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the si...
The first line contains three space-separated integers *a*, *b* and *c* (1<=≤<=*a*,<=*b*,<=*c*<=≤<=1000,<=*a*<=&gt;<=*b*). The first number (*a*) denotes the size of data needed to watch one second of the video. The second number (*b*) denotes the size of data Valeric and Valerko can download from the Net per second. T...
Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
[ "4 1 1\n", "10 3 2\n", "13 12 1\n" ]
[ "3\n", "5\n", "1\n" ]
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watch...
500
[ { "input": "4 1 1", "output": "3" }, { "input": "10 3 2", "output": "5" }, { "input": "13 12 1", "output": "1" }, { "input": "2 1 3", "output": "3" }, { "input": "6 2 4", "output": "8" }, { "input": "5 2 1", "output": "2" }, { "input": "2 1...
1,698,107,546
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
from math import ceil def can_watch_video(a, b, c, t): total_data_needed = a * c downloaded_data = b * t data_left = total_data_needed - downloaded_data time_needed = data_left / b time_covered = ceil(downloaded_data / a) return time_covered >= time_needed def minimum_wait_time(a, b, c): ...
Title: Let's Watch Football Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn ...
```python from math import ceil def can_watch_video(a, b, c, t): total_data_needed = a * c downloaded_data = b * t data_left = total_data_needed - downloaded_data time_needed = data_left / b time_covered = ceil(downloaded_data / a) return time_covered >= time_needed def minimum_wait_time(a...
0
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,558,252,897
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
0
import math a = int(input()) b = int(input()) def count(a): i = 0 while(a > 0): x = a%10 if(x != 0): i = i + 1 a = a//10 return i def removedzero(a): s= 0 j = 0 while(a > 0): x = a%10 if(x == 0): s...
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 import math a = int(input()) b = int(input()) def count(a): i = 0 while(a > 0): x = a%10 if(x != 0): i = i + 1 a = a//10 return i def removedzero(a): s= 0 j = 0 while(a > 0): x = a%10 if(x == 0): ...
0
319
C
Kalila and Dimna in the Logging Industry
PROGRAMMING
2,100
[ "dp", "geometry" ]
null
null
Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut *n* trees with heights *a*1,<=*a*2,<=...,<=*a**n*. They bought a chain saw from a shop. Each time they use the chain sa...
The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line of input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line of input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (0<=≤<=*b**i*<=≤<=109). It's guaranteed that *a*1<==<=1, *b**n*<==<=0, *a*1<=&l...
The only line of output must contain the minimum cost of cutting all the trees completely. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "5\n1 2 3 4 5\n5 4 3 2 0\n", "6\n1 2 3 10 20 30\n6 5 4 3 2 0\n" ]
[ "25\n", "138\n" ]
none
1,500
[ { "input": "5\n1 2 3 4 5\n5 4 3 2 0", "output": "25" }, { "input": "6\n1 2 3 10 20 30\n6 5 4 3 2 0", "output": "138" } ]
1,509,295,575
2,147,483,647
PyPy 3
OK
TESTS
24
608
13,312,000
f = lambda: list(map(int, input().split())) g = lambda j: a[i] * b[j] + t[j] h = lambda j, k: (t[i] - t[j]) * (b[j] - b[k]) < (t[j] - t[k]) * (b[i] - b[j]) n = int(input()) a, b = f(), f() t = [0] * n p = [0] for i in range(1, n): while len(p) > 1 and g(p[1]) < g(p[0]): p.pop(0) t[i] = g(p[0]) w...
Title: Kalila and Dimna in the Logging Industry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle a...
```python f = lambda: list(map(int, input().split())) g = lambda j: a[i] * b[j] + t[j] h = lambda j, k: (t[i] - t[j]) * (b[j] - b[k]) < (t[j] - t[k]) * (b[i] - b[j]) n = int(input()) a, b = f(), f() t = [0] * n p = [0] for i in range(1, n): while len(p) > 1 and g(p[1]) < g(p[0]): p.pop(0) t[i] = g(p[...
3
618
B
Guess the Permutation
PROGRAMMING
1,100
[ "constructive algorithms" ]
null
null
Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the number *a**i*,<=*j*<==<=*min*(*p**i*,<=*p**j*). He writes *a**i*,<=*i*<==<=0 for all integer *i* from 1 to *n...
The first line of the input will contain a single integer *n* (2<=≤<=*n*<=≤<=50). The next *n* lines will contain the values of *a**i*,<=*j*. The *j*-th number on the *i*-th line will represent *a**i*,<=*j*. The *i*-th number on the *i*-th line will be 0. It's guaranteed that *a**i*,<=*j*<==<=*a**j*,<=*i* and there is...
Print *n* space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
[ "2\n0 1\n1 0\n", "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n" ]
[ "2 1\n", "2 5 4 1 3\n" ]
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
1,000
[ { "input": "2\n0 1\n1 0", "output": "2 1" }, { "input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3" }, { "input": "10\n0 1 5 2 5 3 4 5 5 5\n1 0 1 1 1 1 1 1 1 1\n5 1 0 2 6 3 4 6 6 6\n2 1 2 0 2 2 2 2 2 2\n5 1 6 2 0 3 4 8 8 7\n3 1 3 2 3 0 3 3 3 3\n4 1 4...
1,671,478,349
2,147,483,647
Python 3
OK
TESTS
23
61
0
import sys f=sys.stdin n=int(f.readline()) arr=[max(map(int, f.readline().split())) for i in range(n)] arr[arr.index(n-1)]=n print(" ".join(map(str, arr)))
Title: Guess the Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bob has a permutation of integers from 1 to *n*. Denote this permutation as *p*. The *i*-th element of *p* will be denoted as *p**i*. For all pairs of distinct integers *i*,<=*j* between 1 and *n*, he wrote the nu...
```python import sys f=sys.stdin n=int(f.readline()) arr=[max(map(int, f.readline().split())) for i in range(n)] arr[arr.index(n-1)]=n print(" ".join(map(str, arr))) ```
3
433
A
Kitahara Haruki's Gift
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equa...
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of apples. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (*w**i*<==<=100 or *w**i*<==<=200), where *w**i* is the weight of the *i*-th apple.
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
[ "3\n100 200 100\n", "4\n100 100 100 200\n" ]
[ "YES\n", "NO\n" ]
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.
500
[ { "input": "3\n100 200 100", "output": "YES" }, { "input": "4\n100 100 100 200", "output": "NO" }, { "input": "1\n100", "output": "NO" }, { "input": "1\n200", "output": "NO" }, { "input": "2\n100 100", "output": "YES" }, { "input": "2\n200 200", "o...
1,658,121,623
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
from itertools import combinations n=int(input()) l=list(map(int,input().split())) t=sum(l) if t%2==0: print('YES') else: print('NO')
Title: Kitahara Haruki's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kitahara Haruki has bought *n* apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends. Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't w...
```python from itertools import combinations n=int(input()) l=list(map(int,input().split())) t=sum(l) if t%2==0: print('YES') else: print('NO') ```
0
810
B
Summer sell-off
PROGRAMMING
1,300
[ "greedy", "sortings" ]
null
null
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag...
The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin...
Print a single integer denoting the maximal number of products that shop can sell.
[ "4 2\n2 1\n3 5\n2 3\n1 5\n", "4 1\n0 2\n0 3\n3 5\n0 6\n" ]
[ "10", "5" ]
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the s...
1,000
[ { "input": "4 2\n2 1\n3 5\n2 3\n1 5", "output": "10" }, { "input": "4 1\n0 2\n0 3\n3 5\n0 6", "output": "5" }, { "input": "1 1\n5 8", "output": "8" }, { "input": "2 1\n8 12\n6 11", "output": "19" }, { "input": "2 1\n6 7\n5 7", "output": "13" }, { "inpu...
1,680,186,034
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
46
0
days,sales = map(int,input().split()) sale = [] for i in range(days): product,customers = map(int,input().split()) day = [product,customers,customers-product,customers-product*2] sale.append(day) sale.sort(key=lambda x: x[2],reverse=True) sum = 0 for i in sale: if i[0] != 0 and i[1] != 0 and sa...
Title: Summer sell-off Time Limit: None seconds Memory Limit: None megabytes Problem Description: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass...
```python days,sales = map(int,input().split()) sale = [] for i in range(days): product,customers = map(int,input().split()) day = [product,customers,customers-product,customers-product*2] sale.append(day) sale.sort(key=lambda x: x[2],reverse=True) sum = 0 for i in sale: if i[0] != 0 and i[1] !...
0
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,679,589,112
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
6
1,419
268,390,400
import math import itertools b, c = map(int, input().split()) def prime_factors(num): l1 = [] while num % 2 == 0: l1.append(2) num = num // 2 for i in range(3, int(math.sqrt(num)) + 1, 2): while num % i == 0: l1.append(i) num = num // i if num > 2: ...
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 import itertools b, c = map(int, input().split()) def prime_factors(num): l1 = [] while num % 2 == 0: l1.append(2) num = num // 2 for i in range(3, int(math.sqrt(num)) + 1, 2): while num % i == 0: l1.append(i) num = num // i if num ...
0
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,481,641,183
2,147,483,647
Python 3
OK
TESTS
30
122
0
a = input() res = "" c = 0 while c < len(a): if a[c:c + 2] == "--": res += "2" c += 2 elif a[c:c + 2] == "-.": res += "1" c += 2 else: res += "0" c += 1 print(res)
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 a = input() res = "" c = 0 while c < len(a): if a[c:c + 2] == "--": res += "2" c += 2 elif a[c:c + 2] == "-.": res += "1" c += 2 else: res += "0" c += 1 print(res) ```
3.9695
912
A
Tricky Alchemy
PROGRAMMING
800
[ "implementation" ]
null
null
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained.
Print a single integer — the minimum number of crystals that Grisha should acquire in addition.
[ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n" ]
[ "2\n", "1\n", "2147483648\n" ]
In the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.
500
[ { "input": "4 3\n2 1 1", "output": "2" }, { "input": "3 9\n1 1 3", "output": "1" }, { "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648" }, { "input": "12 12\n3 5 2", "output": "0" }, { "input": "770 1390\n170 442 311", "output"...
1,524,720,398
2,147,483,647
Python 3
OK
TESTS
38
93
7,372,800
A, B = [int(x) for x in input().split()] x, y, z = [int(x) for x in input().split()] yellow = x*2 + y blue = y + z*3 if A >= yellow: ans1 = 0 else: ans1 = yellow - A if B >= blue: ans2 = 0 else: ans2 = blue - B print(ans1 + ans2)
Title: Tricky Alchemy Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obta...
```python A, B = [int(x) for x in input().split()] x, y, z = [int(x) for x in input().split()] yellow = x*2 + y blue = y + z*3 if A >= yellow: ans1 = 0 else: ans1 = yellow - A if B >= blue: ans2 = 0 else: ans2 = blue - B print(ans1 + ans2) ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen...
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,693,164,547
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
30
0
n = int(input()) ds = [1,5,10,20,100] ds.sort(reverse=True) i=0 c=0 while n>0: if ds[i]<=n: num = n/ds[i] c+=num n = n%ds[i] i+=1 print(int(c))
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$...
```python n = int(input()) ds = [1,5,10,20,100] ds.sort(reverse=True) i=0 c=0 while n>0: if ds[i]<=n: num = n/ds[i] c+=num n = n%ds[i] i+=1 print(int(c)) ```
0
508
A
Pasha and Pixels
PROGRAMMING
1,100
[ "brute force" ]
null
null
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choos...
The first line of the input contains three integers *n*,<=*m*,<=*k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=105) — the number of rows, the number of columns and the number of moves that Pasha is going to perform. The next *k* lines contain Pasha's moves in the order he makes them. Each line contains two integers *i*...
If Pasha loses, print the number of the move when the 2<=×<=2 square consisting of black pixels is formed. If Pasha doesn't lose, that is, no 2<=×<=2 square consisting of black pixels is formed during the given *k* moves, print 0.
[ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n" ]
[ "4\n", "5\n", "0\n" ]
none
500
[ { "input": "2 2 4\n1 1\n1 2\n2 1\n2 2", "output": "4" }, { "input": "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1", "output": "5" }, { "input": "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2", "output": "0" }, { "input": "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3", ...
1,668,439,020
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
327
0
n,m,k = map(int,input().split()) a = [[0 for i in range(m+2)]for j in range(n+2)] def check(p,q,alist): if alist[p-1][q-1] + alist[p][q-1] + alist[p-1][q] == 3: return 1 if alist[p][q-1] + alist[p+1][q-1] + alist[p+1][q] == 3: return 1 if alist[p+1][q] + alist[p+1][q+1] + alist[p]...
Title: Pasha and Pixels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of *n* row ...
```python n,m,k = map(int,input().split()) a = [[0 for i in range(m+2)]for j in range(n+2)] def check(p,q,alist): if alist[p-1][q-1] + alist[p][q-1] + alist[p-1][q] == 3: return 1 if alist[p][q-1] + alist[p+1][q-1] + alist[p+1][q] == 3: return 1 if alist[p+1][q] + alist[p+1][q+1] ...
0
228
A
Is your horseshoe on the other hoof?
PROGRAMMING
800
[ "implementation" ]
null
null
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th...
The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has. Consider all possible colors indexed with integers.
Print a single integer — the minimum number of horseshoes Valera needs to buy.
[ "1 7 3 3\n", "7 7 7 7\n" ]
[ "1\n", "3\n" ]
none
500
[ { "input": "1 7 3 3", "output": "1" }, { "input": "7 7 7 7", "output": "3" }, { "input": "81170865 673572653 756938629 995577259", "output": "0" }, { "input": "3491663 217797045 522540872 715355328", "output": "0" }, { "input": "251590420 586975278 916631563 58697...
1,689,889,673
2,147,483,647
Python 3
OK
TESTS
34
62
0
herraduras = list(map(int,input().split())) diferentes = set(herraduras) respuesta = 4 - len(diferentes) print(respuesta)
Title: Is your horseshoe on the other hoof? Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ...
```python herraduras = list(map(int,input().split())) diferentes = set(herraduras) respuesta = 4 - len(diferentes) print(respuesta) ```
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (...
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }...
1,589,284,530
2,147,483,647
Python 3
OK
TESTS
106
171
20,787,200
#ROUNIAAUDI ans=int(input()) list1=list(map(int,input().split())) sum2=sum(list1) s=sum2/2 k=0 i=0 while s>k: k += list1[i] i+=1 print(i)
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve...
```python #ROUNIAAUDI ans=int(input()) list1=list(map(int,input().split())) sum2=sum(list1) s=sum2/2 k=0 i=0 while s>k: k += list1[i] i+=1 print(i) ```
3
0
none
none
none
0
[ "none" ]
null
null
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th...
The first line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*t*<=≤<=109) — the length of Efim's grade and the number of seconds till the end of the break respectively. The second line contains the grade itself. It's guaranteed that the grade is a positive number, containing at least on...
Print the maximum grade that Efim can get in *t* seconds. Do not print trailing zeroes.
[ "6 1\n10.245\n", "6 2\n10.245\n", "3 100\n9.2\n" ]
[ "10.25\n", "10.3\n", "9.2\n" ]
In the first two samples Efim initially has grade 10.245. During the first second Efim can obtain grade 10.25, and then 10.3 during the next second. Note, that the answer 10.30 will be considered incorrect. In the third sample the optimal strategy is to not perform any rounding at all.
0
[ { "input": "6 1\n10.245", "output": "10.25" }, { "input": "6 2\n10.245", "output": "10.3" }, { "input": "3 100\n9.2", "output": "9.2" }, { "input": "12 5\n872.04488525", "output": "872.1" }, { "input": "35 8\n984227318.2031144444444444494637612", "output": "98...
1,476,019,886
4,886
Python 3
TIME_LIMIT_EXCEEDED
TESTS
7
1,000
7,168,000
n, t = map(int, input().split()) xs = input() pos = xs.find('.') integer = xs[:pos] decimal = list(map(int, xs[pos+1:])) l = len(decimal) inc = 0 done = False got = False while(l > 0) and t > 0: if done: break got = False for i in range(l): if decimal[i] >= 5: got = True ...
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a...
```python n, t = map(int, input().split()) xs = input() pos = xs.find('.') integer = xs[:pos] decimal = list(map(int, xs[pos+1:])) l = len(decimal) inc = 0 done = False got = False while(l > 0) and t > 0: if done: break got = False for i in range(l): if decimal[i] >= 5: got = Tr...
0
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,597,325,841
1,641
Python 3
WRONG_ANSWER
TESTS
0
93
204,800
for _ in range(int(input())): s=input() s=list(s) n=len(s) ans=[] flag1=0 for i in s: if i=='X': flag1=1 if i=='O': flag2=1 if flag1==1: ans.append((1,12)) if flag2!=1: ans.append((12,1)) flag1=0 flag2=0 ...
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 for _ in range(int(input())): s=input() s=list(s) n=len(s) ans=[] flag1=0 for i in s: if i=='X': flag1=1 if i=='O': flag2=1 if flag1==1: ans.append((1,12)) if flag2!=1: ans.append((12,1)) flag1=0 fl...
0
791
A
Bear and Big Brother
PROGRAMMING
800
[ "implementation" ]
null
null
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's we...
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10) — the weight of Limak and the weight of Bob respectively.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
[ "4 7\n", "4 9\n", "1 1\n" ]
[ "2\n", "3\n", "1\n" ]
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li...
500
[ { "input": "4 7", "output": "2" }, { "input": "4 9", "output": "3" }, { "input": "1 1", "output": "1" }, { "input": "4 6", "output": "2" }, { "input": "1 10", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "1 2", "output...
1,698,331,635
2,147,483,647
Python 3
OK
TESTS
62
46
0
a,b = map(int, input().split()) i = 0 while True: a=a*3 b=b*2 i=i+1 if a > b: print(i) break
Title: Bear and Big Brother Time Limit: None seconds Memory Limit: None megabytes Problem Description: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e...
```python a,b = map(int, input().split()) i = 0 while True: a=a*3 b=b*2 i=i+1 if a > b: print(i) break ```
3
476
B
Dreamoon and WiFi
PROGRAMMING
1,300
[ "bitmasks", "brute force", "combinatorics", "dp", "math", "probabilities" ]
null
null
Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, de...
The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes ...
Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9.
[ "++-+-\n+-+-+\n", "+-+-\n+-??\n", "+++\n??-\n" ]
[ "1.000000000000\n", "0.500000000000\n", "0.000000000000\n" ]
For the first sample, both *s*<sub class="lower-index">1</sub> and *s*<sub class="lower-index">2</sub> will lead Dreamoon to finish at the same position  + 1. For the second sample, *s*<sub class="lower-index">1</sub> will lead Dreamoon to finish at position 0, while there are four possibilites for *s*<sub class="low...
1,500
[ { "input": "++-+-\n+-+-+", "output": "1.000000000000" }, { "input": "+-+-\n+-??", "output": "0.500000000000" }, { "input": "+++\n??-", "output": "0.000000000000" }, { "input": "++++++++++\n+++??++?++", "output": "0.125000000000" }, { "input": "--+++---+-\n????????...
1,694,424,722
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
93
2,150,400
from math import comb import sys input = sys.stdin.readline s1, s2 = input(), input() q = s2.count('?') d = s1.count('+') - s2.count('+') print(0 if q < d or d < 0 else comb(q, d) / (2**q))
Title: Dreamoon and WiFi Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go...
```python from math import comb import sys input = sys.stdin.readline s1, s2 = input(), input() q = s2.count('?') d = s1.count('+') - s2.count('+') print(0 if q < d or d < 0 else comb(q, d) / (2**q)) ```
-1
136
A
Presents
PROGRAMMING
800
[ "implementation" ]
null
null
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If...
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift....
Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*.
[ "4\n2 3 4 1\n", "3\n1 3 2\n", "2\n1 2\n" ]
[ "4 1 2 3\n", "1 3 2\n", "1 2\n" ]
none
500
[ { "input": "4\n2 3 4 1", "output": "4 1 2 3" }, { "input": "3\n1 3 2", "output": "1 3 2" }, { "input": "2\n1 2", "output": "1 2" }, { "input": "1\n1", "output": "1" }, { "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10" }, { "input"...
1,685,879,005
2,147,483,647
Python 3
OK
TESTS
101
92
0
n = int(input()) givers = list(map(int, input().split())) result = [0] * n for i in range(n): friend = i + 1 giver = givers[i] result[giver - 1] = friend print(' '.join(map(str, result)))
Title: Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t...
```python n = int(input()) givers = list(map(int, input().split())) result = [0] * n for i in range(n): friend = i + 1 giver = givers[i] result[giver - 1] = friend print(' '.join(map(str, result))) ```
3
653
A
Bear and Three Balls
PROGRAMMING
900
[ "brute force", "implementation", "sortings" ]
null
null
Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes th...
The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball.
Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).
[ "4\n18 55 16 17\n", "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17. In the second sample, there is no way to give gifts to three friends without breaking the rules. In the third sample, there is even more than one way to choose bal...
500
[ { "input": "4\n18 55 16 17", "output": "YES" }, { "input": "6\n40 41 43 44 44 44", "output": "NO" }, { "input": "8\n5 972 3 4 1 4 970 971", "output": "YES" }, { "input": "3\n959 747 656", "output": "NO" }, { "input": "4\n1 2 2 3", "output": "YES" }, { ...
1,458,376,975
475
Python 3
WRONG_ANSWER
PRETESTS
4
62
4,608,000
#!/usr/bin/python3 def good_pair(a, b): return 0 < (max(a, b) - min(a, b)) <= 2 n = int(input()) balls = sorted(list(map(int, input().split()))) ans = "NO" for i in range(1, n - 1): if good_pair(balls[i], balls[i + 1]) and good_pair(balls[i], balls[i - 1]) and good_pair(balls[i - 1], balls[i + 1]): an...
Title: Bear and Three Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make fri...
```python #!/usr/bin/python3 def good_pair(a, b): return 0 < (max(a, b) - min(a, b)) <= 2 n = int(input()) balls = sorted(list(map(int, input().split()))) ans = "NO" for i in range(1, n - 1): if good_pair(balls[i], balls[i + 1]) and good_pair(balls[i], balls[i - 1]) and good_pair(balls[i - 1], balls[i + 1]): ...
0
869
A
The Artful Expedient
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive integer *n* is decided first. Both Koyomi and Karen independently choose *n* distinct positive integers, deno...
The first line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=2<=000) — the length of both sequences. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=2·106) — the integers finally chosen by Koyomi. The third line contains *n* space-separated integers *y*1,<=...
Output one line — the name of the winner, that is, "Koyomi" or "Karen" (without quotes). Please be aware of the capitalization.
[ "3\n1 2 3\n4 5 6\n", "5\n2 4 6 8 10\n9 7 5 3 1\n" ]
[ "Karen\n", "Karen\n" ]
In the first example, there are 6 pairs satisfying the constraint: (1, 1), (1, 2), (2, 1), (2, 3), (3, 2) and (3, 3). Thus, Karen wins since 6 is an even number. In the second example, there are 16 such pairs, and Karen wins again.
500
[ { "input": "3\n1 2 3\n4 5 6", "output": "Karen" }, { "input": "5\n2 4 6 8 10\n9 7 5 3 1", "output": "Karen" }, { "input": "1\n1\n2000000", "output": "Karen" }, { "input": "2\n97153 2000000\n1999998 254", "output": "Karen" }, { "input": "15\n31 30 29 28 27 26 25 24...
1,549,303,523
2,147,483,647
PyPy 3
OK
TESTS
49
202
614,400
n=int(input()) Lko = list(map(int, input().split())) Lka=list(map(int,input().split())) E=set(Lko+Lka) c=0; for i in range(n) : for j in range(n) : if((Lko[i]^Lka[j])in E) : c=c+1; if (c%2==0): print("Karen") else: print("Koyomi")
Title: The Artful Expedient Time Limit: None seconds Memory Limit: None megabytes Problem Description: Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-scissors, her brother, Koyomi, comes up with a new game as a substitute. The game works as follows. A positive int...
```python n=int(input()) Lko = list(map(int, input().split())) Lka=list(map(int,input().split())) E=set(Lko+Lka) c=0; for i in range(n) : for j in range(n) : if((Lko[i]^Lka[j])in E) : c=c+1; if (c%2==0): print("Karen") else: print("Koyomi") ```
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on...
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (...
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }...
1,558,983,328
2,147,483,647
Python 3
OK
TESTS
106
1,637
13,516,800
x=int(input()) s=[int(n) for n in input().split()] j=x//2 if sum(s[:j+1])*2>sum(s): n=j+1 while sum(s[:n])*2>=sum(s): n-=1 print(n+1) elif sum(s[:j+1])*2==sum(s): print(j+1) else: n=j+1 while sum(s[:n])*2<sum(s): n+=1 print(n)
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve...
```python x=int(input()) s=[int(n) for n in input().split()] j=x//2 if sum(s[:j+1])*2>sum(s): n=j+1 while sum(s[:n])*2>=sum(s): n-=1 print(n+1) elif sum(s[:j+1])*2==sum(s): print(j+1) else: n=j+1 while sum(s[:n])*2<sum(s): n+=1 print(n) ```
3
770
A
New Password
PROGRAMMING
800
[ "*special", "implementation" ]
null
null
Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should cons...
The first line contains two positive integers *n* and *k* (2<=≤<=*n*<=≤<=100, 2<=≤<=*k*<=≤<=*min*(*n*,<=26)) — the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists.
Print any password which satisfies all conditions given by Innokentiy.
[ "4 3\n", "6 6\n", "5 2\n" ]
[ "java\n", "python\n", "phphp\n" ]
In the first test there is one of the appropriate new passwords — java, because its length is equal to 4 and 3 distinct lowercase letters a, j and v are used in it. In the second test there is one of the appropriate new passwords — python, because its length is equal to 6 and it consists of 6 distinct lowercase letter...
500
[ { "input": "4 3", "output": "abca" }, { "input": "6 6", "output": "abcdef" }, { "input": "5 2", "output": "ababa" }, { "input": "3 2", "output": "aba" }, { "input": "10 2", "output": "ababababab" }, { "input": "26 13", "output": "abcdefghijklmabcde...
1,647,034,592
2,147,483,647
Python 3
OK
TESTS
47
46
0
n, k = map(int, input().split()) alphabets = "abcdefghijklmnopqrstuvwxyz" print((alphabets[:k])*(n//k)+alphabets[:n%k])
Title: New Password Time Limit: None seconds Memory Limit: None megabytes Problem Description: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the foll...
```python n, k = map(int, input().split()) alphabets = "abcdefghijklmnopqrstuvwxyz" print((alphabets[:k])*(n//k)+alphabets[:n%k]) ```
3
996
A
Hit the Lottery
PROGRAMMING
800
[ "dp", "greedy" ]
null
null
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance?
The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$).
Output the minimum number of bills that Allen could receive.
[ "125\n", "43\n", "1000000000\n" ]
[ "3\n", "5\n", "10000000\n" ]
In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills. In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills. In the third sample case, Allen...
500
[ { "input": "125", "output": "3" }, { "input": "43", "output": "5" }, { "input": "1000000000", "output": "10000000" }, { "input": "4", "output": "4" }, { "input": "5", "output": "1" }, { "input": "1", "output": "1" }, { "input": "74", "o...
1,698,041,811
2,147,483,647
PyPy 3-64
COMPILATION_ERROR
TESTS
0
0
0
// Online C++ compiler to run C++ program online #include <iostream> using namespace std; int main() { int a,sum=0; cin>>a; while (a!=1) { if (a>=100) { sum+=a/100; a=a%100; } else if (a>=20) { sum+=a/20; ...
Title: Hit the Lottery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$...
```python // Online C++ compiler to run C++ program online #include <iostream> using namespace std; int main() { int a,sum=0; cin>>a; while (a!=1) { if (a>=100) { sum+=a/100; a=a%100; } else if (a>=20) { sum+=a/...
-1
602
B
Approximating a Constant Range
PROGRAMMING
1,400
[ "dp", "implementation", "two pointers" ]
null
null
When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choosing a sufficiently large number of consecutive data points that seems as constant as possible and taking their aver...
The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of data points. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100<=000).
Print a single number — the maximum length of an almost constant range of the given sequence.
[ "5\n1 2 3 3 2\n", "11\n5 4 5 5 6 7 8 8 8 7 6\n" ]
[ "4\n", "5\n" ]
In the first sample, the longest almost constant range is [2, 5]; its length (the number of data points in it) is 4. In the second sample, there are three almost constant ranges of length 4: [1, 4], [6, 9] and [7, 10]; the only almost constant range of the maximum length 5 is [6, 10].
1,000
[ { "input": "5\n1 2 3 3 2", "output": "4" }, { "input": "11\n5 4 5 5 6 7 8 8 8 7 6", "output": "5" }, { "input": "2\n3 2", "output": "2" }, { "input": "4\n1001 1000 1000 1001", "output": "4" }, { "input": "4\n1 1 2 3", "output": "3" }, { "input": "3\n1 ...
1,642,355,913
2,147,483,647
PyPy 3-64
OK
TESTS
107
156
14,643,200
a=int(input()) b=list(map(int,input().split())) c=1 d=0 e=0 g=0 for i in range(1,a): f=b[i]-b[i-1] if(f!=0): if(f==d): g=e+1 e=i-1 d=f c=max(c,i-g+1) print(c)
Title: Approximating a Constant Range Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Xellos was doing a practice course in university, he once had to measure the intensity of an effect that slowly approached equilibrium. A good way to determine the equilibrium intensity would be choo...
```python a=int(input()) b=list(map(int,input().split())) c=1 d=0 e=0 g=0 for i in range(1,a): f=b[i]-b[i-1] if(f!=0): if(f==d): g=e+1 e=i-1 d=f c=max(c,i-g+1) print(c) ```
3
875
E
Delivery Club
PROGRAMMING
2,600
[ "binary search", "data structures", "dp" ]
null
null
Petya and Vasya got employed as couriers. During the working day they are to deliver packages to *n* different points on the line. According to the company's internal rules, the delivery of packages must be carried out strictly in a certain order. Initially, Petya is at the point with the coordinate *s*1, Vasya is at t...
The first line contains three integers *n*, *s*1, *s*2 (1<=≤<=*n*<=≤<=100<=000, 0<=≤<=*s*1,<=*s*2<=≤<=109) — number of points of delivery and starting positions of Petya and Vasya. The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — customers coordinates (0<=≤<=*x**i*<=≤<=109), in the order to make a de...
Output the only integer, minimum possible maximal distance between couriers during delivery.
[ "2 0 10\n5 6\n", "3 2 1\n3 4 5\n", "1 4 5\n2\n" ]
[ "10\n", "1\n", "2\n" ]
In the first test case the initial distance between the couriers is 10. This value will be the answer, for example, Petya can perform both deliveries, and Vasya will remain at the starting point. In the second test case you can optimally act, for example, like this: Vasya delivers the package to the first customer, Pe...
2,000
[]
1,689,176,397
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
30
0
print("_RANDOM_GUESS_1689176397.439151")# 1689176397.4391732
Title: Delivery Club Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya and Vasya got employed as couriers. During the working day they are to deliver packages to *n* different points on the line. According to the company's internal rules, the delivery of packages must be carried out st...
```python print("_RANDOM_GUESS_1689176397.439151")# 1689176397.4391732 ```
0
199
B
Special Olympics
PROGRAMMING
1,900
[ "geometry" ]
null
null
A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine. Let us remind you that a ring is a region located between two...
The input contains two lines. Each line has four space-separated integers *x**i*, *y**i*, *r**i*, *R**i*, that describe the *i*-th ring; *x**i* and *y**i* are coordinates of the ring's center, *r**i* and *R**i* are the internal and external radii of the ring correspondingly (<=-<=100<=≤<=*x**i*,<=*y**i*<=≤<=100; 1<=≤...
A single integer — the number of ways to cut out a circle from the canvas.
[ "60 60 45 55\n80 80 8 32\n", "60 60 45 55\n80 60 15 25\n", "50 50 35 45\n90 50 35 45\n" ]
[ "1", "4", "0" ]
Figures for test samples are given below. The possible cuts are marked with red dotted line.
1,000
[ { "input": "60 60 45 55\n80 80 8 32", "output": "1" }, { "input": "60 60 45 55\n80 60 15 25", "output": "4" }, { "input": "50 50 35 45\n90 50 35 45", "output": "0" }, { "input": "0 0 50 70\n1 0 60 80", "output": "2" }, { "input": "0 0 1 2\n10 0 2 20", "output"...
1,593,323,644
2,147,483,647
Python 3
OK
TESTS
140
218
6,963,200
def okay(xc, yc, rc, xr, yr, rr, Rr): d = ((xc-xr) ** 2 + (yc-yr) ** 2) ** 0.5 if d + rc <= rr: return True if d >= rc + Rr: return True if d + Rr <= rc: return True return False x1, y1, r1, R1 = map(float, input().split()) x2, y2, r2, R2 = map(float, input().split()) ans = ...
Title: Special Olympics Time Limit: None seconds Memory Limit: None megabytes Problem Description: A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones wi...
```python def okay(xc, yc, rc, xr, yr, rr, Rr): d = ((xc-xr) ** 2 + (yc-yr) ** 2) ** 0.5 if d + rc <= rr: return True if d >= rc + Rr: return True if d + Rr <= rc: return True return False x1, y1, r1, R1 = map(float, input().split()) x2, y2, r2, R2 = map(float, input().split...
3
312
A
Whose sentence is it?
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Freda always said "lala." at the end of her sentences, while Rainbow always said "miao." at the beginning of ...
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=10), number of sentences in the chat record. Each of the next *n* lines contains a sentence. A sentence is a string that contains only Latin letters (A-Z, a-z), underline (_), comma (,), point (.) and space ( ). Its length doesn’t exceed 100.
For each sentence, output "Freda's" if the sentence was said by Freda, "Rainbow's" if the sentence was said by Rainbow, or "OMG&gt;.&lt; I don't know!" if liouzhou_101 can’t recognize whose sentence it is. He can’t recognize a sentence if it begins with "miao." and ends with "lala.", or satisfies neither of the conditi...
[ "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .\n" ]
[ "Freda's\nOMG&gt;.&lt; I don't know!\nOMG&gt;.&lt; I don't know!\nRainbow's\nOMG&gt;.&lt; I don't know!\n" ]
none
500
[ { "input": "5\nI will go to play with you lala.\nwow, welcome.\nmiao.lala.\nmiao.\nmiao .", "output": "Freda's\nOMG>.< I don't know!\nOMG>.< I don't know!\nRainbow's\nOMG>.< I don't know!" }, { "input": "10\nLpAEKiHVJrzSZqBVSSyY\nYECGBlala.\nUZeGpeM.UCwiHmmA\nqt_,.b_.LSwJtJ.\nFAnXZtHlala.\nmiao.iape...
1,639,996,479
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
n=int(input()) for i in range(n): s=input() a=s.split(' ') ans=0 if(a[0]=='miao.'): ans+=1 if(a[-1]=='lala.'): ans+=2 if(ans==1): print("Rainbow's") elif(ans==2): print("Freda's") else: print("OMG>.< I don't know!")
Title: Whose sentence is it? Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, liouzhou_101 got a chat record of Freda and Rainbow. Out of curiosity, he wanted to know which sentences were said by Freda, and which were said by Rainbow. According to his experience, he thought that Fr...
```python n=int(input()) for i in range(n): s=input() a=s.split(' ') ans=0 if(a[0]=='miao.'): ans+=1 if(a[-1]=='lala.'): ans+=2 if(ans==1): print("Rainbow's") elif(ans==2): print("Freda's") else: print("OMG>.< I don't know!") ```
0
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis...
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla...
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "11101001...
1,621,706,426
2,147,483,647
Python 3
OK
TESTS
37
124
102,400
s=input() flag=False for z in range(len(s)): if s[z]=='0': s=s[:z]+s[z+1:] flag=True break if flag: print(s) else: print(s[1:])
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought...
```python s=input() flag=False for z in range(len(s)): if s[z]=='0': s=s[:z]+s[z+1:] flag=True break if flag: print(s) else: print(s[1:]) ```
3
182
D
Common Divisors
PROGRAMMING
1,400
[ "brute force", "hashing", "implementation", "math", "strings" ]
null
null
Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String *a* is the divisor of string *b* if and only if there exists a positive integer *x* such that if we write out string *a* consecutively *x* times, we get string *b*. For exam...
The first input line contains a non-empty string *s*1. The second input line contains a non-empty string *s*2. Lengths of strings *s*1 and *s*2 are positive and do not exceed 105. The strings only consist of lowercase Latin letters.
Print the number of common divisors of strings *s*1 and *s*2.
[ "abcdabcd\nabcdabcdabcdabcd\n", "aaa\naa\n" ]
[ "2\n", "1\n" ]
In first sample the common divisors are strings "abcd" and "abcdabcd". In the second sample the common divisor is a single string "a". String "aa" isn't included in the answer as it isn't a divisor of string "aaa".
1,000
[ { "input": "abcdabcd\nabcdabcdabcdabcd", "output": "2" }, { "input": "aaa\naa", "output": "1" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaa", "output": "3" }, { "input": "aaaaaaaaaaaaaa\naaaaaaaaaaaaaa", "output": "4" }, { "input": "a\nb", ...
1,552,737,497
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
47
312
7,884,800
s1, s2 = input(), input() L1, L2 = len(s1), len(s2) D = set() for d in range(1, int(L1 * .5) + 1): if L1 % d == 0: D |= {d, L1 // d} S = [s1[:d] for d in D if s1[:d] * (L1//d) == s1] print(sum(s * (L2//len(s)) == s2 for s in S))
Title: Common Divisors Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has recently learned at school what a number's divisor is and decided to determine a string's divisor. Here is what he came up with. String *a* is the divisor of string *b* if and only if there exists a positive ...
```python s1, s2 = input(), input() L1, L2 = len(s1), len(s2) D = set() for d in range(1, int(L1 * .5) + 1): if L1 % d == 0: D |= {d, L1 // d} S = [s1[:d] for d in D if s1[:d] * (L1//d) == s1] print(sum(s * (L2//len(s)) == s2 for s in S)) ```
0
331
C1
The Great Julya Calendar
PROGRAMMING
1,100
[ "dp" ]
null
null
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open ...
The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with co...
Print a single integer — the minimum number of subtractions that turns the magic number to a zero.
[ "24\n" ]
[ "5" ]
In the first test sample the minimum number of operations can be reached by the following sequence of subtractions:
20
[ { "input": "24", "output": "5" }, { "input": "0", "output": "0" }, { "input": "3", "output": "1" }, { "input": "8", "output": "1" }, { "input": "9", "output": "1" }, { "input": "10", "output": "2" }, { "input": "31", "output": "6" }, ...
1,580,361,228
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS1
7
248
0
#Ashish Sagar n=input() s=list(n) if n!='0': for i in range(len(s)): s[i]=int(s[i]) if max(s)>(s[-1]): s[-1]=0 else: s[-1]=5 z="" for i in range(len(s)): z+=str(s[i]) z=int(z) print(z//5) else: print(0)
Title: The Great Julya Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on i...
```python #Ashish Sagar n=input() s=list(n) if n!='0': for i in range(len(s)): s[i]=int(s[i]) if max(s)>(s[-1]): s[-1]=0 else: s[-1]=5 z="" for i in range(len(s)): z+=str(s[i]) z=int(z) print(z//5) else: print(0) ```
0
696
C
PLEASE
PROGRAMMING
2,000
[ "combinatorics", "dp", "implementation", "math", "matrices" ]
null
null
As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. Then at one turn Barney swaps the cup in the middle with a...
The first line of input contains a single integer *k* (1<=≤<=*k*<=≤<=105) — the number of elements in array Barney gave you. The second line contains *k* integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=1018) — the elements of the array.
In the only line of output print a single string *x*<=/<=*y* where *x* is the remainder of dividing *p* by 109<=+<=7 and *y* is the remainder of dividing *q* by 109<=+<=7.
[ "1\n2\n", "3\n1 1 1\n" ]
[ "1/2\n", "0/1\n" ]
none
1,500
[ { "input": "1\n2", "output": "1/2" }, { "input": "3\n1 1 1", "output": "0/1" }, { "input": "1\n983155795040951739", "output": "145599903/436799710" }, { "input": "2\n467131402341701583 956277077729692725", "output": "63467752/190403257" }, { "input": "10\n21767322...
1,613,137,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
46
204,800
n = int(input()) ls = [int(x) for x in input().split(' ')] t = 1 mod = 1000000007 def qpow(n: int, m: int): m %= mod - 1 ans = 1 while m: if m & 1: ans = ans * n % mod n = n * n % mod m >>= 1 return ans k = 0 for x in ls: t = t * x % (mod * 2 - 2) i...
Title: PLEASE Time Limit: None seconds Memory Limit: None megabytes Problem Description: As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney'...
```python n = int(input()) ls = [int(x) for x in input().split(' ')] t = 1 mod = 1000000007 def qpow(n: int, m: int): m %= mod - 1 ans = 1 while m: if m & 1: ans = ans * n % mod n = n * n % mod m >>= 1 return ans k = 0 for x in ls: t = t * x % (mod * 2 -...
0
25
A
IQ test
PROGRAMMING
1,300
[ "brute force" ]
A. IQ test
2
256
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i...
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.
Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.
[ "5\n2 4 7 8 10\n", "4\n1 2 1 1\n" ]
[ "3\n", "2\n" ]
none
0
[ { "input": "5\n2 4 7 8 10", "output": "3" }, { "input": "4\n1 2 1 1", "output": "2" }, { "input": "3\n1 2 2", "output": "1" }, { "input": "3\n100 99 100", "output": "2" }, { "input": "3\n5 3 2", "output": "3" }, { "input": "4\n43 28 1 91", "output"...
1,634,028,541
2,147,483,647
Python 3
OK
TESTS
32
122
6,963,200
n=int(input()) lst=list(map(int,input().split())) ans=0 t=(lst[0]%2==0)+(lst[1]%2==0)+(lst[2]%2==0)<=1 for i in range(n): if t^(lst[i]%2==1): ans=i+1 break print(ans)
Title: IQ test Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t...
```python n=int(input()) lst=list(map(int,input().split())) ans=0 t=(lst[0]%2==0)+(lst[1]%2==0)+(lst[2]%2==0)<=1 for i in range(n): if t^(lst[i]%2==1): ans=i+1 break print(ans) ```
3.95653
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,522,942
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
inputData = input() splitted = inputData.split() m = int(splitted[0]) n = int(splitted[1]) a = int(splitted[2]) countM=0 countN = 0 if n <=1: if a <= 10**9: while m>=0: m = m - a countM = countM + 1 while n>=0: n = n -a countN = countN +1 print(countM*countN) else...
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 inputData = input() splitted = inputData.split() m = int(splitted[0]) n = int(splitted[1]) a = int(splitted[2]) countM=0 countN = 0 if n <=1: if a <= 10**9: while m>=0: m = m - a countM = countM + 1 while n>=0: n = n -a countN = countN +1 print(countM*count...
0
883
I
Photo Processing
PROGRAMMING
1,900
[ "binary search", "dp" ]
null
null
Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo *i* has a contrast *v**i*. In order for the processing to be truly of high quality, the application must receive at least *k* photos with contrasts which differ as little as possible. Evlampiy a...
The first line contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=3·105) — number of photos and minimum size of a group. The second line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109), where *v**i* is the contrast of the *i*-th photo.
Print the minimal processing time of the division into groups.
[ "5 2\n50 110 130 40 120\n", "4 1\n2 3 4 1\n" ]
[ "20\n", "0\n" ]
In the first example the photos should be split into 2 groups: [40, 50] and [110, 120, 130]. The processing time of the first group is 10, and the processing time of the second group is 20. Maximum among 10 and 20 is 20. It is impossible to split the photos into groups in a such way that the processing time of division...
0
[ { "input": "5 2\n50 110 130 40 120", "output": "20" }, { "input": "4 1\n2 3 4 1", "output": "0" }, { "input": "1 1\n4", "output": "0" }, { "input": "2 2\n7 5", "output": "2" }, { "input": "3 2\n34 3 75", "output": "72" }, { "input": "5 2\n932 328 886 9...
1,683,806,170
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
53
3,000
25,088,000
import sys input = lambda: sys.stdin.readline().strip() print = lambda d: sys.stdout.write(str(d) + "\n") n, k = input().split(" ") n, k = int(n), int(k) arr = [int(val) for val in input().split(" ")] arr.sort() cnt_sum = [0 for i in range(n + 1)] def is_ok(val): # is_end_ok = [False for i in ran...
Title: Photo Processing Time Limit: None seconds Memory Limit: None megabytes Problem Description: Evlampiy has found one more cool application to process photos. However the application has certain limitations. Each photo *i* has a contrast *v**i*. In order for the processing to be truly of high quality, the appli...
```python import sys input = lambda: sys.stdin.readline().strip() print = lambda d: sys.stdout.write(str(d) + "\n") n, k = input().split(" ") n, k = int(n), int(k) arr = [int(val) for val in input().split(" ")] arr.sort() cnt_sum = [0 for i in range(n + 1)] def is_ok(val): # is_end_ok = [False fo...
0
584
D
Dima and Lisa
PROGRAMMING
1,800
[ "brute force", "math", "number theory" ]
null
null
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer *n*. Find a set of numbers *p**i* (1<=≤<=*i*<=≤<=*k*), such that 1. 1<=...
The single line contains an odd number *n* (3<=≤<=*n*<=&lt;<=109).
In the first line print *k* (1<=≤<=*k*<=≤<=3), showing how many numbers are in the representation you found. In the second line print numbers *p**i* in any order. If there are multiple possible solutions, you can print any of them.
[ "27\n" ]
[ "3\n5 11 11\n" ]
A prime is an integer strictly larger than one that is divisible only by one and by itself.
2,000
[ { "input": "27", "output": "3\n2 2 23" }, { "input": "3", "output": "1\n3" }, { "input": "25", "output": "2\n2 23" }, { "input": "9", "output": "2\n2 7" }, { "input": "91", "output": "2\n2 89" }, { "input": "57", "output": "3\n2 2 53" }, { ...
1,689,343,116
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
15
0
print("_RANDOM_GUESS_1689343116.331787")# 1689343116.331794
Title: Dima and Lisa Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, ...
```python print("_RANDOM_GUESS_1689343116.331787")# 1689343116.331794 ```
0
598
B
Queries on a String
PROGRAMMING
1,300
[ "implementation", "strings" ]
null
null
You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**i*] *k**i* times. The queries should be processed one after another in the order they are given. One ope...
The first line of the input contains the string *s* (1<=≤<=|*s*|<=≤<=10<=000) in its initial state, where |*s*| stands for the length of *s*. It contains only lowercase English letters. Second line contains a single integer *m* (1<=≤<=*m*<=≤<=300) — the number of queries. The *i*-th of the next *m* lines contains thr...
Print the resulting string *s* after processing all *m* queries.
[ "abacaba\n2\n3 6 1\n1 4 2\n" ]
[ "baabcaa\n" ]
The sample is described in problem statement.
0
[ { "input": "abacaba\n2\n3 6 1\n1 4 2", "output": "baabcaa" }, { "input": "u\n1\n1 1 1", "output": "u" }, { "input": "p\n5\n1 1 5\n1 1 9\n1 1 10\n1 1 10\n1 1 4", "output": "p" }, { "input": "ssssssssss\n5\n5 7 9\n3 9 3\n2 7 1\n7 7 10\n1 9 6", "output": "ssssssssss" }, ...
1,678,023,047
1,847
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
7
2,000
12,390,400
# for iiiii in range(int(input())): # n=int(input()) # p=int(input()) # p=list(map(int, p.strip())) # s=(list(map(int,input().split(' ')))) # l=list(input()) s=input() for i in range(int(input())): l,r,k=(list(map(int,input().split(' ')))) ss=s[l-1:r] # print(ss) for j in range(k): ss=...
Title: Queries on a String Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string *s* and should process *m* queries. Each query is described by two 1-based indices *l**i*, *r**i* and integer *k**i*. It means that you should cyclically shift the substring *s*[*l**i*... *r**...
```python # for iiiii in range(int(input())): # n=int(input()) # p=int(input()) # p=list(map(int, p.strip())) # s=(list(map(int,input().split(' ')))) # l=list(input()) s=input() for i in range(int(input())): l,r,k=(list(map(int,input().split(' ')))) ss=s[l-1:r] # print(ss) for j in range(k)...
0