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
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 the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party.
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,690,737,183
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
def foo(s): s = s.split(" ") k = set() c = 0 for i in s: if i in k: c += 1 else: k.add(i) print(c) foo("1 7 3 3") foo("7 7 7 7")
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 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 the store and buy some few more horseshoes, not to lose face in front of his stylish comrades. Fortunately, the store sells horseshoes of all colors under the sun and Valera has enough money to buy any four of them. However, in order to save the money, he would like to spend as little money as possible, so you need to help Valera and determine what is the minimum number of horseshoes he needs to buy to wear four horseshoes of different colors to a party. Input Specification: 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. Output Specification: Print a single integer — the minimum number of horseshoes Valera needs to buy. Demo Input: ['1 7 3 3\n', '7 7 7 7\n'] Demo Output: ['1\n', '3\n'] Note: none
```python def foo(s): s = s.split(" ") k = set() c = 0 for i in s: if i in k: c += 1 else: k.add(i) print(c) foo("1 7 3 3") foo("7 7 7 7") ```
0
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. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
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* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
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,495,566,661
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
41
124
0
n=int(input()) t={} t1={} k=n-1 for i in range(n) : a,b=map(int,input().split()) t[a]=t.get(a,0)+1 t1[b]=t1.get(b,0)+1 for x in t : k=k-t.get(x,0)+1 for x in t1 : k=k-t1.get(x,0)+1 print(k)
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 that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input Specification: 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* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. Output Specification: 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. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n=int(input()) t={} t1={} k=n-1 for i in range(n) : a,b=map(int,input().split()) t[a]=t.get(a,0)+1 t1[b]=t1.get(b,0)+1 for x in t : k=k-t.get(x,0)+1 for x in t1 : k=k-t1.get(x,0)+1 print(k) ```
0
378
A
Playing with Dice
PROGRAMMING
800
[ "brute force" ]
null
null
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?
The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly.
Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.
[ "2 5\n", "2 4\n" ]
[ "3 0 3\n", "2 1 3\n" ]
The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
500
[ { "input": "2 5", "output": "3 0 3" }, { "input": "2 4", "output": "2 1 3" }, { "input": "5 3", "output": "2 1 3" }, { "input": "1 6", "output": "3 0 3" }, { "input": "5 1", "output": "3 1 2" }, { "input": "6 3", "output": "2 0 4" }, { "inp...
1,567,886,563
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
93
0
import numpy as np a,b=(int(s) for s in input().split()) def dice(a,b): dicerolls=[1,2,3,4,5,6] awins=0 draw=0 bwins=0 for i in dicerolls: if np.abs(a-i)>np.abs(b-i): awins+=1 elif np.abs(b-i)>np.abs(a-i): bwins+=1 else: draw+=1 print(awins,draw,bwins) dice(a,b)
Title: Playing with Dice Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? Input Specification: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. Output Specification: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Demo Input: ['2 5\n', '2 4\n'] Demo Output: ['3 0 3\n', '2 1 3\n'] Note: The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct. You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| &lt; |*b* - *x*|.
```python import numpy as np a,b=(int(s) for s in input().split()) def dice(a,b): dicerolls=[1,2,3,4,5,6] awins=0 draw=0 bwins=0 for i in dicerolls: if np.abs(a-i)>np.abs(b-i): awins+=1 elif np.abs(b-i)>np.abs(a-i): bwins+=1 else: draw+=1 print(awins,draw,bwins) dice(a,b) ```
-1
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 weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob?
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. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
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,695,017,597
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
46
0
a,b = input('enter your number: ').split(" ") i = 0 while True: if int(a)>int(b): break a = int(a)*3 b = int(b)*2 i +=1 print(i)
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 equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? Input Specification: 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. Output Specification: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Demo Input: ['4 7\n', '4 9\n', '1 1\n'] Demo Output: ['2\n', '3\n', '1\n'] Note: 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. Limak became larger than Bob after two years so you should print 2. In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights. In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
```python a,b = input('enter your number: ').split(" ") i = 0 while True: if int(a)>int(b): break a = int(a)*3 b = int(b)*2 i +=1 print(i) ```
0
451
B
Sort the Array
PROGRAMMING
1,300
[ "implementation", "sortings" ]
null
null
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109).
Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.
[ "3\n3 2 1\n", "4\n2 1 3 4\n", "4\n3 1 2 4\n", "2\n1 2\n" ]
[ "yes\n1 3\n", "yes\n1 2\n", "no\n", "yes\n1 1\n" ]
Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted. Sample 3. No segment can be reversed such that the array will be sorted. Definitions A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*]. If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become: *a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
1,000
[ { "input": "3\n3 2 1", "output": "yes\n1 3" }, { "input": "4\n2 1 3 4", "output": "yes\n1 2" }, { "input": "4\n3 1 2 4", "output": "no" }, { "input": "2\n1 2", "output": "yes\n1 1" }, { "input": "2\n58 4", "output": "yes\n1 2" }, { "input": "5\n69 37 2...
1,692,643,598
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
31
0
def sol(): n = int(input()) arr = list(map(int, input().split())) sort_arr = sorted(arr) # print(sort_arr) for i in range(n): for j in range(i, n): # print(i, j) temp = arr[i:j + 1][::-1] # print(temp) # print(temp + arr[j + 1:]) if temp + arr[j + 1:] == sort_arr: print("yes") return i, j else: return "no" s = sol() if s == "no": print(s) else: print(s[0] + 1, s[1] + 1)
Title: Sort the Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers. Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array *a* (in increasing order) by reversing exactly one segment of *a*? See definitions of segment and reversing in the notes. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*. The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). Output Specification: Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. Demo Input: ['3\n3 2 1\n', '4\n2 1 3 4\n', '4\n3 1 2 4\n', '2\n1 2\n'] Demo Output: ['yes\n1 3\n', 'yes\n1 2\n', 'no\n', 'yes\n1 1\n'] Note: Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted. Sample 3. No segment can be reversed such that the array will be sorted. Definitions A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*]. If you have an array *a* of size *n* and you reverse its segment [*l*, *r*], the array will become: *a*[1], *a*[2], ..., *a*[*l* - 2], *a*[*l* - 1], *a*[*r*], *a*[*r* - 1], ..., *a*[*l* + 1], *a*[*l*], *a*[*r* + 1], *a*[*r* + 2], ..., *a*[*n* - 1], *a*[*n*].
```python def sol(): n = int(input()) arr = list(map(int, input().split())) sort_arr = sorted(arr) # print(sort_arr) for i in range(n): for j in range(i, n): # print(i, j) temp = arr[i:j + 1][::-1] # print(temp) # print(temp + arr[j + 1:]) if temp + arr[j + 1:] == sort_arr: print("yes") return i, j else: return "no" s = sol() if s == "no": print(s) else: print(s[0] + 1, s[1] + 1) ```
0
39
D
Cubical Planet
PROGRAMMING
1,100
[ "math" ]
D. Cubical Planet
2
64
You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube.
The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly.
Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO".
[ "0 0 0\n0 1 0\n", "1 1 0\n0 1 0\n", "0 0 0\n1 1 1\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
0
[ { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "1 1 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 1", "output": "NO" }, { "input": "0 0 0\n1 0 0", "output": "YES" }, { "input": "0 0 0\n0 1 0", "output": "YES" }, { "input": "0 0 0\n1 1 ...
1,662,300,234
2,147,483,647
Python 3
OK
TESTS
59
92
0
a, b, c = map(int, input().split()) x, y, z = map(int, input().split()) if a == x: print('YES') elif a != x: if b == y: print('YES') elif b != y: if c == z: print('YES') elif c != z: print('NO')
Title: Cubical Planet Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,<=0,<=0) and (1,<=1,<=1). Two flies live on the planet. At the moment they are sitting on two different vertices of the cubical planet. Your task is to determine whether they see each other or not. The flies see each other when the vertices they occupy lie on the same face of the cube. Input Specification: The first line contains three space-separated integers (0 or 1) — the coordinates of the first fly, the second line analogously contains the coordinates of the second fly. Output Specification: Output "YES" (without quotes) if the flies see each other. Otherwise, output "NO". Demo Input: ['0 0 0\n0 1 0\n', '1 1 0\n0 1 0\n', '0 0 0\n1 1 1\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python a, b, c = map(int, input().split()) x, y, z = map(int, input().split()) if a == x: print('YES') elif a != x: if b == y: print('YES') elif b != y: if c == z: print('YES') elif c != z: print('NO') ```
3.977
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,690,895,673
2,147,483,647
Python 3
OK
TESTS
59
46
0
def gcd(a, b): while b > 0: a, b = b, a % b return a a, b = map(int, input().split()) c = 1 for i in range(1, min(a, b) + 1): c *= i print(c)
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python def gcd(a, b): while b > 0: a, b = b, a % b return a a, b = map(int, input().split()) c = 1 for i in range(1, min(a, b) + 1): c *= i print(c) ```
3
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "inpu...
1,586,256,691
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
186
307,200
def gcd(p,q): if p==q: return p elif p>q: return gcd(p-q,q) else: return gcd(p,q-p) a,b,n=map(int,input().split()) c=0 d=0 i=0 while(n>0): if i%2==0: x=gcd(a,n) if n>=x: c+=x n-=x i+=1 else: c=-1 break else: x=gcd(b,n) if n>=x: d+=x n-=x i+=1 else: d=-1 break if c==-1 or c>d: print("0") else: print("1")
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python def gcd(p,q): if p==q: return p elif p>q: return gcd(p-q,q) else: return gcd(p,q-p) a,b,n=map(int,input().split()) c=0 d=0 i=0 while(n>0): if i%2==0: x=gcd(a,n) if n>=x: c+=x n-=x i+=1 else: c=-1 break else: x=gcd(b,n) if n>=x: d+=x n-=x i+=1 else: d=-1 break if c==-1 or c>d: print("0") else: print("1") ```
0
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,412,006,691
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
92
0
f = open('input.txt') g = open('output.txt','w') x = f.readline() y = f.readline() if x == 'front': if y == '1': g.write('L') else: g.write ('R') else: if y == '1': g.write ('R') else: g.write ('L') g.close() f.close()
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. Input Specification: The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. Output Specification: Print character "R" if the VIP is right-handed or "L" if he is left-handed. Demo Input: ['front\n1\n'] Demo Output: ['L\n'] Note: none
```python f = open('input.txt') g = open('output.txt','w') x = f.readline() y = f.readline() if x == 'front': if y == '1': g.write('L') else: g.write ('R') else: if y == '1': g.write ('R') else: g.write ('L') g.close() f.close() ```
0
544
B
Sea and Islands
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists.
The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form.
If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands.
[ "5 2\n", "5 25\n" ]
[ "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n", "NO\n" ]
none
1,000
[ { "input": "5 2", "output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS" }, { "input": "5 25", "output": "NO" }, { "input": "82 6047", "output": "NO" }, { "input": "6 5", "output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS" }, { "input": "10 80", "outpu...
1,484,445,529
1,429
Python 3
WRONG_ANSWER
TESTS
0
30
4,608,000
import sys n,k = map(int, input().split()) a = [['S']*n for i in range(0,n)] k1 = k for i in range(0, n): for j in range(i%2,n,2): a[i][j] = 'L' k1 -= 1; if k1 == 0: for i in range(0, n): for j in range(0, n): print(a[i][j], end = '') print('') sys.exit(); k1 = k a = [['S']*n for i in range(0,n)] for i in range(0, n): for j in range(1 - i%2,n,2): a[i][j] = 'L' k1 -= 1; if k1 == 0: for i in range(0, n): for j in range(0, n): print(a[i][j], end = '') print('') sys.exit(); print("NO");
Title: Sea and Islands Time Limit: None seconds Memory Limit: None megabytes Problem Description: A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists. Input Specification: The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. Output Specification: If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands. Demo Input: ['5 2\n', '5 25\n'] Demo Output: ['YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n', 'NO\n'] Note: none
```python import sys n,k = map(int, input().split()) a = [['S']*n for i in range(0,n)] k1 = k for i in range(0, n): for j in range(i%2,n,2): a[i][j] = 'L' k1 -= 1; if k1 == 0: for i in range(0, n): for j in range(0, n): print(a[i][j], end = '') print('') sys.exit(); k1 = k a = [['S']*n for i in range(0,n)] for i in range(0, n): for j in range(1 - i%2,n,2): a[i][j] = 'L' k1 -= 1; if k1 == 0: for i in range(0, n): for j in range(0, n): print(a[i][j], end = '') print('') sys.exit(); print("NO"); ```
0
630
C
Lucky Numbers
PROGRAMMING
1,100
[ "combinatorics", "math" ]
null
null
The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits.
The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold.
Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits.
[ "2\n" ]
[ "6" ]
none
0
[ { "input": "2", "output": "6" }, { "input": "1", "output": "2" }, { "input": "3", "output": "14" }, { "input": "5", "output": "62" }, { "input": "12", "output": "8190" }, { "input": "34", "output": "34359738366" }, { "input": "43", "out...
1,691,300,055
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) j = 2 for i in range(n-1): j += (j * 2) print(j)
Title: Lucky Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. Input Specification: The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. Output Specification: Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Demo Input: ['2\n'] Demo Output: ['6'] Note: none
```python n = int(input()) j = 2 for i in range(n-1): j += (j * 2) print(j) ```
0
616
A
Comparing Two Long Integers
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits.
Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=".
[ "9\n10\n", "11\n10\n", "00012345\n12345\n", "0123\n9\n", "0123\n111\n" ]
[ "&lt;\n", "&gt;\n", "=\n", "&gt;\n", "&gt;\n" ]
none
0
[ { "input": "9\n10", "output": "<" }, { "input": "11\n10", "output": ">" }, { "input": "00012345\n12345", "output": "=" }, { "input": "0123\n9", "output": ">" }, { "input": "0123\n111", "output": ">" }, { "input": "9\n9", "output": "=" }, { ...
1,592,372,878
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
def removingleadingzeroes(s): if(s[0]=='0'): i=0 while(s[i]!='0'): i+=1 t=s[i:] return t else: return s a=str(input()) b=str(input()) c=removingleadingzeroes(a) d=removingleadingzeroes(b) print(max(c,d))
Title: Comparing Two Long Integers Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two very long integers *a*,<=*b* (leading zeroes are allowed). You should check what number *a* or *b* is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). Input Specification: The first line contains a non-negative integer *a*. The second line contains a non-negative integer *b*. The numbers *a*,<=*b* may contain leading zeroes. Each of them contains no more than 106 digits. Output Specification: Print the symbol "&lt;" if *a*<=&lt;<=*b* and the symbol "&gt;" if *a*<=&gt;<=*b*. If the numbers are equal print the symbol "=". Demo Input: ['9\n10\n', '11\n10\n', '00012345\n12345\n', '0123\n9\n', '0123\n111\n'] Demo Output: ['&lt;\n', '&gt;\n', '=\n', '&gt;\n', '&gt;\n'] Note: none
```python def removingleadingzeroes(s): if(s[0]=='0'): i=0 while(s[i]!='0'): i+=1 t=s[i:] return t else: return s a=str(input()) b=str(input()) c=removingleadingzeroes(a) d=removingleadingzeroes(b) print(max(c,d)) ```
0
938
A
Word Correction
PROGRAMMING
800
[ "implementation" ]
null
null
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction.
Output the word *s* after the correction.
[ "5\nweird\n", "4\nword\n", "5\naaeaa\n" ]
[ "werd\n", "word\n", "a\n" ]
Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
0
[ { "input": "5\nweird", "output": "werd" }, { "input": "4\nword", "output": "word" }, { "input": "5\naaeaa", "output": "a" }, { "input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw", "output": "abbbbbocadabbbbb...
1,579,331,212
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
155
0
import sys import math import bisect import itertools def main(): n = int(input()) A = [] for c in input(): A.append(c) if len(A) >= 2 and A[-2] in 'aeiou' and A[-1] in 'aeiou': A.pop() print(''.join(A)) if __name__ == "__main__": main()
Title: Word Correction Time Limit: None seconds Memory Limit: None megabytes Problem Description: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters — the word before the correction. Output Specification: Output the word *s* after the correction. Demo Input: ['5\nweird\n', '4\nword\n', '5\naaeaa\n'] Demo Output: ['werd\n', 'word\n', 'a\n'] Note: Explanations of the examples: 1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aeaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aaa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> aa <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> a.
```python import sys import math import bisect import itertools def main(): n = int(input()) A = [] for c in input(): A.append(c) if len(A) >= 2 and A[-2] in 'aeiou' and A[-1] in 'aeiou': A.pop() print(''.join(A)) if __name__ == "__main__": main() ```
0
902
A
Visiting a Friend
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*).
Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).
[ "3 5\n0 2\n2 4\n3 5\n", "3 7\n0 4\n2 5\n6 7\n" ]
[ "YES\n", "NO\n" ]
The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
500
[ { "input": "3 5\n0 2\n2 4\n3 5", "output": "YES" }, { "input": "3 7\n0 4\n2 5\n6 7", "output": "NO" }, { "input": "1 1\n0 0", "output": "NO" }, { "input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7...
1,681,621,502
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n, m = [int(i) for i in input().split()] teleport = [] arr = list(range(0, m)) currenLastEnd = arr[0] for _ in range(n): start, end = [int(i) for i in input().split()] if currenLastEnd >= start: currenLastEnd = end else: break if currenLastEnd == m: print('YES') else: print('NO')
Title: Visiting a Friend Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point *m* on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport. Formally, a teleport located at point *x* with limit *y* can move Pig from point *x* to any point within the segment [*x*;<=*y*], including the bounds. Determine if Pig can visit the friend using teleports only, or he should use his car. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house. The next *n* lines contain information about teleports. The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where *a**i* is the location of the *i*-th teleport, and *b**i* is its limit. It is guaranteed that *a**i*<=≥<=*a**i*<=-<=1 for every *i* (2<=≤<=*i*<=≤<=*n*). Output Specification: Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower). Demo Input: ['3 5\n0 2\n2 4\n3 5\n', '3 7\n0 4\n2 5\n6 7\n'] Demo Output: ['YES\n', 'NO\n'] Note: The first example is shown on the picture below: Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives. The second example is shown on the picture below: You can see that there is no path from Pig's house to his friend's house that uses only teleports.
```python n, m = [int(i) for i in input().split()] teleport = [] arr = list(range(0, m)) currenLastEnd = arr[0] for _ in range(n): start, end = [int(i) for i in input().split()] if currenLastEnd >= start: currenLastEnd = end else: break if currenLastEnd == m: print('YES') else: print('NO') ```
0
36
B
Fractal
PROGRAMMING
1,600
[ "implementation" ]
B. Fractal
2
64
Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm: Step 1. The paper is divided into *n*2 identical squares and some of them are painted black according to the model. Step 2. Every square that remains white is divided into *n*2 smaller squares and some of them are painted black according to the model. Every following step repeats step 2. Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals.
The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square.
Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm.
[ "2 3\n.*\n..\n", "3 2\n.*.\n***\n.*.\n" ]
[ ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n", ".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n" ]
none
1,000
[ { "input": "2 3\n.*\n..", "output": ".*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........" }, { "input": "3 2\n.*.\n***\n.*.", "output": ".*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*." }, { "input": "2 1\n..\n....
1,699,093,108
2,147,483,647
Python 3
OK
TESTS
30
186
614,400
with open('input.txt', 'r') as file: line = file.readlines() n, k = [int(x) for x in line[0].split()] template = [x.strip() for x in line[1:]] def fractal(n,k): if k == 1: return [list(x) for x in template] new_grid = [["."]*(n**k) for i in range(n**k)] #creates the n^k by n^k grid with ., for i in range(n): for j in range(n): if template[i][j] == "*": for ii in range(n**(k-1)): for jj in range(n**(k-1)): x = i*(n**(k-1)) + ii y = j*(n**(k-1)) + jj new_grid[x][y] = "*" else: xd = fractal(n,k-1) for ii in range(n**(k-1)): for jj in range(n**(k-1)): x = i*(n**(k-1)) + ii y = j*(n**(k-1)) + jj new_grid[x][y] = xd[ii][jj] return new_grid with open('output.txt', 'w') as file: for x in fractal(n, k): file.write(''.join(x)+'\n')
Title: Fractal Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Ever since Kalevitch, a famous Berland abstractionist, heard of fractals, he made them the main topic of his canvases. Every morning the artist takes a piece of graph paper and starts with making a model of his future canvas. He takes a square as big as *n*<=×<=*n* squares and paints some of them black. Then he takes a clean square piece of paper and paints the fractal using the following algorithm: Step 1. The paper is divided into *n*2 identical squares and some of them are painted black according to the model. Step 2. Every square that remains white is divided into *n*2 smaller squares and some of them are painted black according to the model. Every following step repeats step 2. Unfortunately, this tiresome work demands too much time from the painting genius. Kalevitch has been dreaming of making the process automatic to move to making 3D or even 4D fractals. Input Specification: The first line contains integers *n* and *k* (2<=≤<=*n*<=≤<=3, 1<=≤<=*k*<=≤<=5), where *k* is the amount of steps of the algorithm. Each of the following *n* lines contains *n* symbols that determine the model. Symbol «.» stands for a white square, whereas «*» stands for a black one. It is guaranteed that the model has at least one white square. Output Specification: Output a matrix *n**k*<=×<=*n**k* which is what a picture should look like after *k* steps of the algorithm. Demo Input: ['2 3\n.*\n..\n', '3 2\n.*.\n***\n.*.\n'] Demo Output: ['.*******\n..******\n.*.*****\n....****\n.***.***\n..**..**\n.*.*.*.*\n........\n', '.*.***.*.\n*********\n.*.***.*.\n*********\n*********\n*********\n.*.***.*.\n*********\n.*.***.*.\n'] Note: none
```python with open('input.txt', 'r') as file: line = file.readlines() n, k = [int(x) for x in line[0].split()] template = [x.strip() for x in line[1:]] def fractal(n,k): if k == 1: return [list(x) for x in template] new_grid = [["."]*(n**k) for i in range(n**k)] #creates the n^k by n^k grid with ., for i in range(n): for j in range(n): if template[i][j] == "*": for ii in range(n**(k-1)): for jj in range(n**(k-1)): x = i*(n**(k-1)) + ii y = j*(n**(k-1)) + jj new_grid[x][y] = "*" else: xd = fractal(n,k-1) for ii in range(n**(k-1)): for jj in range(n**(k-1)): x = i*(n**(k-1)) + ii y = j*(n**(k-1)) + jj new_grid[x][y] = xd[ii][jj] return new_grid with open('output.txt', 'w') as file: for x in fractal(n, k): file.write(''.join(x)+'\n') ```
3.948922
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,696,437,011
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
342
2,252,800
r0=list(map(int,input().split())) r1=list(map(int,input().split())) r2=list(map(int,input().split())) r3=list(map(int,input().split())) r4=list(map(int,input().split())) s=0 m=[r0,r1,r2,r3,r4] for x in range(5): if 1 in m[x]: i1=[x,x.index(1)] s=abs(2-i1[0])+abs(2-i1[1]) print(s)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python r0=list(map(int,input().split())) r1=list(map(int,input().split())) r2=list(map(int,input().split())) r3=list(map(int,input().split())) r4=list(map(int,input().split())) s=0 m=[r0,r1,r2,r3,r4] for x in range(5): if 1 in m[x]: i1=[x,x.index(1)] s=abs(2-i1[0])+abs(2-i1[1]) print(s) ```
-1
137
C
History
PROGRAMMING
1,500
[ "sortings" ]
null
null
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=&lt;<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=&lt;<=*a**i* and *b**i*<=&lt;<=*b**j*. Your task is simpler: find the number of events that are included in some other event.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order.
Print the only integer — the answer to the problem.
[ "5\n1 10\n2 9\n3 8\n4 7\n5 6\n", "5\n1 100\n2 50\n51 99\n52 98\n10 60\n", "1\n1 1000000000\n" ]
[ "4\n", "4\n", "0\n" ]
In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
1,500
[ { "input": "5\n1 10\n2 9\n3 8\n4 7\n5 6", "output": "4" }, { "input": "5\n1 100\n2 50\n51 99\n52 98\n10 60", "output": "4" }, { "input": "1\n1 1000000000", "output": "0" }, { "input": "2\n100 1000\n500 1500", "output": "0" }, { "input": "4\n1 100\n50 150\n120 200\...
1,645,600,120
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
6
92
0
def solve(): years = [[int(i) for i in input().split()] for i in range(int(input()))] # table = {f"{a}-{b}":[] for a,b in years} counts = [0 for i in range(len(years))] years.sort() ind = -1 for i in years: ind += 1 for ii in years: if ii[1] < i[1] and ii[0] > i[0]: # table[f"{i[0]}-{i[1]}"] += [[ii[0],ii[1]]] counts[ind] += 1 print(max(counts)) solve()
Title: History Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history. Everybody knows that the World history encompasses exactly *n* events: the *i*-th event had continued from the year *a**i* to the year *b**i* inclusive (*a**i*<=&lt;<=*b**i*). Polycarpus easily learned the dates when each of *n* events started and ended (Polycarpus inherited excellent memory from his great-great-granddad). But the teacher gave him a more complicated task: Polycaprus should know when all events began and ended and he should also find out for each event whether it includes another event. Polycarpus' teacher thinks that an event *j* includes an event *i* if *a**j*<=&lt;<=*a**i* and *b**i*<=&lt;<=*b**j*. Your task is simpler: find the number of events that are included in some other event. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=105) which represents the number of events. Next *n* lines contain descriptions of the historical events, one event per line. The *i*<=+<=1 line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*<=&lt;<=*b**i*<=≤<=109) — the beginning and the end of the *i*-th event. No two events start or finish in the same year, that is, *a**i*<=≠<=*a**j*,<=*a**i*<=≠<=*b**j*,<=*b**i*<=≠<=*a**j*,<=*b**i*<=≠<=*b**j* for all *i*, *j* (where *i*<=≠<=*j*). Events are given in arbitrary order. Output Specification: Print the only integer — the answer to the problem. Demo Input: ['5\n1 10\n2 9\n3 8\n4 7\n5 6\n', '5\n1 100\n2 50\n51 99\n52 98\n10 60\n', '1\n1 1000000000\n'] Demo Output: ['4\n', '4\n', '0\n'] Note: In the first example the fifth event is contained in the fourth. Similarly, the fourth event is contained in the third, the third — in the second and the second — in the first. In the second example all events except the first one are contained in the first. In the third example only one event, so the answer is 0.
```python def solve(): years = [[int(i) for i in input().split()] for i in range(int(input()))] # table = {f"{a}-{b}":[] for a,b in years} counts = [0 for i in range(len(years))] years.sort() ind = -1 for i in years: ind += 1 for ii in years: if ii[1] < i[1] and ii[0] > i[0]: # table[f"{i[0]}-{i[1]}"] += [[ii[0],ii[1]]] counts[ind] += 1 print(max(counts)) solve() ```
0
0
none
none
none
0
[ "none" ]
null
null
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day.
The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days. The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*. The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*.
Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*.
[ "3\n10 10 5\n5 7 2\n", "5\n30 25 20 15 10\n9 10 12 4 13\n" ]
[ "5 12 4\n", "9 20 35 11 25\n" ]
In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
0
[ { "input": "3\n10 10 5\n5 7 2", "output": "5 12 4" }, { "input": "5\n30 25 20 15 10\n9 10 12 4 13", "output": "9 20 35 11 25" }, { "input": "4\n0 0 0 0\n1 2 3 4", "output": "0 0 0 0" }, { "input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "output": "10 0 9...
1,520,700,407
4,307
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
3
1,000
15,974,400
days = int(input()) volume = input().split() volume = [int(x) for x in volume] temp = input().split() temp = [int(x) for x in temp] leftOver = [0] for i in range(days): melted = 0 for j in range(len(leftOver)): if leftOver[j] > temp[i]: melted += temp[i] leftOver[j] -= temp[i] else: melted += leftOver[j] leftOver[j] = 0 if temp[i] > volume[i]: melted += volume[i] else: melted += temp[i] leftOver.append(volume[i] - temp[i]) print(melted, end=" ")
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. Input Specification: The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days. The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*. The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*. Output Specification: Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. Demo Input: ['3\n10 10 5\n5 7 2\n', '5\n30 25 20 15 10\n9 10 12 4 13\n'] Demo Output: ['5 12 4\n', '9 20 35 11 25\n'] Note: In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has only a single pile of size 3. On the third day he makes a smaller pile than usual, but as the temperature dropped too, both piles survive till the end of the day.
```python days = int(input()) volume = input().split() volume = [int(x) for x in volume] temp = input().split() temp = [int(x) for x in temp] leftOver = [0] for i in range(days): melted = 0 for j in range(len(leftOver)): if leftOver[j] > temp[i]: melted += temp[i] leftOver[j] -= temp[i] else: melted += leftOver[j] leftOver[j] = 0 if temp[i] > volume[i]: melted += volume[i] else: melted += temp[i] leftOver.append(volume[i] - temp[i]) print(melted, end=" ") ```
0
705
A
Hulk
PROGRAMMING
800
[ "implementation" ]
null
null
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner.
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate.
Print Dr.Banner's feeling in one line.
[ "1\n", "2\n", "3\n" ]
[ "I hate it\n", "I hate that I love it\n", "I hate that I love that I hate it\n" ]
none
500
[ { "input": "1", "output": "I hate it" }, { "input": "2", "output": "I hate that I love it" }, { "input": "3", "output": "I hate that I love that I hate it" }, { "input": "4", "output": "I hate that I love that I hate that I love it" }, { "input": "5", "output"...
1,691,855,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
n = int(input()) feeling = "" for i in range(1, n+1): if i % 2 == 1: feeling += "I hate that " else: feeling += "I love that " feeling += "it" print(feeling)
Title: Hulk Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner. Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. Output Specification: Print Dr.Banner's feeling in one line. Demo Input: ['1\n', '2\n', '3\n'] Demo Output: ['I hate it\n', 'I hate that I love it\n', 'I hate that I love that I hate it\n'] Note: none
```python n = int(input()) feeling = "" for i in range(1, n+1): if i % 2 == 1: feeling += "I hate that " else: feeling += "I love that " feeling += "it" print(feeling) ```
0
915
C
Permute Digits
PROGRAMMING
1,700
[ "dp", "greedy" ]
null
null
You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is.
The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists.
Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*.
[ "123\n222\n", "3921\n10000\n", "4940\n5000\n" ]
[ "213\n", "9321\n", "4940\n" ]
none
0
[ { "input": "123\n222", "output": "213" }, { "input": "3921\n10000", "output": "9321" }, { "input": "4940\n5000", "output": "4940" }, { "input": "23923472834\n23589234723", "output": "23498743322" }, { "input": "102391019\n491010301", "output": "399211100" },...
1,524,922,099
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
93
7,270,400
a = input() b = input() s=[] ans='' for i in range(len(a)): s.append(a[i]) s.sort() if (len(b)>len(a)): for i in range(len(s)): print(s[len(s)-i-1],end='') else: for i in range(len(a)): j=0 while ((j<len(s)-1) and (s[j+1]<=b[i])): j+=1 ans+=s[j] s.remove(s[j]) if (ans[i]<b[i]): for k in range(len(s)): ans+=s[len(s)-k-1] if (len(ans)==len(a)): break print(ans)
Title: Permute Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two positive integer numbers *a* and *b*. Permute (change order) of the digits of *a* to construct maximal number not exceeding *b*. No number in input and/or output can start with the digit 0. It is allowed to leave *a* as it is. Input Specification: The first line contains integer *a* (1<=≤<=*a*<=≤<=1018). The second line contains integer *b* (1<=≤<=*b*<=≤<=1018). Numbers don't have leading zeroes. It is guaranteed that answer exists. Output Specification: Print the maximum possible number that is a permutation of digits of *a* and is not greater than *b*. The answer can't have any leading zeroes. It is guaranteed that the answer exists. The number in the output should have exactly the same length as number *a*. It should be a permutation of digits of *a*. Demo Input: ['123\n222\n', '3921\n10000\n', '4940\n5000\n'] Demo Output: ['213\n', '9321\n', '4940\n'] Note: none
```python a = input() b = input() s=[] ans='' for i in range(len(a)): s.append(a[i]) s.sort() if (len(b)>len(a)): for i in range(len(s)): print(s[len(s)-i-1],end='') else: for i in range(len(a)): j=0 while ((j<len(s)-1) and (s[j+1]<=b[i])): j+=1 ans+=s[j] s.remove(s[j]) if (ans[i]<b[i]): for k in range(len(s)): ans+=s[len(s)-k-1] if (len(ans)==len(a)): break print(ans) ```
0
265
A
Colorful Stones (Simplified Edition)
PROGRAMMING
800
[ "implementation" ]
null
null
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.
The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence.
Print the final 1-based position of Liss in a single line.
[ "RGB\nRRR\n", "RRRBGBRBBB\nBBBRR\n", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n" ]
[ "2\n", "3\n", "15\n" ]
none
500
[ { "input": "RGB\nRRR", "output": "2" }, { "input": "RRRBGBRBBB\nBBBRR", "output": "3" }, { "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15" }, { "input": "G\nRRBBRBRRBR", "output": "1" }, ...
1,640,314,251
2,147,483,647
Python 3
OK
TESTS
19
92
0
S = str(input()) T = str(input()) pedraS = list(S) instrucaoT = list(T) i= 0 n = 0 for n in range(0, len(instrucaoT)): if pedraS[i] == instrucaoT[n]: i = i + 1 print(i+1)
Title: Colorful Stones (Simplified Edition) Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. Input Specification: The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. Output Specification: Print the final 1-based position of Liss in a single line. Demo Input: ['RGB\nRRR\n', 'RRRBGBRBBB\nBBBRR\n', 'BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n'] Demo Output: ['2\n', '3\n', '15\n'] Note: none
```python S = str(input()) T = str(input()) pedraS = list(S) instrucaoT = list(T) i= 0 n = 0 for n in range(0, len(instrucaoT)): if pedraS[i] == instrucaoT[n]: i = i + 1 print(i+1) ```
3
513
A
Game
PROGRAMMING
800
[ "constructive algorithms", "math" ]
null
null
Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally.
The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission.
Output "First" if the first player wins and "Second" otherwise.
[ "2 2 1 2\n", "2 1 1 1\n" ]
[ "Second\n", "First\n" ]
Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
3
[ { "input": "2 2 1 2", "output": "Second" }, { "input": "2 1 1 1", "output": "First" }, { "input": "5 7 4 1", "output": "Second" }, { "input": "5 7 1 4", "output": "Second" }, { "input": "5 7 10 10", "output": "Second" }, { "input": "5 7 1 10", "out...
1,553,431,352
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
n1, n2, k1, k2 = map(int,input().split()) m1 = (n1//k1)+(n1%k1) m2 = (n2//k2)+(n2%k2) if m1 == m2: print('First') elif m1>m2: print('Second') else: print('First')
Title: Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two players play a simple game. Each player is provided with a box with balls. First player's box contains exactly *n*1 balls and second player's box contains exactly *n*2 balls. In one move first player can take from 1 to *k*1 balls from his box and throw them away. Similarly, the second player can take from 1 to *k*2 balls from his box in his move. Players alternate turns and the first player starts the game. The one who can't make a move loses. Your task is to determine who wins if both players play optimally. Input Specification: The first line contains four integers *n*1,<=*n*2,<=*k*1,<=*k*2. All numbers in the input are from 1 to 50. This problem doesn't have subproblems. You will get 3 points for the correct submission. Output Specification: Output "First" if the first player wins and "Second" otherwise. Demo Input: ['2 2 1 2\n', '2 1 1 1\n'] Demo Output: ['Second\n', 'First\n'] Note: Consider the first sample test. Each player has a box with 2 balls. The first player draws a single ball from his box in one move and the second player can either take 1 or 2 balls from his box in one move. No matter how the first player acts, the second player can always win if he plays wisely.
```python n1, n2, k1, k2 = map(int,input().split()) m1 = (n1//k1)+(n1%k1) m2 = (n2//k2)+(n2%k2) if m1 == m2: print('First') elif m1>m2: print('Second') else: print('First') ```
0
0
none
none
none
0
[ "none" ]
null
null
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out.
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days.
[ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n" ]
[ "2\n", "0\n", "1\n" ]
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
0
[ { "input": "4\n1 3 2 0", "output": "2" }, { "input": "7\n1 3 3 2 1 2 3", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8" }, { "input": "100\n3 2 3 3 3 2 3 1 ...
1,634,797,597
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
4,505,600
n = int(input()) z= list(map(int,input().split())) x = 0 y = 0 def vacation(cur , prev ) : if cur == n : return 0 if z[cur] == 0 : return 1+vacation(cur+1,0) elif z[cur] == 1 : if prev == 1 : return 1+vacation(cur+1,0) else : return min( vacation(cur+1,1) , 1+vacation(cur+1,0)) elif z[cur] == 2 : if prev == 2 : return 1+vacation(cur+1,0) else : return min( vacation(cur+1,2) , 1+vacation(cur+1,0)) else : if prev == 1 : return min( vacation(cur+1,2) , 1+vacation(cur+1,0)) elif prev == 2 : return min( vacation(cur+1,1) , 1+vacation(cur+1,0)) else : return min( vacation(cur+1,1) , min(1+vacation(cur+1,0), vacation(cur+1,2) )) print(vacation(0,0))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. Output Specification: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Demo Input: ['4\n1 3 2 0\n', '7\n1 3 3 2 1 2 3\n', '2\n2 2\n'] Demo Output: ['2\n', '0\n', '1\n'] Note: In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days. In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day. In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
```python n = int(input()) z= list(map(int,input().split())) x = 0 y = 0 def vacation(cur , prev ) : if cur == n : return 0 if z[cur] == 0 : return 1+vacation(cur+1,0) elif z[cur] == 1 : if prev == 1 : return 1+vacation(cur+1,0) else : return min( vacation(cur+1,1) , 1+vacation(cur+1,0)) elif z[cur] == 2 : if prev == 2 : return 1+vacation(cur+1,0) else : return min( vacation(cur+1,2) , 1+vacation(cur+1,0)) else : if prev == 1 : return min( vacation(cur+1,2) , 1+vacation(cur+1,0)) elif prev == 2 : return min( vacation(cur+1,1) , 1+vacation(cur+1,0)) else : return min( vacation(cur+1,1) , min(1+vacation(cur+1,0), vacation(cur+1,2) )) print(vacation(0,0)) ```
0
763
A
Timofey and a tree
PROGRAMMING
1,600
[ "dfs and similar", "dp", "dsu", "graphs", "implementation", "trees" ]
null
null
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can. Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex. A subtree of some vertex is a subgraph containing that vertex and all its descendants. Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices.
Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.
[ "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "3\n1 2\n2 3\n1 2 3\n", "4\n1 2\n2 3\n3 4\n1 2 1 2\n" ]
[ "YES\n2", "YES\n2", "NO" ]
none
500
[ { "input": "4\n1 2\n2 3\n3 4\n1 2 1 1", "output": "YES\n2" }, { "input": "3\n1 2\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 4\n4 3\n1 1 ...
1,617,646,288
2,147,483,647
PyPy 3
OK
TESTS
67
218
17,920,000
import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ Neo = lambda : list(map(int,input().split())) test, = Neo() n = test edges = [] for _ in range(n - 1): u, v = Neo() u -= 1 v -= 1 edges.append((u, v)) colors = Neo() suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]] if len(suspect) == 0: print("YES") print(1) else: cands = set(suspect[0]) for u, v in suspect: cands &= set([u, v]) # print(cands) if len(cands) == 0: print("NO") else: print("YES") e = list(cands)[0] print(e + 1)
Title: Timofey and a tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can. Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex. A subtree of some vertex is a subgraph containing that vertex and all its descendants. Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices. Output Specification: Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them. Demo Input: ['4\n1 2\n2 3\n3 4\n1 2 1 1\n', '3\n1 2\n2 3\n1 2 3\n', '4\n1 2\n2 3\n3 4\n1 2 1 2\n'] Demo Output: ['YES\n2', 'YES\n2', 'NO'] Note: none
```python import sys,os,io import math,bisect,operator inf,mod = float('inf'),10**9+7 # sys.setrecursionlimit(10 ** 6) from itertools import groupby,accumulate from heapq import heapify,heappop,heappush from collections import deque,Counter,defaultdict input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ Neo = lambda : list(map(int,input().split())) test, = Neo() n = test edges = [] for _ in range(n - 1): u, v = Neo() u -= 1 v -= 1 edges.append((u, v)) colors = Neo() suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]] if len(suspect) == 0: print("YES") print(1) else: cands = set(suspect[0]) for u, v in suspect: cands &= set([u, v]) # print(cands) if len(cands) == 0: print("NO") else: print("YES") e = list(cands)[0] print(e + 1) ```
3
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
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,595,388,035
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
93
6,656,000
s = input() eq = "hello" j = 0 for i in s: if j == 5: print("YES") break if i == eq[j]: j += 1 if j < 5: print("NO")
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: 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. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python s = input() eq = "hello" j = 0 for i in s: if j == 5: print("YES") break if i == eq[j]: j += 1 if j < 5: print("NO") ```
0
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,644,747,520
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
5
61
0
n, k = map(int,input().split()) if n%k == 0: print(n+k) else: k1 = k * 2 n1 = n while True: n = k1 k1 += k if n%k == 0 and n1<=n: break print(n)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Output Specification: Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Demo Input: ['5 3\n', '25 13\n', '26 13\n'] Demo Output: ['6\n', '26\n', '39\n'] Note: none
```python n, k = map(int,input().split()) if n%k == 0: print(n+k) else: k1 = k * 2 n1 = n while True: n = k1 k1 += k if n%k == 0 and n1<=n: break print(n) ```
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 unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
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,684,959,735
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
278
13,824,000
from fractions import Fraction def solve(): y,x = input().split() luck = max(y,x) luck = int(luck) luck = 7-luck her_chances = Fraction(luck,6) if her_chances == 1: print('1/1') else: print(str(her_chances))
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 Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: 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 Specification: 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». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python from fractions import Fraction def solve(): y,x = input().split() luck = max(y,x) luck = int(luck) luck = 7-luck her_chances = Fraction(luck,6) if her_chances == 1: print('1/1') else: print(str(her_chances)) ```
0
263
A
Beautiful Matrix
PROGRAMMING
800
[ "implementation" ]
null
null
You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful.
The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one.
Print a single integer — the minimum number of moves needed to make the matrix beautiful.
[ "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n" ]
[ "3\n", "1\n" ]
none
500
[ { "input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "3" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "1" }, { "input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "0" }, { "input": "0 0 0 0 0...
1,694,510,586
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
matrix = [] row, col = 0, 0 for i in range(5): for j in range(5): matrix[i][j] = int(input()) if matrix[i][j] == 1: row, col = i, j moves = 0 if row != 2 or col != 2: if row < 2: moves += 2 row += 2 elif row > 2: moves += 2 row -= 2 if col < 2: moves += 2 col += 2 elif col > 2: moves += 2 col -= 2 print(moves)
Title: Beautiful Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a 5<=×<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix: 1. Swap two neighboring matrix rows, that is, rows with indexes *i* and *i*<=+<=1 for some integer *i* (1<=≤<=*i*<=&lt;<=5). 1. Swap two neighboring matrix columns, that is, columns with indexes *j* and *j*<=+<=1 for some integer *j* (1<=≤<=*j*<=&lt;<=5). You think that a matrix looks beautiful, if the single number one of the matrix is located in its middle (in the cell that is on the intersection of the third row and the third column). Count the minimum number of moves needed to make the matrix beautiful. Input Specification: The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. Output Specification: Print a single integer — the minimum number of moves needed to make the matrix beautiful. Demo Input: ['0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n', '0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n'] Demo Output: ['3\n', '1\n'] Note: none
```python matrix = [] row, col = 0, 0 for i in range(5): for j in range(5): matrix[i][j] = int(input()) if matrix[i][j] == 1: row, col = i, j moves = 0 if row != 2 or col != 2: if row < 2: moves += 2 row += 2 elif row > 2: moves += 2 row -= 2 if col < 2: moves += 2 col += 2 elif col > 2: moves += 2 col -= 2 print(moves) ```
-1
734
A
Anton and Danik
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game.
If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes).
[ "6\nADAAAA\n", "7\nDDDAADA\n", "6\nDADADA\n" ]
[ "Anton\n", "Danik\n", "Friendship\n" ]
In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
500
[ { "input": "6\nADAAAA", "output": "Anton" }, { "input": "7\nDDDAADA", "output": "Danik" }, { "input": "6\nDADADA", "output": "Friendship" }, { "input": "10\nDDDDADDADD", "output": "Danik" }, { "input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA", "output": ...
1,700,064,036
2,147,483,647
Python 3
OK
TESTS
25
61
204,800
n = input() n = int(n) s = input() a = 0 d = 0 for i in range(n): if s[i] == 'A': a += 1 else: d += 1 if (a > d): print("Anton") elif a < d: print("Danik") else: print("Friendship")
Title: Anton and Danik Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. Output Specification: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Demo Input: ['6\nADAAAA\n', '7\nDDDAADA\n', '6\nDADADA\n'] Demo Output: ['Anton\n', 'Danik\n', 'Friendship\n'] Note: In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton". In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik". In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".
```python n = input() n = int(n) s = input() a = 0 d = 0 for i in range(n): if s[i] == 'A': a += 1 else: d += 1 if (a > d): print("Anton") elif a < d: print("Danik") else: print("Friendship") ```
3
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 *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers.
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* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has.
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 fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
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,595,851,236
2,147,483,647
Python 3
OK
TESTS
20
109
6,656,000
n = int(input()) a = list(map(int,input().split())) ans = [] for x in range(n): sec = 15*a[x] q = list(map(int,input().split())) for y in q: sec += 5*y ans.append(sec) 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* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has *k**i* people. The *j*-th person standing in the queue to the *i*-th cashier has *m**i*,<=*j* items in the basket. Vasya knows that: - the cashier needs 5 seconds to scan one item; - after the cashier scans each item of some customer, he needs 15 seconds to take the customer's money and give him the change. Of course, Vasya wants to select a queue so that he can leave the supermarket as soon as possible. Help him write a program that displays the minimum number of seconds after which Vasya can get to one of the cashiers. Input Specification: 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* space-separated integers: *m**i*,<=1,<=*m**i*,<=2,<=...,<=*m**i*,<=*k**i* (1<=≤<=*m**i*,<=*j*<=≤<=100) — the number of products the *j*-th person in the queue for the *i*-th cash has. Output Specification: Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. Demo Input: ['1\n1\n1\n', '4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n'] Demo Output: ['20\n', '100\n'] Note: 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 fourth one. Thus, Vasya gets to the cashier quicker if he chooses the second or the third queue.
```python n = int(input()) a = list(map(int,input().split())) ans = [] for x in range(n): sec = 15*a[x] q = list(map(int,input().split())) for y in q: sec += 5*y ans.append(sec) print (min(ans)) ```
3
400
C
Inna and Huge Candy Matrix
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*). The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!
The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell.
For each of the *p* candies, print on a single line its space-separated new coordinates.
[ "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n" ]
[ "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n" ]
Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
1,500
[ { "input": "3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3", "output": "1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1" }, { "input": "5 5 0 0 0 1\n1 4", "output": "1 4" }, { "input": "14 76 376219315 550904689 16684615 24\n11 21\n1 65\n5 25\n14 63\n11 30\n1 19\n5 7\n9 51\n2 49\n1...
1,659,045,612
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
31
0
N, M, X, Y, Z, Q = map(int, input().split()) for q in range(Q): r, c = map(int, input().split()) if X % 4 == 1: r, c = c, N - r + 1 elif X % 4 == 2: r, c = N - r + 1, M - c + 1 elif X % 4 == 3: r, c = M - c + 1, r if Y % 2 == 1: c = M - c + 1 if Z % 4 == 1: r, c = M - c + 1, r elif Z % 4 == 2: r, c = N - r + 1, M - c + 1 elif Z % 4 == 3: r, c = c, N - r + 1 print(r, c)
Title: Inna and Huge Candy Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to *n* from top to bottom and the columns — from 1 to *m*, from left to right. We'll represent the cell on the intersection of the *i*-th row and *j*-th column as (*i*,<=*j*). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has *p* candies: the *k*-th candy is at cell (*x**k*,<=*y**k*). The time moved closer to dinner and Inna was already going to eat *p* of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix *x* times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix *y* times. And then he rotated the matrix *z* times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like. Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made! Input Specification: The first line of the input contains fix integers *n*, *m*, *x*, *y*, *z*, *p* (1<=≤<=*n*,<=*m*<=≤<=109; 0<=≤<=*x*,<=*y*,<=*z*<=≤<=109; 1<=≤<=*p*<=≤<=105). Each of the following *p* lines contains two integers *x**k*, *y**k* (1<=≤<=*x**k*<=≤<=*n*; 1<=≤<=*y**k*<=≤<=*m*) — the initial coordinates of the *k*-th candy. Two candies can lie on the same cell. Output Specification: For each of the *p* candies, print on a single line its space-separated new coordinates. Demo Input: ['3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n'] Demo Output: ['1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n'] Note: Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:
```python N, M, X, Y, Z, Q = map(int, input().split()) for q in range(Q): r, c = map(int, input().split()) if X % 4 == 1: r, c = c, N - r + 1 elif X % 4 == 2: r, c = N - r + 1, M - c + 1 elif X % 4 == 3: r, c = M - c + 1, r if Y % 2 == 1: c = M - c + 1 if Z % 4 == 1: r, c = M - c + 1, r elif Z % 4 == 2: r, c = N - r + 1, M - c + 1 elif Z % 4 == 3: r, c = c, N - r + 1 print(r, c) ```
0
959
A
Mahmoud and Ehab and the even-odd game
PROGRAMMING
800
[ "games", "math" ]
null
null
Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally?
The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game.
Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise.
[ "1\n", "2\n" ]
[ "Ehab", "Mahmoud" ]
In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
500
[ { "input": "1", "output": "Ehab" }, { "input": "2", "output": "Mahmoud" }, { "input": "10000", "output": "Mahmoud" }, { "input": "33333", "output": "Ehab" }, { "input": "5", "output": "Ehab" }, { "input": "1000000000", "output": "Mahmoud" }, { ...
1,619,698,731
2,147,483,647
Python 3
OK
TESTS
20
62
0
n=int(input()) print('Mahmoud'if n%2==0 else 'Ehab')
Title: Mahmoud and Ehab and the even-odd game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. Output Specification: Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. Demo Input: ['1\n', '2\n'] Demo Output: ['Ehab', 'Mahmoud'] Note: In the first sample, Mahmoud can't choose any integer *a* initially because there is no positive even integer less than or equal to 1 so Ehab wins. In the second sample, Mahmoud has to choose *a* = 2 and subtract it from *n*. It's Ehab's turn and *n* = 0. There is no positive odd integer less than or equal to 0 so Mahmoud wins.
```python n=int(input()) print('Mahmoud'if n%2==0 else 'Ehab') ```
3
762
A
k-th divisor
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109).
If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*.
[ "4 2\n", "5 3\n", "12 5\n" ]
[ "2\n", "-1\n", "6\n" ]
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.
0
[ { "input": "4 2", "output": "2" }, { "input": "5 3", "output": "-1" }, { "input": "12 5", "output": "6" }, { "input": "1 1", "output": "1" }, { "input": "866421317361600 26880", "output": "866421317361600" }, { "input": "866421317361600 26881", "ou...
1,686,502,891
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
2,048,000
import sys input = sys.stdin.buffer.readline n, k = map(int, input().split()) # kth smallest dicisor of n if not then -1 div = [] for i in range(1, n+1): if not n%i: div.append(i) print(div[k-1] if len(div) >= k else -1)
Title: k-th divisor Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*k*<=≤<=109). Output Specification: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Demo Input: ['4 2\n', '5 3\n', '12 5\n'] Demo Output: ['2\n', '-1\n', '6\n'] Note: 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.
```python import sys input = sys.stdin.buffer.readline n, k = map(int, input().split()) # kth smallest dicisor of n if not then -1 div = [] for i in range(1, n+1): if not n%i: div.append(i) print(div[k-1] if len(div) >= k else -1) ```
0
1,004
A
Sonya and Hotels
PROGRAMMING
900
[ "implementation" ]
null
null
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$.
The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels.
Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$.
[ "4 3\n-3 2 9 16\n", "5 2\n4 8 11 18 19\n" ]
[ "6\n", "5\n" ]
In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
500
[ { "input": "4 3\n-3 2 9 16", "output": "6" }, { "input": "5 2\n4 8 11 18 19", "output": "5" }, { "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8" }, { "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9" }, { "input": "100 1\n0 1 2 3...
1,530,982,768
2,147,483,647
Python 3
OK
TESTS
45
124
0
def scanf(t=int): return list(map(t, input().split())) import math n, d = scanf() m = scanf() ans = sum([ 2 - (m[i] - m[i-1] == 2 * d) for i in range(1, n) if m[i] - m[i-1] >= 2 * d]) print(ans + 2)
Title: Sonya and Hotels Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. Input Specification: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$) — the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$) — coordinates of Sonya's hotels. Output Specification: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Demo Input: ['4 3\n-3 2 9 16\n', '5 2\n4 8 11 18 19\n'] Demo Output: ['6\n', '5\n'] Note: In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$. In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$.
```python def scanf(t=int): return list(map(t, input().split())) import math n, d = scanf() m = scanf() ans = sum([ 2 - (m[i] - m[i-1] == 2 * d) for i in range(1, n) if m[i] - m[i-1] >= 2 * d]) print(ans + 2) ```
3
17
A
Noldbach problem
PROGRAMMING
1,000
[ "brute force", "math", "number theory" ]
A. Noldbach problem
2
64
Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong.
The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000).
Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO.
[ "27 2\n", "45 7\n" ]
[ "YES", "NO" ]
In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
0
[ { "input": "27 2", "output": "YES" }, { "input": "45 7", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "15 1", "output": "YES" }, { "input": "17 1", "output": "YES" }, { "input": "34 5", "output": "NO" }, { "input": "37 ...
1,666,835,352
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
w = input() while not w.isnumeric(): if len(w) > 10: b = (len(w)-2) ft, lt = (w[0], w[-1]) print(f"{ft}{b}{lt}") break elif len(w) <= 10: print(w) break
Title: Noldbach problem Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick's attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least *k* prime numbers from 2 to *n* inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1. Two prime numbers are called neighboring if there are no other prime numbers between them. You are to help Nick, and find out if he is right or wrong. Input Specification: The first line of the input contains two integers *n* (2<=≤<=*n*<=≤<=1000) and *k* (0<=≤<=*k*<=≤<=1000). Output Specification: Output YES if at least *k* prime numbers from 2 to *n* inclusively can be expressed as it was described above. Otherwise output NO. Demo Input: ['27 2\n', '45 7\n'] Demo Output: ['YES', 'NO'] Note: In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.
```python w = input() while not w.isnumeric(): if len(w) > 10: b = (len(w)-2) ft, lt = (w[0], w[-1]) print(f"{ft}{b}{lt}") break elif len(w) <= 10: print(w) break ```
0
113
B
Petr#
PROGRAMMING
2,000
[ "brute force", "data structures", "hashing", "strings" ]
B. Petr#
2
256
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* and ending with the *s**end* (it is possible *s**begin*<==<=*s**end*), the given string *t* has. Substrings are different if and only if their contents aren't equal, their positions of occurence don't matter. Petya wasn't quite good at math, that's why he couldn't count this number. Help him!
The input file consists of three lines. The first line contains string *t*. The second and the third lines contain the *s**begin* and *s**end* identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters.
Output the only number — the amount of different substrings of *t* that start with *s**begin* and end with *s**end*.
[ "round\nro\nou\n", "codeforces\ncode\nforca\n", "abababab\na\nb\n", "aba\nab\nba\n" ]
[ "1\n", "0\n", "4\n", "1\n" ]
In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab. In the fourth sample identificators intersect.
1,000
[ { "input": "round\nro\nou", "output": "1" }, { "input": "codeforces\ncode\nforca", "output": "0" }, { "input": "abababab\na\nb", "output": "4" }, { "input": "aba\nab\nba", "output": "1" }, { "input": "abcdefghijklmnopqrstuvwxyz\nabc\nxyz", "output": "1" }, ...
1,611,823,703
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
186
0
t = input() sb = input() sbl = len(sb) se = input() sel = len(se) n = len(t) s = set() b = 0 for i in range(n): if hash(t[b+i:b+sbl+i]) == hash(sb): b = i for j in range(b, n): if hash(t[j:sel + j]) == hash(se) and j >= b: if hash(sb) == hash(se) or j > b: s.add(t[b:j + sel]) # # print(len(s)) # Thu Jan 28 2021 11:48:22 GMT+0300 (Москва, стандартное время)
Title: Petr# Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the *s**begin* and ending with the *s**end* (it is possible *s**begin*<==<=*s**end*), the given string *t* has. Substrings are different if and only if their contents aren't equal, their positions of occurence don't matter. Petya wasn't quite good at math, that's why he couldn't count this number. Help him! Input Specification: The input file consists of three lines. The first line contains string *t*. The second and the third lines contain the *s**begin* and *s**end* identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. Output Specification: Output the only number — the amount of different substrings of *t* that start with *s**begin* and end with *s**end*. Demo Input: ['round\nro\nou\n', 'codeforces\ncode\nforca\n', 'abababab\na\nb\n', 'aba\nab\nba\n'] Demo Output: ['1\n', '0\n', '4\n', '1\n'] Note: In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab. In the fourth sample identificators intersect.
```python t = input() sb = input() sbl = len(sb) se = input() sel = len(se) n = len(t) s = set() b = 0 for i in range(n): if hash(t[b+i:b+sbl+i]) == hash(sb): b = i for j in range(b, n): if hash(t[j:sel + j]) == hash(se) and j >= b: if hash(sb) == hash(se) or j > b: s.add(t[b:j + sel]) # # print(len(s)) # Thu Jan 28 2021 11:48:22 GMT+0300 (Москва, стандартное время) ```
0
765
A
Neverending competitions
PROGRAMMING
900
[ "implementation", "math" ]
null
null
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!
In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
[ "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n" ]
[ "home\n", "contest\n" ]
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
500
[ { "input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home" }, { "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest" }, { "input": "1\nESJ\nESJ->TSJ", "output": "contest" }, { "input": "2\nXMR\nFAJ->XMR\nXMR->FAJ", "output": "home" }, ...
1,556,813,445
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
109
0
def main(): n_flights = int(input()) home = input() flights_from_home = [] flights_to_home = [] for _ in range(n_flights): flight = input().split('->') if flight[0] == home: flights_from_home += [flight[1]] else: flights_to_home += [flight[0]] away = False for flight in flights_from_home: if flight not in flights_to_home: away = True break print('contest' if away else 'home') if __name__ == '__main__': main()
Title: Neverending competitions Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! Input Specification: In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. Output Specification: If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". Demo Input: ['4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n', '3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n'] Demo Output: ['home\n', 'contest\n'] Note: In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
```python def main(): n_flights = int(input()) home = input() flights_from_home = [] flights_to_home = [] for _ in range(n_flights): flight = input().split('->') if flight[0] == home: flights_from_home += [flight[1]] else: flights_to_home += [flight[0]] away = False for flight in flights_from_home: if flight not in flights_to_home: away = True break print('contest' if away else 'home') if __name__ == '__main__': main() ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chn...
1,668,558,638
2,147,483,647
PyPy 3-64
OK
TESTS
30
124
0
s=input() upper,lower=0,0 for char in s: if char.islower():lower+=1 else:upper+=1 print(s.upper() if upper>lower else s.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python s=input() upper,lower=0,0 for char in s: if char.islower():lower+=1 else:upper+=1 print(s.upper() if upper>lower else s.lower()) ```
3.969
80
A
Panoramix's Prediction
PROGRAMMING
800
[ "brute force" ]
A. Panoramix's Prediction
2
256
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?
The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4.
Print YES, if *m* is the next prime number after *n*, or NO otherwise.
[ "3 5\n", "7 11\n", "7 9\n" ]
[ "YES", "YES", "NO" ]
none
500
[ { "input": "3 5", "output": "YES" }, { "input": "7 11", "output": "YES" }, { "input": "7 9", "output": "NO" }, { "input": "2 3", "output": "YES" }, { "input": "2 4", "output": "NO" }, { "input": "3 4", "output": "NO" }, { "input": "3 5", ...
1,629,910,953
2,147,483,647
PyPy 3
OK
TESTS
45
248
20,172,800
primes_50 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] # print(len(primes_50)) n = list(map(int, input().split())) if n[0] in primes_50: j = primes_50.index(n[0]) if j < len(primes_50)-1: if primes_50[j+1] == n[1]: print('YES') else: print("NO") else: print("NO")
Title: Panoramix's Prediction Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is not the next prime number for 2. One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside. Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly *x* Roman soldiers, where *x* is a prime number, and next day they beat exactly *y* Roman soldiers, where *y* is the next prime number after *x*, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song. Yesterday the Gauls beat *n* Roman soldiers and it turned out that the number *n* was prime! Today their victims were a troop of *m* Romans (*m*<=&gt;<=*n*). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix? Input Specification: The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=&lt;<=*m*<=≤<=50). It is guaranteed that *n* is prime. Pretests contain all the cases with restrictions 2<=≤<=*n*<=&lt;<=*m*<=≤<=4. Output Specification: Print YES, if *m* is the next prime number after *n*, or NO otherwise. Demo Input: ['3 5\n', '7 11\n', '7 9\n'] Demo Output: ['YES', 'YES', 'NO'] Note: none
```python primes_50 = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] # print(len(primes_50)) n = list(map(int, input().split())) if n[0] in primes_50: j = primes_50.index(n[0]) if j < len(primes_50)-1: if primes_50[j+1] == n[1]: print('YES') else: print("NO") else: print("NO") ```
3.900425
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617...
1,694,069,002
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
92
0
def main(): line=input() line=line.split() line2=input() line2=line2.split() n=int(line[0]) m=int(line[1]) z=[] for c in line2: z.append(int(c)) z.sort() while len(z)!=n: if z[1]-z[0] > z[-1]-z[-2]: z.pop(0) else: z.pop() print(z[-1]-z[0]) main()
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python def main(): line=input() line=line.split() line2=input() line2=line2.split() n=int(line[0]) m=int(line[1]) z=[] for c in line2: z.append(int(c)) z.sort() while len(z)!=n: if z[1]-z[0] > z[-1]-z[-2]: z.pop(0) else: z.pop() print(z[-1]-z[0]) main() ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output...
1,690,156,021
2,147,483,647
Python 3
OK
TESTS
51
124
102,400
num = input() count = 0 sum = 0 while len(num) != 1: for n in num: sum += int(n) num = str(sum) sum = 0 count += 1 print(count)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python num = input() count = 0 sum = 0 while len(num) != 1: for n in num: sum += int(n) num = str(sum) sum = 0 count += 1 print(count) ```
3.968816
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. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
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,699,727,184
2,147,483,647
Python 3
OK
TESTS
85
92
0
word = input() ds=set(word) if len(ds)%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 thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. Input Specification: The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. Output Specification: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Demo Input: ['wjmzbmr\n', 'xiaodao\n', 'sevenkplus\n'] Demo Output: ['CHAT WITH HER!\n', 'IGNORE HIM!\n', 'CHAT WITH HER!\n'] Note: 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!".
```python word = input() ds=set(word) if len(ds)%2==0: print("CHAT WITH HER!") else: print("IGNORE HIM!") ```
3
99
A
Help Far Away Kingdom
PROGRAMMING
800
[ "strings" ]
A. Help Far Away Kingdom
2
256
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order?
The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data.
If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes).
[ "0.0\n", "1.49\n", "1.50\n", "2.71828182845904523536\n", "3.14159265358979323846\n", "12345678901234567890.1\n", "123456789123456789.999\n" ]
[ "0", "1", "2", "3", "3", "12345678901234567890", "GOTO Vasilisa." ]
none
500
[ { "input": "0.0", "output": "0" }, { "input": "1.49", "output": "1" }, { "input": "1.50", "output": "2" }, { "input": "2.71828182845904523536", "output": "3" }, { "input": "3.14159265358979323846", "output": "3" }, { "input": "12345678901234567890.1", ...
1,634,946,255
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
109
124
4,710,400
#Davidson Lisboa Della Piazza, 169786 from decimal import * import math x = Decimal(input()) inte = x//1 dec = x % 1 intdigs = [int(a) for a in str(inte)] decdigs = [] for i in str(dec): if(i!="."): decdigs.append(i) if(intdigs[-1]!=9): if(dec<0.5): print(inte) else: print(inte+1) else: print("GOTO Vasilisa.")
Title: Help Far Away Kingdom Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Kingdom healers had already had three appointments with the merchants who were asked to sell, say, exactly 0.273549107 beer barrels. To deal with the problem somehow, the King issued an order obliging rounding up all numbers to the closest integer to simplify calculations. Specifically, the order went like this: - If a number's integer part does not end with digit 9 and its fractional part is strictly less than 0.5, then the rounded up number coincides with the number’s integer part. - If a number's integer part does not end with digit 9 and its fractional part is not less than 0.5, the rounded up number is obtained if we add 1 to the last digit of the number’s integer part.- If the number’s integer part ends with digit 9, to round up the numbers one should go to Vasilisa the Wise. In the whole Kingdom she is the only one who can perform the tricky operation of carrying into the next position. Merchants found the algorithm very sophisticated and they asked you (the ACMers) to help them. Can you write a program that would perform the rounding according to the King’s order? Input Specification: The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empty set of decimal digits). The number's length does not exceed 1000 characters, including the dot. There are no other characters in the input data. Output Specification: If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). Demo Input: ['0.0\n', '1.49\n', '1.50\n', '2.71828182845904523536\n', '3.14159265358979323846\n', '12345678901234567890.1\n', '123456789123456789.999\n'] Demo Output: ['0', '1', '2', '3', '3', '12345678901234567890', 'GOTO Vasilisa.'] Note: none
```python #Davidson Lisboa Della Piazza, 169786 from decimal import * import math x = Decimal(input()) inte = x//1 dec = x % 1 intdigs = [int(a) for a in str(inte)] decdigs = [] for i in str(dec): if(i!="."): decdigs.append(i) if(intdigs[-1]!=9): if(dec<0.5): print(inte) else: print(inte+1) else: print("GOTO Vasilisa.") ```
-1
38
B
Chess
PROGRAMMING
1,200
[ "brute force", "implementation", "math" ]
B. Chess
2
256
Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square.
The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide.
Print a single number which is the required number of ways.
[ "a1\nb2\n", "a8\nd4\n" ]
[ "44\n", "38\n" ]
none
0
[ { "input": "a1\nb2", "output": "44" }, { "input": "a8\nd4", "output": "38" }, { "input": "a8\nf1", "output": "42" }, { "input": "f8\nh3", "output": "42" }, { "input": "g8\nb7", "output": "42" }, { "input": "h1\ng5", "output": "42" }, { "inp...
1,681,577,980
2,147,483,647
PyPy 3
OK
TESTS
40
186
0
#######<786>####### #######[_PUTIN Still Alive_]###### ######Let's start rock and Roolllll########### pi="31415926535897932384626433832795"####### ################# ############################### ############################### ############################### '''sudo upgrade && update pip install PUTIN Loading PUTIN...################### 99% done... Download Successfully... from PUTIN import Putin_er_Khel as Conquer ''' # for _ in range(int(input())):s=input();print("wins" if s==s[::-1] else "loses") """ Even death, Putin is The Hero while(true){ printf("I am the fan of PUTIN\n"); } """ x=input() y=input() a1=ord(x[0])-ord('a')+1 b1=int(x[1]) a2=ord(y[0])-ord('a')+1 b2=int(y[1]) r=0 for i in range(1,9): for j in range(1,9): if not((i==a1 or j==b1) or (i==a2 and j==b2) or (abs((i-a1)*(j-b1))==2 or abs((i-a2)*(j-b2))==2)): r+=1 print(r) #for _ in range(int(input())):print("YES" if int(input())>=30 else "NO") # for _ in range(int(input())): # n=int(input()) # s=str(input())[:n] # x=0;y=0 # for i in range(n): # if s[i]=="U":y+=1 # elif s[i]=="D":y-=1 # elif s[i]=="R":x+=1 # else:x-=1 # if x==1 and y==1:print("YES");break # if x!=1 or y!=1:print("NO") # for i in range(int(input())): # v,t=map(int,input().split());print(2*v*t) #// When I wrote this, only ALLAH and I understood what I was doing. # Now, ALLAH only knows. #/* You are not meant to understand this */ """ while(1>0) { 1.Wait here until Vikings PUTIN strike again. 2.PUTIN always support us.. } """ ############################################################################################################################# #### ###### ############## ##### ###### ######## ################ ######### #### ########## ##### ############## ############## ###################### ############### # ############# ######### #### ########## ##### ############## ############## ###################### ############### ### ########### ######### #### ########## ##### ############## ############## ###################### ############### #### ########## ######### #### ########## ##### ############## ############## ###################### ############### ##### ######### ######### #### ########## ##### ############## ############## ###################### ############### ####### ####### ######### #### ##### ############## ############## ###################### ############### ######## ###### ######### #### ################# ############## ############## ###################### ############### ######### ##### ######### #### ################# ############## ############## ###################### ############### ########### ### ######### #### ################# ############## ############## ###################### ############### ############ ## ######### #### ################# ############## ############## ###################### ############### ############# # ######### #### #################### ################# ############### ####### ############## ########### ############################################################################################################################# """ created by Mahid """
Title: Chess Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Two chess pieces, a rook and a knight, stand on a standard chessboard 8<=×<=8 in size. The positions in which they are situated are known. It is guaranteed that none of them beats the other one. Your task is to find the number of ways to place another knight on the board so that none of the three pieces on the board beat another one. A new piece can only be placed on an empty square. Input Specification: The first input line contains the description of the rook's position on the board. This description is a line which is 2 in length. Its first symbol is a lower-case Latin letter from a to h, and its second symbol is a number from 1 to 8. The second line contains the description of the knight's position in a similar way. It is guaranteed that their positions do not coincide. Output Specification: Print a single number which is the required number of ways. Demo Input: ['a1\nb2\n', 'a8\nd4\n'] Demo Output: ['44\n', '38\n'] Note: none
```python #######<786>####### #######[_PUTIN Still Alive_]###### ######Let's start rock and Roolllll########### pi="31415926535897932384626433832795"####### ################# ############################### ############################### ############################### '''sudo upgrade && update pip install PUTIN Loading PUTIN...################### 99% done... Download Successfully... from PUTIN import Putin_er_Khel as Conquer ''' # for _ in range(int(input())):s=input();print("wins" if s==s[::-1] else "loses") """ Even death, Putin is The Hero while(true){ printf("I am the fan of PUTIN\n"); } """ x=input() y=input() a1=ord(x[0])-ord('a')+1 b1=int(x[1]) a2=ord(y[0])-ord('a')+1 b2=int(y[1]) r=0 for i in range(1,9): for j in range(1,9): if not((i==a1 or j==b1) or (i==a2 and j==b2) or (abs((i-a1)*(j-b1))==2 or abs((i-a2)*(j-b2))==2)): r+=1 print(r) #for _ in range(int(input())):print("YES" if int(input())>=30 else "NO") # for _ in range(int(input())): # n=int(input()) # s=str(input())[:n] # x=0;y=0 # for i in range(n): # if s[i]=="U":y+=1 # elif s[i]=="D":y-=1 # elif s[i]=="R":x+=1 # else:x-=1 # if x==1 and y==1:print("YES");break # if x!=1 or y!=1:print("NO") # for i in range(int(input())): # v,t=map(int,input().split());print(2*v*t) #// When I wrote this, only ALLAH and I understood what I was doing. # Now, ALLAH only knows. #/* You are not meant to understand this */ """ while(1>0) { 1.Wait here until Vikings PUTIN strike again. 2.PUTIN always support us.. } """ ############################################################################################################################# #### ###### ############## ##### ###### ######## ################ ######### #### ########## ##### ############## ############## ###################### ############### # ############# ######### #### ########## ##### ############## ############## ###################### ############### ### ########### ######### #### ########## ##### ############## ############## ###################### ############### #### ########## ######### #### ########## ##### ############## ############## ###################### ############### ##### ######### ######### #### ########## ##### ############## ############## ###################### ############### ####### ####### ######### #### ##### ############## ############## ###################### ############### ######## ###### ######### #### ################# ############## ############## ###################### ############### ######### ##### ######### #### ################# ############## ############## ###################### ############### ########### ### ######### #### ################# ############## ############## ###################### ############### ############ ## ######### #### ################# ############## ############## ###################### ############### ############# # ######### #### #################### ################# ############### ####### ############## ########### ############################################################################################################################# """ created by Mahid """ ```
3.9535
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" ...
1,568,818,808
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
307,200
def find(a, b): for i in range(len(a)): if a[i] == b: ans = i return ans d = ["a", "b", "c", "d", "e", "f", "g", "h"] a = input() b = input() a = [find(d, a[0])+1, int(a[1])] b = [find(d, b[0])+1, int(b[1])] h = a[1]-b[1] l = a[0]-b[0] print(max(abs(h), abs(l))) while h !=0 and l != 0: if h == 0: if l>0: l-=1 print("L") else: l += 1 print("R") elif l == 0: if h > 0: h-=1 print("D") else: h +=1 print("U") elif h > 0: h-=1 if l > 0: l-=1 print("LD") else: l+=1 print("RD") elif h < 0: h += 1 if l > 0: l -=1 print("LU") else: l+=1 print("RU")
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). Input Specification: The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output Specification: In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Demo Input: ['a8\nh1\n'] Demo Output: ['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n'] Note: none
```python def find(a, b): for i in range(len(a)): if a[i] == b: ans = i return ans d = ["a", "b", "c", "d", "e", "f", "g", "h"] a = input() b = input() a = [find(d, a[0])+1, int(a[1])] b = [find(d, b[0])+1, int(b[1])] h = a[1]-b[1] l = a[0]-b[0] print(max(abs(h), abs(l))) while h !=0 and l != 0: if h == 0: if l>0: l-=1 print("L") else: l += 1 print("R") elif l == 0: if h > 0: h-=1 print("D") else: h +=1 print("U") elif h > 0: h-=1 if l > 0: l-=1 print("LD") else: l+=1 print("RD") elif h < 0: h += 1 if l > 0: l -=1 print("LU") else: l+=1 print("RU") ```
0
266
A
Stones on the Table
PROGRAMMING
800
[ "implementation" ]
null
null
There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.
The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue.
Print a single integer — the answer to the problem.
[ "3\nRRG\n", "5\nRRRRR\n", "4\nBRBG\n" ]
[ "1\n", "4\n", "0\n" ]
none
500
[ { "input": "3\nRRG", "output": "1" }, { "input": "5\nRRRRR", "output": "4" }, { "input": "4\nBRBG", "output": "0" }, { "input": "1\nB", "output": "0" }, { "input": "2\nBG", "output": "0" }, { "input": "3\nBGB", "output": "0" }, { "input": "...
1,694,274,767
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
60
0
for i in range(int(input())): n=int(input()) b= [int(x) for x in input().split()] t=0 k=False for c in range(1,n): if b[c-1]>b[c]: k=True while k==False: b=[x+1 for x in b] b[-1]=b[-1]-2 for c in range(1,n): if b[c-1]>b[c]: k=True break else: k=False t=t+1
Title: Stones on the Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['3\nRRG\n', '5\nRRRRR\n', '4\nBRBG\n'] Demo Output: ['1\n', '4\n', '0\n'] Note: none
```python for i in range(int(input())): n=int(input()) b= [int(x) for x in input().split()] t=0 k=False for c in range(1,n): if b[c-1]>b[c]: k=True while k==False: b=[x+1 for x in b] b[-1]=b[-1]-2 for c in range(1,n): if b[c-1]>b[c]: k=True break else: k=False t=t+1 ```
-1
960
B
Minimize the error
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed.
The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*.
Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*.
[ "2 0 0\n1 2\n2 3\n", "2 1 0\n1 2\n2 2\n", "2 5 7\n3 4\n14 4\n" ]
[ "2", "0", "1" ]
In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
1,000
[ { "input": "2 0 0\n1 2\n2 3", "output": "2" }, { "input": "2 1 0\n1 2\n2 2", "output": "0" }, { "input": "2 5 7\n3 4\n14 4", "output": "1" }, { "input": "2 0 1\n1 2\n2 2", "output": "0" }, { "input": "2 1 1\n0 0\n1 1", "output": "0" }, { "input": "5 5 ...
1,664,392,049
2,147,483,647
Python 3
OK
TESTS
80
46
0
n, x, y=[int(k) for k in input().split()] w=[int(k) for k in input().split()] z=[int(k) for k in input().split()] q=[abs(w[k]-z[k]) for k in range(n)] length=2**len(bin(len(q))[2:]) eta=[0 for k in range(2*length-1)] for j in range(n): eta[length-1+j]=q[j] def upward(u, k): if k>length-1: return u[k-1] else: u[k-1]=max(upward(u, 2*k), upward(u, 2*k+1)) return u[k-1] def findmax(u, k): if k>length-1: u[k-1]-=1 return k-1 else: if u[2*k-1]>=u[2*k]: return findmax(u, 2*k) else: return findmax(u, 2*k+1) def update(u, k): while k>1: k//=2 u[k-1]=max(u[2*k-1], u[2*k]) #upward(eta, 1) #print(eta) #zxc=findmax(eta, 1) #print(eta) #update(eta, zxc+1) #print(eta) upward(eta, 1) for j in range(x+y): if eta[0]==0: print((x+y-j)%2) break else: zxc=findmax(eta, 1) update(eta, zxc+1) else: res=0 for k in eta[length-1:]: res+=k**2 print(res) #print(eta)
Title: Minimize the error Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. Input Specification: The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*. Output Specification: Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. Demo Input: ['2 0 0\n1 2\n2 3\n', '2 1 0\n1 2\n2 2\n', '2 5 7\n3 4\n14 4\n'] Demo Output: ['2', '0', '1'] Note: In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E* = (1 - 2)<sup class="upper-index">2</sup> + (2 - 3)<sup class="upper-index">2</sup> = 2. In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we increment the first element of *A* by 1. Now, *A* = [2, 2]. The error is now *E* = (2 - 2)<sup class="upper-index">2</sup> + (2 - 2)<sup class="upper-index">2</sup> = 0. This is the minimum possible error obtainable. In the third sample case, we can increase the first element of *A* to 8, using the all of the 5 moves available to us. Also, the first element of *B* can be reduced to 8 using the 6 of the 7 available moves. Now *A* = [8, 4] and *B* = [8, 4]. The error is now *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 4)<sup class="upper-index">2</sup> = 0, but we are still left with 1 move for array *B*. Increasing the second element of *B* to 5 using the left move, we get *B* = [8, 5] and *E* = (8 - 8)<sup class="upper-index">2</sup> + (4 - 5)<sup class="upper-index">2</sup> = 1.
```python n, x, y=[int(k) for k in input().split()] w=[int(k) for k in input().split()] z=[int(k) for k in input().split()] q=[abs(w[k]-z[k]) for k in range(n)] length=2**len(bin(len(q))[2:]) eta=[0 for k in range(2*length-1)] for j in range(n): eta[length-1+j]=q[j] def upward(u, k): if k>length-1: return u[k-1] else: u[k-1]=max(upward(u, 2*k), upward(u, 2*k+1)) return u[k-1] def findmax(u, k): if k>length-1: u[k-1]-=1 return k-1 else: if u[2*k-1]>=u[2*k]: return findmax(u, 2*k) else: return findmax(u, 2*k+1) def update(u, k): while k>1: k//=2 u[k-1]=max(u[2*k-1], u[2*k]) #upward(eta, 1) #print(eta) #zxc=findmax(eta, 1) #print(eta) #update(eta, zxc+1) #print(eta) upward(eta, 1) for j in range(x+y): if eta[0]==0: print((x+y-j)%2) break else: zxc=findmax(eta, 1) update(eta, zxc+1) else: res=0 for k in eta[length-1:]: res+=k**2 print(res) #print(eta) ```
3
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 choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed.
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* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move.
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,441,307
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
46
0
n,m,k = map(int,input().split()) ls = [];f = [];num = 0 for j in range(k): num += 1 a = list(map(int,input().split())) if ls.count(a) == 0: ls.append(a) t = len(ls) if t >= 4: ls.sort(key=lambda x:(x[0],x[1])) for p in range(t): x = ls[p][0];y = ls[p][1] if [x-1,y-1] in ls and [x-1,y] in ls and [x,y-1] in ls: f.append(num) break elif [x-1,y] in ls and [x-1,y+1] in ls and [x,y+1] in ls: f.append(num) break elif [x,y-1] in ls and [x+1,y-1] in ls and [x+1,y] in ls: f.append(num) break elif [x,y+1] in ls and [x+1,y] in ls and [x+1,y+1] in ls: f.append(num) break print(min(f))
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 with *m* pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2<=×<=2 square consisting of black pixels is formed. Pasha has made a plan of *k* moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers *i* and *j*, denoting respectively the row and the column of the pixel to be colored on the current move. Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2<=×<=2 square consisting of black pixels is formed. Input Specification: 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* and *j* (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*j*<=≤<=*m*), representing the row number and column number of the pixel that was painted during a move. Output Specification: 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. Demo Input: ['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'] Demo Output: ['4\n', '5\n', '0\n'] Note: none
```python n,m,k = map(int,input().split()) ls = [];f = [];num = 0 for j in range(k): num += 1 a = list(map(int,input().split())) if ls.count(a) == 0: ls.append(a) t = len(ls) if t >= 4: ls.sort(key=lambda x:(x[0],x[1])) for p in range(t): x = ls[p][0];y = ls[p][1] if [x-1,y-1] in ls and [x-1,y] in ls and [x,y-1] in ls: f.append(num) break elif [x-1,y] in ls and [x-1,y+1] in ls and [x,y+1] in ls: f.append(num) break elif [x,y-1] in ls and [x+1,y-1] in ls and [x+1,y] in ls: f.append(num) break elif [x,y+1] in ls and [x+1,y] in ls and [x+1,y+1] in ls: f.append(num) break print(min(f)) ```
-1
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem.
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95",...
1,617,614,412
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
24
93
0
l,r = list(map(int,input().split())) print(2)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. Input Specification: The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). Output Specification: Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Demo Input: ['19 29\n', '3 6\n'] Demo Output: ['2\n', '3\n'] Note: Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
```python l,r = list(map(int,input().split())) print(2) ```
0
222
B
Cosmic Tables
PROGRAMMING
1,300
[ "data structures", "implementation" ]
null
null
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: - The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly. Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106. Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers. - If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*). The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*.
For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
[ "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n", "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n" ]
[ "8\n9\n6\n", "5\n" ]
Let's see how the table changes in the second test case. After the first operation is fulfilled, the table looks like that: 2 1 4 1 3 5 After the second operation is fulfilled, the table looks like that: 1 3 5 2 1 4 So the answer to the third query (the number located in the first row and in the third column) will be 5.
1,000
[ { "input": "3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2", "output": "8\n9\n6" }, { "input": "2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3", "output": "5" }, { "input": "1 1 15\n1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1 1\ng 1...
1,552,641,229
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
0
of_practical_value = 0 if not of_practical_value: print("The practical value of this problem for me is", of_practical_value)
Title: Cosmic Tables Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an *n*<=×<=*m* table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries: - The query to swap two table rows; - The query to swap two table columns; - The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you. Input Specification: The first line contains three space-separated integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=500000) — the number of table columns and rows and the number of queries, correspondingly. Next *n* lines contain *m* space-separated numbers each — the initial state of the table. Each number *p* in the table is an integer and satisfies the inequality 0<=≤<=*p*<=≤<=106. Next *k* lines contain queries in the format "*s**i* *x**i* *y**i*", where *s**i* is one of the characters "с", "r" or "g", and *x**i*, *y**i* are two integers. - If *s**i* = "c", then the current query is the query to swap columns with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*m*,<=*x*<=≠<=*y*); - If *s**i* = "r", then the current query is the query to swap rows with indexes *x**i* and *y**i* (1<=≤<=*x*,<=*y*<=≤<=*n*,<=*x*<=≠<=*y*); - If *s**i* = "g", then the current query is the query to obtain the number that located in the *x**i*-th row and in the *y**i*-th column (1<=≤<=*x*<=≤<=*n*,<=1<=≤<=*y*<=≤<=*m*). The table rows are considered to be indexed from top to bottom from 1 to *n*, and the table columns — from left to right from 1 to *m*. Output Specification: For each query to obtain a number (*s**i* = "g") print the required number. Print the answers to the queries in the order of the queries in the input. Demo Input: ['3 3 5\n1 2 3\n4 5 6\n7 8 9\ng 3 2\nr 3 2\nc 2 3\ng 2 2\ng 3 2\n', '2 3 3\n1 2 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n'] Demo Output: ['8\n9\n6\n', '5\n'] Note: Let's see how the table changes in the second test case. After the first operation is fulfilled, the table looks like that: 2 1 4 1 3 5 After the second operation is fulfilled, the table looks like that: 1 3 5 2 1 4 So the answer to the third query (the number located in the first row and in the third column) will be 5.
```python of_practical_value = 0 if not of_practical_value: print("The practical value of this problem for me is", of_practical_value) ```
0
49
B
Sum
PROGRAMMING
1,500
[ "math" ]
B. Sum
2
256
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the expression as written in the base *p* positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78<=+<=87 in the base 16 positional notation is equal to *FF*16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length. The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78<=+<=87<==<=? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.
The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands.
Print a single number — the length of the longest answer.
[ "78 87\n", "1 1\n" ]
[ "3\n", "2\n" ]
none
1,000
[ { "input": "78 87", "output": "3" }, { "input": "1 1", "output": "2" }, { "input": "9 7", "output": "2" }, { "input": "11 11", "output": "3" }, { "input": "43 21", "output": "3" }, { "input": "84 89", "output": "3" }, { "input": "12 34", ...
1,678,395,191
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
import math a=input() l=int(max(a))+1 c=list(map(int,a.split(' '))) b=c[0]+c[1] print(math.floor(math.log(b,l))+1)
Title: Sum Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying *a*<=+<=*b*<==<=?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base *p* and regard the expression as written in the base *p* positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78<=+<=87 in the base 16 positional notation is equal to *FF*16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length. The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78<=+<=87<==<=? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones. Input Specification: The first letter contains two space-separated numbers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=1000) which represent the given summands. Output Specification: Print a single number — the length of the longest answer. Demo Input: ['78 87\n', '1 1\n'] Demo Output: ['3\n', '2\n'] Note: none
```python import math a=input() l=int(max(a))+1 c=list(map(int,a.split(' '))) b=c[0]+c[1] print(math.floor(math.log(b,l))+1) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "outpu...
1,619,187,677
2,147,483,647
Python 3
OK
TESTS
35
156
0
x, y = map(int,input().split()) res = x*y #if( (x % 2) and (y % 2)): # res-= 1 print(int(res/2))
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python x, y = map(int,input().split()) res = x*y #if( (x % 2) and (y % 2)): # res-= 1 print(int(res/2)) ```
3.961
789
A
Anastasia and pebbles
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket.
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type.
The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles.
[ "3 2\n2 3 4\n", "5 4\n3 1 8 9 7\n" ]
[ "3\n", "5\n" ]
In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
500
[ { "input": "3 2\n2 3 4", "output": "3" }, { "input": "5 4\n3 1 8 9 7", "output": "5" }, { "input": "1 22\n1", "output": "1" }, { "input": "3 57\n78 165 54", "output": "3" }, { "input": "5 72\n74 10 146 189 184", "output": "6" }, { "input": "9 13\n132 8...
1,595,571,360
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
1,000
7,270,400
n,k = map(int,input().split()) arr = list(map(int,input().split())) ans=0 d=0 i=0 while sum(arr)!=0: if i==n: i=0 continue if arr[i]!=0: if arr[i]<=k: d+=1 arr[i]=0 elif arr[i]>k: arr[i]-=k d+=1 if d==2: ans+=1 d=0 i+=1 if d==1: print(ans+1) else: print(ans)
Title: Anastasia and pebbles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park. She has only two pockets. She can put at most *k* pebbles in each pocket at the same time. There are *n* different pebble types in the park, and there are *w**i* pebbles of the *i*-th type. Anastasia is very responsible, so she never mixes pebbles of different types in same pocket. However, she can put different kinds of pebbles in different pockets at the same time. Unfortunately, she can't spend all her time collecting pebbles, so she can collect pebbles from the park only once a day. Help her to find the minimum number of days needed to collect all the pebbles of Uzhlyandian Central Park, taking into consideration that Anastasia can't place pebbles of different types in same pocket. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. Output Specification: The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. Demo Input: ['3 2\n2 3 4\n', '5 4\n3 1 8 9 7\n'] Demo Output: ['3\n', '5\n'] Note: In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day. Optimal sequence of actions in the second sample case: - In the first day Anastasia collects 8 pebbles of the third type. - In the second day she collects 8 pebbles of the fourth type. - In the third day she collects 3 pebbles of the first type and 1 pebble of the fourth type. - In the fourth day she collects 7 pebbles of the fifth type. - In the fifth day she collects 1 pebble of the second type.
```python n,k = map(int,input().split()) arr = list(map(int,input().split())) ans=0 d=0 i=0 while sum(arr)!=0: if i==n: i=0 continue if arr[i]!=0: if arr[i]<=k: d+=1 arr[i]=0 elif arr[i]>k: arr[i]-=k d+=1 if d==2: ans+=1 d=0 i+=1 if d==1: print(ans+1) else: print(ans) ```
0
862
B
Mahmoud and Ehab and the bipartiteness
PROGRAMMING
1,300
[ "dfs and similar", "graphs", "trees" ]
null
null
Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .
The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.
Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.
[ "3\n1 2\n1 3\n", "5\n1 2\n2 3\n3 4\n4 5\n" ]
[ "0\n", "2\n" ]
Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
1,000
[ { "input": "3\n1 2\n1 3", "output": "0" }, { "input": "5\n1 2\n2 3\n3 4\n4 5", "output": "2" }, { "input": "10\n3 8\n6 2\n9 7\n10 1\n3 5\n1 3\n6 7\n5 4\n3 6", "output": "16" }, { "input": "10\n7 6\n2 7\n4 1\n8 5\n9 4\n5 3\n8 7\n10 8\n10 4", "output": "16" }, { "in...
1,562,494,397
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
16
530
12,697,600
WHITE, BLACK = 0, 1 def dfs(adj, node_colors, k, color): node_colors[k] = color for i in range(len(adj[k])): if node_colors[adj[k][i]] == -1: dfs(adj, node_colors, adj[k][i], 1 - color) n = int(input()) adj = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) node_colors = [-1] * n dfs(adj, node_colors, 0, WHITE) n_nodes = (node_colors.count(WHITE), node_colors.count(BLACK)) print(sum([n_nodes[1 - node_colors[i]] - len(adj[i]) for i in range(n)]) // 2)
Title: Mahmoud and Ehab and the bipartiteness Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees. A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (*u*,<=*v*) that belongs to the graph, *u* and *v* belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below. Dr. Evil gave Mahmoud and Ehab a tree consisting of *n* nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add? A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same . Input Specification: The first line of input contains an integer *n* — the number of nodes in the tree (1<=≤<=*n*<=≤<=105). The next *n*<=-<=1 lines contain integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*) — the description of the edges of the tree. It's guaranteed that the given graph is a tree. Output Specification: Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions. Demo Input: ['3\n1 2\n1 3\n', '5\n1 2\n2 3\n3 4\n4 5\n'] Demo Output: ['0\n', '2\n'] Note: Tree definition: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)) Bipartite graph definition: [https://en.wikipedia.org/wiki/Bipartite_graph](https://en.wikipedia.org/wiki/Bipartite_graph) In the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0. In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).
```python WHITE, BLACK = 0, 1 def dfs(adj, node_colors, k, color): node_colors[k] = color for i in range(len(adj[k])): if node_colors[adj[k][i]] == -1: dfs(adj, node_colors, adj[k][i], 1 - color) n = int(input()) adj = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) adj[a - 1].append(b - 1) adj[b - 1].append(a - 1) node_colors = [-1] * n dfs(adj, node_colors, 0, WHITE) n_nodes = (node_colors.count(WHITE), node_colors.count(BLACK)) print(sum([n_nodes[1 - node_colors[i]] - len(adj[i]) for i in range(n)]) // 2) ```
-1
389
A
Fox and Number Game
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum.
The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100).
Output a single integer — the required minimal sum.
[ "2\n1 2\n", "3\n2 4 6\n", "2\n12 18\n", "5\n45 12 27 30 18\n" ]
[ "2\n", "6\n", "12\n", "15\n" ]
In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 4 6", "output": "6" }, { "input": "2\n12 18", "output": "12" }, { "input": "5\n45 12 27 30 18", "output": "15" }, { "input": "2\n1 1", "output": "2" }, { "input": "2\n100 100", "output": "200" ...
1,679,121,646
2,147,483,647
Python 3
OK
TESTS
34
46
0
n=int(input()) a=list(map(int,input().split(' '))) a.sort() while(n): x=max(a) y=min(a) xi=a.index(x) if x>y: a[xi]=x-y else: break print(sum(a))
Title: Fox and Number Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel is playing a game with numbers now. Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* &gt; *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. Please help Ciel to find this minimal sum. Input Specification: The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the required minimal sum. Demo Input: ['2\n1 2\n', '3\n2 4 6\n', '2\n12 18\n', '5\n45 12 27 30 18\n'] Demo Output: ['2\n', '6\n', '12\n', '15\n'] Note: In the first example the optimal way is to do the assignment: *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>. In the second example the optimal sequence of operations is: *x*<sub class="lower-index">3</sub> = *x*<sub class="lower-index">3</sub> - *x*<sub class="lower-index">2</sub>, *x*<sub class="lower-index">2</sub> = *x*<sub class="lower-index">2</sub> - *x*<sub class="lower-index">1</sub>.
```python n=int(input()) a=list(map(int,input().split(' '))) a.sort() while(n): x=max(a) y=min(a) xi=a.index(x) if x>y: a[xi]=x-y else: break print(sum(a)) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "ou...
1,634,538,324
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
13,721,600
from math import gcd a,b=list(map(int,input().split())) f=1 f1=1 for i in range(2,a+1): f*=i for j in range(2,b+1): f1*=j print(gcd(f1, f))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python from math import gcd a,b=list(map(int,input().split())) f=1 f1=1 for i in range(2,a+1): f*=i for j in range(2,b+1): f1*=j print(gcd(f1, f)) ```
0
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 Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
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,658,250,080
2,147,483,647
PyPy 3-64
OK
TESTS
20
61
0
size=input().split() n,m,a=size width=int(n)/int(a) if int(n)%int(a)>0: width=int(width)+1 height=int(m)/int(a) if int(m)%int(a)>0: height=int(height)+1 print(int(height*width))
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 flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python size=input().split() n,m,a=size width=int(n)/int(a) if int(n)%int(a)>0: width=int(width)+1 height=int(m)/int(a) if int(m)%int(a)>0: height=int(height)+1 print(int(height*width)) ```
3.9695
12
C
Fruits
PROGRAMMING
1,100
[ "greedy", "implementation", "sortings" ]
C. Fruits
1
256
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).
The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy.
Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
[ "5 3\n4 2 1 10 5\napple\norange\nmango\n", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n" ]
[ "7 19\n", "11 30\n" ]
none
0
[ { "input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19" }, { "input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30" }, { "input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl", "output": "173 173" }, { "input"...
1,615,589,221
2,147,483,647
PyPy 3
OK
TESTS
25
124
307,200
from collections import Counter n, m = [int(x) for x in input().split()] p = [int(x) for x in input().split()] p = sorted(p) pu = sorted(p, reverse = True) f = [] tl = 0 tu = 0 for i in range(m): f.append(input()) fru = list(Counter(f).values()) fru = sorted(fru, reverse = True) for i in range(len(fru)): tl += fru[i] * p[i] tu += fru[i] * pu[i] print(tl, tu)
Title: Fruits Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input Specification: The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Specification: Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Demo Input: ['5 3\n4 2 1 10 5\napple\norange\nmango\n', '6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n'] Demo Output: ['7 19\n', '11 30\n'] Note: none
```python from collections import Counter n, m = [int(x) for x in input().split()] p = [int(x) for x in input().split()] p = sorted(p) pu = sorted(p, reverse = True) f = [] tl = 0 tu = 0 for i in range(m): f.append(input()) fru = list(Counter(f).values()) fru = sorted(fru, reverse = True) for i in range(len(fru)): tl += fru[i] * p[i] tu += fru[i] * pu[i] print(tl, tu) ```
3.937428
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 she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
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,680,710,046
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
0
k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) if k == 1 or l == 1 or m == 1 or n == 1: print(d) else: hk = [i for i in range(1, d+1) if i % k == 0] hl = [i for i in range(1, d+1) if i % l == 0 and i not in hk] hm = [i for i in range(1, d+1) if i % m == 0 and i not in hl and i not in hk] hn = [i for i in range(1, d+1) if i % n == 0 and i not in hm and i not in hm and i not in hl and i not in hk] print(len(hk) + len(hl) + len(hm) + len(hn))
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 entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: 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 Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: 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.
```python k = int(input()) l = int(input()) m = int(input()) n = int(input()) d = int(input()) if k == 1 or l == 1 or m == 1 or n == 1: print(d) else: hk = [i for i in range(1, d+1) if i % k == 0] hl = [i for i in range(1, d+1) if i % l == 0 and i not in hk] hm = [i for i in range(1, d+1) if i % m == 0 and i not in hl and i not in hk] hn = [i for i in range(1, d+1) if i % n == 0 and i not in hm and i not in hm and i not in hl and i not in hk] print(len(hk) + len(hl) + len(hm) + len(hn)) ```
0
0
none
none
none
0
[ "none" ]
null
null
You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones?
The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consisting of zeros and ones.
Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations.
[ "5 1 10\n01000\n", "5 10 1\n01000\n", "7 2 3\n1111111\n" ]
[ "11\n", "2\n", "0\n" ]
In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «10000» $\to$ «11111». The total cost of operations is $1 + 10 = 11$. In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «11000» $\to$ «11111». The overall cost is $1 + 1 = 2$. In the third example, string already consists only of ones, so the answer is $0$.
0
[ { "input": "5 1 10\n01000", "output": "11" }, { "input": "5 10 1\n01000", "output": "2" }, { "input": "7 2 3\n1111111", "output": "0" }, { "input": "1 60754033 959739508\n0", "output": "959739508" }, { "input": "1 431963980 493041212\n1", "output": "0" }, ...
1,569,651,478
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
108
0
n,x,y=map(int,input().split()) s=str(input()) if(s[0]=="0"): c=1 else: c=0 for i in range(1,n): if(s[i]=="0" and s[i]!=s[i-1]): c+=1 #print(c) print(((c-1)*(min(x,y)))+y)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? Input Specification: The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consisting of zeros and ones. Output Specification: Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. Demo Input: ['5 1 10\n01000\n', '5 10 1\n01000\n', '7 2 3\n1111111\n'] Demo Output: ['11\n', '2\n', '0\n'] Note: In the first sample, at first you need to reverse substring $[1 \dots 2]$, and then you need to invert substring $[2 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «10000» $\to$ «11111». The total cost of operations is $1 + 10 = 11$. In the second sample, at first you need to invert substring $[1 \dots 1]$, and then you need to invert substring $[3 \dots 5]$. Then the string was changed as follows: «01000» $\to$ «11000» $\to$ «11111». The overall cost is $1 + 1 = 2$. In the third example, string already consists only of ones, so the answer is $0$.
```python n,x,y=map(int,input().split()) s=str(input()) if(s[0]=="0"): c=1 else: c=0 for i in range(1,n): if(s[i]=="0" and s[i]!=s[i-1]): c+=1 #print(c) print(((c-1)*(min(x,y)))+y) ```
0
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. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates.
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* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct.
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,465,036,471
2,147,483,647
Python 3
OK
TESTS
76
372
5,939,200
import bisect,sys import queue from collections import deque, namedtuple sys.setrecursionlimit(20000) N = 105 visited = [0]*N adj = [(0,0)]*N def dfs(s,n): x,y = adj[s][0],adj[s][1] visited[s] = 1 for i in range(n): if (not visited[i]) and (adj[i][0] == x or adj[i][1] == y): dfs(i,n) def main(): n,ans = int(input()),0 for _ in range(n): adj[_] = tuple(map(int,input().split())) for _ in range(n): if not visited[_]: ans += 1 visited[_] = 1 dfs(_,n) print(ans-1) if __name__ == "__main__": main()
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 that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. Input Specification: 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* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. Output Specification: 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. Demo Input: ['2\n2 1\n1 2\n', '2\n2 1\n4 1\n'] Demo Output: ['1\n', '0\n'] Note: none
```python import bisect,sys import queue from collections import deque, namedtuple sys.setrecursionlimit(20000) N = 105 visited = [0]*N adj = [(0,0)]*N def dfs(s,n): x,y = adj[s][0],adj[s][1] visited[s] = 1 for i in range(n): if (not visited[i]) and (adj[i][0] == x or adj[i][1] == y): dfs(i,n) def main(): n,ans = int(input()),0 for _ in range(n): adj[_] = tuple(map(int,input().split())) for _ in range(n): if not visited[_]: ans += 1 visited[_] = 1 dfs(_,n) print(ans-1) if __name__ == "__main__": main() ```
3
492
A
Vanya and Cubes
PROGRAMMING
800
[ "implementation" ]
null
null
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.
The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya.
Print the maximum possible height of the pyramid in the single line.
[ "1\n", "25\n" ]
[ "1\n", "4\n" ]
Illustration to the second sample:
500
[ { "input": "1", "output": "1" }, { "input": "25", "output": "4" }, { "input": "2", "output": "1" }, { "input": "4115", "output": "28" }, { "input": "9894", "output": "38" }, { "input": "7969", "output": "35" }, { "input": "6560", "outpu...
1,686,972,185
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
n=int(input()) a=0 x=0 v=0 while a<n: x+=1 a=a+x n=n-a v+=1 print(v)
Title: Vanya and Cubes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. Output Specification: Print the maximum possible height of the pyramid in the single line. Demo Input: ['1\n', '25\n'] Demo Output: ['1\n', '4\n'] Note: Illustration to the second sample:
```python n=int(input()) a=0 x=0 v=0 while a<n: x+=1 a=a+x n=n-a v+=1 print(v) ```
0
811
A
Vladik and Courtesy
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy.
Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively.
Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise.
[ "1 1\n", "7 6\n" ]
[ "Valera\n", "Vladik\n" ]
Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "1 1", "output": "Valera" }, { "input": "7 6", "output": "Vladik" }, { "input": "25 38", "output": "Vladik" }, { "input": "8311 2468", "output": "Valera" }, { "input": "250708 857756", "output": "Vladik" }, { "input": "957985574 24997558", ...
1,609,223,951
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
33
139
1,433,600
a,b=map(int,input().split()) i=1 f=0 while a >= i or b >= i: if i%2==0: b-=i f=0 else: a-=i f=1 i+=1 if f: print("Valera") else: print("Vladik")
Title: Vladik and Courtesy Time Limit: None seconds Memory Limit: None megabytes Problem Description: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. Input Specification: Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. Output Specification: Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Demo Input: ['1 1\n', '7 6\n'] Demo Output: ['Valera\n', 'Vladik\n'] Note: Illustration for first test case: <img class="tex-graphics" src="https://espresso.codeforces.com/ad9b7d0e481208de8e3a585aa1d96b9e1dda4fd7.png" style="max-width: 100.0%;max-height: 100.0%;"/> Illustration for second test case: <img class="tex-graphics" src="https://espresso.codeforces.com/9f4836d2ccdffaee5a63898e5d4e6caf2ed4678c.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python a,b=map(int,input().split()) i=1 f=0 while a >= i or b >= i: if i%2==0: b-=i f=0 else: a-=i f=1 i+=1 if f: print("Valera") else: print("Vladik") ```
0
994
A
Fingerprints
PROGRAMMING
800
[ "implementation" ]
null
null
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints.
In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.
[ "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "4 4\n3 4 1 0\n0 1 7 9\n" ]
[ "7 1 2\n", "1 0\n" ]
In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
500
[ { "input": "7 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2" }, { "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0" }, { "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8", "output": "8 6 4 2" }, { "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9", "output": "3 7 4 9 0" }, { "...
1,629,887,704
2,147,483,647
Python 3
OK
TESTS
31
62
6,758,400
n,m=[int(_) for (_) in input().split()] l=list(map(int,input().split()))[:n] p=list(map(int,input().split()))[:m] x=[] for i in l: if i in p: x.append(i) print(*(x))
Title: Fingerprints Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. Input Specification: The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. Output Specification: In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. Demo Input: ['7 3\n3 5 7 1 6 2 8\n1 2 7\n', '4 4\n3 4 1 0\n0 1 7 9\n'] Demo Output: ['7 1 2\n', '1 0\n'] Note: In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important.
```python n,m=[int(_) for (_) in input().split()] l=list(map(int,input().split()))[:n] p=list(map(int,input().split()))[:m] x=[] for i in l: if i in p: x.append(i) print(*(x)) ```
3
656
F
Ace It!
PROGRAMMING
1,900
[ "*special" ]
null
null
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer.
The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid").
Output a single integer.
[ "A221033\n", "A223635\n", "A232726\n" ]
[ "21\n", "22\n", "23\n" ]
none
0
[ { "input": "A221033", "output": "21" }, { "input": "A223635", "output": "22" }, { "input": "A232726", "output": "23" }, { "input": "A102210", "output": "25" }, { "input": "A231010", "output": "26" }, { "input": "A222222", "output": "13" }, { ...
1,459,533,252
6,851
Python 3
WRONG_ANSWER
TESTS
3
62
5,017,600
pre = """A000527 52 A001134 113 A001520 15 A001986 19 A002155 15 A004810 10 A004811 11 A004812 12 A005110 11 A006614 14 A006615 15 A006616 16 A007304 30 A008710 10 A008879 87 A008900 89 A008901 90 A010171 10 A010172 10 A010173 10 A010174 10 A010175 10 A010176 10 A010177 10 A010178 10 A010179 10 A010180 10 A010181 10 A010182 10 A010183 10 A010184 10 A010212 12 A010569 10 A010692 10 A011753 11 A013718 13 A013752 13 A013798 13 A013866 13 A014136 36 A014313 31 A015226 22 A015831 15 A015876 15 A015979 59 A016792 16 A016828 16 A016876 16 A016898 16 A016936 16 A016958 16 A017416 16 A017427 27 A018823 18 A019360 19 A019384 19 A019393 19 A020143 14 A020211 21 A020250 25 A020258 25 A020325 25 A022011 11 A022978 22 A022985 29 A023264 23 A023278 23 A023295 23 A023338 233 A023679 23 A025283 25 A025378 78 A027182 18 A027500 27 A027786 78 A029817 17 A031028 10 A031077 10 A031105 10 A031119 11 A031167 11 A031174 117 A031207 12 A031339 13 A031373 13 A031382 13 A031390 13 A031415 41 A031464 64 A031486 48 A031704 170 A033176 31 A033353 33 A033355 35 A033824 24 A034025 25 A034107 10 A035123 12 A036329 32 A036510 36 A036785 36 A036927 27 A037932 32 A039332 32 A039353 39 A039360 36 A039363 63 A039422 39 A039441 44 A039467 39 A039531 53 A039552 95 A039600 96 A039833 33 A040109 10 A040110 11 A040111 11 A040118 11 A040136 13 A040215 15 A040318 18 A040421 21 A040523 23 A040625 25 A040727 27 A040829 29 A040931 31 A041210 10 A041264 12 A041266 12 A041268 12 A041270 12 A041272 12 A041274 12 A041276 12 A041278 12 A041280 12 A041282 12 A041284 12 A041286 12 A041288 12 A041290 12 A041292 12 A041294 12 A041296 12 A041298 12 A041312 13 A041314 13 A041316 13 A041318 13 A041320 13 A041322 13 A041324 13 A041326 13 A041328 13 A041330 13 A041332 13 A041334 13 A041336 13 A041338 13 A041340 13 A041342 13 A041344 13 A041346 13 A041348 13 A041350 13 A041352 13 A041354 13 A041356 13 A041358 13 A041360 13 A041362 13 A041400 14 A041402 14 A041404 14 A041406 14 A041408 14 A041410 14 A041412 14 A041414 14 A041416 14 A041418 14 A041516 16 A041618 18 A041820 20 A042124 24 A042250 25 A042252 25 A042254 25 A042256 25 A042258 25 A042326 26 A042528 28 A042830 30 A042967 29 A042969 29 A042973 29 A043107 10 A043113 13 A043114 14 A043118 18 A043135 35 A043173 31 A043181 18 A043202 32 A043208 43 A043233 23 A043375 43 A043400 400 A043956 39 A043988 43 A044107 41 A044113 11 A044153 15 A044179 41 A044182 44 A044207 20 A044229 42 A044231 44 A044278 27 A044293 42 A044295 44 A044368 36 A044375 43 A044376 44 A044522 52 A044563 44 A044564 45 A044612 44 A044614 46 A044631 63 A044676 44 A044678 46 A044702 70 A044757 44 A044760 47 A044792 79 A044864 64 A044982 82 A045118 511 A045189 18 A045207 20 A045249 24 A045268 68 A045566 45 A046117 11 A046301 30 A046455 64 A047948 47 A048126 26 A050234 23 A050439 39 A050944 44 A051310 13 A051315 31 A051392 13 A051419 14 A051779 17 A051983 519 A052230 23 A053014 30 A053070 53 A053236 23 A053652 53 A053736 53 A054032 32 A055310 10 A055311 11 A055312 12 A055313 13 A057800 78 A057803 78 A057806 78 A059164 16 A059256 59 A060061 61 A060225 60 A060229 29 A060259 59 A060489 60 A060512 60 A060513 60 A060936 36 A061016 10 A061116 11 A061157 11 A061381 13 A061550 15 A061759 59 A062661 61 A063470 34 A063710 10 A063913 13 A064267 26 A064399 39 A064561 45 A064816 16 A065915 15 A066024 24 A068405 84 A069295 29 A069795 79 A070179 17 A070332 32 A071263 12 A071279 12 A072244 24 A072412 72 A072711 11 A073319 19 A073567 35 A073761 61 A075589 89 A076130 13 A077263 63 A077711 11 A078138 13 A079130 13 A080933 33 A081062 10 A081317 13 A081702 17 A082128 21 A082452 45 A082972 82 A083310 10 A083511 11 A084224 24 A085413 13 A085482 54 A085625 25 A086126 61 A086711 11 A087530 53 A088188 81 A088993 89 A089113 13 A089158 89 A089296 29 A089297 29 A089823 23 A090635 63 A091022 10 A091216 16 A091832 18 A091896 18 A092212 22 A092215 22 A092221 22 A092770 27 A092995 29 A094203 20 A094552 52 A095318 31 A095527 52 A095539 53 A095541 54 A097205 72 A097439 39 A097459 59 A098116 11 A098413 13 A099103 10 A099115 11 A099911 11 A100316 16 A100500 10 A100813 10 A100830 10 A100844 10 A100916 10 A100929 10 A100992 10 A101145 11 A101156 10 A101188 18 A101467 10 A101795 179 A101869 10 A102130 13 A102249 10 A102357 10 A102361 10 A102362 10 A102488 10 A102490 10 A102492 10 A102494 10 A102502 10 A102542 10 A102546 10 A102690 10 A102695 10 A102708 27 A102850 10 A102906 29 A103098 30 A103208 10 A103325 32 A103611 11 A103618 10 A103757 10 A104044 10 A104045 10 A104118 11 A104128 10 A104130 10 A104132 13 A104213 13 A104218 18 A104341 10 A104486 10 A104520 10 A104645 10 A104788 10 A104801 10 A104863 10 A104865 10 A104867 10 A104868 10 A104869 10 A104935 49 A105155 10 A105156 10 A105162 10 A105938 10 A105959 10 A105991 10 A106134 13 A106414 41 A106695 10 A106755 67 A106789 10 A107126 10 A107175 17 A107215 107 A107258 25 A107781 10 A107787 77 A107830 10 A107954 79 A108580 10 A108584 10 A108603 10 A108614 10 A108697 10 A108703 10 A108777 10 A108792 10 A108793 10 A108892 10 A108965 10 A109013 10 A109100 10 A109211 21 A109279 10 A109280 10 A109334 10 A109373 10 A109394 10 A109597 10 A109604 10 A109644 44 A109751 10 A109893 10 A109958 10 A109959 10 A110044 11 A110059 11 A110089 11 A110093 11 A110186 10 A110368 10 A110383 11 A110398 11 A110402 11 A110403 11 A110406 11 A110408 11 A110410 10 A110411 41 A110414 11 A110415 11 A110418 10 A110429 10 A110434 11 A110435 11 A110463 10 A110466 11 A110732 11 A110733 11 A110735 110 A110736 110 A110743 11 A110745 11 A110747 11 A110767 11 A110774 11 A110776 11 A110780 11 A110782 11 A110786 11 A110798 11 A110799 11 A110804 10 A110831 31 A110934 10 A111015 11 A111070 11 A111080 11 A111151 15 A111255 11 A111257 11 A111322 11 A111334 11 A111337 11 A111347 11 A111380 13 A111463 11 A111477 11 A111478 11 A111872 18 A111931 11 A112033 12 A112054 12 A112063 11 A112131 12 A112134 11 A112386 11 A112415 12 A112548 12 A112733 11 A112769 12 A112795 79 A112854 11 A112880 12 A113017 13 A113172 13 A113316 16 A113403 11 A113548 13 A113579 13 A113585 11 A113587 11 A113600 11 A113601 13 A113615 11 A113616 11 A113831 13 A113943 13 A114012 14 A114120 11 A114167 11 A114354 11 A114382 14 A114445 11 A114504 50 A114754 11 A114758 11 A114821 48 A114872 14 A114948 11 A114962 14 A114985 14 A115132 132 A115174 15 A115480 48 A115560 11 A115565 11 A115595 11 A115737 11 A115768 11 A115776 15 A115811 15 A115853 11 A115912 12 A115972 11 A116011 11 A116055 55 A116057 11 A116059 11 A116061 11 A116098 11 A116102 16 A116124 61 A116129 11 A116190 16 A116193 11 A116270 62 A116610 10 A116999 11 A117047 11 A117293 11 A117314 11 A117390 17 A117697 11 A117873 11 A117874 17 A118133 11 A118293 18 A118359 83 A118512 11 A118513 13 A118572 11 A118592 11 A118638 11 A118648 11 A118798 79 A118922 89 A118936 11 A118937 11 A119247 11 A119555 19 A119667 196 A119742 11 A119890 11 A120090 12 A120141 14 A120145 20 A120159 15 A120169 12 A120210 20 A120356 12 A120360 12 A120570 12 A120571 12 A120644 12 A120692 20 A120693 20 A121030 10 A121032 12 A121155 11 A121171 11 A121495 14 A121594 15 A121628 21 A121683 216 A121710 17 A121851 18 A121938 19 A121985 12 A122040 12 A122242 42 A122253 12 A122500 25 A122878 12 A123132 12 A123171 123 A123213 21 A123238 32 A123711 12 A123782 23 A123933 12 A123980 12 A123983 12 A124110 11 A124140 24 A124144 144 A124205 12 A124206 12 A124238 38 A124269 12 A124283 24 A124337 37 A124351 12 A124517 17 A124521 12 A124626 12 A124657 24 A124672 12 A125197 19 A125290 12 A125638 63 A125664 12 A125998 12 A126170 126 A126195 12 A126272 27 A126687 12 A126706 12 A126763 12 A126766 76 A126855 12 A127146 12 A127354 12 A127401 12 A127422 12 A127579 127 A127869 12 A128043 12 A129006 12 A129197 12 A129287 29 A129367 36 A129498 12 A129639 12 A129813 29 A129887 98 A129939 12 A130038 30 A130281 28 A130310 10 A130611 13 A130621 13 A130817 17 A130868 13 A131019 13 A131021 13 A131541 15 A131557 55 A131633 31 A131700 13 A131762 31 A131992 31 A132067 20 A132156 13 A132233 13 A132235 23 A132260 13 A132261 13 A132300 32 A132386 13 A132420 24 A132485 13 A132540 25 A132542 13 A132580 13 A132585 25 A132946 13 A132947 13 A133534 35 A133901 33 A134070 13 A134159 13 A134196 19 A134257 13 A134550 13 A134814 14 A134864 13 A135024 13 A135172 13 A135189 18 A135241 13 A135283 13 A135535 13 A135971 13 A136191 13 A136316 13 A136359 36 A136373 13 A136773 13 A137188 13 A137194 13 A137263 26 A137411 11 A137675 37 A137724 37 A137833 37 A137834 37 A138353 13 A138368 13 A138375 13 A138535 13 A138596 13 A138604 60 A138685 13 A138686 13 A138931 13 A139070 13 A139103 10 A139106 10 A139109 10 A139113 11 A139114 11 A139157 13 A139166 16 A139168 13 A139228 22 A139311 11 A139494 13 A139530 13 A139610 10 A139611 11 A139612 12 A139613 13 A139614 14 A139615 15 A139616 16 A139617 17 A139618 18 A139619 19 A139620 20 A139838 13 A139849 13 A139860 13 A139863 13 A139866 13 A139873 13 A139880 13 A139911 13 A139926 13 A139974 13 A140212 12 A140619 19 A140702 40 A140729 40 A140739 14 A140784 14 A140798 140 A141174 17 A141195 11 A141274 12 A141682 16 A141838 14 A141842 18 A141881 41 A141898 41 A141922 41 A141923 19 A141931 31 A141939 41 A141942 19 A141957 41 A141960 19 A141973 19 A141988 41 A141995 19 A142190 19 A142241 14 A142302 23 A142324 23 A142374 23 A142411 41 A142671 67 A142837 283 A142865 14 A142905 29 A142938 29 A143204 14 A143754 75 A144552 45 A144585 14 A144928 49 A145188 14 A145319 45 A145332 53 A145510 10 A145528 455 A145693 14 A146563 14 A151900 19 A152099 15 A152161 21 A152246 15 A152294 29 A152586 15 A152587 15 A152962 29 A153465 34 A153642 36 A154060 15 A154267 15 A154369 15 A154410 10 A154806 15 A154810 10 A154988 15 A155111 15 A155573 73 A155711 11 A156063 15 A156110 11 A156849 156 A157137 15 A157352 35 A157446 15 A157643 15 A157651 57 A158238 23 A158287 287 A158339 39 A158402 840 A158482 15 A158490 90 A158529 29 A158557 15 A158771 77 A159404 40 A159446 46 A160130 13 A160778 16 A160917 60 A161424 16 A161454 14 A161723 23 A161735 17 A161851 16 A161853 61 A161874 16 A161884 16 A161914 14 A162008 16 A162422 22 A162451 24 A162465 24 A162819 16 A163113 13 A163935 35 A164324 16 A164337 64 A164413 13 A165117 16 A165121 16 A165158 65 A165160 16 A165338 16 A165373 37 A165798 65 A166112 16 A166394 63 A166595 16 A166710 10 A167062 16 A167471 16 A167574 167 A167690 16 A167741 41 A167824 24 A167997 16 A168100 10 A168103 10 A168576 16 A169834 34 A169882 16 A171125 11 A171168 17 A171169 17 A171242 242 A171286 12 A171291 17 A171304 30 A171318 13 A171322 17 A171569 15 A171687 17 A171704 17 A171748 17 A171766 17 A171954 17 A172280 17 A172287 17 A172424 24 A172456 17 A172521 17 A173054 17 A173647 17 A173727 72 A173728 72 A174214 14 A174380 17 A174408 17 A174601 60 A174819 19 A175161 16 A175384 17 A175602 56 A175710 10 A175960 17 A176254 17 A176622 17 A176783 17 A176810 10 A176838 17 A177076 17 A177112 12 A177135 17 A177378 37 A177418 41 A177835 17 A178050 17 A178424 17 A178634 63 A178716 17 A178917 89 A179038 17 A179039 17 A179093 17 A179157 17 A179512 12 A179816 17 A179818 17 A180113 11 A180117 18 A180553 53 A181147 11 A181149 14 A181150 11 A181182 11 A181223 81 A181262 126 A181453 18 A181460 46 A181711 18 A181761 18 A182052 18 A182226 18 A182277 82 A182286 18 A182311 18 A182329 29 A182464 24 A183215 32 A183427 27 A183498 18 A183523 23 A183616 36 A184086 86 A184126 84 A184190 19 A184539 45 A184540 45 A184548 45 A184710 10 A184764 64 A185099 18 A185499 99 A185884 588 A186122 18 A186129 18 A186158 18 A186261 26 A186398 186 A186441 64 A186781 18 A186811 11 A187710 10 A188212 18 A188522 88 A188606 88 A188613 88 A188717 17 A188762 88 A188850 88 A188857 88 A188991 88 A189156 15 A189612 12 A189777 97 A190267 19 A190524 24 A190715 15 A191047 19 A191111 11 A191514 51 A191915 15 A192130 21 A192491 24 A192505 19 A195117 11 A195461 19 A195615 15 A195749 19 A195756 19 A196028 28 A196114 11 A196117 11 A196185 19 A196188 19 A196216 16 A196312 12 A196541 19 A196717 17 A197121 21 A198251 51 A198476 76 A198525 52 A199112 11 A199132 19 A199245 19 A199532 32 A199716 16 A199819 19 A200424 20 A200470 20 A200532 53 A200892 200 A200900 20 A201027 10 A201111 11 A201117 11 A201137 20 A201147 47 A201150 11 A201153 53 A201175 11 A201185 11 A201210 10 A201622 16 A201705 17 A201724 20 A201792 17 A202136 13 A202577 20 A202957 20 A203328 28 A203462 34 A203488 48 A204214 21 A204616 16 A204716 16 A204794 47 A204837 2048 A205171 17 A205220 20 A205221 52 A205312 20 A205992 92 A206614 14 A206782 20 A206891 20 A206938 20 A206953 69 A207002 20 A207091 20 A207121 21 A207125 12 A207127 20 A207181 81 A207223 23 A207230 23 A207372 20 A207402 20 A207431 31 A207546 75 A207552 75 A207740 40 A207751 20 A207948 20 A208016 16 A208017 20 A208026 26 A208072 20 A208115 15 A208120 12 A208122 20 A208141 20 A208146 14 A208155 15 A208559 20 A208642 64 A208948 20 A209228 28 A209524 52 A209547 20 A210090 90 A210137 10 A210168 10 A210169 101 A210589 10 A210652 10 A210813 10 A211021 11 A211032 10 A211102 10 A211107 10 A211144 14 A211191 11 A211238 11 A211253 21 A211322 11 A211401 11 A211457 11 A211460 21 A211464 21 A211486 11 A211563 15 A211687 68 A211692 69 A211968 11 A212192 21 A212406 21 A212596 12 A212734 21 A212786 21 A213310 10 A213355 13 A213655 13 A213665 13 A213686 13 A213698 13 A214037 21 A214099 21 A214108 10 A214163 41 A214175 17 A214184 41 A214512 12 A214521 14 A214572 45 A215012 12 A215236 15 A215431 31 A215657 65 A215903 15 A215951 15 A215965 21 A216160 16 A216306 16 A216467 21 A217044 17 A217114 11 A217150 21 A217195 17 A217263 21 A217409 17 A217453 17 A217543 17 A217641 17 A217790 77 A217796 17 A217960 17 A218249 21 A218404 40 A218486 48 A218763 21 A218821 21 A218840 21 A219000 21 A219104 21 A219110 10 A219140 21 A219154 21 A219171 21 A219215 21 A219297 21 A219308 21 A219316 16 A219379 21 A219385 21 A219401 21 A219408 21 A219419 21 A219439 21 A219449 21 A219584 84 A219593 21 A219599 21 A219625 21 A219631 21 A219684 21 A219690 21 A219739 21 A219814 21 A219820 21 A219850 21 A219856 21 A219881 21 A219886 21 A219913 21 A219919 21 A219957 19 A219983 21 A220006 20 A220013 20 A220040 20 A220046 20 A220150 15 A220156 15 A220200 20 A220207 20 A220312 12 A220928 20 A221033 21 A221043 10 A221045 10 A221048 21 A221122 21 A221164 21 A221289 12 A221369 13 A221497 21 A221607 16 A221639 22 A221665 16 A221684 16 A221698 22 A221722 21 A221733 21 A221771 21 A221779 21 A221928 28 A222336 36 A222414 14 A222614 14 A222916 16 A223010 10 A223016 16 A223250 32 A223258 25 A223278 27 A223472 72 A223606 23 A223618 22 A223624 22 A223635 22 A223642 22 A223667 22 A223678 22 A223715 22 A223720 22 A223733 33 A223737 22 A223768 22 A223775 22 A223781 22 A223784 22 A223786 86 A223812 22 A223821 22 A223826 22 A223836 22 A223883 22 A223890 22 A223913 22 A223917 239 A223928 22 A223932 239 A223970 22 A223974 239 A224052 22 A224144 22 A224156 22 A224160 16 A224185 22 A224257 22 A224305 22 A224313 243 A224356 243 A224369 22 A224377 243 A224407 22 A224431 224 A224907 24 A225008 22 A225135 25 A225388 25 A225418 25 A225873 25 A225898 22 A226041 41 A226475 75 A226713 67 A226836 36 A227010 10 A227115 27 A227340 73 A227492 27 A227816 16 A228010 10 A228213 13 A228215 21 A228255 25 A228310 10 A228742 28 A228810 88 A228811 11 A228963 228 A229059 29 A229124 22 A229221 21 A229357 35 A229367 22 A229375 22 A229432 43 A230021 21 A230456 23 A230558 30 A230703 30 A231073 23 A231207 23 A231215 12 A231216 23 A231225 22 A231260 12 A231261 23 A231298 12 A231401 23 A231439 23 A231453 23 A231459 14 A231512 12 A231521 21 A231546 15 A231695 16 A231704 17 A232051 32 A232116 11 A232235 23 A232277 22 A232415 15 A232474 24 A232521 52 A232596 32 A232668 26 A232726 23 A232827 23 A232912 12 A232913 32 A233014 14 A233064 33 A233100 10 A233109 23 A233143 23 A233213 23 A233226 23 A233235 23 A233362 23 A233363 36 A233385 23 A233820 20 A234132 32 A234176 76 A234327 432 A235982 82 A236059 360 A236302 23 A236324 32 A236516 16 A236781 81 A236811 81 A236812 81 A236819 81 A237481 81 A237592 237 A237766 23 A237857 37 A238056 23 A238172 81 A238173 81 A238180 81 A238677 23 A238772 72 A238854 23 A239044 90 A239315 15 A239562 39 A239563 23 A239647 64 A239718 71 A240068 24 A240109 10 A240152 15 A240158 15 A240268 24 A240524 24 A240628 40 A240641 41 A240820 20 A241041 10 A241042 24 A241053 10 A241081 41 A241111 41 A241127 11 A241254 24 A241286 24 A241327 41 A241362 24 A241374 41 A241434 24 A241441 24 A241481 48 A241622 41 A241848 18 A241890 24 A241965 19 A242144 42 A242145 42 A242149 421 A242152 15 A242167 16 A242191 21 A242262 26 A242358 23 A242837 24 A242844 24 A242912 12 A243106 10 A243138 13 A243301 30 A243542 54 A243820 38 A244323 23 A244770 47 A244794 24 A244908 24 A246192 24 A246215 24 A246625 25 A247110 11 A247135 35 A247436 43 A247825 24 A247902 90 A248422 22 A248429 29 A248456 48 A248693 24 A249236 92 A249300 93 A250020 20 A250083 83 A250141 14 A250169 16 A250191 25 A250232 32 A250291 29 A250318 25 A250364 64 A250446 44 A250447 44 A250520 50 A250527 50 A250559 25 A250611 11 A250724 50 A250772 72 A251125 125 A251195 25 A251213 21 A251262 26 A251310 10 A251311 25 A251344 51 A251351 51 A251362 25 A251425 42 A251451 45 A251460 46 A251467 46 A251769 17 A251925 25 A251932 51 A252228 228 A252231 31 A252335 52 A252336 52 A252343 52 A252713 52 A252826 26 A253017 25 A253018 25 A253025 25 A253053 25 A253111 53 A253112 53 A253119 53 A253353 335 A253417 17 A254014 2540 A254021 2540 A254226 25 A254512 512 A254701 54 A254836 36 A255222 22 A255417 17 A255419 25 A255424 42 A255608 25 A256515 56 A256517 17 A256519 25 A256694 69 A256822 256 A257137 13 A257708 25 A257720 25 A257933 79 A258160 16 A258319 25 A258876 25 A258966 66 A259028 25 A259995 99 A260179 17 A260199 26 A260200 26 A260207 26 A260248 48 A260517 51 A260561 61 A260729 29 A261030 30 A261138 11 A261173 11 A261395 13 A261537 53 A261548 48 A261932 26 A262076 26 A262107 26 A262271 26 A262424 42 A262428 24 A262476 26 A262756 26 A263222 26 A263282 63 A263310 10 A263372 37 A263606 60 A263945 26 A263946 26 A264007 64 A264016 64 A264058 64 A264075 64 A264086 64 A264094 64 A264127 64 A264146 64 A264164 16 A264169 16 A264188 64 A264210 64 A264221 64 A264259 25 A264260 64 A264275 64 A264298 29 A264345 64 A264361 36 A264513 13 A264811 11 A265114 11 A265153 15 A265877 26 A265923 92 A265959 26 A265979 26 A266030 26 A266214 14 A267024 24 A267963 63 A268089 26 A268265 65 A268331 26 A268753 53 A269424 24 A269658 26 A269786 97 A271035 10 """ ans = 1 x = input() for line in pre.split('\n'): if line: key, value = line.split() if x == key: ans = value break print(ans)
Title: Ace It! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output a single integer. Input Specification: The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). Output Specification: Output a single integer. Demo Input: ['A221033\n', 'A223635\n', 'A232726\n'] Demo Output: ['21\n', '22\n', '23\n'] Note: none
```python pre = """A000527 52 A001134 113 A001520 15 A001986 19 A002155 15 A004810 10 A004811 11 A004812 12 A005110 11 A006614 14 A006615 15 A006616 16 A007304 30 A008710 10 A008879 87 A008900 89 A008901 90 A010171 10 A010172 10 A010173 10 A010174 10 A010175 10 A010176 10 A010177 10 A010178 10 A010179 10 A010180 10 A010181 10 A010182 10 A010183 10 A010184 10 A010212 12 A010569 10 A010692 10 A011753 11 A013718 13 A013752 13 A013798 13 A013866 13 A014136 36 A014313 31 A015226 22 A015831 15 A015876 15 A015979 59 A016792 16 A016828 16 A016876 16 A016898 16 A016936 16 A016958 16 A017416 16 A017427 27 A018823 18 A019360 19 A019384 19 A019393 19 A020143 14 A020211 21 A020250 25 A020258 25 A020325 25 A022011 11 A022978 22 A022985 29 A023264 23 A023278 23 A023295 23 A023338 233 A023679 23 A025283 25 A025378 78 A027182 18 A027500 27 A027786 78 A029817 17 A031028 10 A031077 10 A031105 10 A031119 11 A031167 11 A031174 117 A031207 12 A031339 13 A031373 13 A031382 13 A031390 13 A031415 41 A031464 64 A031486 48 A031704 170 A033176 31 A033353 33 A033355 35 A033824 24 A034025 25 A034107 10 A035123 12 A036329 32 A036510 36 A036785 36 A036927 27 A037932 32 A039332 32 A039353 39 A039360 36 A039363 63 A039422 39 A039441 44 A039467 39 A039531 53 A039552 95 A039600 96 A039833 33 A040109 10 A040110 11 A040111 11 A040118 11 A040136 13 A040215 15 A040318 18 A040421 21 A040523 23 A040625 25 A040727 27 A040829 29 A040931 31 A041210 10 A041264 12 A041266 12 A041268 12 A041270 12 A041272 12 A041274 12 A041276 12 A041278 12 A041280 12 A041282 12 A041284 12 A041286 12 A041288 12 A041290 12 A041292 12 A041294 12 A041296 12 A041298 12 A041312 13 A041314 13 A041316 13 A041318 13 A041320 13 A041322 13 A041324 13 A041326 13 A041328 13 A041330 13 A041332 13 A041334 13 A041336 13 A041338 13 A041340 13 A041342 13 A041344 13 A041346 13 A041348 13 A041350 13 A041352 13 A041354 13 A041356 13 A041358 13 A041360 13 A041362 13 A041400 14 A041402 14 A041404 14 A041406 14 A041408 14 A041410 14 A041412 14 A041414 14 A041416 14 A041418 14 A041516 16 A041618 18 A041820 20 A042124 24 A042250 25 A042252 25 A042254 25 A042256 25 A042258 25 A042326 26 A042528 28 A042830 30 A042967 29 A042969 29 A042973 29 A043107 10 A043113 13 A043114 14 A043118 18 A043135 35 A043173 31 A043181 18 A043202 32 A043208 43 A043233 23 A043375 43 A043400 400 A043956 39 A043988 43 A044107 41 A044113 11 A044153 15 A044179 41 A044182 44 A044207 20 A044229 42 A044231 44 A044278 27 A044293 42 A044295 44 A044368 36 A044375 43 A044376 44 A044522 52 A044563 44 A044564 45 A044612 44 A044614 46 A044631 63 A044676 44 A044678 46 A044702 70 A044757 44 A044760 47 A044792 79 A044864 64 A044982 82 A045118 511 A045189 18 A045207 20 A045249 24 A045268 68 A045566 45 A046117 11 A046301 30 A046455 64 A047948 47 A048126 26 A050234 23 A050439 39 A050944 44 A051310 13 A051315 31 A051392 13 A051419 14 A051779 17 A051983 519 A052230 23 A053014 30 A053070 53 A053236 23 A053652 53 A053736 53 A054032 32 A055310 10 A055311 11 A055312 12 A055313 13 A057800 78 A057803 78 A057806 78 A059164 16 A059256 59 A060061 61 A060225 60 A060229 29 A060259 59 A060489 60 A060512 60 A060513 60 A060936 36 A061016 10 A061116 11 A061157 11 A061381 13 A061550 15 A061759 59 A062661 61 A063470 34 A063710 10 A063913 13 A064267 26 A064399 39 A064561 45 A064816 16 A065915 15 A066024 24 A068405 84 A069295 29 A069795 79 A070179 17 A070332 32 A071263 12 A071279 12 A072244 24 A072412 72 A072711 11 A073319 19 A073567 35 A073761 61 A075589 89 A076130 13 A077263 63 A077711 11 A078138 13 A079130 13 A080933 33 A081062 10 A081317 13 A081702 17 A082128 21 A082452 45 A082972 82 A083310 10 A083511 11 A084224 24 A085413 13 A085482 54 A085625 25 A086126 61 A086711 11 A087530 53 A088188 81 A088993 89 A089113 13 A089158 89 A089296 29 A089297 29 A089823 23 A090635 63 A091022 10 A091216 16 A091832 18 A091896 18 A092212 22 A092215 22 A092221 22 A092770 27 A092995 29 A094203 20 A094552 52 A095318 31 A095527 52 A095539 53 A095541 54 A097205 72 A097439 39 A097459 59 A098116 11 A098413 13 A099103 10 A099115 11 A099911 11 A100316 16 A100500 10 A100813 10 A100830 10 A100844 10 A100916 10 A100929 10 A100992 10 A101145 11 A101156 10 A101188 18 A101467 10 A101795 179 A101869 10 A102130 13 A102249 10 A102357 10 A102361 10 A102362 10 A102488 10 A102490 10 A102492 10 A102494 10 A102502 10 A102542 10 A102546 10 A102690 10 A102695 10 A102708 27 A102850 10 A102906 29 A103098 30 A103208 10 A103325 32 A103611 11 A103618 10 A103757 10 A104044 10 A104045 10 A104118 11 A104128 10 A104130 10 A104132 13 A104213 13 A104218 18 A104341 10 A104486 10 A104520 10 A104645 10 A104788 10 A104801 10 A104863 10 A104865 10 A104867 10 A104868 10 A104869 10 A104935 49 A105155 10 A105156 10 A105162 10 A105938 10 A105959 10 A105991 10 A106134 13 A106414 41 A106695 10 A106755 67 A106789 10 A107126 10 A107175 17 A107215 107 A107258 25 A107781 10 A107787 77 A107830 10 A107954 79 A108580 10 A108584 10 A108603 10 A108614 10 A108697 10 A108703 10 A108777 10 A108792 10 A108793 10 A108892 10 A108965 10 A109013 10 A109100 10 A109211 21 A109279 10 A109280 10 A109334 10 A109373 10 A109394 10 A109597 10 A109604 10 A109644 44 A109751 10 A109893 10 A109958 10 A109959 10 A110044 11 A110059 11 A110089 11 A110093 11 A110186 10 A110368 10 A110383 11 A110398 11 A110402 11 A110403 11 A110406 11 A110408 11 A110410 10 A110411 41 A110414 11 A110415 11 A110418 10 A110429 10 A110434 11 A110435 11 A110463 10 A110466 11 A110732 11 A110733 11 A110735 110 A110736 110 A110743 11 A110745 11 A110747 11 A110767 11 A110774 11 A110776 11 A110780 11 A110782 11 A110786 11 A110798 11 A110799 11 A110804 10 A110831 31 A110934 10 A111015 11 A111070 11 A111080 11 A111151 15 A111255 11 A111257 11 A111322 11 A111334 11 A111337 11 A111347 11 A111380 13 A111463 11 A111477 11 A111478 11 A111872 18 A111931 11 A112033 12 A112054 12 A112063 11 A112131 12 A112134 11 A112386 11 A112415 12 A112548 12 A112733 11 A112769 12 A112795 79 A112854 11 A112880 12 A113017 13 A113172 13 A113316 16 A113403 11 A113548 13 A113579 13 A113585 11 A113587 11 A113600 11 A113601 13 A113615 11 A113616 11 A113831 13 A113943 13 A114012 14 A114120 11 A114167 11 A114354 11 A114382 14 A114445 11 A114504 50 A114754 11 A114758 11 A114821 48 A114872 14 A114948 11 A114962 14 A114985 14 A115132 132 A115174 15 A115480 48 A115560 11 A115565 11 A115595 11 A115737 11 A115768 11 A115776 15 A115811 15 A115853 11 A115912 12 A115972 11 A116011 11 A116055 55 A116057 11 A116059 11 A116061 11 A116098 11 A116102 16 A116124 61 A116129 11 A116190 16 A116193 11 A116270 62 A116610 10 A116999 11 A117047 11 A117293 11 A117314 11 A117390 17 A117697 11 A117873 11 A117874 17 A118133 11 A118293 18 A118359 83 A118512 11 A118513 13 A118572 11 A118592 11 A118638 11 A118648 11 A118798 79 A118922 89 A118936 11 A118937 11 A119247 11 A119555 19 A119667 196 A119742 11 A119890 11 A120090 12 A120141 14 A120145 20 A120159 15 A120169 12 A120210 20 A120356 12 A120360 12 A120570 12 A120571 12 A120644 12 A120692 20 A120693 20 A121030 10 A121032 12 A121155 11 A121171 11 A121495 14 A121594 15 A121628 21 A121683 216 A121710 17 A121851 18 A121938 19 A121985 12 A122040 12 A122242 42 A122253 12 A122500 25 A122878 12 A123132 12 A123171 123 A123213 21 A123238 32 A123711 12 A123782 23 A123933 12 A123980 12 A123983 12 A124110 11 A124140 24 A124144 144 A124205 12 A124206 12 A124238 38 A124269 12 A124283 24 A124337 37 A124351 12 A124517 17 A124521 12 A124626 12 A124657 24 A124672 12 A125197 19 A125290 12 A125638 63 A125664 12 A125998 12 A126170 126 A126195 12 A126272 27 A126687 12 A126706 12 A126763 12 A126766 76 A126855 12 A127146 12 A127354 12 A127401 12 A127422 12 A127579 127 A127869 12 A128043 12 A129006 12 A129197 12 A129287 29 A129367 36 A129498 12 A129639 12 A129813 29 A129887 98 A129939 12 A130038 30 A130281 28 A130310 10 A130611 13 A130621 13 A130817 17 A130868 13 A131019 13 A131021 13 A131541 15 A131557 55 A131633 31 A131700 13 A131762 31 A131992 31 A132067 20 A132156 13 A132233 13 A132235 23 A132260 13 A132261 13 A132300 32 A132386 13 A132420 24 A132485 13 A132540 25 A132542 13 A132580 13 A132585 25 A132946 13 A132947 13 A133534 35 A133901 33 A134070 13 A134159 13 A134196 19 A134257 13 A134550 13 A134814 14 A134864 13 A135024 13 A135172 13 A135189 18 A135241 13 A135283 13 A135535 13 A135971 13 A136191 13 A136316 13 A136359 36 A136373 13 A136773 13 A137188 13 A137194 13 A137263 26 A137411 11 A137675 37 A137724 37 A137833 37 A137834 37 A138353 13 A138368 13 A138375 13 A138535 13 A138596 13 A138604 60 A138685 13 A138686 13 A138931 13 A139070 13 A139103 10 A139106 10 A139109 10 A139113 11 A139114 11 A139157 13 A139166 16 A139168 13 A139228 22 A139311 11 A139494 13 A139530 13 A139610 10 A139611 11 A139612 12 A139613 13 A139614 14 A139615 15 A139616 16 A139617 17 A139618 18 A139619 19 A139620 20 A139838 13 A139849 13 A139860 13 A139863 13 A139866 13 A139873 13 A139880 13 A139911 13 A139926 13 A139974 13 A140212 12 A140619 19 A140702 40 A140729 40 A140739 14 A140784 14 A140798 140 A141174 17 A141195 11 A141274 12 A141682 16 A141838 14 A141842 18 A141881 41 A141898 41 A141922 41 A141923 19 A141931 31 A141939 41 A141942 19 A141957 41 A141960 19 A141973 19 A141988 41 A141995 19 A142190 19 A142241 14 A142302 23 A142324 23 A142374 23 A142411 41 A142671 67 A142837 283 A142865 14 A142905 29 A142938 29 A143204 14 A143754 75 A144552 45 A144585 14 A144928 49 A145188 14 A145319 45 A145332 53 A145510 10 A145528 455 A145693 14 A146563 14 A151900 19 A152099 15 A152161 21 A152246 15 A152294 29 A152586 15 A152587 15 A152962 29 A153465 34 A153642 36 A154060 15 A154267 15 A154369 15 A154410 10 A154806 15 A154810 10 A154988 15 A155111 15 A155573 73 A155711 11 A156063 15 A156110 11 A156849 156 A157137 15 A157352 35 A157446 15 A157643 15 A157651 57 A158238 23 A158287 287 A158339 39 A158402 840 A158482 15 A158490 90 A158529 29 A158557 15 A158771 77 A159404 40 A159446 46 A160130 13 A160778 16 A160917 60 A161424 16 A161454 14 A161723 23 A161735 17 A161851 16 A161853 61 A161874 16 A161884 16 A161914 14 A162008 16 A162422 22 A162451 24 A162465 24 A162819 16 A163113 13 A163935 35 A164324 16 A164337 64 A164413 13 A165117 16 A165121 16 A165158 65 A165160 16 A165338 16 A165373 37 A165798 65 A166112 16 A166394 63 A166595 16 A166710 10 A167062 16 A167471 16 A167574 167 A167690 16 A167741 41 A167824 24 A167997 16 A168100 10 A168103 10 A168576 16 A169834 34 A169882 16 A171125 11 A171168 17 A171169 17 A171242 242 A171286 12 A171291 17 A171304 30 A171318 13 A171322 17 A171569 15 A171687 17 A171704 17 A171748 17 A171766 17 A171954 17 A172280 17 A172287 17 A172424 24 A172456 17 A172521 17 A173054 17 A173647 17 A173727 72 A173728 72 A174214 14 A174380 17 A174408 17 A174601 60 A174819 19 A175161 16 A175384 17 A175602 56 A175710 10 A175960 17 A176254 17 A176622 17 A176783 17 A176810 10 A176838 17 A177076 17 A177112 12 A177135 17 A177378 37 A177418 41 A177835 17 A178050 17 A178424 17 A178634 63 A178716 17 A178917 89 A179038 17 A179039 17 A179093 17 A179157 17 A179512 12 A179816 17 A179818 17 A180113 11 A180117 18 A180553 53 A181147 11 A181149 14 A181150 11 A181182 11 A181223 81 A181262 126 A181453 18 A181460 46 A181711 18 A181761 18 A182052 18 A182226 18 A182277 82 A182286 18 A182311 18 A182329 29 A182464 24 A183215 32 A183427 27 A183498 18 A183523 23 A183616 36 A184086 86 A184126 84 A184190 19 A184539 45 A184540 45 A184548 45 A184710 10 A184764 64 A185099 18 A185499 99 A185884 588 A186122 18 A186129 18 A186158 18 A186261 26 A186398 186 A186441 64 A186781 18 A186811 11 A187710 10 A188212 18 A188522 88 A188606 88 A188613 88 A188717 17 A188762 88 A188850 88 A188857 88 A188991 88 A189156 15 A189612 12 A189777 97 A190267 19 A190524 24 A190715 15 A191047 19 A191111 11 A191514 51 A191915 15 A192130 21 A192491 24 A192505 19 A195117 11 A195461 19 A195615 15 A195749 19 A195756 19 A196028 28 A196114 11 A196117 11 A196185 19 A196188 19 A196216 16 A196312 12 A196541 19 A196717 17 A197121 21 A198251 51 A198476 76 A198525 52 A199112 11 A199132 19 A199245 19 A199532 32 A199716 16 A199819 19 A200424 20 A200470 20 A200532 53 A200892 200 A200900 20 A201027 10 A201111 11 A201117 11 A201137 20 A201147 47 A201150 11 A201153 53 A201175 11 A201185 11 A201210 10 A201622 16 A201705 17 A201724 20 A201792 17 A202136 13 A202577 20 A202957 20 A203328 28 A203462 34 A203488 48 A204214 21 A204616 16 A204716 16 A204794 47 A204837 2048 A205171 17 A205220 20 A205221 52 A205312 20 A205992 92 A206614 14 A206782 20 A206891 20 A206938 20 A206953 69 A207002 20 A207091 20 A207121 21 A207125 12 A207127 20 A207181 81 A207223 23 A207230 23 A207372 20 A207402 20 A207431 31 A207546 75 A207552 75 A207740 40 A207751 20 A207948 20 A208016 16 A208017 20 A208026 26 A208072 20 A208115 15 A208120 12 A208122 20 A208141 20 A208146 14 A208155 15 A208559 20 A208642 64 A208948 20 A209228 28 A209524 52 A209547 20 A210090 90 A210137 10 A210168 10 A210169 101 A210589 10 A210652 10 A210813 10 A211021 11 A211032 10 A211102 10 A211107 10 A211144 14 A211191 11 A211238 11 A211253 21 A211322 11 A211401 11 A211457 11 A211460 21 A211464 21 A211486 11 A211563 15 A211687 68 A211692 69 A211968 11 A212192 21 A212406 21 A212596 12 A212734 21 A212786 21 A213310 10 A213355 13 A213655 13 A213665 13 A213686 13 A213698 13 A214037 21 A214099 21 A214108 10 A214163 41 A214175 17 A214184 41 A214512 12 A214521 14 A214572 45 A215012 12 A215236 15 A215431 31 A215657 65 A215903 15 A215951 15 A215965 21 A216160 16 A216306 16 A216467 21 A217044 17 A217114 11 A217150 21 A217195 17 A217263 21 A217409 17 A217453 17 A217543 17 A217641 17 A217790 77 A217796 17 A217960 17 A218249 21 A218404 40 A218486 48 A218763 21 A218821 21 A218840 21 A219000 21 A219104 21 A219110 10 A219140 21 A219154 21 A219171 21 A219215 21 A219297 21 A219308 21 A219316 16 A219379 21 A219385 21 A219401 21 A219408 21 A219419 21 A219439 21 A219449 21 A219584 84 A219593 21 A219599 21 A219625 21 A219631 21 A219684 21 A219690 21 A219739 21 A219814 21 A219820 21 A219850 21 A219856 21 A219881 21 A219886 21 A219913 21 A219919 21 A219957 19 A219983 21 A220006 20 A220013 20 A220040 20 A220046 20 A220150 15 A220156 15 A220200 20 A220207 20 A220312 12 A220928 20 A221033 21 A221043 10 A221045 10 A221048 21 A221122 21 A221164 21 A221289 12 A221369 13 A221497 21 A221607 16 A221639 22 A221665 16 A221684 16 A221698 22 A221722 21 A221733 21 A221771 21 A221779 21 A221928 28 A222336 36 A222414 14 A222614 14 A222916 16 A223010 10 A223016 16 A223250 32 A223258 25 A223278 27 A223472 72 A223606 23 A223618 22 A223624 22 A223635 22 A223642 22 A223667 22 A223678 22 A223715 22 A223720 22 A223733 33 A223737 22 A223768 22 A223775 22 A223781 22 A223784 22 A223786 86 A223812 22 A223821 22 A223826 22 A223836 22 A223883 22 A223890 22 A223913 22 A223917 239 A223928 22 A223932 239 A223970 22 A223974 239 A224052 22 A224144 22 A224156 22 A224160 16 A224185 22 A224257 22 A224305 22 A224313 243 A224356 243 A224369 22 A224377 243 A224407 22 A224431 224 A224907 24 A225008 22 A225135 25 A225388 25 A225418 25 A225873 25 A225898 22 A226041 41 A226475 75 A226713 67 A226836 36 A227010 10 A227115 27 A227340 73 A227492 27 A227816 16 A228010 10 A228213 13 A228215 21 A228255 25 A228310 10 A228742 28 A228810 88 A228811 11 A228963 228 A229059 29 A229124 22 A229221 21 A229357 35 A229367 22 A229375 22 A229432 43 A230021 21 A230456 23 A230558 30 A230703 30 A231073 23 A231207 23 A231215 12 A231216 23 A231225 22 A231260 12 A231261 23 A231298 12 A231401 23 A231439 23 A231453 23 A231459 14 A231512 12 A231521 21 A231546 15 A231695 16 A231704 17 A232051 32 A232116 11 A232235 23 A232277 22 A232415 15 A232474 24 A232521 52 A232596 32 A232668 26 A232726 23 A232827 23 A232912 12 A232913 32 A233014 14 A233064 33 A233100 10 A233109 23 A233143 23 A233213 23 A233226 23 A233235 23 A233362 23 A233363 36 A233385 23 A233820 20 A234132 32 A234176 76 A234327 432 A235982 82 A236059 360 A236302 23 A236324 32 A236516 16 A236781 81 A236811 81 A236812 81 A236819 81 A237481 81 A237592 237 A237766 23 A237857 37 A238056 23 A238172 81 A238173 81 A238180 81 A238677 23 A238772 72 A238854 23 A239044 90 A239315 15 A239562 39 A239563 23 A239647 64 A239718 71 A240068 24 A240109 10 A240152 15 A240158 15 A240268 24 A240524 24 A240628 40 A240641 41 A240820 20 A241041 10 A241042 24 A241053 10 A241081 41 A241111 41 A241127 11 A241254 24 A241286 24 A241327 41 A241362 24 A241374 41 A241434 24 A241441 24 A241481 48 A241622 41 A241848 18 A241890 24 A241965 19 A242144 42 A242145 42 A242149 421 A242152 15 A242167 16 A242191 21 A242262 26 A242358 23 A242837 24 A242844 24 A242912 12 A243106 10 A243138 13 A243301 30 A243542 54 A243820 38 A244323 23 A244770 47 A244794 24 A244908 24 A246192 24 A246215 24 A246625 25 A247110 11 A247135 35 A247436 43 A247825 24 A247902 90 A248422 22 A248429 29 A248456 48 A248693 24 A249236 92 A249300 93 A250020 20 A250083 83 A250141 14 A250169 16 A250191 25 A250232 32 A250291 29 A250318 25 A250364 64 A250446 44 A250447 44 A250520 50 A250527 50 A250559 25 A250611 11 A250724 50 A250772 72 A251125 125 A251195 25 A251213 21 A251262 26 A251310 10 A251311 25 A251344 51 A251351 51 A251362 25 A251425 42 A251451 45 A251460 46 A251467 46 A251769 17 A251925 25 A251932 51 A252228 228 A252231 31 A252335 52 A252336 52 A252343 52 A252713 52 A252826 26 A253017 25 A253018 25 A253025 25 A253053 25 A253111 53 A253112 53 A253119 53 A253353 335 A253417 17 A254014 2540 A254021 2540 A254226 25 A254512 512 A254701 54 A254836 36 A255222 22 A255417 17 A255419 25 A255424 42 A255608 25 A256515 56 A256517 17 A256519 25 A256694 69 A256822 256 A257137 13 A257708 25 A257720 25 A257933 79 A258160 16 A258319 25 A258876 25 A258966 66 A259028 25 A259995 99 A260179 17 A260199 26 A260200 26 A260207 26 A260248 48 A260517 51 A260561 61 A260729 29 A261030 30 A261138 11 A261173 11 A261395 13 A261537 53 A261548 48 A261932 26 A262076 26 A262107 26 A262271 26 A262424 42 A262428 24 A262476 26 A262756 26 A263222 26 A263282 63 A263310 10 A263372 37 A263606 60 A263945 26 A263946 26 A264007 64 A264016 64 A264058 64 A264075 64 A264086 64 A264094 64 A264127 64 A264146 64 A264164 16 A264169 16 A264188 64 A264210 64 A264221 64 A264259 25 A264260 64 A264275 64 A264298 29 A264345 64 A264361 36 A264513 13 A264811 11 A265114 11 A265153 15 A265877 26 A265923 92 A265959 26 A265979 26 A266030 26 A266214 14 A267024 24 A267963 63 A268089 26 A268265 65 A268331 26 A268753 53 A269424 24 A269658 26 A269786 97 A271035 10 """ ans = 1 x = input() for line in pre.split('\n'): if line: key, value = line.split() if x == key: ans = value break print(ans) ```
0
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43...
1,577,304,904
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
22
312
0
n,m=map(int,input().split()) R=list(map(int,input().split())) W=list(map(int,input().split())) R.sort() W.sort() if max(R)<min(W): for i in R: if i*2<max(R): print(max(R)) break else: for i in R: if max(R)<i*2<min(W): print(i*2) break else: print(-1) else: print(-1)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python n,m=map(int,input().split()) R=list(map(int,input().split())) W=list(map(int,input().split())) R.sort() W.sort() if max(R)<min(W): for i in R: if i*2<max(R): print(max(R)) break else: for i in R: if max(R)<i*2<min(W): print(i*2) break else: print(-1) else: print(-1) ```
0
580
A
Kefa and First Steps
PROGRAMMING
900
[ "brute force", "dp", "implementation" ]
null
null
Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task!
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*.
[ "6\n2 2 1 3 4 1\n", "3\n2 2 9\n" ]
[ "3", "3" ]
In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
750
[ { "input": "6\n2 2 1 3 4 1", "output": "3" }, { "input": "3\n2 2 9", "output": "3" }, { "input": "5\n10 100 111 1 2", "output": "3" }, { "input": "10\n1 2 3 4 1 2 3 4 5 6", "output": "6" }, { "input": "50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,697,380,834
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
61
0
def solution(n,l): count=maxx=0 for i in range(1,len(l)): if l[i-1]<=l[i]: count+=1 else: maxx=max(maxx,count) count=0 return maxx+1 print(solution(input(),list(map(lambda x: int(x), input().split()))))
Title: Kefa and First Steps Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kefa decided to make some money doing business on the Internet for exactly *n* days. He knows that on the *i*-th day (1<=≤<=*i*<=≤<=*n*) he makes *a**i* money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence *a**i*. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the length of the maximum non-decreasing subsegment of sequence *a*. Demo Input: ['6\n2 2 1 3 4 1\n', '3\n2 2 9\n'] Demo Output: ['3', '3'] Note: In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.
```python def solution(n,l): count=maxx=0 for i in range(1,len(l)): if l[i-1]<=l[i]: count+=1 else: maxx=max(maxx,count) count=0 return maxx+1 print(solution(input(),list(map(lambda x: int(x), input().split())))) ```
0
34
B
Sale
PROGRAMMING
900
[ "greedy", "sortings" ]
B. Sale
2
256
Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn.
The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets.
Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets.
[ "5 3\n-6 0 35 -2 4\n", "4 2\n7 0 0 -7\n" ]
[ "8\n", "7\n" ]
none
1,000
[ { "input": "5 3\n-6 0 35 -2 4", "output": "8" }, { "input": "4 2\n7 0 0 -7", "output": "7" }, { "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495" }, { "input": "5 5\n976 437 937 788 518", "output": "0" }, { "input": "5 3\n-2 -2 -2 -2 -2", "output": "...
1,589,196,719
2,147,483,647
Python 3
OK
TESTS
25
218
6,963,200
""" ~~ author : dokueki ~~ created : 11~05~2020 """ import sys INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize)-1 sys.setrecursionlimit(10**7) mod = 1000000007 def IOE(): sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") def main(): n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) a.sort() neg = 0 for i in a: if i < 0: neg += 1 print(abs(sum(a[:min(neg, m)]))) if __name__ == "__main__": try: IOE() except: pass main()
Title: Sale Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. Input Specification: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. Output Specification: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Demo Input: ['5 3\n-6 0 35 -2 4\n', '4 2\n7 0 0 -7\n'] Demo Output: ['8\n', '7\n'] Note: none
```python """ ~~ author : dokueki ~~ created : 11~05~2020 """ import sys INT_MAX = sys.maxsize INT_MIN = -(sys.maxsize)-1 sys.setrecursionlimit(10**7) mod = 1000000007 def IOE(): sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") def main(): n, m = map(int, sys.stdin.readline().split()) a = list(map(int, sys.stdin.readline().split())) a.sort() neg = 0 for i in a: if i < 0: neg += 1 print(abs(sum(a[:min(neg, m)]))) if __name__ == "__main__": try: IOE() except: pass main() ```
3.93253
660
C
Hard Process
PROGRAMMING
1,600
[ "binary search", "dp", "two pointers" ]
null
null
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them.
[ "7 1\n1 0 0 1 1 0 1\n", "10 2\n1 0 0 1 0 1 0 1 0 1\n" ]
[ "4\n1 0 0 1 1 1 1\n", "5\n1 0 0 1 1 1 1 1 0 1\n" ]
none
0
[ { "input": "7 1\n1 0 0 1 1 0 1", "output": "4\n1 0 0 1 1 1 1" }, { "input": "10 2\n1 0 0 1 0 1 0 1 0 1", "output": "5\n1 0 0 1 1 1 1 1 0 1" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "7 0\n0 1 0 0 0 1 0", "o...
1,624,950,690
2,147,483,647
PyPy 3
OK
TESTS
38
405
22,425,600
n,k=map(int,input().split()) a=list(map(int,input().split())) ki=i=s=0;po=1 for j in range(n): if a[j]==0:s+=1 while s>k: if a[i]==0: s-=1 i+=1 if j-i>ki-po: po=i ki=j print(ki-po+1) a[po:ki+1]=[1]*(ki-po+1) print(*a)
Title: Hard Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. Output Specification: On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them. Demo Input: ['7 1\n1 0 0 1 1 0 1\n', '10 2\n1 0 0 1 0 1 0 1 0 1\n'] Demo Output: ['4\n1 0 0 1 1 1 1\n', '5\n1 0 0 1 1 1 1 1 0 1\n'] Note: none
```python n,k=map(int,input().split()) a=list(map(int,input().split())) ki=i=s=0;po=1 for j in range(n): if a[j]==0:s+=1 while s>k: if a[i]==0: s-=1 i+=1 if j-i>ki-po: po=i ki=j print(ki-po+1) a[po:ki+1]=[1]*(ki-po+1) print(*a) ```
3
567
A
Lineland Mail
PROGRAMMING
900
[ "greedy", "implementation" ]
null
null
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city
The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order.
Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city.
[ "4\n-5 -2 2 7\n", "2\n-1 1\n" ]
[ "3 12\n3 9\n4 7\n5 12\n", "2 2\n2 2\n" ]
none
500
[ { "input": "4\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12" }, { "input": "2\n-1 1", "output": "2 2\n2 2" }, { "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2" }, { "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4" }, { "input": "3\n-1000000000 0 1000000000", ...
1,698,876,208
2,147,483,647
Python 3
OK
TESTS
54
358
13,926,400
n=int(input()) ; c=list(map(int,input().split())) for i in range(n): if i == 0: print(c[i+1]-c[i],c[-1]-c[i]) elif i == n-1: print(c[i]-c[i-1],c[i]-c[0]) else: print(min(c[i]-c[i-1],abs(c[i]-c[i+1])),max(c[i]-c[0] , abs(c[i]-c[-1])))
Title: Lineland Mail Time Limit: None seconds Memory Limit: None megabytes Problem Description: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city Input Specification: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. Output Specification: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Demo Input: ['4\n-5 -2 2 7\n', '2\n-1 1\n'] Demo Output: ['3 12\n3 9\n4 7\n5 12\n', '2 2\n2 2\n'] Note: none
```python n=int(input()) ; c=list(map(int,input().split())) for i in range(n): if i == 0: print(c[i+1]-c[i],c[-1]-c[i]) elif i == n-1: print(c[i]-c[i-1],c[i]-c[0]) else: print(min(c[i]-c[i-1],abs(c[i]-c[i+1])),max(c[i]-c[0] , abs(c[i]-c[-1]))) ```
3
742
A
Arpa’s hard exam and Mehrdad’s naive cheat
PROGRAMMING
1,000
[ "implementation", "math", "number theory" ]
null
null
There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.
The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109).
Print single integer — the last digit of 1378*n*.
[ "1\n", "2\n" ]
[ "8", "4" ]
In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
500
[ { "input": "1", "output": "8" }, { "input": "2", "output": "4" }, { "input": "1000", "output": "6" }, { "input": "3", "output": "2" }, { "input": "4", "output": "6" }, { "input": "1000000000", "output": "6" }, { "input": "5", "output": ...
1,667,186,771
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
43,622,400
n=int(input()) if(n==0): print(8) else: ans=pow(8,n) print(ans%10)
Title: Arpa’s hard exam and Mehrdad’s naive cheat Time Limit: None seconds Memory Limit: None megabytes Problem Description: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given *n*, print the last digit of 1378*n*. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. Input Specification: The single line of input contains one integer *n* (0<=<=≤<=<=*n*<=<=≤<=<=109). Output Specification: Print single integer — the last digit of 1378*n*. Demo Input: ['1\n', '2\n'] Demo Output: ['8', '4'] Note: In the first example, last digit of 1378<sup class="upper-index">1</sup> = 1378 is 8. In the second example, last digit of 1378<sup class="upper-index">2</sup> = 1378·1378 = 1898884 is 4.
```python n=int(input()) if(n==0): print(8) else: ans=pow(8,n) print(ans%10) ```
0
275
A
Lights Out
PROGRAMMING
900
[ "implementation" ]
null
null
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light.
The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed.
Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0".
[ "1 0 0\n0 0 0\n0 0 1\n", "1 0 1\n8 8 8\n2 0 3\n" ]
[ "001\n010\n100\n", "010\n011\n100\n" ]
none
500
[ { "input": "1 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100" }, { "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100" }, { "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000" }, { "input": "96 95 5\n8 84 74\n67 31 61", "output": "011\n011\n101" }, {...
1,577,441,524
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
124
307,200
m=[] for i in range(3): m.append([int(q) for q in input().split()]) z=[[0 for i in range(3)] for j in range(3)] z[0][0]=m[0][0] + m[0][1] + m[1][0] + m[1][1] z[0][1]=m[0][0] + m[0][1] + m[0][2] + m[1][1] z[0][2]=m[0][1] + m[0][2] + m[1][2] + m[1][1] z[1][0]=m[0][0] + m[0][1] + m[1][0] + m[1][1] z[1][1]=m[0][1] + m[1][0] + m[1][1] + m[1][2] + m[2][1] z[1][2]=m[0][2] + m[1][2] + m[2][2] + m[1][1] z[2][0]=m[1][1] + m[1][0] + m[2][0] + m[2][1] z[2][1]=m[2][0] + m[2][1] + m[2][2] + m[1][1] z[2][2]=m[2][2] + m[2][1] + m[1][2] + m[1][1] for i in range(3): for j in range(3): if z[i][j]%2==0: z[i][j]=1 else: z[i][j]=0 for i in range(3): for j in range(3): print(z[i][j],end="") print("")
Title: Lights Out Time Limit: None seconds Memory Limit: None megabytes Problem Description: Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. Input Specification: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. Output Specification: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Demo Input: ['1 0 0\n0 0 0\n0 0 1\n', '1 0 1\n8 8 8\n2 0 3\n'] Demo Output: ['001\n010\n100\n', '010\n011\n100\n'] Note: none
```python m=[] for i in range(3): m.append([int(q) for q in input().split()]) z=[[0 for i in range(3)] for j in range(3)] z[0][0]=m[0][0] + m[0][1] + m[1][0] + m[1][1] z[0][1]=m[0][0] + m[0][1] + m[0][2] + m[1][1] z[0][2]=m[0][1] + m[0][2] + m[1][2] + m[1][1] z[1][0]=m[0][0] + m[0][1] + m[1][0] + m[1][1] z[1][1]=m[0][1] + m[1][0] + m[1][1] + m[1][2] + m[2][1] z[1][2]=m[0][2] + m[1][2] + m[2][2] + m[1][1] z[2][0]=m[1][1] + m[1][0] + m[2][0] + m[2][1] z[2][1]=m[2][0] + m[2][1] + m[2][2] + m[1][1] z[2][2]=m[2][2] + m[2][1] + m[1][2] + m[1][1] for i in range(3): for j in range(3): if z[i][j]%2==0: z[i][j]=1 else: z[i][j]=0 for i in range(3): for j in range(3): print(z[i][j],end="") print("") ```
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14...
1,543,393,397
2,147,483,647
Python 3
OK
TESTS
28
109
0
def shift(n): a=[] c='' for i in range(len(n)): a+=n[i] b=a[-1] for i in range(len(a)-1): b+=a[i] for i in range(len(b)): c+=b[i] return c word=input() a=[word] for i in range(len(word)): word=shift(word) if word in a: continue else: a+=[word] print(len(a))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). Output Specification: Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. Demo Input: ['abcd\n', 'bbb\n', 'yzyz\n'] Demo Output: ['4\n', '1\n', '2\n'] Note: For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
```python def shift(n): a=[] c='' for i in range(len(n)): a+=n[i] b=a[-1] for i in range(len(a)-1): b+=a[i] for i in range(len(b)): c+=b[i] return c word=input() a=[word] for i in range(len(word)): word=shift(word) if word in a: continue else: a+=[word] print(len(a)) ```
3
729
A
Interview with Oleg
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters.
Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences.
[ "7\naogogob\n", "13\nogogmgogogogo\n", "9\nogoogoogo\n" ]
[ "a***b\n", "***gmg***\n", "*********\n" ]
The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
500
[ { "input": "7\naogogob", "output": "a***b" }, { "input": "13\nogogmgogogogo", "output": "***gmg***" }, { "input": "9\nogoogoogo", "output": "*********" }, { "input": "32\nabcdefogoghijklmnogoopqrstuvwxyz", "output": "abcdef***ghijklmn***opqrstuvwxyz" }, { "input":...
1,671,605,096
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
def f(): n=int(input()) s=input() for i in range(n): if(s[i]=='o' and s[i+1]=='g' and s[i+2]=='o'): print("***") while(i+3<n and i+4<n and s[i+3]=='g' and s[i+4]=='o'): i+=2 continue else: print(s[i]) continue f()
Title: Interview with Oleg Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters. Output Specification: Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. Demo Input: ['7\naogogob\n', '13\nogogmgogogogo\n', '9\nogoogoogo\n'] Demo Output: ['a***b\n', '***gmg***\n', '*********\n'] Note: The first sample contains one filler word ogogo, so the interview for printing is "a***b". The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***".
```python def f(): n=int(input()) s=input() for i in range(n): if(s[i]=='o' and s[i+1]=='g' and s[i+2]=='o'): print("***") while(i+3<n and i+4<n and s[i+3]=='g' and s[i+4]=='o'): i+=2 continue else: print(s[i]) continue f() ```
0
412
B
Network Configuration
PROGRAMMING
900
[ "greedy", "sortings" ]
null
null
The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible?
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer.
Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer.
[ "3 2\n40 20 30\n", "6 4\n100 20 40 20 50 50\n" ]
[ "30\n", "40\n" ]
In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
1,000
[ { "input": "3 2\n40 20 30", "output": "30" }, { "input": "6 4\n100 20 40 20 50 50", "output": "40" }, { "input": "1 1\n16", "output": "16" }, { "input": "2 1\n10000 17", "output": "10000" }, { "input": "2 2\n200 300", "output": "200" }, { "input": "3 1...
1,592,931,972
2,147,483,647
PyPy 3
OK
TESTS
34
155
20,172,800
n , k = map(int,input().split()) arr = list(map(int,input().split())) arr = list(reversed(sorted(arr))) res = [] for i in range(k): res.append(arr[i]) print(min(res))
Title: Network Configuration Time Limit: None seconds Memory Limit: None megabytes Problem Description: The R1 company wants to hold a web search championship. There were *n* computers given for the competition, each of them is connected to the Internet. The organizers believe that the data transfer speed directly affects the result. The higher the speed of the Internet is, the faster the participant will find the necessary information. Therefore, before the competition started, each computer had its maximum possible data transfer speed measured. On the *i*-th computer it was *a**i* kilobits per second. There will be *k* participants competing in the championship, each should get a separate computer. The organizing company does not want any of the participants to have an advantage over the others, so they want to provide the same data transfer speed to each participant's computer. Also, the organizers want to create the most comfortable conditions for the participants, so the data transfer speed on the participants' computers should be as large as possible. The network settings of the R1 company has a special option that lets you to cut the initial maximum data transfer speed of any computer to any lower speed. How should the R1 company configure the network using the described option so that at least *k* of *n* computers had the same data transfer speed and the data transfer speed on these computers was as large as possible? Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=100) — the number of computers and the number of participants, respectively. In the second line you have a space-separated sequence consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (16<=≤<=*a**i*<=≤<=32768); number *a**i* denotes the maximum data transfer speed on the *i*-th computer. Output Specification: Print a single integer — the maximum Internet speed value. It is guaranteed that the answer to the problem is always an integer. Demo Input: ['3 2\n40 20 30\n', '6 4\n100 20 40 20 50 50\n'] Demo Output: ['30\n', '40\n'] Note: In the first test case the organizers can cut the first computer's speed to 30 kilobits. Then two computers (the first and the third one) will have the same speed of 30 kilobits. They should be used as the participants' computers. This answer is optimal.
```python n , k = map(int,input().split()) arr = list(map(int,input().split())) arr = list(reversed(sorted(arr))) res = [] for i in range(k): res.append(arr[i]) print(min(res)) ```
3
9
A
Die Roll
PROGRAMMING
800
[ "math", "probabilities" ]
A. Die Roll
1
64
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.
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,693,246,196
2,147,483,647
PyPy 3
COMPILATION_ERROR
TESTS
0
0
0
listA = list(map(int,input().split(" ))) maxNum = max(listA) ans = [] for i in range(maxNum,7): ans.append(i) length = len(ans) if length==0: print("0/1") elif length==1: print("1/6") elif length==2: print("1/3") elif length==3: print("1/2") elif length==4: print("2/3") elif length==5: print("5/6") else: print("1/1")
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 Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place. But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams. Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania. It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win. Input Specification: 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 Specification: 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». Demo Input: ['4 2\n'] Demo Output: ['1/2\n'] Note: Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.
```python listA = list(map(int,input().split(" ))) maxNum = max(listA) ans = [] for i in range(maxNum,7): ans.append(i) length = len(ans) if length==0: print("0/1") elif length==1: print("1/6") elif length==2: print("1/3") elif length==3: print("1/2") elif length==4: print("2/3") elif length==5: print("5/6") else: print("1/1") ```
-1
250
B
Restoring IPv6
PROGRAMMING
1,500
[ "implementation", "strings" ]
null
null
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full. Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address. Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below: - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon. The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. You've got several short records of IPv6 addresses. Restore their full record.
The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address.
For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input.
[ "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n" ]
[ "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n" ]
none
1,000
[ { "input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0", "output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000...
1,557,585,066
2,147,483,647
PyPy 3
OK
TESTS
40
310
1,945,600
def nts(x): x = str(hex(x))[2:] return '0' * (4 - len(x)) + x def ch(s): if s == '': return '' a = [e for e in s.split(':')] for i in range(len(a)): a[i] = int(a[i], 16) return ':'.join(nts(e) for e in a) def cnt(s): if s == '': return 0 return sum([int(i == ':') for i in s]) + 1 def get(n): return ':'.join(['0000' for i in range(n)]) T = int(input()) for cas in range(T): s = input() p, n = -1, len(s) for i in range(n - 1): if s[i] == s[i + 1] == ':': p = i break if p == -1: s = ch(s) else: s1 = ch(s[:i]) s3 = ch(s[i + 2:]) a, b = cnt(s1), cnt(s3) s2 = get(8 - a - b) s = s1 + ('' if s2 == '' or s1 == '' else ':') + s2 + ('' if s3 == '' or (s1 == '' and s2 == '') else ':') + s3 print(s)
Title: Restoring IPv6 Time Limit: None seconds Memory Limit: None megabytes Problem Description: An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef". We'll call such format of recording an IPv6-address full. Besides the full record of an IPv6 address there is a short record format. The record of an IPv6 address can be shortened by removing one or more leading zeroes at the beginning of each block. However, each block should contain at least one digit in the short format. For example, the leading zeroes can be removed like that: "a56f:00d3:0000:0124:0001:f19a:1000:0000" <=→<= "a56f:d3:0:0124:01:f19a:1000:00". There are more ways to shorten zeroes in this IPv6 address. Some IPv6 addresses contain long sequences of zeroes. Continuous sequences of 16-bit zero blocks can be shortened to "::". A sequence can consist of one or several consecutive blocks, with all 16 bits equal to 0. You can see examples of zero block shortenings below: - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::"; - "a56f:0000:0000:0124:0001:0000:1234:0ff0" <=→<= "a56f::0124:0001:0000:1234:0ff0"; - "a56f:0000:0000:0000:0001:0000:1234:0ff0" <=→<= "a56f:0000::0000:0001:0000:1234:0ff0"; - "a56f:00d3:0000:0124:0001:0000:0000:0000" <=→<= "a56f:00d3:0000:0124:0001::0000"; - "0000:0000:0000:0000:0000:0000:0000:0000" <=→<= "::". It is not allowed to shorten zero blocks in the address more than once. This means that the short record can't contain the sequence of characters "::" more than once. Otherwise, it will sometimes be impossible to determine the number of zero blocks, each represented by a double colon. The format of the record of the IPv6 address after removing the leading zeroes and shortening the zero blocks is called short. You've got several short records of IPv6 addresses. Restore their full record. Input Specification: The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:". It is guaranteed that each short address is obtained by the way that is described in the statement from some full IPv6 address. Output Specification: For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. Demo Input: ['6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n'] Demo Output: ['a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n'] Note: none
```python def nts(x): x = str(hex(x))[2:] return '0' * (4 - len(x)) + x def ch(s): if s == '': return '' a = [e for e in s.split(':')] for i in range(len(a)): a[i] = int(a[i], 16) return ':'.join(nts(e) for e in a) def cnt(s): if s == '': return 0 return sum([int(i == ':') for i in s]) + 1 def get(n): return ':'.join(['0000' for i in range(n)]) T = int(input()) for cas in range(T): s = input() p, n = -1, len(s) for i in range(n - 1): if s[i] == s[i + 1] == ':': p = i break if p == -1: s = ch(s) else: s1 = ch(s[:i]) s3 = ch(s[i + 2:]) a, b = cnt(s1), cnt(s3) s2 = get(8 - a - b) s = s1 + ('' if s2 == '' or s1 == '' else ':') + s2 + ('' if s3 == '' or (s1 == '' and s2 == '') else ':') + s3 print(s) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "...
1,598,209,598
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
6,656,000
l=[] s=input() t=input() s=list(s) t=list(t) for i in range(len(s)): if((s[i]=='1' and t[i]=='1') or (s[i]=='0' and t[i]=='0')): l.append('0') else: l.append('1') for i in range(len(l)): print(l[i])
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python l=[] s=input() t=input() s=list(s) t=list(t) for i in range(len(s)): if((s[i]=='1' and t[i]=='1') or (s[i]=='0' and t[i]=='0')): l.append('0') else: l.append('1') for i in range(len(l)): print(l[i]) ```
0
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, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
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,694,577,079
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
46
0
strng = input() x = 0 a = 0 for i in 'hello': for j in range(a, len(strng)): a += 1 if i == strng[j]: x += 1 break print(x)
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 letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*. Input Specification: 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. Output Specification: If Vasya managed to say hello, print "YES", otherwise print "NO". Demo Input: ['ahhellllloou\n', 'hlelo\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python strng = input() x = 0 a = 0 for i in 'hello': for j in range(a, len(strng)): a += 1 if i == strng[j]: x += 1 break print(x) ```
0
599
A
Patrick and Shopping
PROGRAMMING
800
[ "implementation" ]
null
null
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled.
The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops.
Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house.
[ "10 20 30\n", "1 1 5\n" ]
[ "60\n", "4\n" ]
The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
500
[ { "input": "10 20 30", "output": "60" }, { "input": "1 1 5", "output": "4" }, { "input": "100 33 34", "output": "134" }, { "input": "777 777 777", "output": "2331" }, { "input": "2 2 8", "output": "8" }, { "input": "12 34 56", "output": "92" }, ...
1,587,904,331
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
77
0
d1,d2,d3=map(int,input().split()) print(min(d1,d2)+min(d1+d2,d3)+max(d1,d2))
Title: Patrick and Shopping Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. Input Specification: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. Output Specification: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Demo Input: ['10 20 30\n', '1 1 5\n'] Demo Output: ['60\n', '4\n'] Note: The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house. In the second sample one of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> second shop <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> house.
```python d1,d2,d3=map(int,input().split()) print(min(d1,d2)+min(d1+d2,d3)+max(d1,d2)) ```
0
609
B
The Best Gift
PROGRAMMING
1,100
[ "constructive algorithms", "implementation" ]
null
null
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*.
The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre.
Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109.
[ "4 3\n2 1 3 1\n", "7 4\n4 2 3 1 2 4 3\n" ]
[ "5\n", "18\n" ]
The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
0
[ { "input": "4 3\n2 1 3 1", "output": "5" }, { "input": "7 4\n4 2 3 1 2 4 3", "output": "18" }, { "input": "2 2\n1 2", "output": "1" }, { "input": "3 2\n1 2 2", "output": "2" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "45" }, { "input": "9 2...
1,522,398,224
2,147,483,647
Python 3
OK
TESTS
42
171
10,956,800
if __name__ == '__main__': n, m = list(map(int,input().split())) a = list(map(int, input().split())) res = 0 count = [0] * m for x in a: count[x-1]+=1 for i in range(0,m-1): for j in range(i+1,m): res += count[i]*count[j] print(res)
Title: The Best Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres. In the bookshop, Jack decides to buy two books of different genres. Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book. The books are given by indices of their genres. The genres are numbered from 1 to *m*. Input Specification: The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres. The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book. It is guaranteed that for each genre there is at least one book of that genre. Output Specification: Print the only integer — the number of ways in which Jack can choose books. It is guaranteed that the answer doesn't exceed the value 2·109. Demo Input: ['4 3\n2 1 3 1\n', '7 4\n4 2 3 1 2 4 3\n'] Demo Output: ['5\n', '18\n'] Note: The answer to the first test sample equals 5 as Sasha can choose: 1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books.
```python if __name__ == '__main__': n, m = list(map(int,input().split())) a = list(map(int, input().split())) res = 0 count = [0] * m for x in a: count[x-1]+=1 for i in range(0,m-1): for j in range(i+1,m): res += count[i]*count[j] print(res) ```
3
248
B
Chilly Willy
PROGRAMMING
1,400
[ "math", "number theory" ]
null
null
Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneously divisible by all numbers Willy already knows (2, 3, 5 and 7). Help him with that. A number's length is the number of digits in its decimal representation without leading zeros.
A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105).
Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist.
[ "1\n", "5\n" ]
[ "-1\n", "10080" ]
none
1,000
[ { "input": "1", "output": "-1" }, { "input": "5", "output": "10080" }, { "input": "6", "output": "100170" }, { "input": "4", "output": "1050" }, { "input": "15", "output": "100000000000110" }, { "input": "16", "output": "1000000000000050" }, { ...
1,573,548,415
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
0
n=int(input()) if n<=2: print(-1) else: i=1 while 1: if pow(10,n-1)<210*i<pow(10,n): print(210*i) break else: i+=1
Title: Chilly Willy Time Limit: None seconds Memory Limit: None megabytes Problem Description: Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length *n*, such that it is simultaneously divisible by all numbers Willy already knows (2, 3, 5 and 7). Help him with that. A number's length is the number of digits in its decimal representation without leading zeros. Input Specification: A single input line contains a single integer *n* (1<=≤<=*n*<=≤<=105). Output Specification: Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. Demo Input: ['1\n', '5\n'] Demo Output: ['-1\n', '10080'] Note: none
```python n=int(input()) if n<=2: print(-1) else: i=1 while 1: if pow(10,n-1)<210*i<pow(10,n): print(210*i) break else: i+=1 ```
0
4
C
Registration System
PROGRAMMING
1,300
[ "data structures", "hashing", "implementation" ]
C. Registration system
5
64
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database.
The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
[ "4\nabacaba\nacaba\nabacaba\nacab\n", "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n" ]
[ "OK\nOK\nabacaba1\nOK\n", "OK\nfirst1\nOK\nsecond1\nOK\nthird1\n" ]
none
0
[ { "input": "4\nabacaba\nacaba\nabacaba\nacab", "output": "OK\nOK\nabacaba1\nOK" }, { "input": "6\nfirst\nfirst\nsecond\nsecond\nthird\nthird", "output": "OK\nfirst1\nOK\nsecond1\nOK\nthird1" }, { "input": "1\nn", "output": "OK" }, { "input": "2\nu\nu", "output": "OK\nu1" ...
1,690,131,640
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
92
0
a = int(input()) counter = 0 c = list() flist=list() for i in range(0,a): b = str(input()) if b in c: sc=c.count(b) b = b + str(sc) c.append(b) flist.append(b) else: c.append(b) flist.append("OK") for j in range(0,a): print(flist[j])
Title: Registration System Time Limit: 5 seconds Memory Limit: 64 megabytes Problem Description: A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle. Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least *i* is found so that name*i* does not yet exist in the database. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=105). The following *n* lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters. Output Specification: Print *n* lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken. Demo Input: ['4\nabacaba\nacaba\nabacaba\nacab\n', '6\nfirst\nfirst\nsecond\nsecond\nthird\nthird\n'] Demo Output: ['OK\nOK\nabacaba1\nOK\n', 'OK\nfirst1\nOK\nsecond1\nOK\nthird1\n'] Note: none
```python a = int(input()) counter = 0 c = list() flist=list() for i in range(0,a): b = str(input()) if b in c: sc=c.count(b) b = b + str(sc) c.append(b) flist.append(b) else: c.append(b) flist.append("OK") for j in range(0,a): print(flist[j]) ```
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 of Gems you saw in the Gauntlet determine the names of absent Gems.
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 English letters.
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,616,734,430
2,147,483,647
Python 3
OK
TESTS
64
77
307,200
n=int(input()) gauntlet_color=['purple', 'green', 'blue', 'orange', 'red', 'yellow'] gauntlet={'purple':'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind'} color=[] print(6-n) for i in range(n): color.append(input()) diff = [i for i in gauntlet_color if i not in color] for c in diff: print(gauntlet[c])
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 Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: 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 English letters. Output Specification: 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. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: 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.
```python n=int(input()) gauntlet_color=['purple', 'green', 'blue', 'orange', 'red', 'yellow'] gauntlet={'purple':'Power', 'green':'Time', 'blue':'Space', 'orange':'Soul', 'red':'Reality', 'yellow':'Mind'} color=[] print(6-n) for i in range(n): color.append(input()) diff = [i for i in gauntlet_color if i not in color] for c in diff: print(gauntlet[c]) ```
3
689
B
Mike and Shortcuts
PROGRAMMING
1,600
[ "dfs and similar", "graphs", "greedy", "shortest paths" ]
null
null
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*).
In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*.
[ "3\n2 2 3\n", "5\n1 2 3 4 5\n", "7\n4 4 4 4 7 7 7\n" ]
[ "0 1 2 \n", "0 1 2 3 4 \n", "0 1 2 1 2 3 3 \n" ]
In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
1,000
[ { "input": "3\n2 2 3", "output": "0 1 2 " }, { "input": "5\n1 2 3 4 5", "output": "0 1 2 3 4 " }, { "input": "7\n4 4 4 4 7 7 7", "output": "0 1 2 1 2 3 3 " }, { "input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87...
1,606,085,271
2,147,483,647
Python 3
OK
TESTS
54
2,043
16,384,000
import queue n = int(input()) m = input().split(' ') usado = [] a = [] for i in range(0, n): usado.append(False) a.append(-1) q = queue.Queue() q.put(0) a[0] = 0 while not(q.empty()): v = q.get() for dl in range(-1, +2): u = v + dl if 0 <= u and u < n and a[u] == -1: a[u] = a[v] + 1 q.put(u) u = int(m[v]) - 1 if a[u] == -1: a[u] = a[v] + 1 q.put(u) for i in range(0, n): print(a[i])
Title: Mike and Shortcuts Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Walking from intersection number *i* to intersection *j* requires |*i*<=-<=*j*| units of energy. The total energy spent by Mike to visit a sequence of intersections *p*1<==<=1,<=*p*2,<=...,<=*p**k* is equal to units of energy. Of course, walking would be boring if there were no shortcuts. A shortcut is a special path that allows Mike walking from one intersection to another requiring only 1 unit of energy. There are exactly *n* shortcuts in Mike's city, the *i**th* of them allows walking from intersection *i* to intersection *a**i* (*i*<=≤<=*a**i*<=≤<=*a**i*<=+<=1) (but not in the opposite direction), thus there is exactly one shortcut starting at each intersection. Formally, if Mike chooses a sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k* then for each 1<=≤<=*i*<=&lt;<=*k* satisfying *p**i*<=+<=1<==<=*a**p**i* and *a**p**i*<=≠<=*p**i* Mike will spend only 1 unit of energy instead of |*p**i*<=-<=*p**i*<=+<=1| walking from the intersection *p**i* to intersection *p**i*<=+<=1. For example, if Mike chooses a sequence *p*1<==<=1,<=*p*2<==<=*a**p*1,<=*p*3<==<=*a**p*2,<=...,<=*p**k*<==<=*a**p**k*<=-<=1, he spends exactly *k*<=-<=1 units of total energy walking around them. Before going on his adventure, Mike asks you to find the minimum amount of energy required to reach each of the intersections from his home. Formally, for each 1<=≤<=*i*<=≤<=*n* Mike is interested in finding minimum possible total energy of some sequence *p*1<==<=1,<=*p*2,<=...,<=*p**k*<==<=*i*. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of energy. Please note that the shortcuts don't allow walking in opposite directions (from *a**i* to *i*). Output Specification: In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. Demo Input: ['3\n2 2 3\n', '5\n1 2 3 4 5\n', '7\n4 4 4 4 7 7 7\n'] Demo Output: ['0 1 2 \n', '0 1 2 3 4 \n', '0 1 2 1 2 3 3 \n'] Note: In the first sample case desired sequences are: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = 1; 3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2. In the second sample case the sequence for any intersection 1 &lt; *i* is always 1, *i* and *m*<sub class="lower-index">*i*</sub> = |1 - *i*|. In the third sample case — consider the following intersection sequences: 1: 1; *m*<sub class="lower-index">1</sub> = 0; 2: 1, 2; *m*<sub class="lower-index">2</sub> = |2 - 1| = 1; 3: 1, 4, 3; *m*<sub class="lower-index">3</sub> = 1 + |4 - 3| = 2; 4: 1, 4; *m*<sub class="lower-index">4</sub> = 1; 5: 1, 4, 5; *m*<sub class="lower-index">5</sub> = 1 + |4 - 5| = 2; 6: 1, 4, 6; *m*<sub class="lower-index">6</sub> = 1 + |4 - 6| = 3; 7: 1, 4, 5, 7; *m*<sub class="lower-index">7</sub> = 1 + |4 - 5| + 1 = 3.
```python import queue n = int(input()) m = input().split(' ') usado = [] a = [] for i in range(0, n): usado.append(False) a.append(-1) q = queue.Queue() q.put(0) a[0] = 0 while not(q.empty()): v = q.get() for dl in range(-1, +2): u = v + dl if 0 <= u and u < n and a[u] == -1: a[u] = a[v] + 1 q.put(u) u = int(m[v]) - 1 if a[u] == -1: a[u] = a[v] + 1 q.put(u) for i in range(0, n): print(a[i]) ```
3
414
B
Mashmokh and ACM
PROGRAMMING
1,400
[ "combinatorics", "dp", "number theory" ]
null
null
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7).
The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000).
Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7).
[ "3 2\n", "6 4\n", "2 1\n" ]
[ "5\n", "39\n", "2\n" ]
In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
1,000
[ { "input": "3 2", "output": "5" }, { "input": "6 4", "output": "39" }, { "input": "2 1", "output": "2" }, { "input": "1478 194", "output": "312087753" }, { "input": "1415 562", "output": "953558593" }, { "input": "1266 844", "output": "735042656" ...
1,521,317,088
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
namespace ConsoleApp1 { using System; using System.Linq; class Program { private static int _mod = 1000000007; static void Main(string[] args) { string[] line = Console.ReadLine().Split(); int n = int.Parse(line[0]); int k = int.Parse(line[1]); int[][] layers = new int[k + 1][]; for (int i = 0; i < k + 1; i++) { layers[i] = new int[n + 1]; } layers[0][1] = 1; for (int layerId = 1; layerId < k + 1; layerId++) { for (int preproduct = 1; preproduct < n + 1; preproduct++) { for (int multiplicator = 1; multiplicator <= n / preproduct; multiplicator++) { int product = preproduct * multiplicator; layers[layerId][product] += layers[layerId - 1][preproduct]; } } } Console.WriteLine(layers.Last().Select(x => (long)x % _mod).Sum() % _mod); } } }
Title: Mashmokh and ACM Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn't able to solve them. That's why he asked you to help him with these tasks. One of these tasks is the following. A sequence of *l* integers *b*1,<=*b*2,<=...,<=*b**l* (1<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**l*<=≤<=*n*) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all *i* (1<=≤<=*i*<=≤<=*l*<=-<=1). Given *n* and *k* find the number of good sequences of length *k*. As the answer can be rather large print it modulo 1000000007 (109<=+<=7). Input Specification: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*,<=*k*<=≤<=2000). Output Specification: Output a single integer — the number of good sequences of length *k* modulo 1000000007 (109<=+<=7). Demo Input: ['3 2\n', '6 4\n', '2 1\n'] Demo Output: ['5\n', '39\n', '2\n'] Note: In the first sample the good sequences are: [1, 1], [2, 2], [3, 3], [1, 2], [1, 3].
```python namespace ConsoleApp1 { using System; using System.Linq; class Program { private static int _mod = 1000000007; static void Main(string[] args) { string[] line = Console.ReadLine().Split(); int n = int.Parse(line[0]); int k = int.Parse(line[1]); int[][] layers = new int[k + 1][]; for (int i = 0; i < k + 1; i++) { layers[i] = new int[n + 1]; } layers[0][1] = 1; for (int layerId = 1; layerId < k + 1; layerId++) { for (int preproduct = 1; preproduct < n + 1; preproduct++) { for (int multiplicator = 1; multiplicator <= n / preproduct; multiplicator++) { int product = preproduct * multiplicator; layers[layerId][product] += layers[layerId - 1][preproduct]; } } } Console.WriteLine(layers.Last().Select(x => (long)x % _mod).Sum() % _mod); } } } ```
-1
722
C
Destroying Array
PROGRAMMING
1,600
[ "data structures", "dsu" ]
null
null
You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements.
Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed.
[ "4\n1 3 2 5\n3 4 1 2\n", "5\n1 2 3 4 5\n4 2 3 5 1\n", "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n" ]
[ "5\n4\n3\n0\n", "6\n5\n5\n1\n0\n", "18\n16\n11\n8\n8\n6\n6\n0\n" ]
Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
1,000
[ { "input": "4\n1 3 2 5\n3 4 1 2", "output": "5\n4\n3\n0" }, { "input": "5\n1 2 3 4 5\n4 2 3 5 1", "output": "6\n5\n5\n1\n0" }, { "input": "8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6", "output": "18\n16\n11\n8\n8\n6\n6\n0" }, { "input": "10\n3 3 3 5 6 9 3 1 7 3\n3 4 6 7 5 1 10 9 2 8"...
1,476,699,931
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
4,608,000
size = int(raw_input()) num = map(int, raw_input().split(" ")) rem = map(lambda x: int(x) - 1, raw_input().split(" ")) def subsum(lst): ms = 0 cs = 0 for i in lst: cs += i if i == 0 and cs > ms: ms = cs cs = 0 return ms if ms > cs else cs for i in rem: num[i] = 0 print (subsum(num))
Title: Destroying Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array consisting of *n* non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to *n* defining the order elements of the array are destroyed. After each element is destroyed you have to find out the segment of the array, such that it contains no destroyed elements and the sum of its elements is maximum possible. The sum of elements in the empty segment is considered to be 0. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). The third line contains a permutation of integers from 1 to *n* — the order used to destroy elements. Output Specification: Print *n* lines. The *i*-th line should contain a single integer — the maximum possible sum of elements on the segment containing no destroyed elements, after first *i* operations are performed. Demo Input: ['4\n1 3 2 5\n3 4 1 2\n', '5\n1 2 3 4 5\n4 2 3 5 1\n', '8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n'] Demo Output: ['5\n4\n3\n0\n', '6\n5\n5\n1\n0\n', '18\n16\n11\n8\n8\n6\n6\n0\n'] Note: Consider the first sample: 1. Third element is destroyed. Array is now 1 3  *  5. Segment with maximum sum 5 consists of one integer 5. 1. Fourth element is destroyed. Array is now 1 3  *   * . Segment with maximum sum 4 consists of two integers 1 3. 1. First element is destroyed. Array is now  *  3  *   * . Segment with maximum sum 3 consists of one integer 3. 1. Last element is destroyed. At this moment there are no valid nonempty segments left in this array, so the answer is equal to 0.
```python size = int(raw_input()) num = map(int, raw_input().split(" ")) rem = map(lambda x: int(x) - 1, raw_input().split(" ")) def subsum(lst): ms = 0 cs = 0 for i in lst: cs += i if i == 0 and cs > ms: ms = cs cs = 0 return ms if ms > cs else cs for i in rem: num[i] = 0 print (subsum(num)) ```
-1
30
A
Accounting
PROGRAMMING
1,400
[ "brute force", "math" ]
A. Accounting
2
256
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative.
The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10).
Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them.
[ "2 18 2\n", "-1 8 3\n", "0 0 10\n", "1 16 5\n" ]
[ "3", "-2", "5", "No solution" ]
none
500
[ { "input": "2 18 2", "output": "3" }, { "input": "-1 8 3", "output": "-2" }, { "input": "0 0 10", "output": "5" }, { "input": "1 16 5", "output": "No solution" }, { "input": "0 1 2", "output": "No solution" }, { "input": "3 0 4", "output": "0" },...
1,602,768,355
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
218
307,200
import sys a, b, n = map(int, input().split()) if a == 0 and b == 0: print(1) sys.exit() if a == 0 or b == 0: print('No solution') sys.exit() x = b / a if x != int(x): print('No solution') sys.exit() x = int(x) for i in range(-b, b + 1): if i ** n == x: print(i) sys.exit() print('No solution') # Thu Oct 15 2020 16:25:53 GMT+0300 (Москва, стандартное время)
Title: Accounting Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. Input Specification: The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). Output Specification: Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. Demo Input: ['2 18 2\n', '-1 8 3\n', '0 0 10\n', '1 16 5\n'] Demo Output: ['3', '-2', '5', 'No solution'] Note: none
```python import sys a, b, n = map(int, input().split()) if a == 0 and b == 0: print(1) sys.exit() if a == 0 or b == 0: print('No solution') sys.exit() x = b / a if x != int(x): print('No solution') sys.exit() x = int(x) for i in range(-b, b + 1): if i ** n == x: print(i) sys.exit() print('No solution') # Thu Oct 15 2020 16:25:53 GMT+0300 (Москва, стандартное время) ```
0
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input"...
1,660,645,437
2,147,483,647
Python 3
OK
TESTS
37
61
409,600
n, m = map(int, input().split()) save = {} for _ in range(m): x, y = input().split() save[x] = y lecture = input() output = [] for noun in lecture.split(): if len(noun) > len(save[noun]): output.append(save[noun]) else: output.append(noun) print(*output)
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n, m = map(int, input().split()) save = {} for _ in range(m): x, y = input().split() save[x] = y lecture = input() output = [] for noun in lecture.split(): if len(noun) > len(save[noun]): output.append(save[noun]) else: output.append(noun) print(*output) ```
3
735
A
Ostap and Grasshopper
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
[ "5 2\n#G#T#\n", "6 1\nT....G\n", "7 3\nT..#..G\n", "6 2\n..GT..\n" ]
[ "YES\n", "YES\n", "NO\n", "NO\n" ]
In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
500
[ { "input": "5 2\n#G#T#", "output": "YES" }, { "input": "6 1\nT....G", "output": "YES" }, { "input": "7 3\nT..#..G", "output": "NO" }, { "input": "6 2\n..GT..", "output": "NO" }, { "input": "2 1\nGT", "output": "YES" }, { "input": "100 5\nG####.####.###...
1,662,639,325
2,147,483,647
Python 3
OK
TESTS
83
46
0
def add_possible_jumps(n, k, visited, current, stack): if current - k >= 0 and not visited[current - k]: stack.append(current - k) if current + k < n and not visited[current + k]: stack.append(current + k) def ostap_and_grasshopper(n, k, sequence): visited = [False] * n start = sequence.find("G") visited[start] = True stack = [] add_possible_jumps(n, k, visited, start, stack) while len(stack) > 0: current = stack.pop() if sequence[current] == "T": return True else: visited[current] = True if sequence[current] == ".": add_possible_jumps(n, k, visited, current, stack) return False if __name__ == '__main__': [n, k] = input().split(" ") sequence = input() output = ostap_and_grasshopper(int(n), int(k), sequence) print("YES" if output else "NO")
Title: Ostap and Grasshopper Time Limit: None seconds Memory Limit: None megabytes Problem Description: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. Input Specification: The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. Output Specification: If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Demo Input: ['5 2\n#G#T#\n', '6 1\nT....G\n', '7 3\nT..#..G\n', '6 2\n..GT..\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n', 'NO\n'] Note: In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
```python def add_possible_jumps(n, k, visited, current, stack): if current - k >= 0 and not visited[current - k]: stack.append(current - k) if current + k < n and not visited[current + k]: stack.append(current + k) def ostap_and_grasshopper(n, k, sequence): visited = [False] * n start = sequence.find("G") visited[start] = True stack = [] add_possible_jumps(n, k, visited, start, stack) while len(stack) > 0: current = stack.pop() if sequence[current] == "T": return True else: visited[current] = True if sequence[current] == ".": add_possible_jumps(n, k, visited, current, stack) return False if __name__ == '__main__': [n, k] = input().split(" ") sequence = input() output = ostap_and_grasshopper(int(n), int(k), sequence) print("YES" if output else "NO") ```
3
595
B
Pasha and Phone
PROGRAMMING
1,600
[ "binary search", "math" ]
null
null
Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*n* is divisible by *k*) *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* and *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k*. Let's split the phone number into blocks of length *k*. The first block will be formed by digits from the phone number that are on positions 1, 2,..., *k*, the second block will be formed by digits from the phone number that are on positions *k*<=+<=1, *k*<=+<=2, ..., 2·*k* and so on. Pasha considers a phone number good, if the *i*-th block doesn't start from the digit *b**i* and is divisible by *a**i* if represented as an integer. To represent the block of length *k* as an integer, let's write it out as a sequence *c*1, *c*2,...,*c**k*. Then the integer is calculated as the result of the expression *c*1·10*k*<=-<=1<=+<=*c*2·10*k*<=-<=2<=+<=...<=+<=*c**k*. Pasha asks you to calculate the number of good phone numbers of length *n*, for the given *k*, *a**i* and *b**i*. As this number can be too big, print it modulo 109<=+<=7.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(*n*,<=9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that *n* is divisible by *k*. The second line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* (1<=≤<=*a**i*<=&lt;<=10*k*). The third line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k* (0<=≤<=*b**i*<=≤<=9).
Print a single integer — the number of good phone numbers of length *n* modulo 109<=+<=7.
[ "6 2\n38 56 49\n7 3 4\n", "8 2\n1 22 3 44\n5 4 3 2\n" ]
[ "8\n", "32400\n" ]
In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
1,000
[ { "input": "6 2\n38 56 49\n7 3 4", "output": "8" }, { "input": "8 2\n1 22 3 44\n5 4 3 2", "output": "32400" }, { "input": "2 1\n9 9\n9 9", "output": "1" }, { "input": "2 1\n9 9\n0 9", "output": "1" }, { "input": "4 1\n4 3 2 1\n1 2 3 4", "output": "540" }, ...
1,447,003,609
3,409
Python 3
WRONG_ANSWER
PRETESTS
5
46
0
n,k=map(int,input().split()) a=input().split() b=input().split() ans = 1 for i in range(0,n//k): a[i]=int(a[i]) b[i]=int(b[i]) cnt1 = ((10**k-1)//a[i]+1) cnt2 = ((b[i]+1)*(10**(k-1))-1)//a[i] cnt3 = ((b[i])*(10**(k-1))-1)//a[i] ans *= cnt1-(cnt2-cnt3) print(ans)
Title: Pasha and Phone Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has recently bought a new phone jPager and started adding his friends' phone numbers there. Each phone number consists of exactly *n* digits. Also Pasha has a number *k* and two sequences of length *n*<=/<=*k* (*n* is divisible by *k*) *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* and *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k*. Let's split the phone number into blocks of length *k*. The first block will be formed by digits from the phone number that are on positions 1, 2,..., *k*, the second block will be formed by digits from the phone number that are on positions *k*<=+<=1, *k*<=+<=2, ..., 2·*k* and so on. Pasha considers a phone number good, if the *i*-th block doesn't start from the digit *b**i* and is divisible by *a**i* if represented as an integer. To represent the block of length *k* as an integer, let's write it out as a sequence *c*1, *c*2,...,*c**k*. Then the integer is calculated as the result of the expression *c*1·10*k*<=-<=1<=+<=*c*2·10*k*<=-<=2<=+<=...<=+<=*c**k*. Pasha asks you to calculate the number of good phone numbers of length *n*, for the given *k*, *a**i* and *b**i*. As this number can be too big, print it modulo 109<=+<=7. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*min*(*n*,<=9)) — the length of all phone numbers and the length of each block, respectively. It is guaranteed that *n* is divisible by *k*. The second line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *a*1,<=*a*2,<=...,<=*a**n*<=/<=*k* (1<=≤<=*a**i*<=&lt;<=10*k*). The third line of the input contains *n*<=/<=*k* space-separated positive integers — sequence *b*1,<=*b*2,<=...,<=*b**n*<=/<=*k* (0<=≤<=*b**i*<=≤<=9). Output Specification: Print a single integer — the number of good phone numbers of length *n* modulo 109<=+<=7. Demo Input: ['6 2\n38 56 49\n7 3 4\n', '8 2\n1 22 3 44\n5 4 3 2\n'] Demo Output: ['8\n', '32400\n'] Note: In the first test sample good phone numbers are: 000000, 000098, 005600, 005698, 380000, 380098, 385600, 385698.
```python n,k=map(int,input().split()) a=input().split() b=input().split() ans = 1 for i in range(0,n//k): a[i]=int(a[i]) b[i]=int(b[i]) cnt1 = ((10**k-1)//a[i]+1) cnt2 = ((b[i]+1)*(10**(k-1))-1)//a[i] cnt3 = ((b[i])*(10**(k-1))-1)//a[i] ans *= cnt1-(cnt2-cnt3) print(ans) ```
0
572
A
Arrays
PROGRAMMING
900
[ "sortings" ]
null
null
You are given two arrays *A* and *B* consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose *k* numbers in array *A* and choose *m* numbers in array *B* so that any number chosen in the first array is strictly less than any number chosen in the second array.
The first line contains two integers *n**A*,<=*n**B* (1<=≤<=*n**A*,<=*n**B*<=≤<=105), separated by a space — the sizes of arrays *A* and *B*, correspondingly. The second line contains two integers *k* and *m* (1<=≤<=*k*<=≤<=*n**A*,<=1<=≤<=*m*<=≤<=*n**B*), separated by a space. The third line contains *n**A* numbers *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*.
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 numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
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,596,357,632
2,147,483,647
Python 3
OK
TESTS
52
156
17,715,200
R=lambda:map(int,input().split()) n,m=R() k,l=R() a=(list(R())) b=(list(R())) if a[k-1]<b[m-l]: 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 first array is strictly less than any number chosen in the second array. Input Specification: 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 *a*1,<=*a*2,<=... *a**n**A* (<=-<=109<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n**A*<=≤<=109), separated by spaces — elements of array *A*. The fourth line contains *n**B* integers *b*1,<=*b*2,<=... *b**n**B* (<=-<=109<=≤<=*b*1<=≤<=*b*2<=≤<=...<=≤<=*b**n**B*<=≤<=109), separated by spaces — elements of array *B*. Output Specification: 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). Demo Input: ['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'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: 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 numbers chosen in *A* will be less than all the numbers chosen in *B*: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7280148ed5eab0a7d418d4f92b32061243a8ca58.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python R=lambda:map(int,input().split()) n,m=R() k,l=R() a=(list(R())) b=(list(R())) if a[k-1]<b[m-l]: print("YES") else: print("NO") ```
3
22
A
Second Order Statistics
PROGRAMMING
800
[ "brute force" ]
A. Second Order Statistics
2
256
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem.
The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value.
If the given sequence has the second order statistics, output this order statistics, otherwise output NO.
[ "4\n1 2 2 -4\n", "5\n1 2 3 1 1\n" ]
[ "1\n", "2\n" ]
none
0
[ { "input": "4\n1 2 2 -4", "output": "1" }, { "input": "5\n1 2 3 1 1", "output": "2" }, { "input": "1\n28", "output": "NO" }, { "input": "2\n-28 12", "output": "12" }, { "input": "3\n-83 40 -80", "output": "-80" }, { "input": "8\n93 77 -92 26 21 -48 53 ...
1,488,809,560
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
2
124
4,608,000
# Second Order Statistics n=int(input('')) listB=[] listA=[int(x) for x in input('').split()] for i in listA: if i not in listB: listB.append(i) sortedB=sorted(listB) print(sortedB[1])
Title: Second Order Statistics Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. Input Specification: The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. Output Specification: If the given sequence has the second order statistics, output this order statistics, otherwise output NO. Demo Input: ['4\n1 2 2 -4\n', '5\n1 2 3 1 1\n'] Demo Output: ['1\n', '2\n'] Note: none
```python # Second Order Statistics n=int(input('')) listB=[] listA=[int(x) for x in input('').split()] for i in listA: if i not in listB: listB.append(i) sortedB=sorted(listB) print(sortedB[1]) ```
-1
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 three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions.
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**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once.
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 recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
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,579,413,260
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
71,270,400
# cook your dish here n,m=map(int,input().split(" ")) d={} for i in range(1,n+1): d[i]=0 matrix=[[0 for i in range(n+1)]for j in range(n+1)] for _ in range(m): u,v=map(int,input().split(" ")) matrix[u][v]=1 matrix[v][u]=1 d[u]+=1 d[v]+=1 #print(d,matrix) ans=-1 for i in range(1,n): j=i+1 while j<=n: if matrix[i][j]==1: k=j+1 while k<=n: if matrix[i][j]==1 and matrix[i][k]==1: if ans==-1: ans=d[i]+d[j]+d[k] else: ans=min(ans,d[i]+d[j]+d[k]) k+=1 j+=1 if ans==-1: print(-1) else: print(ans-6)
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 brave warriors to help him to fight against bad guys. There are *n* warriors. Richelimakieu wants to choose three of them to become musketeers but it's not that easy. The most important condition is that musketeers must know each other to cooperate efficiently. And they shouldn't be too well known because they could be betrayed by old friends. For each musketeer his recognition is the number of warriors he knows, excluding other two musketeers. Help Richelimakieu! Find if it is possible to choose three musketeers knowing each other, and what is minimum possible sum of their recognitions. Input Specification: 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**i*<=≠<=*b**i*). Warriors *a**i* and *b**i* know each other. Each pair of warriors will be listed at most once. Output Specification: If Richelimakieu can choose three musketeers, print the minimum possible sum of their recognitions. Otherwise, print "-1" (without the quotes). Demo Input: ['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'] Demo Output: ['2\n', '-1\n'] Note: 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 recognitions is 0 + 1 + 1 = 2. The other possible triple is 2, 3, 4 but it has greater sum of recognitions, equal to 1 + 1 + 1 = 3. In the second sample there is no triple of warriors knowing each other.
```python # cook your dish here n,m=map(int,input().split(" ")) d={} for i in range(1,n+1): d[i]=0 matrix=[[0 for i in range(n+1)]for j in range(n+1)] for _ in range(m): u,v=map(int,input().split(" ")) matrix[u][v]=1 matrix[v][u]=1 d[u]+=1 d[v]+=1 #print(d,matrix) ans=-1 for i in range(1,n): j=i+1 while j<=n: if matrix[i][j]==1: k=j+1 while k<=n: if matrix[i][j]==1 and matrix[i][k]==1: if ans==-1: ans=d[i]+d[j]+d[k] else: ans=min(ans,d[i]+d[j]+d[k]) k+=1 j+=1 if ans==-1: print(-1) else: print(ans-6) ```
0
678
E
Another Sith Tournament
PROGRAMMING
2,200
[ "bitmasks", "dp", "math", "probabilities" ]
null
null
The rules of Sith Tournament are well known to everyone. *n* Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive. Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=18) — the number of participants of the Sith Tournament. Each of the next *n* lines contains *n* real numbers, which form a matrix *p**ij* (0<=≤<=*p**ij*<=≤<=1). Each its element *p**ij* is the probability that the *i*-th participant defeats the *j*-th in a duel. The elements on the main diagonal *p**ii* are equal to zero. For all different *i*, *j* the equality *p**ij*<=+<=*p**ji*<==<=1 holds. All probabilities are given with no more than six decimal places. Jedi Ivan is the number 1 in the list of the participants.
Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10<=-<=6.
[ "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0\n" ]
[ "0.680000000000000\n" ]
none
0
[ { "input": "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0", "output": "0.680000000000000" }, { "input": "1\n0.0", "output": "1.000000000000000" }, { "input": "2\n0.00 0.75\n0.25 0.00", "output": "0.750000000000000" }, { "input": "4\n0.0 0.6 0.5 0.4\n0.4 0.0 0.3 0.8\n0.5 0.7 0.0 0....
1,665,980,681
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
13
2,136
98,406,400
n=int(input()) p=[] for i in range(n): p.append(list(map(float,input().split()))) dp=[[0]*n for i in range(1<<n)] dp[1][0]=1 for bit in range(1,1<<n): for i in range(n): if (bit>>i)&1: for j in range(n): if (bit>>i)&1 and i!=j: res=dp[bit-(1<<j)][i]*p[i][j]+dp[bit-(1<<i)][j]*p[j][i] dp[bit][i]=max(dp[bit][i],res) print(max(dp[-1]))
Title: Another Sith Tournament Time Limit: None seconds Memory Limit: None megabytes Problem Description: The rules of Sith Tournament are well known to everyone. *n* Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each battle in the Sith Tournament ends with a death of one of opponents? The Tournament ends when the only Sith remains alive. Jedi Ivan accidentally appeared in the list of the participants in the Sith Tournament. However, his skills in the Light Side of the Force are so strong so he can influence the choice of participants either who start the Tournament or who take the loser's place after each battle. Of course, he won't miss his chance to take advantage of it. Help him to calculate the probability of his victory. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=18) — the number of participants of the Sith Tournament. Each of the next *n* lines contains *n* real numbers, which form a matrix *p**ij* (0<=≤<=*p**ij*<=≤<=1). Each its element *p**ij* is the probability that the *i*-th participant defeats the *j*-th in a duel. The elements on the main diagonal *p**ii* are equal to zero. For all different *i*, *j* the equality *p**ij*<=+<=*p**ji*<==<=1 holds. All probabilities are given with no more than six decimal places. Jedi Ivan is the number 1 in the list of the participants. Output Specification: Output a real number — the probability that Jedi Ivan will stay alive after the Tournament. Absolute or relative error of the answer must not exceed 10<=-<=6. Demo Input: ['3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0\n'] Demo Output: ['0.680000000000000\n'] Note: none
```python n=int(input()) p=[] for i in range(n): p.append(list(map(float,input().split()))) dp=[[0]*n for i in range(1<<n)] dp[1][0]=1 for bit in range(1,1<<n): for i in range(n): if (bit>>i)&1: for j in range(n): if (bit>>i)&1 and i!=j: res=dp[bit-(1<<j)][i]*p[i][j]+dp[bit-(1<<i)][j]*p[j][i] dp[bit][i]=max(dp[bit][i],res) print(max(dp[-1])) ```
0
95
D
Horse Races
PROGRAMMING
2,500
[ "dp", "math" ]
D. Horse Races
2
256
Petya likes horse racing very much. Horses numbered from *l* to *r* take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A nearly lucky number is an integer number that has at least two lucky digits the distance between which does not exceed *k*. Petya learned from some of his mates from Lviv that lucky digits are digits 4 and 7. The distance between the digits is the absolute difference between their positions in the number of a horse. For example, if *k*<==<=2, then numbers 412395497, 404, 4070400000070004007 are nearly lucky and numbers 4, 4123954997, 4007000040070004007 are not. Petya prepared *t* intervals [*l**i*,<=*r**i*] and invented number *k*, common for all of them. Your task is to find how many nearly happy numbers there are in each of these segments. Since the answers can be quite large, output them modulo 1000000007 (109<=+<=7).
The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=1000) — the number of segments and the distance between the numbers correspondingly. Next *t* lines contain pairs of integers *l**i* and *r**i* (1<=≤<=*l*<=≤<=*r*<=≤<=101000). All numbers are given without the leading zeroes. Numbers in each line are separated by exactly one space character.
Output *t* lines. In each line print one integer — the answer for the corresponding segment modulo 1000000007 (109<=+<=7).
[ "1 2\n1 100\n", "1 2\n70 77\n", "2 1\n1 20\n80 100\n" ]
[ "4\n", "2\n", "0\n0\n" ]
In the first sample, the four nearly lucky numbers are 44, 47, 74, 77. In the second sample, only 74 and 77 are in the given segment.
2,000
[]
1,689,174,692
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
92
0
print("_RANDOM_GUESS_1689174691.759926")# 1689174691.759939
Title: Horse Races Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya likes horse racing very much. Horses numbered from *l* to *r* take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A nearly lucky number is an integer number that has at least two lucky digits the distance between which does not exceed *k*. Petya learned from some of his mates from Lviv that lucky digits are digits 4 and 7. The distance between the digits is the absolute difference between their positions in the number of a horse. For example, if *k*<==<=2, then numbers 412395497, 404, 4070400000070004007 are nearly lucky and numbers 4, 4123954997, 4007000040070004007 are not. Petya prepared *t* intervals [*l**i*,<=*r**i*] and invented number *k*, common for all of them. Your task is to find how many nearly happy numbers there are in each of these segments. Since the answers can be quite large, output them modulo 1000000007 (109<=+<=7). Input Specification: The first line contains two integers *t* and *k* (1<=≤<=*t*,<=*k*<=≤<=1000) — the number of segments and the distance between the numbers correspondingly. Next *t* lines contain pairs of integers *l**i* and *r**i* (1<=≤<=*l*<=≤<=*r*<=≤<=101000). All numbers are given without the leading zeroes. Numbers in each line are separated by exactly one space character. Output Specification: Output *t* lines. In each line print one integer — the answer for the corresponding segment modulo 1000000007 (109<=+<=7). Demo Input: ['1 2\n1 100\n', '1 2\n70 77\n', '2 1\n1 20\n80 100\n'] Demo Output: ['4\n', '2\n', '0\n0\n'] Note: In the first sample, the four nearly lucky numbers are 44, 47, 74, 77. In the second sample, only 74 and 77 are in the given segment.
```python print("_RANDOM_GUESS_1689174691.759926")# 1689174691.759939 ```
0
805
A
Fake NP
PROGRAMMING
1,000
[ "greedy", "math" ]
null
null
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem.
The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109).
Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.
[ "19 29\n", "3 6\n" ]
[ "2\n", "3\n" ]
Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
500
[ { "input": "19 29", "output": "2" }, { "input": "3 6", "output": "2" }, { "input": "39 91", "output": "2" }, { "input": "76 134", "output": "2" }, { "input": "93 95", "output": "2" }, { "input": "17 35", "output": "2" }, { "input": "94 95",...
1,609,776,046
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
41
202
1,331,200
import math l, r = map(int, input().split()) rs = 0 mx = 0 for i in range(2, int(math.sqrt(r)+1)): x = l // i if l % i != 0: x += 1 x2 = r // i if x2 >= x: if mx < x2 - x + 1: mx = x2 - x + 1 rs = i print(rs)
Title: Fake NP Time Limit: None seconds Memory Limit: None megabytes Problem Description: Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. Input Specification: The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). Output Specification: Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. Demo Input: ['19 29\n', '3 6\n'] Demo Output: ['2\n', '3\n'] Note: Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html) The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
```python import math l, r = map(int, input().split()) rs = 0 mx = 0 for i in range(2, int(math.sqrt(r)+1)): x = l // i if l % i != 0: x += 1 x2 = r // i if x2 >= x: if mx < x2 - x + 1: mx = x2 - x + 1 rs = i print(rs) ```
0
31
A
Worms Evolution
PROGRAMMING
1,200
[ "implementation" ]
A. Worms Evolution
2
256
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
[ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ]
[ "3 2 1\n", "-1\n" ]
none
500
[ { "input": "5\n1 2 3 5 7", "output": "3 2 1" }, { "input": "5\n1 8 1 5 1", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "6\n86 402 133 524 405 610", "output": "6 4 1" }, { "input": "8\n217 779 418 895 996 473 3 22", "output":...
1,576,859,873
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
186
307,200
x = int(input()) y = [int(i) for i in input().split()] z = [-1] k = 0 for i in range(x): for j in range(x): for q in range(x): if i != j and j != q and i != q: if y[i]+y[j]+y[q]==2*max(y[i], y[j], y[q]): z = [i+1, j+1, q+1] k = 1 if k == 1: break if k == 1: break if k == 1: break for i in z: print(i, end=' ')
Title: Worms Evolution Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. Output Specification: Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. Demo Input: ['5\n1 2 3 5 7\n', '5\n1 8 1 5 1\n'] Demo Output: ['3 2 1\n', '-1\n'] Note: none
```python x = int(input()) y = [int(i) for i in input().split()] z = [-1] k = 0 for i in range(x): for j in range(x): for q in range(x): if i != j and j != q and i != q: if y[i]+y[j]+y[q]==2*max(y[i], y[j], y[q]): z = [i+1, j+1, q+1] k = 1 if k == 1: break if k == 1: break if k == 1: break for i in z: print(i, end=' ') ```
0
544
B
Sea and Islands
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists.
The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form.
If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands.
[ "5 2\n", "5 25\n" ]
[ "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n", "NO\n" ]
none
1,000
[ { "input": "5 2", "output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS" }, { "input": "5 25", "output": "NO" }, { "input": "82 6047", "output": "NO" }, { "input": "6 5", "output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS" }, { "input": "10 80", "outpu...
1,508,490,653
4,253
Python 3
WRONG_ANSWER
TESTS
3
61
4,608,000
import sys n,k = map(int,input().split()) if (n % 2 == 0 and n // 2 < k ) or ( n % 2 != 0 and (n // 2)+1 < k ): print('NO') else: print('YES') for i in range(n): if i % 2 == 0: if k > 0: print('L'*n) k -= 1 else: print('S'*n) else: print('S' * n)
Title: Sea and Islands Time Limit: None seconds Memory Limit: None megabytes Problem Description: A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=×<=*n* map, or determine that no such way exists. Input Specification: The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. Output Specification: If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands. Demo Input: ['5 2\n', '5 25\n'] Demo Output: ['YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n', 'NO\n'] Note: none
```python import sys n,k = map(int,input().split()) if (n % 2 == 0 and n // 2 < k ) or ( n % 2 != 0 and (n // 2)+1 < k ): print('NO') else: print('YES') for i in range(n): if i % 2 == 0: if k > 0: print('L'*n) k -= 1 else: print('S'*n) else: print('S' * n) ```
0
678
A
Johny Likes Numbers
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109).
Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*.
[ "5 3\n", "25 13\n", "26 13\n" ]
[ "6\n", "26\n", "39\n" ]
none
0
[ { "input": "5 3", "output": "6" }, { "input": "25 13", "output": "26" }, { "input": "26 13", "output": "39" }, { "input": "1 1", "output": "2" }, { "input": "8 8", "output": "16" }, { "input": "14 15", "output": "15" }, { "input": "197 894"...
1,682,747,846
2,147,483,647
Python 3
OK
TESTS
37
46
0
a,b=map(int,input().split()) q=(a//b)+1 print(q*b)
Title: Johny Likes Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=109). Output Specification: Print the smallest integer *x*<=&gt;<=*n*, so it is divisible by the number *k*. Demo Input: ['5 3\n', '25 13\n', '26 13\n'] Demo Output: ['6\n', '26\n', '39\n'] Note: none
```python a,b=map(int,input().split()) q=(a//b)+1 print(q*b) ```
3