contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
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
sequencelengths
0
7
demo-output
sequencelengths
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
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,650,784,819
2,147,483,647
PyPy 3-64
OK
TESTS
35
124
8,908,800
n = int(input()) def solve(firstNum, secondNum): if not firstNum or not secondNum: return 0 maxNum, minNum = max(firstNum, secondNum), min(firstNum, secondNum) remainder = maxNum % minNum ops = (maxNum - remainder) // minNum return ops + solve(minNum, remainder) array = [] for _ in range(n): pair = list(map(int, input().split())) array.append(pair) for pair in array: print(solve(pair[0], pair[1]))
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python n = int(input()) def solve(firstNum, secondNum): if not firstNum or not secondNum: return 0 maxNum, minNum = max(firstNum, secondNum), min(firstNum, secondNum) remainder = maxNum % minNum ops = (maxNum - remainder) // minNum return ops + solve(minNum, remainder) array = [] for _ in range(n): pair = list(map(int, input().split())) array.append(pair) for pair in array: print(solve(pair[0], pair[1])) ```
3
858
A
k-rounding
PROGRAMMING
1,100
[ "brute force", "math", "number theory" ]
null
null
For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*.
The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8).
Print the *k*-rounding of *n*.
[ "375 4\n", "10000 1\n", "38101 0\n", "123456789 8\n" ]
[ "30000\n", "10000\n", "38101\n", "12345678900000000\n" ]
none
750
[ { "input": "375 4", "output": "30000" }, { "input": "10000 1", "output": "10000" }, { "input": "38101 0", "output": "38101" }, { "input": "123456789 8", "output": "12345678900000000" }, { "input": "1 0", "output": "1" }, { "input": "2 0", "output": "2" }, { "input": "100 0", "output": "100" }, { "input": "1000000000 0", "output": "1000000000" }, { "input": "160 2", "output": "800" }, { "input": "3 0", "output": "3" }, { "input": "10 0", "output": "10" }, { "input": "1 1", "output": "10" }, { "input": "2 1", "output": "10" }, { "input": "3 1", "output": "30" }, { "input": "4 1", "output": "20" }, { "input": "5 1", "output": "10" }, { "input": "6 1", "output": "30" }, { "input": "7 1", "output": "70" }, { "input": "8 1", "output": "40" }, { "input": "9 1", "output": "90" }, { "input": "10 1", "output": "10" }, { "input": "11 1", "output": "110" }, { "input": "12 1", "output": "60" }, { "input": "16 2", "output": "400" }, { "input": "2 2", "output": "100" }, { "input": "1 2", "output": "100" }, { "input": "5 2", "output": "100" }, { "input": "15 2", "output": "300" }, { "input": "36 2", "output": "900" }, { "input": "1 8", "output": "100000000" }, { "input": "8 8", "output": "100000000" }, { "input": "96 8", "output": "300000000" }, { "input": "175 8", "output": "700000000" }, { "input": "9999995 8", "output": "199999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "12345678 8", "output": "617283900000000" }, { "input": "78125 8", "output": "100000000" }, { "input": "390625 8", "output": "100000000" }, { "input": "1953125 8", "output": "500000000" }, { "input": "9765625 8", "output": "2500000000" }, { "input": "68359375 8", "output": "17500000000" }, { "input": "268435456 8", "output": "104857600000000" }, { "input": "125829120 8", "output": "9830400000000" }, { "input": "128000 8", "output": "400000000" }, { "input": "300000 8", "output": "300000000" }, { "input": "3711871 8", "output": "371187100000000" }, { "input": "55555 8", "output": "1111100000000" }, { "input": "222222222 8", "output": "11111111100000000" }, { "input": "479001600 8", "output": "7484400000000" }, { "input": "655360001 7", "output": "6553600010000000" }, { "input": "655360001 8", "output": "65536000100000000" }, { "input": "1000000000 1", "output": "1000000000" }, { "input": "1000000000 7", "output": "1000000000" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "10000000 8", "output": "100000000" }, { "input": "1000000 8", "output": "100000000" }, { "input": "10000009 8", "output": "1000000900000000" }, { "input": "10000005 8", "output": "200000100000000" }, { "input": "10000002 8", "output": "500000100000000" }, { "input": "999999997 8", "output": "99999999700000000" }, { "input": "999999997 7", "output": "9999999970000000" }, { "input": "999999995 8", "output": "19999999900000000" }, { "input": "123 8", "output": "12300000000" }, { "input": "24 2", "output": "600" }, { "input": "16 4", "output": "10000" }, { "input": "123456787 8", "output": "12345678700000000" }, { "input": "100000000 8", "output": "100000000" }, { "input": "7 1", "output": "70" }, { "input": "101 1", "output": "1010" }, { "input": "50 2", "output": "100" }, { "input": "999999818 1", "output": "4999999090" }, { "input": "2 1", "output": "10" }, { "input": "123 1", "output": "1230" }, { "input": "16 1", "output": "80" }, { "input": "1 1", "output": "10" }, { "input": "1000000000 8", "output": "1000000000" }, { "input": "15304 6", "output": "1913000000" }, { "input": "3 8", "output": "300000000" }, { "input": "4 2", "output": "100" }, { "input": "100000 7", "output": "10000000" }, { "input": "5 8", "output": "100000000" }, { "input": "16724 6", "output": "4181000000" }, { "input": "999999999 1", "output": "9999999990" }, { "input": "999999990 8", "output": "9999999900000000" }, { "input": "999999999 8", "output": "99999999900000000" }, { "input": "100000 1", "output": "100000" }, { "input": "8 3", "output": "1000" }, { "input": "16768 6", "output": "262000000" }, { "input": "123456789 1", "output": "1234567890" }, { "input": "2 8", "output": "100000000" }, { "input": "999999937 8", "output": "99999993700000000" }, { "input": "5 1", "output": "10" }, { "input": "2000000 7", "output": "10000000" }, { "input": "1999998 2", "output": "99999900" }, { "input": "125 3", "output": "1000" } ]
1,505,656,494
2,994
Python 3
RUNTIME_ERROR
PRETESTS
4
46
0
n, k = map(int,input().split()) h = 0 p = 0 if int(str(n)+"0"*k)%n == 0: m = ((int(str(n)+"0"*k))) for i in range (1, n): if str(n * i)[len(str(n * i)) - k:] == "0" * k or i == 1000: p = i break h = (n * p) if i == 1000: print(m) else: print(min(m,h))
Title: k-rounding Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. Input Specification: The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=109, 0<=≤<=*k*<=≤<=8). Output Specification: Print the *k*-rounding of *n*. Demo Input: ['375 4\n', '10000 1\n', '38101 0\n', '123456789 8\n'] Demo Output: ['30000\n', '10000\n', '38101\n', '12345678900000000\n'] Note: none
```python n, k = map(int,input().split()) h = 0 p = 0 if int(str(n)+"0"*k)%n == 0: m = ((int(str(n)+"0"*k))) for i in range (1, n): if str(n * i)[len(str(n * i)) - k:] == "0" * k or i == 1000: p = i break h = (n * p) if i == 1000: print(m) else: print(min(m,h)) ```
-1
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" }, { "input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "output": "1" }, { "input": "RRGGBRGRBG\nBRRGGBBGGR", "output": "7" }, { "input": "BBRRGBGGRGBRGBRBRBGR\nGGGRBGGGBRRRRGRBGBGRGRRBGRBGBG", "output": "15" }, { "input": "GBRRBGBGBBBBRRRGBGRRRGBGBBBRGR\nRRGBRRGRBBBBBBGRRBBR", "output": "8" }, { "input": "BRGRRGRGRRGBBGBBBRRBBRRBGBBGRGBBGGRGBRBGGGRRRBGGBB\nRGBBGRRBBBRRGRRBRBBRGBBGGGRGBGRRRRBRBGGBRBGGGRGBRR", "output": "16" }, { "input": "GGRGGBRRGRGBRRGGRBBGGRRGBBBGBBBGGRBGGBRBBRGBRRRBRG\nGGRGRRRRRRRRRGBBBBRGBRGRGRRGBBRGGBRBBRBGBRGRRRRGGR", "output": "18" }, { "input": "RBBRBGBBGGGBRRBGBRGRRGGRBBBBGRBGGBRRBGBBRBRGBBGGGG\nBRRGRBGRBGBRGBRBGGBBBGBBRGRBGRGRBGRBGGRRBGBRGRRBBG", "output": "23" }, { "input": "RRGGRRBRGRGBRGBRGBBRGGGBRBGBRGBRGGBRBRGBGRRBBGGRBR\nBRGRBBBGRBGRRGGRRRRRRRRGGGGGGGGBGGGGGGGRGRBBRGRGBR", "output": "14" }, { "input": "RBRBRRRRRGGR\nBBBBRRGGBGRBRGBBRGGGRGGBRRBRBRBGGG", "output": "12" }, { "input": "GGRGGGBRGRGRBBRGGGRBGRRR\nGBBBBGBGBGBBBRGGRGGBGRRGRRRGBGB", "output": "12" }, { "input": "RGRBGBRBBGBRRGGGBBGBRRBGRGBBBBBGRRRGGRBB\nBGR", "output": "2" }, { "input": "R\nB", "output": "1" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "50" }, { "input": "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" }, { "input": "R\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "1" } ]
1,674,218,600
2,147,483,647
Python 3
OK
TESTS
19
92
0
s = input() t = input() position = 1 index = 0 for i in range(len(t)): if s[index] == t[i]: position += 1 index += 1 else: continue print(position)
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 = input() t = input() position = 1 index = 0 for i in range(len(t)): if s[index] == t[i]: position += 1 index += 1 else: continue print(position) ```
3
950
A
Left-handers, Right-handers and Ambidexters
PROGRAMMING
800
[ "implementation", "math" ]
null
null
You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.
The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.
Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.
[ "1 4 2\n", "5 5 5\n", "0 2 0\n" ]
[ "6\n", "14\n", "0\n" ]
In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
500
[ { "input": "1 4 2", "output": "6" }, { "input": "5 5 5", "output": "14" }, { "input": "0 2 0", "output": "0" }, { "input": "30 70 34", "output": "128" }, { "input": "89 32 24", "output": "112" }, { "input": "89 44 77", "output": "210" }, { "input": "0 0 0", "output": "0" }, { "input": "100 100 100", "output": "300" }, { "input": "1 1 1", "output": "2" }, { "input": "30 70 35", "output": "130" }, { "input": "89 44 76", "output": "208" }, { "input": "0 100 100", "output": "200" }, { "input": "100 0 100", "output": "200" }, { "input": "100 1 100", "output": "200" }, { "input": "1 100 100", "output": "200" }, { "input": "100 100 0", "output": "200" }, { "input": "100 100 1", "output": "200" }, { "input": "1 2 1", "output": "4" }, { "input": "0 0 100", "output": "100" }, { "input": "0 100 0", "output": "0" }, { "input": "100 0 0", "output": "0" }, { "input": "10 8 7", "output": "24" }, { "input": "45 47 16", "output": "108" }, { "input": "59 43 100", "output": "202" }, { "input": "34 1 30", "output": "62" }, { "input": "14 81 1", "output": "30" }, { "input": "53 96 94", "output": "242" }, { "input": "62 81 75", "output": "218" }, { "input": "21 71 97", "output": "188" }, { "input": "49 82 73", "output": "204" }, { "input": "88 19 29", "output": "96" }, { "input": "89 4 62", "output": "132" }, { "input": "58 3 65", "output": "126" }, { "input": "27 86 11", "output": "76" }, { "input": "35 19 80", "output": "134" }, { "input": "4 86 74", "output": "156" }, { "input": "32 61 89", "output": "182" }, { "input": "68 60 98", "output": "226" }, { "input": "37 89 34", "output": "142" }, { "input": "92 9 28", "output": "74" }, { "input": "79 58 98", "output": "234" }, { "input": "35 44 88", "output": "166" }, { "input": "16 24 19", "output": "58" }, { "input": "74 71 75", "output": "220" }, { "input": "83 86 99", "output": "268" }, { "input": "97 73 15", "output": "176" }, { "input": "77 76 73", "output": "226" }, { "input": "48 85 55", "output": "188" }, { "input": "1 2 2", "output": "4" }, { "input": "2 2 2", "output": "6" }, { "input": "2 1 2", "output": "4" }, { "input": "2 2 1", "output": "4" }, { "input": "3 2 1", "output": "6" }, { "input": "1 2 3", "output": "6" }, { "input": "1 3 2", "output": "6" }, { "input": "2 1 3", "output": "6" }, { "input": "2 3 1", "output": "6" }, { "input": "3 1 2", "output": "6" }, { "input": "99 99 99", "output": "296" }, { "input": "99 99 100", "output": "298" }, { "input": "99 100 99", "output": "298" }, { "input": "99 100 100", "output": "298" }, { "input": "100 99 99", "output": "298" }, { "input": "100 99 100", "output": "298" }, { "input": "100 100 99", "output": "298" }, { "input": "89 32 23", "output": "110" }, { "input": "4 5 0", "output": "8" }, { "input": "3 0 3", "output": "6" }, { "input": "0 0 2", "output": "2" }, { "input": "97 97 0", "output": "194" }, { "input": "1 4 0", "output": "2" }, { "input": "5 2 0", "output": "4" }, { "input": "0 5 10", "output": "14" }, { "input": "0 1 2", "output": "2" }, { "input": "5 2 3", "output": "10" }, { "input": "5 5 0", "output": "10" }, { "input": "0 0 10", "output": "10" }, { "input": "0 1 1", "output": "2" }, { "input": "0 0 1", "output": "0" } ]
1,521,148,454
2,147,483,647
Python 3
OK
TESTS
79
93
7,065,600
a = list(map(int, input().split())) t = min(a[0], a[1]) r = max(a[0], a[1]) k = a[2]+t-r n = k>0 m = (t + min((r-t), a[2])+n*k//2)*2 print(m)
Title: Left-handers, Right-handers and Ambidexters Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. Input Specification: The only line contains three integers *l*, *r* and *a* (0<=≤<=*l*,<=*r*,<=*a*<=≤<=100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training. Output Specification: Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players. Demo Input: ['1 4 2\n', '5 5 5\n', '0 2 0\n'] Demo Output: ['6\n', '14\n', '0\n'] Note: In the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team. In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.
```python a = list(map(int, input().split())) t = min(a[0], a[1]) r = max(a[0], a[1]) k = a[2]+t-r n = k>0 m = (t + min((r-t), a[2])+n*k//2)*2 print(m) ```
3
740
A
Alyona and copybooks
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109).
Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4.
[ "1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "999999999 1000000000 1000000000 1000000000\n" ]
[ "3\n", "1\n", "0\n", "1000000000\n" ]
In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
500
[ { "input": "1 1 3 4", "output": "3" }, { "input": "6 2 1 1", "output": "1" }, { "input": "4 4 4 4", "output": "0" }, { "input": "999999999 1000000000 1000000000 1000000000", "output": "1000000000" }, { "input": "1016 3 2 1", "output": "0" }, { "input": "17 100 100 1", "output": "1" }, { "input": "17 2 3 100", "output": "5" }, { "input": "18 1 3 3", "output": "2" }, { "input": "19 1 1 1", "output": "1" }, { "input": "999999997 999999990 1000000000 1000000000", "output": "1000000000" }, { "input": "999999998 1000000000 999999990 1000000000", "output": "999999990" }, { "input": "634074578 336470888 481199252 167959139", "output": "335918278" }, { "input": "999999999 1000000000 1000000000 999999990", "output": "1000000000" }, { "input": "804928248 75475634 54748096 641009859", "output": "0" }, { "input": "535590429 374288891 923264237 524125987", "output": "524125987" }, { "input": "561219907 673102149 496813081 702209411", "output": "673102149" }, { "input": "291882089 412106895 365329221 585325539", "output": "585325539" }, { "input": "757703054 5887448 643910770 58376259", "output": "11774896" }, { "input": "783332532 449924898 72235422 941492387", "output": "0" }, { "input": "513994713 43705451 940751563 824608515", "output": "131116353" }, { "input": "539624191 782710197 514300407 2691939", "output": "8075817" }, { "input": "983359971 640274071 598196518 802030518", "output": "640274071" }, { "input": "8989449 379278816 26521171 685146646", "output": "405799987" }, { "input": "34618927 678092074 895037311 863230070", "output": "678092074" }, { "input": "205472596 417096820 468586155 41313494", "output": "0" }, { "input": "19 5 1 2", "output": "3" }, { "input": "17 1 2 2", "output": "2" }, { "input": "18 3 3 1", "output": "2" }, { "input": "19 4 3 1", "output": "3" }, { "input": "936134778 715910077 747167704 219396918", "output": "438793836" }, { "input": "961764255 454914823 615683844 102513046", "output": "307539138" }, { "input": "692426437 48695377 189232688 985629174", "output": "146086131" }, { "input": "863280107 347508634 912524637 458679894", "output": "347508634" }, { "input": "593942288 86513380 486073481 341796022", "output": "0" }, { "input": "914539062 680293934 764655030 519879446", "output": "764655030" }, { "input": "552472140 509061481 586588704 452405440", "output": "0" }, { "input": "723325809 807874739 160137548 335521569", "output": "335521569" }, { "input": "748955287 546879484 733686393 808572289", "output": "546879484" }, { "input": "774584765 845692742 162011045 691688417", "output": "691688417" }, { "input": "505246946 439473295 30527185 869771841", "output": "30527185" }, { "input": "676100616 178478041 604076030 752887969", "output": "0" }, { "input": "701730093 477291299 177624874 930971393", "output": "654916173" }, { "input": "432392275 216296044 751173719 109054817", "output": "216296044" }, { "input": "458021753 810076598 324722563 992170945", "output": "992170945" }, { "input": "188683934 254114048 48014511 170254369", "output": "48014511" }, { "input": "561775796 937657403 280013594 248004555", "output": "0" }, { "input": "1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 10000 10000 3", "output": "9" }, { "input": "3 12 3 4", "output": "7" }, { "input": "3 10000 10000 1", "output": "3" }, { "input": "3 1000 1000 1", "output": "3" }, { "input": "3 10 10 1", "output": "3" }, { "input": "3 100 100 1", "output": "3" }, { "input": "3 100000 10000 1", "output": "3" }, { "input": "7 10 2 3", "output": "5" }, { "input": "3 1000 1000 2", "output": "6" }, { "input": "1 100000 1 100000", "output": "100000" }, { "input": "7 4 3 1", "output": "3" }, { "input": "3 1000 1000 3", "output": "9" }, { "input": "3 1000 1 1", "output": "2" }, { "input": "3 10 1 1", "output": "2" }, { "input": "3 100000 1 1", "output": "2" }, { "input": "3 100 1 1", "output": "2" }, { "input": "3 100000 100000 1", "output": "3" }, { "input": "3 1000 1 100", "output": "101" }, { "input": "3 1000000000 1 1000000000", "output": "1000000000" }, { "input": "3 1000 1 10", "output": "11" }, { "input": "3 200 1 100", "output": "101" }, { "input": "7 4 1 1", "output": "2" }, { "input": "7 4 12 1", "output": "3" }, { "input": "3 9 1 1", "output": "2" }, { "input": "3 10000000 1000000 1", "output": "3" }, { "input": "7 1000 1000 1", "output": "3" }, { "input": "3 10000 1 30", "output": "31" }, { "input": "3 1000 1 2", "output": "3" }, { "input": "7 12 6 1", "output": "3" }, { "input": "3 100000 1 1000", "output": "1001" }, { "input": "7 1000 1000 3", "output": "9" }, { "input": "3 4 3 1", "output": "3" }, { "input": "3 3000000 1 100000", "output": "100001" }, { "input": "3 3 1 1", "output": "2" }, { "input": "3 10 1 5", "output": "6" }, { "input": "3 2000 2000 1", "output": "3" }, { "input": "3 10000000 10000000 1", "output": "3" }, { "input": "3 5 1 1", "output": "2" }, { "input": "3 100 1 33", "output": "34" }, { "input": "7 9 2 7", "output": "9" }, { "input": "4448 2 3 6", "output": "0" }, { "input": "2228 1 6 3", "output": "0" } ]
1,562,748,984
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
20
140
0
n, a, b, c = map(int,input().split()) ans = n % 4 if ans % 4 == 0 : print(0) else : if ans == 1 : print(min(min(3 * a, c), a + b)) elif ans == 2 : print(min(min(2 * a, b), 2 * c)) elif ans == 3 : print(min(min(a, b + c), 2 * c))
Title: Alyona and copybooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. Input Specification: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=109). Output Specification: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Demo Input: ['1 1 3 4\n', '6 2 1 1\n', '4 4 4 4\n', '999999999 1000000000 1000000000 1000000000\n'] Demo Output: ['3\n', '1\n', '0\n', '1000000000\n'] Note: In the first example Alyona can buy 3 packs of 1 copybook for 3*a* = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for *b* = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook.
```python n, a, b, c = map(int,input().split()) ans = n % 4 if ans % 4 == 0 : print(0) else : if ans == 1 : print(min(min(3 * a, c), a + b)) elif ans == 2 : print(min(min(2 * a, b), 2 * c)) elif ans == 3 : print(min(min(a, b + c), 2 * c)) ```
0
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,663,445,974
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
62
0
x=input() y=input() counter = 0 for i in range (len (x)): if x[i]!=y[-i]: counter+=1 if counter == len(x): print('YES') else:print('NO')
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python x=input() y=input() counter = 0 for i in range (len (x)): if x[i]!=y[-i]: counter+=1 if counter == len(x): print('YES') else:print('NO') ```
0
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" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,627,200,119
2,147,483,647
PyPy 3
OK
TESTS
45
186
20,172,800
import math a,b,n = map(int,input().split()) count = 1 while n >= 0: if count % 2 != 0: d = math.gcd(a,n) if n >= d: n -= d count += 1 else: print(1) break if count % 2 == 0: d = math.gcd(b,n) if n >= d: n -= d count +=1 else: print(0) break
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 import math a,b,n = map(int,input().split()) count = 1 while n >= 0: if count % 2 != 0: d = math.gcd(a,n) if n >= d: n -= d count += 1 else: print(1) break if count % 2 == 0: d = math.gcd(b,n) if n >= d: n -= d count +=1 else: print(0) break ```
3
884
A
Book Reading
PROGRAMMING
800
[ "implementation" ]
null
null
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day.
The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*.
[ "2 2\n86400 86398\n", "2 86400\n0 86400\n" ]
[ "2\n", "1\n" ]
none
0
[ { "input": "2 2\n86400 86398", "output": "2" }, { "input": "2 86400\n0 86400", "output": "1" }, { "input": "2 86400\n1 86399", "output": "2" }, { "input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "12" }, { "input": "1 1\n86399", "output": "1" }, { "input": "6 1200\n86400 86400 86000 86000 86000 86400", "output": "5" }, { "input": "6 1200\n86400 86400 86000 86000 86001 86399", "output": "6" }, { "input": "4 172799\n1 1 86400 0", "output": "4" }, { "input": "4 172799\n0 86400 86399 0", "output": "4" }, { "input": "6 1\n1 1 86400 1 86399 1", "output": "1" }, { "input": "4 1\n86400 86399 86400 86400", "output": "2" }, { "input": "4 1\n86400 86400 0 86400", "output": "3" } ]
1,626,103,664
2,147,483,647
Python 3
OK
TESTS
16
77
6,758,400
n,t = map(int,input().split()) a = list(map(int,input().split())) i = 0 while t>0: t -= (86400-a[i]) i+=1 print(i)
Title: Book Reading Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed *n*. Remember that there are 86400 seconds in a day. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. Output Specification: Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed *n*. Demo Input: ['2 2\n86400 86398\n', '2 86400\n0 86400\n'] Demo Output: ['2\n', '1\n'] Note: none
```python n,t = map(int,input().split()) a = list(map(int,input().split())) i = 0 while t>0: t -= (86400-a[i]) i+=1 print(i) ```
3
224
B
Array
PROGRAMMING
1,500
[ "bitmasks", "implementation", "two pointers" ]
null
null
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property.
The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105).
Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them.
[ "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "7 4\n4 7 7 4 7 4 7\n" ]
[ "1 2\n", "2 5\n", "-1 -1\n" ]
In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
1,000
[ { "input": "4 2\n1 2 2 3", "output": "1 2" }, { "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5" }, { "input": "7 4\n4 7 7 4 7 4 7", "output": "-1 -1" }, { "input": "5 1\n1 7 2 3 2", "output": "1 1" }, { "input": "1 2\n666", "output": "-1 -1" }, { "input": "1 1\n5", "output": "1 1" }, { "input": "10 4\n1 1 2 2 3 3 4 4 4 4", "output": "2 7" }, { "input": "4 2\n3 3 4 3", "output": "2 3" }, { "input": "4 3\n4 4 4 2", "output": "-1 -1" }, { "input": "10 5\n15 17 2 13 3 16 4 5 9 12", "output": "1 5" }, { "input": "17 13\n34 15 156 11 183 147 192 112 145 30 88 37 1 98 3 162 148", "output": "1 13" }, { "input": "17 14\n271 158 573 88 792 767 392 646 392 392 271 549 402 767 573 925 796", "output": "-1 -1" }, { "input": "8 5\n1 2 1 1 2 3 4 5", "output": "4 8" }, { "input": "7 3\n2 1 2 2 1 2 3", "output": "5 7" }, { "input": "6 3\n1 3 1 1 4 5", "output": "2 5" }, { "input": "5 3\n1 2 1 1 3", "output": "2 5" }, { "input": "9 3\n1 2 1 2 1 2 2 3 1", "output": "5 8" }, { "input": "4 3\n1 2 1 3", "output": "2 4" }, { "input": "5 3\n1 3 1 3 4", "output": "3 5" }, { "input": "6 3\n1 3 3 1 4 4", "output": "3 5" }, { "input": "5 3\n1 2 1 2 3", "output": "3 5" }, { "input": "8 4\n1 2 3 2 1 2 3 4", "output": "5 8" }, { "input": "10 4\n1 2 3 1 2 3 4 3 2 1", "output": "4 7" }, { "input": "10 3\n1 1 1 2 1 2 3 3 3 4", "output": "5 7" }, { "input": "10 3\n1 1 2 1 2 2 3 4 5 6", "output": "4 7" } ]
1,645,013,944
1,081
PyPy 3
OK
TESTS
49
310
12,595,200
import sys import math from collections import deque,Counter from sys import stdin #sys.setrecursionlimit(10**7) int1=lambda x: int(x)-1 stinput=lambda :stdin.readline()[:-1] ii=lambda :int(stinput()) mi=lambda :map(int, stdin.readline().split()) li=lambda :list(mi()) mi1=lambda :map(int1, stdin.readline().split()) li1=lambda :list(mi1()) mis=lambda :map(str, stdin.readline().split()) lis=lambda :list(mis()) from collections import defaultdict #d=defaultdict(int) #d=defaultdict(lambda:1) import heapq #heapq.heapify(hq) #heapq.heappop(hq) #heapq.heappush(hq,1) mod=10**9+7 Mod=998244353 INF=10**18 ans=0 n,m=mi() a=li() l=0 cnt=0 d=defaultdict(int) r=-1 while cnt<m and r+1<n: r+=1 if d[a[r]]==0: cnt+=1 d[a[r]]+=1 if cnt<m: print(-1,-1) exit() ans=r-l ansl=l ansr=r for l in range(1,n): d[a[l-1]]-=1 if d[a[l-1]]==0: cnt-=1 while cnt<m and r+1<n: r+=1 if d[a[r]]==0: cnt+=1 d[a[r]]+=1 if cnt==m: if ans>r-l: ans=r-l ansl=l ansr=r print(ansl+1,ansr+1)
Title: Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. Input Specification: The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. Demo Input: ['4 2\n1 2 2 3\n', '8 3\n1 1 2 2 3 3 4 5\n', '7 4\n4 7 7 4 7 4 7\n'] Demo Output: ['1 2\n', '2 5\n', '-1 -1\n'] Note: In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers. In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments. In the third sample there is no segment with four distinct numbers.
```python import sys import math from collections import deque,Counter from sys import stdin #sys.setrecursionlimit(10**7) int1=lambda x: int(x)-1 stinput=lambda :stdin.readline()[:-1] ii=lambda :int(stinput()) mi=lambda :map(int, stdin.readline().split()) li=lambda :list(mi()) mi1=lambda :map(int1, stdin.readline().split()) li1=lambda :list(mi1()) mis=lambda :map(str, stdin.readline().split()) lis=lambda :list(mis()) from collections import defaultdict #d=defaultdict(int) #d=defaultdict(lambda:1) import heapq #heapq.heapify(hq) #heapq.heappop(hq) #heapq.heappush(hq,1) mod=10**9+7 Mod=998244353 INF=10**18 ans=0 n,m=mi() a=li() l=0 cnt=0 d=defaultdict(int) r=-1 while cnt<m and r+1<n: r+=1 if d[a[r]]==0: cnt+=1 d[a[r]]+=1 if cnt<m: print(-1,-1) exit() ans=r-l ansl=l ansr=r for l in range(1,n): d[a[l-1]]-=1 if d[a[l-1]]==0: cnt-=1 while cnt<m and r+1<n: r+=1 if d[a[r]]==0: cnt+=1 d[a[r]]+=1 if cnt==m: if ans>r-l: ans=r-l ansl=l ansr=r print(ansl+1,ansr+1) ```
3
804
A
Find Amir
PROGRAMMING
1,000
[ "constructive algorithms", "greedy", "math" ]
null
null
A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools.
Print single integer: the minimum cost of tickets needed to visit all schools.
[ "2\n", "10\n" ]
[ "0\n", "4\n" ]
In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
500
[ { "input": "2", "output": "0" }, { "input": "10", "output": "4" }, { "input": "43670", "output": "21834" }, { "input": "4217", "output": "2108" }, { "input": "17879", "output": "8939" }, { "input": "31809", "output": "15904" }, { "input": "40873", "output": "20436" }, { "input": "77859", "output": "38929" }, { "input": "53022", "output": "26510" }, { "input": "79227", "output": "39613" }, { "input": "100000", "output": "49999" }, { "input": "82801", "output": "41400" }, { "input": "5188", "output": "2593" }, { "input": "86539", "output": "43269" }, { "input": "12802", "output": "6400" }, { "input": "20289", "output": "10144" }, { "input": "32866", "output": "16432" }, { "input": "33377", "output": "16688" }, { "input": "31775", "output": "15887" }, { "input": "60397", "output": "30198" }, { "input": "100000", "output": "49999" }, { "input": "99999", "output": "49999" }, { "input": "99998", "output": "49998" }, { "input": "99997", "output": "49998" }, { "input": "99996", "output": "49997" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "1" }, { "input": "4", "output": "1" }, { "input": "1", "output": "0" }, { "input": "3", "output": "1" } ]
1,596,463,792
2,147,483,647
PyPy 3
OK
TESTS
31
140
20,172,800
I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) n=I() print(((n+1)//2)-1)
Title: Find Amir Time Limit: None seconds Memory Limit: None megabytes Problem Description: A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are *n* schools numerated from 1 to *n*. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools *i* and *j* costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of schools. Output Specification: Print single integer: the minimum cost of tickets needed to visit all schools. Demo Input: ['2\n', '10\n'] Demo Output: ['0\n', '4\n'] Note: In the first example we can buy a ticket between the schools that costs <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c67d72010e0498bfd065a6a38fdeaec90358507b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
```python I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) n=I() print(((n+1)//2)-1) ```
3
767
A
Snacktower
PROGRAMMING
1,100
[ "data structures", "implementation" ]
null
null
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents.
The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*.
Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.
[ "3\n3 1 2\n", "5\n4 5 1 2 3\n" ]
[ "3\n \n2 1", "5 4\n \n \n3 2 1\n" ]
In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
500
[ { "input": "3\n3 1 2", "output": "3 \n\n2 1 " }, { "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 " }, { "input": "1\n1", "output": "1 " }, { "input": "2\n1 2", "output": "2 1 " }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1 " }, { "input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 " }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "100 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n99 98 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 \n\n\n\n\n\n\n\n\n80 79 78 77 76 75 74 73 \n72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 \n39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 " }, { "input": "2\n2 1", "output": "2 \n1 " } ]
1,584,366,470
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
77
307,200
def snackTower(n, snacks): sortedSnacks = sorted(snacks, reverse = True) dailySnacks = [] count = 0 for i in range(n): dailySnacks.append(snacks[i]) if snacks[i] == sortedSnacks[count]: count += 1 dailySnacks.reverse() print(*dailySnacks) dailySnacks = [] else: print(" ") if dailySnacks != []: dailySnacks.reverse() print(*dailySnacks) n = int(input()) snacks = list(map(int,input().split())) snackTower(n, snacks)
Title: Snacktower Time Limit: None seconds Memory Limit: None megabytes Problem Description: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. Input Specification: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. Output Specification: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Demo Input: ['3\n3 1 2\n', '5\n4 5 1 2 3\n'] Demo Output: ['3\n\xa0\n2 1', '5 4\n\xa0\n\xa0\n3 2 1\n'] Note: In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.
```python def snackTower(n, snacks): sortedSnacks = sorted(snacks, reverse = True) dailySnacks = [] count = 0 for i in range(n): dailySnacks.append(snacks[i]) if snacks[i] == sortedSnacks[count]: count += 1 dailySnacks.reverse() print(*dailySnacks) dailySnacks = [] else: print(" ") if dailySnacks != []: dailySnacks.reverse() print(*dailySnacks) n = int(input()) snacks = list(map(int,input().split())) snackTower(n, snacks) ```
0
435
B
Pasha Maximizes
PROGRAMMING
1,400
[ "greedy" ]
null
null
Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps.
The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100).
Print the maximum number that Pasha can get if he makes at most *k* swaps.
[ "1990 1\n", "300 0\n", "1034 2\n", "9090000078001234 6\n" ]
[ "9190\n", "300\n", "3104\n", "9907000008001234\n" ]
none
1,000
[ { "input": "1990 1", "output": "9190" }, { "input": "300 0", "output": "300" }, { "input": "1034 2", "output": "3104" }, { "input": "9090000078001234 6", "output": "9907000008001234" }, { "input": "1234 3", "output": "4123" }, { "input": "5 100", "output": "5" }, { "input": "1234 5", "output": "4312" }, { "input": "1234 6", "output": "4321" }, { "input": "9022 2", "output": "9220" }, { "input": "66838 4", "output": "86863" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "5314 4", "output": "5431" }, { "input": "1026 9", "output": "6210" }, { "input": "4529 8", "output": "9542" }, { "input": "83811284 3", "output": "88321184" }, { "input": "92153348 6", "output": "98215334" }, { "input": "5846059 3", "output": "8654059" }, { "input": "521325125110071928 4", "output": "552132125110071928" }, { "input": "39940894417248510 10", "output": "99984304417248510" }, { "input": "77172428736634377 29", "output": "87777764122363437" }, { "input": "337775999910796051 37", "output": "999997733751076051" }, { "input": "116995340392134308 27", "output": "999654331120134308" }, { "input": "10120921290110921 20", "output": "99221010120110921" }, { "input": "929201010190831892 30", "output": "999928201010103182" }, { "input": "111111111111111119 8", "output": "111111111911111111" }, { "input": "219810011901120912 100", "output": "999822211111110000" }, { "input": "191919191919119911 100", "output": "999999991111111111" }, { "input": "801211288881101019 22", "output": "982111028888110101" }, { "input": "619911311932347059 3", "output": "969111311932347059" }, { "input": "620737553540689123 2", "output": "672037553540689123" }, { "input": "621563797296514835 3", "output": "662153797296514835" }, { "input": "915277434701161 9", "output": "977541234701161" }, { "input": "15603712376708 28", "output": "87761503123670" }, { "input": "784069392990841 0", "output": "784069392990841" }, { "input": "787464780004 2", "output": "877644780004" }, { "input": "74604713975 29", "output": "97776544310" }, { "input": "901000000954321789 5", "output": "910009000054321789" }, { "input": "901000000954321789 10", "output": "991000000504321789" }, { "input": "901000000954321789 28", "output": "999100050000432178" }, { "input": "901000000954321789 40", "output": "999810000050043217" }, { "input": "901000000954321789 70", "output": "999875410000300021" }, { "input": "1234567891234567 99", "output": "9877665544332211" }, { "input": "123456789123456789 100", "output": "998877665544213123" }, { "input": "12345670123456789 100", "output": "98776655443322101" }, { "input": "12 100", "output": "21" }, { "input": "11223344556677889 47", "output": "98821213344556677" } ]
1,685,421,526
2,147,483,647
PyPy 3-64
OK
TESTS
46
77
0
import sys from collections import defaultdict def perform_swaps(j, i, values): for x in range(j, i , -1): values[x], values[x - 1] = values[x - 1], values[x] def main() -> None: read = sys.stdin.readline values, k = read().split() k: int = int(k) values: list[int] = [int(c) for c in values.strip()] next_insertion = 0 while next_insertion < len(values): # Find the range we are considering max_value = -1 max_value_idx = -1 for j in range(next_insertion + 1, min(next_insertion + k + 1, len(values))): if values[j] > max_value: max_value = values[j] max_value_idx = j if max_value > 0 and max_value > values[next_insertion]: # Do a swap cost = max_value_idx - next_insertion k -= cost perform_swaps(max_value_idx, next_insertion, values) next_insertion += 1 print(''.join((str(c) for c in values))) if __name__ == '__main__': main() # For the other
Title: Pasha Maximizes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a positive integer *a* without leading zeroes. Today he decided that the number is too small and he should make it larger. Unfortunately, the only operation Pasha can do is to swap two adjacent decimal digits of the integer. Help Pasha count the maximum number he can get if he has the time to make at most *k* swaps. Input Specification: The single line contains two integers *a* and *k* (1<=≤<=*a*<=≤<=1018; 0<=≤<=*k*<=≤<=100). Output Specification: Print the maximum number that Pasha can get if he makes at most *k* swaps. Demo Input: ['1990 1\n', '300 0\n', '1034 2\n', '9090000078001234 6\n'] Demo Output: ['9190\n', '300\n', '3104\n', '9907000008001234\n'] Note: none
```python import sys from collections import defaultdict def perform_swaps(j, i, values): for x in range(j, i , -1): values[x], values[x - 1] = values[x - 1], values[x] def main() -> None: read = sys.stdin.readline values, k = read().split() k: int = int(k) values: list[int] = [int(c) for c in values.strip()] next_insertion = 0 while next_insertion < len(values): # Find the range we are considering max_value = -1 max_value_idx = -1 for j in range(next_insertion + 1, min(next_insertion + k + 1, len(values))): if values[j] > max_value: max_value = values[j] max_value_idx = j if max_value > 0 and max_value > values[next_insertion]: # Do a swap cost = max_value_idx - next_insertion k -= cost perform_swaps(max_value_idx, next_insertion, values) next_insertion += 1 print(''.join((str(c) for c in values))) if __name__ == '__main__': main() # For the other ```
3
546
A
Soldier and Bananas
PROGRAMMING
800
[ "brute force", "implementation", "math" ]
null
null
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas?
The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
[ "3 17 4\n" ]
[ "13" ]
none
500
[ { "input": "3 17 4", "output": "13" }, { "input": "1 2 1", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 5 6", "output": "16" }, { "input": "1 1000000000 1", "output": "0" }, { "input": "1000 0 1000", "output": "500500000" }, { "input": "859 453892 543", "output": "126416972" }, { "input": "1000 1000000000 1000", "output": "0" }, { "input": "1000 500500000 1000", "output": "0" }, { "input": "1000 500500001 1000", "output": "0" }, { "input": "1000 500499999 1000", "output": "1" }, { "input": "634 87973 214", "output": "14497197" }, { "input": "432 10000 241", "output": "12587552" }, { "input": "111 111111111 111", "output": "0" }, { "input": "20 43 3", "output": "77" } ]
1,694,623,140
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
k, n, w = input().split() n = int(n) k = int(k) w = int(w) total = 0 for i in range(1, w + 1): total = total + (i * K) if n < total: print(total - n) else: print(0)
Title: Soldier and Bananas Time Limit: None seconds Memory Limit: None megabytes Problem Description: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? Input Specification: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. Output Specification: Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Demo Input: ['3 17 4\n'] Demo Output: ['13'] Note: none
```python k, n, w = input().split() n = int(n) k = int(k) w = int(w) total = 0 for i in range(1, w + 1): total = total + (i * K) if n < total: print(total - n) else: print(0) ```
-1
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, 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": "tymbzjyqhymedasloqbq", "output": "NO" }, { "input": "yehluhlkwo", "output": "NO" }, { "input": "hatlevhhalrohairnolsvocafgueelrqmlqlleello", "output": "YES" }, { "input": "hhhtehdbllnhwmbyhvelqqyoulretpbfokflhlhreeflxeftelziclrwllrpflflbdtotvlqgoaoqldlroovbfsq", "output": "YES" }, { "input": "rzlvihhghnelqtwlexmvdjjrliqllolhyewgozkuovaiezgcilelqapuoeglnwmnlftxxiigzczlouooi", "output": "YES" }, { "input": "pfhhwctyqdlkrwhebfqfelhyebwllhemtrmeblgrynmvyhioesqklclocxmlffuormljszllpoo", "output": "YES" }, { "input": "lqllcolohwflhfhlnaow", "output": "NO" }, { "input": "heheeellollvoo", "output": "YES" }, { "input": "hellooo", "output": "YES" }, { "input": "o", "output": "NO" }, { "input": "hhqhzeclohlehljlhtesllylrolmomvuhcxsobtsckogdv", "output": "YES" }, { "input": "yoegfuzhqsihygnhpnukluutocvvwuldiighpogsifealtgkfzqbwtmgghmythcxflebrkctlldlkzlagovwlstsghbouk", "output": "YES" }, { "input": "uatqtgbvrnywfacwursctpagasnhydvmlinrcnqrry", "output": "NO" }, { "input": "tndtbldbllnrwmbyhvqaqqyoudrstpbfokfoclnraefuxtftmgzicorwisrpfnfpbdtatvwqgyalqtdtrjqvbfsq", "output": "NO" }, { "input": "rzlvirhgemelnzdawzpaoqtxmqucnahvqnwldklrmjiiyageraijfivigvozgwngiulttxxgzczptusoi", "output": "YES" }, { "input": "kgyelmchocojsnaqdsyeqgnllytbqietpdlgknwwumqkxrexgdcnwoldicwzwofpmuesjuxzrasscvyuqwspm", "output": "YES" }, { "input": "pnyvrcotjvgynbeldnxieghfltmexttuxzyac", "output": "NO" }, { "input": "dtwhbqoumejligbenxvzhjlhosqojetcqsynlzyhfaevbdpekgbtjrbhlltbceobcok", "output": "YES" }, { "input": "crrfpfftjwhhikwzeedrlwzblckkteseofjuxjrktcjfsylmlsvogvrcxbxtffujqshslemnixoeezivksouefeqlhhokwbqjz", "output": "YES" }, { "input": "jhfbndhyzdvhbvhmhmefqllujdflwdpjbehedlsqfdsqlyelwjtyloxwsvasrbqosblzbowlqjmyeilcvotdlaouxhdpoeloaovb", "output": "YES" }, { "input": "hwlghueoemiqtjhhpashjsouyegdlvoyzeunlroypoprnhlyiwiuxrghekaylndhrhllllwhbebezoglydcvykllotrlaqtvmlla", "output": "YES" }, { "input": "wshiaunnqnqxodholbipwhhjmyeblhgpeleblklpzwhdunmpqkbuzloetmwwxmeltkrcomulxauzlwmlklldjodozxryghsnwgcz", "output": "YES" }, { "input": "shvksednttggehroewuiptvvxtrzgidravtnjwuqrlnnkxbplctzkckinpkgjopjfoxdbojtcvsuvablcbkrzajrlhgobkcxeqti", "output": "YES" }, { "input": "hyyhddqhxhekehkwfhlnlsihzefwchzerevcjtokefplholrbvxlltdlafjxrfhleglrvlolojoqaolagtbeyogxlbgfolllslli", "output": "YES" }, { "input": "iaagrdhhelxpdegueiulflquvlzidoprzkehthkldaytrjwhyhprwjxlltinxvuilxohqgjqcvkkdcuoliekcnlilwgqlnlzouoo", "output": "YES" }, { "input": "wfluaeseldgxyvxpwuhkptdmlflnlhktwxiabsvkolsquymrmhzczzoybvlilhmvsuunggvgxzgyyffk", "output": "NO" }, { "input": "loee", "output": "NO" }, { "input": "izdipwylefqmjbuoznfglgcfvedeouflkeehxbasaqmiooppfsqlhprospqgxvzrcpwlfdddngoqvpwvggsnvvxhmjoslwjudjlo", "output": "NO" }, { "input": "pplynflbjlseflaegzqpdxswgunhnlglqhycrbcwdfhclmcrwekkzsoosmfblljeenwfjyifcvxihhhbyhmhlkvtskeglaovjnsi", "output": "YES" }, { "input": "xqjqmenkodmlhzyzmmvofdngktygbbxbzpluzcohohmalkoeuwfikblltaaigv", "output": "NO" }, { "input": "hello", "output": "YES" }, { "input": "oohell", "output": "NO" }, { "input": "hell", "output": "NO" }, { "input": "eloellohoelo", "output": "NO" }, { "input": "helllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllo", "output": "YES" } ]
1,606,148,569
2,147,483,647
PyPy 3
OK
TESTS
40
155
0
s = input() try: s = s[s.index('h'):len(s)-s[::-1].index('o')] except ValueError: print("NO") exit(0) try: if s[s.index("e"):].count('l') >= 2: print("YES") else: print("NO") except ValueError: 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() try: s = s[s.index('h'):len(s)-s[::-1].index('o')] except ValueError: print("NO") exit(0) try: if s[s.index("e"):].count('l') >= 2: print("YES") else: print("NO") except ValueError: print("NO") ```
3.9225
110
A
Nearly Lucky Number
PROGRAMMING
800
[ "implementation" ]
A. Nearly Lucky Number
2
256
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number.
The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes).
[ "40047\n", "7747774\n", "1000000000000000000\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
500
[ { "input": "40047", "output": "NO" }, { "input": "7747774", "output": "YES" }, { "input": "1000000000000000000", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "4", "output": "NO" }, { "input": "474404774", "output": "NO" }, { "input": "4744000695826", "output": "YES" }, { "input": "10000000004744744", "output": "YES" }, { "input": "446486416781684178", "output": "YES" }, { "input": "999999999", "output": "NO" }, { "input": "7777", "output": "YES" }, { "input": "87414417444", "output": "NO" }, { "input": "111222333444555667", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "4700", "output": "NO" }, { "input": "3794555488744477", "output": "NO" }, { "input": "444444444444444444", "output": "NO" }, { "input": "474447447774444774", "output": "NO" }, { "input": "777777777777777", "output": "NO" }, { "input": "34777745021000000", "output": "NO" }, { "input": "963", "output": "NO" }, { "input": "855474448854788540", "output": "NO" }, { "input": "999999999999994744", "output": "YES" }, { "input": "400000000474", "output": "YES" }, { "input": "123456789123456789", "output": "YES" }, { "input": "740577777584945874", "output": "NO" }, { "input": "7777777", "output": "YES" }, { "input": "4444000111222333", "output": "YES" }, { "input": "9847745885202111", "output": "YES" }, { "input": "123456000000", "output": "NO" }, { "input": "4744447444444", "output": "NO" }, { "input": "7477", "output": "YES" }, { "input": "4747477", "output": "YES" }, { "input": "777777777444444444", "output": "NO" } ]
1,694,508,780
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
# -*- coding: utf-8 -*- """ Created on Tue Sep 12 16:30:18 2023 @author: gzk16 """ lucky_number = input() numbers = [int(x) for x in lucky_number] if all(x == 4 or x == 7 for x in numbers): print('YES') else: count = 0 for number in numbers: if number == 4 or number == 7: count += 1 if count == 4 or 7: print('YES') else: print('NO')
Title: Nearly Lucky Number Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. Input Specification: The only line contains an integer *n* (1<=≤<=*n*<=≤<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. Output Specification: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Demo Input: ['40047\n', '7747774\n', '1000000000000000000\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO". In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES". In the third sample there are no lucky digits, so the answer is "NO".
```python # -*- coding: utf-8 -*- """ Created on Tue Sep 12 16:30:18 2023 @author: gzk16 """ lucky_number = input() numbers = [int(x) for x in lucky_number] if all(x == 4 or x == 7 for x in numbers): print('YES') else: count = 0 for number in numbers: if number == 4 or number == 7: count += 1 if count == 4 or 7: print('YES') else: print('NO') ```
0
955
B
Not simply beatiful strings
PROGRAMMING
1,400
[ "implementation" ]
null
null
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string.
The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters.
Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case.
[ "ababa\n", "zzcxx\n", "yeee\n" ]
[ "Yes\n", "Yes\n", "No\n" ]
In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
1,000
[ { "input": "ababa", "output": "Yes" }, { "input": "zzcxx", "output": "Yes" }, { "input": "yeee", "output": "No" }, { "input": "a", "output": "No" }, { "input": "bbab", "output": "No" }, { "input": "abcd", "output": "Yes" }, { "input": "abc", "output": "No" }, { "input": "abcdaaaa", "output": "Yes" }, { "input": "aaaaaaaaaaaaaaa", "output": "No" }, { "input": "adb", "output": "No" }, { "input": "dcccbad", "output": "Yes" }, { "input": "bcbccccccca", "output": "Yes" }, { "input": "abcdefgh", "output": "No" }, { "input": "aabcdef", "output": "No" }, { "input": "aabc", "output": "Yes" }, { "input": "ssab", "output": "Yes" }, { "input": "ccdd", "output": "Yes" }, { "input": "abcc", "output": "Yes" }, { "input": "ab", "output": "No" }, { "input": "abcde", "output": "No" }, { "input": "aa", "output": "No" }, { "input": "aaabbb", "output": "Yes" }, { "input": "bbbba", "output": "No" }, { "input": "abbbc", "output": "Yes" }, { "input": "baabaa", "output": "Yes" }, { "input": "abacabadde", "output": "No" }, { "input": "aabbcc", "output": "Yes" }, { "input": "abbc", "output": "Yes" }, { "input": "aaaaaaabbbbbbcder", "output": "No" }, { "input": "aabb", "output": "Yes" }, { "input": "aabbccddee", "output": "No" }, { "input": "abca", "output": "Yes" }, { "input": "aaabbbccc", "output": "Yes" } ]
1,521,830,944
8,044
Python 3
WRONG_ANSWER
PRETESTS
5
93
7,065,600
s = sorted(list(input())) d = dict((l,s.count(l)) for l in set(s)) count = 0 for l in set(s): if d[l] > 1: count += 1 if count > 1: print('Yes') else: print('No')
Title: Not simply beatiful strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of *a*-s and others — a group of *b*-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string *s*. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string. Input Specification: The only line contains *s* (1<=≤<=|*s*|<=≤<=105) consisting of lowercase latin letters. Output Specification: Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case. Demo Input: ['ababa\n', 'zzcxx\n', 'yeee\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n'] Note: In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
```python s = sorted(list(input())) d = dict((l,s.count(l)) for l in set(s)) count = 0 for l in set(s): if d[l] > 1: count += 1 if count > 1: print('Yes') else: print('No') ```
0
475
B
Strongly Connected City
PROGRAMMING
1,400
[ "brute force", "dfs and similar", "graphs", "implementation" ]
null
null
Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.
The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character is equal to '&lt;', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.
If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO".
[ "3 3\n&gt;&lt;&gt;\nv^v\n", "4 6\n&lt;&gt;&lt;&gt;\nv^v^v^\n" ]
[ "NO\n", "YES\n" ]
The figure above shows street directions in the second sample test case.
1,000
[ { "input": "3 3\n><>\nv^v", "output": "NO" }, { "input": "4 6\n<><>\nv^v^v^", "output": "YES" }, { "input": "2 2\n<>\nv^", "output": "YES" }, { "input": "2 2\n>>\n^v", "output": "NO" }, { "input": "3 3\n>><\n^^v", "output": "YES" }, { "input": "3 4\n>><\n^v^v", "output": "YES" }, { "input": "3 8\n>><\nv^^^^^^^", "output": "NO" }, { "input": "7 2\n<><<<<>\n^^", "output": "NO" }, { "input": "4 5\n><<<\n^^^^v", "output": "YES" }, { "input": "2 20\n><\n^v^^v^^v^^^v^vv^vv^^", "output": "NO" }, { "input": "2 20\n<>\nv^vv^v^^vvv^^^v^vvv^", "output": "YES" }, { "input": "20 2\n<><<><<>><<<>><><<<<\n^^", "output": "NO" }, { "input": "20 2\n><>><>><>><<<><<><><\n^v", "output": "YES" }, { "input": "11 12\n><<<><><<>>\nvv^^^^vvvvv^", "output": "NO" }, { "input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^", "output": "YES" }, { "input": "16 11\n<<<<>><><<<<<><<\nvv^v^vvvv^v", "output": "NO" }, { "input": "14 7\n><<<<>>>>>>><<\nvv^^^vv", "output": "NO" }, { "input": "5 14\n<<><>\nv^vv^^vv^v^^^v", "output": "NO" }, { "input": "8 18\n>>>><>>>\nv^vv^v^^^^^vvv^^vv", "output": "NO" }, { "input": "18 18\n<<><>><<>><>><><<<\n^^v^v^vvvv^v^vv^vv", "output": "NO" }, { "input": "4 18\n<<<>\n^^^^^vv^vv^^vv^v^v", "output": "NO" }, { "input": "19 18\n><><>>><<<<<>>><<<>\n^^v^^v^^v^vv^v^vvv", "output": "NO" }, { "input": "14 20\n<<<><><<>><><<\nvvvvvvv^v^vvvv^^^vv^", "output": "NO" }, { "input": "18 18\n><>>><<<>><><>>>><\nvv^^^^v^v^^^^v^v^^", "output": "NO" }, { "input": "8 18\n<><<<>>>\n^^^^^^v^^^vv^^vvvv", "output": "NO" }, { "input": "11 12\n><><><<><><\n^^v^^^^^^^^v", "output": "YES" }, { "input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^", "output": "YES" }, { "input": "16 11\n>><<><<<<>>><><<\n^^^^vvvv^vv", "output": "YES" }, { "input": "14 7\n<><><<<>>>><>>\nvv^^v^^", "output": "YES" }, { "input": "5 14\n>>>><\n^v^v^^^vv^vv^v", "output": "YES" }, { "input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^", "output": "YES" }, { "input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v", "output": "YES" }, { "input": "4 18\n<<>>\nv^v^v^^vvvv^v^^vv^", "output": "YES" }, { "input": "19 18\n>>>><><<>>><<<><<<<\n^v^^^^vv^^v^^^^v^v", "output": "YES" }, { "input": "14 20\n<>><<<><<>>>>>\nvv^^v^^^^v^^vv^^vvv^", "output": "YES" }, { "input": "18 18\n><><<><><>>><>>>><\n^^vvv^v^^^v^vv^^^v", "output": "YES" }, { "input": "8 18\n<<<><>>>\nv^^vvv^^v^v^vvvv^^", "output": "YES" }, { "input": "20 19\n<><>>>>><<<<<><<>>>>\nv^vv^^vvvvvv^vvvv^v", "output": "NO" }, { "input": "20 19\n<<<><<<>><<<>><><><>\nv^v^vvv^vvv^^^vvv^^", "output": "YES" }, { "input": "19 20\n<><<<><><><<<<<<<<>\n^v^^^^v^^vvvv^^^^vvv", "output": "NO" }, { "input": "19 20\n>>>>>>>><>>><><<<><\n^v^v^^^vvv^^^v^^vvvv", "output": "YES" }, { "input": "20 20\n<<<>>>><>><<>><<>>>>\n^vvv^^^^vv^^^^^v^^vv", "output": "NO" }, { "input": "20 20\n>>><><<><<<<<<<><<><\nvv^vv^vv^^^^^vv^^^^^", "output": "NO" }, { "input": "20 20\n><<><<<<<<<>>><>>><<\n^^^^^^^^vvvv^vv^vvvv", "output": "YES" }, { "input": "20 20\n<>>>>>>>><>>><>><<<>\nvv^^vv^^^^v^vv^v^^^^", "output": "YES" }, { "input": "20 20\n><>><<>><>>>>>>>><<>\n^^v^vv^^^vvv^v^^^vv^", "output": "NO" }, { "input": "20 20\n<<<<><<>><><<<>><<><\nv^^^^vvv^^^vvvv^v^vv", "output": "NO" }, { "input": "20 20\n><<<><<><>>><><<<<<<\nvv^^vvv^^v^^v^vv^vvv", "output": "NO" }, { "input": "20 20\n<<>>><>>>><<<<>>><<>\nv^vv^^^^^vvv^^v^^v^v", "output": "NO" }, { "input": "20 20\n><<><<><<<<<<>><><>>\nv^^^v^vv^^v^^vvvv^vv", "output": "NO" }, { "input": "20 20\n<<<<<<<<><>><><>><<<\n^vvv^^^v^^^vvv^^^^^v", "output": "NO" }, { "input": "20 20\n>>><<<<<>>><><><<><<\n^^^vvv^^^v^^v^^v^vvv", "output": "YES" }, { "input": "20 20\n<><<<><><>><><><<<<>\n^^^vvvv^vv^v^^^^v^vv", "output": "NO" }, { "input": "20 20\n>>>>>>>>>><>>><>><>>\n^vvv^^^vv^^^^^^vvv^v", "output": "NO" }, { "input": "20 20\n<><>><><<<<<>><<>>><\nv^^^v^v^v^vvvv^^^vv^", "output": "NO" }, { "input": "20 20\n><<<><<<><<<><>>>><<\nvvvv^^^^^vv^v^^vv^v^", "output": "NO" }, { "input": "20 20\n<<><<<<<<>>>>><<<>>>\nvvvvvv^v^vvv^^^^^^^^", "output": "YES" }, { "input": "20 20\n><<><<>>>>><><>><>>>\nv^^^^vvv^^^^^v^v^vv^", "output": "NO" }, { "input": "20 20\n<<>>><>><<>>>><<<><<\n^^vvv^^vvvv^vv^^v^v^", "output": "NO" }, { "input": "20 20\n><<>><>>>><<><>><><<\n^v^^^^^^vvvv^v^v^v^^", "output": "NO" }, { "input": "20 20\n<<><<<<><><<>>><>>>>\n^^vvvvv^v^^^^^^^vvv^", "output": "NO" }, { "input": "20 20\n>><<<<<<><>>>><>>><>\n^^^v^v^vv^^vv^vvv^^^", "output": "NO" }, { "input": "20 20\n>>>>>>>>>>>>>>>>>>>>\nvvvvvvvvvvvvvvvvvvvv", "output": "NO" }, { "input": "2 2\n><\nv^", "output": "NO" }, { "input": "2 2\n<>\n^v", "output": "NO" }, { "input": "3 3\n>><\nvvv", "output": "NO" }, { "input": "2 3\n<>\nv^^", "output": "YES" }, { "input": "4 4\n>>><\nvvv^", "output": "NO" }, { "input": "20 20\n<><><><><><><><><><>\nvvvvvvvvvvvvvvvvvvvv", "output": "NO" }, { "input": "4 4\n<>>>\nv^^^", "output": "YES" }, { "input": "20 20\n<><><><><><><><><><>\nv^v^v^v^v^v^v^v^v^v^", "output": "YES" }, { "input": "2 3\n<>\n^v^", "output": "NO" }, { "input": "4 3\n<><>\n^vv", "output": "NO" }, { "input": "3 3\n<<>\nvv^", "output": "YES" }, { "input": "2 3\n><\nvv^", "output": "NO" }, { "input": "7 6\n>>><>><\n^vv^vv", "output": "YES" }, { "input": "2 2\n<<\nv^", "output": "NO" }, { "input": "3 3\n>><\n^^^", "output": "NO" }, { "input": "3 3\n<><\nv^v", "output": "NO" }, { "input": "20 20\n><><><><><><><><><><\n^v^v^v^v^v^v^v^v^v^v", "output": "YES" }, { "input": "4 4\n<>>>\nvvv^", "output": "YES" } ]
1,412,516,250
2,250
Python 3
OK
TESTS
81
62
0
#!/usr/bin/python3 n, m = input().split() n = int(n) m = int(m) if n == m == 1: print("YES") else: x, y = input(), input() x = (1 if x[0] == '<' else 0, 1 if x[-1] == '>' else 0) y = (1 if y[0] == 'v' else 0, 1 if y[-1] == '^' else 0) if (sum(x) + sum(y)) % 4 == 0: print("YES") else: print("NO")
Title: Strongly Connected City Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern. Input Specification: The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character is equal to '&lt;', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east. Output Specification: If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". Demo Input: ['3 3\n&gt;&lt;&gt;\nv^v\n', '4 6\n&lt;&gt;&lt;&gt;\nv^v^v^\n'] Demo Output: ['NO\n', 'YES\n'] Note: The figure above shows street directions in the second sample test case.
```python #!/usr/bin/python3 n, m = input().split() n = int(n) m = int(m) if n == m == 1: print("YES") else: x, y = input(), input() x = (1 if x[0] == '<' else 0, 1 if x[-1] == '>' else 0) y = (1 if y[0] == 'v' else 0, 1 if y[-1] == '^' else 0) if (sum(x) + sum(y)) % 4 == 0: print("YES") else: print("NO") ```
3
884
D
Boxes And Balls
PROGRAMMING
2,300
[ "data structures", "greedy" ]
null
null
Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some turns. Each turn he does the following: 1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3. The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes. Help Ivan to determine the minimum possible penalty of the game!
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*.
Print one number — the minimum possible penalty of the game.
[ "3\n1 2 3\n", "4\n2 3 4 5\n" ]
[ "6\n", "19\n" ]
In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5. Total penalty is 19.
0
[ { "input": "3\n1 2 3", "output": "6" }, { "input": "4\n2 3 4 5", "output": "19" }, { "input": "6\n1 4 4 4 4 4", "output": "38" }, { "input": "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158", "output": "8176373828" }, { "input": "1\n10", "output": "0" }, { "input": "1\n4", "output": "0" }, { "input": "1\n12312", "output": "0" }, { "input": "1\n1", "output": "0" }, { "input": "2\n3 4", "output": "7" } ]
1,509,698,970
7,170
Python 3
WRONG_ANSWER
TESTS
2
46
0
# import sys, codecs # # save_stdin = sys.stdin # save_stdout = sys.stdout # sys.stdin = codecs.open("input.txt", "r", "utf-8") # sys.stdout = codecs.open("output.txt", "w+") # TODO: solve n = int(input()) colors_lens = list(map(int, input().split())) boxes = [sum(colors_lens)] boxes.extend([0 for __ in range(n - 1)]) shtraf = 0 if n % 2 == 0: colors_lens.append(0) colors_lens.sort() while len(colors_lens) != 1: if len(colors_lens) > 2: shtraf += sum(colors_lens[:3]) colors_lens = [sum(colors_lens[:3])] + colors_lens[3:] elif len(colors_lens) == 2: shtraf += sum(colors_lens[:2]) colors_lens = [sum(colors_lens)] print(shtraf)
Title: Boxes And Balls Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has *n* different boxes. The first of them contains some balls of *n* different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every *i* (1<=≤<=*i*<=≤<=*n*) *i*-th box will contain all balls with color *i*. In order to do this, Ivan will make some turns. Each turn he does the following: 1. Ivan chooses any non-empty box and takes all balls from this box; 1. Then Ivan chooses any *k* empty boxes (the box from the first step becomes empty, and Ivan is allowed to choose it), separates the balls he took on the previous step into *k* non-empty groups and puts each group into one of the boxes. He should put each group into a separate box. He can choose either *k*<==<=2 or *k*<==<=3. The penalty of the turn is the number of balls Ivan takes from the box during the first step of the turn. And penalty of the game is the total penalty of turns made by Ivan until he distributes all balls to corresponding boxes. Help Ivan to determine the minimum possible penalty of the game! Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200000) — the number of boxes and colors. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the number of balls with color *i*. Output Specification: Print one number — the minimum possible penalty of the game. Demo Input: ['3\n1 2 3\n', '4\n2 3 4 5\n'] Demo Output: ['6\n', '19\n'] Note: In the first example you take all the balls from the first box, choose *k* = 3 and sort all colors to corresponding boxes. Penalty is 6. In the second example you make two turns: 1. Take all the balls from the first box, choose *k* = 3, put balls of color 3 to the third box, of color 4 — to the fourth box and the rest put back into the first box. Penalty is 14; 1. Take all the balls from the first box, choose *k* = 2, put balls of color 1 to the first box, of color 2 — to the second box. Penalty is 5. Total penalty is 19.
```python # import sys, codecs # # save_stdin = sys.stdin # save_stdout = sys.stdout # sys.stdin = codecs.open("input.txt", "r", "utf-8") # sys.stdout = codecs.open("output.txt", "w+") # TODO: solve n = int(input()) colors_lens = list(map(int, input().split())) boxes = [sum(colors_lens)] boxes.extend([0 for __ in range(n - 1)]) shtraf = 0 if n % 2 == 0: colors_lens.append(0) colors_lens.sort() while len(colors_lens) != 1: if len(colors_lens) > 2: shtraf += sum(colors_lens[:3]) colors_lens = [sum(colors_lens[:3])] + colors_lens[3:] elif len(colors_lens) == 2: shtraf += sum(colors_lens[:2]) colors_lens = [sum(colors_lens)] print(shtraf) ```
0
816
B
Karen and Coffee
PROGRAMMING
1,400
[ "binary search", "data structures", "implementation" ]
null
null
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste. Karen thinks that a temperature is admissible if at least *k* recipes recommend it. Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range?
The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive. The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
[ "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n", "2 1 1\n1 1\n200000 200000\n90 100\n" ]
[ "3\n3\n0\n4\n", "0\n" ]
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it. She asks 4 questions. In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible. In the second test case, Karen knows 2 recipes. 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it. In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
1,000
[ { "input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4" }, { "input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0" }, { "input": "1 1 1\n1 1\n1 1", "output": "1" }, { "input": "1 1 1\n200000 200000\n200000 200000", "output": "1" } ]
1,686,769,956
2,147,483,647
Python 3
OK
TESTS
45
1,840
8,089,600
n, k, q = map(int, input().split()) # initialize temperature difference list temperature_diffs = [0] * 200005 # loop through ranges and add temperature differences for i in range(n): range_start, range_end = map(int, input().split()) temperature_diffs[range_start] += 1 temperature_diffs[range_end+1] -= 1 # calculate cumulative temperature differences for j in range(1, 200005): temperature_diffs[j] += temperature_diffs[j-1] # set acceptable temperatures of 0 and 1 for m in range(len(temperature_diffs)): temperature_diffs[m] = 1 if temperature_diffs[m] >= k else 0 # calculate cumulative temperature differences again for y in range(1, 200005): temperature_diffs[y] += temperature_diffs[y-1] # loop through queries and print results for x in range(q): query_start, query_end = map(int, input().split()) num_acceptable_temperatures = temperature_diffs[query_end] - temperature_diffs[query_start-1] print(num_acceptable_temperatures)
Title: Karen and Coffee Time Limit: None seconds Memory Limit: None megabytes Problem Description: To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste. Karen thinks that a temperature is admissible if at least *k* recipes recommend it. Karen has a rather fickle mind, and so she asks *q* questions. In each question, given that she only wants to prepare coffee with a temperature between *a* and *b*, inclusive, can you tell her how many admissible integer temperatures fall within the range? Input Specification: The first line of input contains three integers, *n*, *k* (1<=≤<=*k*<=≤<=*n*<=≤<=200000), and *q* (1<=≤<=*q*<=≤<=200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive. The next *q* lines describe the questions. Each of these lines contains *a* and *b*, (1<=≤<=*a*<=≤<=*b*<=≤<=200000), describing that she wants to know the number of admissible integer temperatures between *a* and *b* degrees, inclusive. Output Specification: For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive. Demo Input: ['3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100\n', '2 1 1\n1 1\n200000 200000\n90 100\n'] Demo Output: ['3\n3\n0\n4\n', '0\n'] Note: In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 1. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 1. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature is admissible if at least 2 recipes recommend it. She asks 4 questions. In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible. In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible. In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none. In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible. In the second test case, Karen knows 2 recipes. 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree. 1. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees. A temperature is admissible if at least 1 recipe recommends it. In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.
```python n, k, q = map(int, input().split()) # initialize temperature difference list temperature_diffs = [0] * 200005 # loop through ranges and add temperature differences for i in range(n): range_start, range_end = map(int, input().split()) temperature_diffs[range_start] += 1 temperature_diffs[range_end+1] -= 1 # calculate cumulative temperature differences for j in range(1, 200005): temperature_diffs[j] += temperature_diffs[j-1] # set acceptable temperatures of 0 and 1 for m in range(len(temperature_diffs)): temperature_diffs[m] = 1 if temperature_diffs[m] >= k else 0 # calculate cumulative temperature differences again for y in range(1, 200005): temperature_diffs[y] += temperature_diffs[y-1] # loop through queries and print results for x in range(q): query_start, query_end = map(int, input().split()) num_acceptable_temperatures = temperature_diffs[query_end] - temperature_diffs[query_start-1] print(num_acceptable_temperatures) ```
3
875
A
Classroom Watch
PROGRAMMING
1,200
[ "brute force", "math" ]
null
null
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova.
The first line contains integer *n* (1<=≤<=*n*<=≤<=109).
In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order.
[ "21\n", "20\n" ]
[ "1\n15\n", "0\n" ]
In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
500
[ { "input": "21", "output": "1\n15" }, { "input": "20", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "1\n1" }, { "input": "3", "output": "0" }, { "input": "100000001", "output": "2\n99999937\n100000000" }, { "input": "1000000000", "output": "1\n999999932" }, { "input": "999999979", "output": "2\n999999899\n999999908" }, { "input": "9", "output": "0" }, { "input": "10", "output": "1\n5" }, { "input": "11", "output": "1\n10" }, { "input": "39", "output": "1\n33" }, { "input": "66", "output": "1\n60" }, { "input": "75", "output": "0" }, { "input": "100", "output": "1\n86" }, { "input": "101", "output": "2\n91\n100" }, { "input": "2014", "output": "2\n1988\n2006" }, { "input": "999999994", "output": "0" } ]
1,628,891,889
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
6,963,200
n = int(input()) counter = 0 x = [] for i in range(n): sum_digit = i for j in str(i): sum_digit += int(j) if sum_digit == n: counter += 1 x.append(i) print(counter) for i in range(len(x)): print(x[i])
Title: Classroom Watch Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=109). Output Specification: In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order. Demo Input: ['21\n', '20\n'] Demo Output: ['1\n15\n', '0\n'] Note: In the first test case *x* = 15 there is only one variant: 15 + 1 + 5 = 21. In the second test case there are no such *x*.
```python n = int(input()) counter = 0 x = [] for i in range(n): sum_digit = i for j in str(i): sum_digit += int(j) if sum_digit == n: counter += 1 x.append(i) print(counter) for i in range(len(x)): print(x[i]) ```
0
59
B
Fortune Telling
PROGRAMMING
1,200
[ "implementation", "number theory" ]
B. Fortune Telling
2
256
Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are *n* camomiles growing in the field, possessing the numbers of petals equal to *a*1,<=*a*2,<=... *a**n*. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100), which is the number of flowers growing in the field. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) which represent the number of petals on a given *i*-th camomile.
Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower.
[ "1\n1\n", "1\n2\n", "3\n5 6 7\n" ]
[ "1\n", "0\n", "13\n" ]
none
1,000
[ { "input": "1\n1", "output": "1" }, { "input": "1\n2", "output": "0" }, { "input": "3\n5 6 7", "output": "13" }, { "input": "2\n5 7", "output": "7" }, { "input": "3\n1 2 3", "output": "5" }, { "input": "4\n4 3 1 2", "output": "9" }, { "input": "10\n90 72 76 60 22 87 5 67 17 65", "output": "561" }, { "input": "10\n18 42 20 68 88 10 87 37 55 51", "output": "439" }, { "input": "100\n25 43 35 79 53 13 91 91 45 65 83 57 9 41 39 85 45 71 51 61 59 31 13 63 39 25 21 79 39 91 67 21 61 97 75 93 83 29 79 59 97 11 37 63 51 39 55 91 23 21 17 47 23 35 75 49 5 69 99 5 7 41 17 25 89 15 79 21 63 53 81 43 91 59 91 69 99 85 15 91 51 49 37 65 7 89 81 21 93 61 63 97 93 45 17 13 69 57 25 75", "output": "5355" }, { "input": "100\n22 93 43 39 5 39 55 89 97 7 35 63 75 85 97 75 35 91 5 29 97 69 23 97 95 59 23 81 87 67 85 95 33 41 57 9 39 25 55 9 87 57 69 31 23 27 13 81 51 11 61 35 69 59 51 33 73 29 77 75 9 15 41 93 65 89 69 37 51 11 57 21 97 95 13 67 23 69 3 29 83 97 7 49 13 51 65 33 99 9 27 99 55 47 37 11 37 13 91 79", "output": "5193" }, { "input": "100\n82 6 42 34 4 32 12 50 16 58 48 92 44 94 36 94 96 50 68 38 78 10 18 88 38 66 60 72 76 24 60 62 86 8 16 14 74 54 38 100 88 28 44 78 90 42 20 24 90 21 81 29 53 95 75 5 57 31 37 69 55 65 1 67 61 71 17 99 15 15 67 77 19 95 79 87 29 97 13 95 61 91 45 77 91 79 55 81 37 81 15 89 67 61 19 25 97 53 7 95", "output": "5445" }, { "input": "100\n64 16 64 48 12 88 18 38 12 14 90 82 68 40 90 78 66 50 56 50 78 12 18 100 14 92 70 96 90 26 60 94 88 26 70 100 34 86 8 38 72 24 32 80 56 28 32 48 92 52 71 43 95 23 71 89 51 93 61 39 75 3 19 79 71 11 33 21 61 29 13 55 61 23 17 45 93 11 15 29 45 91 43 9 41 37 99 67 25 33 83 55 59 85 59 41 67 67 37 17", "output": "5217" }, { "input": "100\n12 84 30 14 36 18 4 82 26 22 10 88 96 84 50 100 88 40 70 94 94 58 16 50 80 38 94 100 34 20 22 54 34 58 92 18 6 8 22 92 82 28 42 54 96 8 18 40 64 90 58 63 97 89 17 11 21 55 71 91 47 93 55 95 39 81 51 7 77 13 25 65 51 47 47 49 19 35 67 5 7 65 65 65 79 33 71 15 17 91 13 43 81 31 7 17 17 93 9 25", "output": "4945" }, { "input": "100\n64 58 12 86 50 16 48 32 30 2 30 36 4 6 96 84 58 94 14 50 28 100 32 84 54 76 26 100 42 100 76 32 86 72 84 16 36 10 26 82 54 64 78 66 62 30 4 80 28 16 44 82 8 2 24 56 28 98 20 92 30 10 28 32 44 18 58 2 12 64 14 4 12 84 16 14 8 78 94 98 34 16 28 76 82 50 40 78 28 16 60 58 64 68 56 46 24 72 72 69", "output": "4725" }, { "input": "100\n92 46 50 24 68 60 70 30 52 22 18 74 68 98 20 82 4 46 26 68 100 78 84 58 74 98 38 88 68 86 64 80 82 100 20 22 98 98 52 6 94 10 48 68 2 18 38 22 22 82 44 20 66 72 36 58 64 6 36 60 4 96 76 64 12 90 10 58 64 60 74 28 90 26 24 60 40 58 2 16 76 48 58 36 82 60 24 44 4 78 28 38 8 12 40 16 38 6 66 24", "output": "0" }, { "input": "99\n49 37 55 57 97 79 53 25 89 13 15 77 91 51 73 39 29 83 13 43 79 15 89 97 67 25 23 77 71 41 15 83 39 13 43 1 51 49 1 11 95 57 65 7 79 43 51 33 33 71 97 73 3 65 73 55 21 7 37 75 39 9 21 47 31 97 33 11 61 79 67 63 81 21 77 57 73 19 21 47 55 11 37 31 71 5 15 73 23 93 83 25 37 17 23 75 77 97 93", "output": "4893" }, { "input": "99\n26 77 13 25 33 67 89 57 49 35 7 15 17 5 1 73 53 19 35 83 31 49 51 1 25 23 3 63 19 9 53 25 65 43 27 71 3 95 77 89 95 85 67 27 93 3 11 45 99 31 21 35 83 31 43 93 75 93 3 51 11 29 73 3 33 63 57 71 43 15 69 55 53 7 13 73 7 5 57 61 97 53 13 39 79 19 35 71 27 97 19 57 39 51 89 63 21 47 53", "output": "4451" }, { "input": "99\n50 22 22 94 100 18 74 2 98 16 66 54 14 90 38 26 12 30 32 66 26 54 44 36 52 30 54 56 36 16 16 34 22 40 64 94 18 2 40 42 76 56 24 18 36 64 14 96 50 69 53 9 27 61 81 37 29 1 21 79 17 81 41 23 89 29 47 65 17 11 95 21 19 71 1 73 45 25 19 83 93 27 21 31 25 3 91 89 59 35 35 7 9 1 97 55 25 65 93", "output": "4333" }, { "input": "99\n86 16 38 20 68 60 84 16 28 88 60 48 80 28 4 92 70 60 46 46 20 34 12 100 76 2 40 10 8 86 6 80 50 66 12 34 14 28 26 70 46 64 34 96 10 90 98 96 56 88 49 73 69 93 1 93 23 65 67 45 21 29 5 9 63 31 87 13 97 99 63 57 49 17 49 49 7 37 7 15 53 1 59 53 61 83 91 97 3 71 65 25 13 87 99 15 9 5 87", "output": "4849" }, { "input": "99\n82 36 50 30 80 2 48 48 92 10 70 46 72 46 4 60 60 40 4 78 98 8 88 82 70 44 76 50 64 48 82 74 50 100 98 8 60 72 26 50 94 54 58 20 10 66 20 72 26 20 22 29 21 17 31 69 75 91 77 93 81 71 93 91 65 37 41 69 19 15 67 79 39 9 53 69 73 93 85 45 51 5 73 87 49 95 35 71 1 3 65 81 61 59 73 89 79 73 25", "output": "5439" }, { "input": "99\n28 50 100 90 56 60 54 16 54 62 48 6 2 14 40 48 28 48 58 68 90 74 82 2 98 4 74 64 34 98 94 24 44 74 50 18 40 100 80 96 10 42 66 46 26 26 84 34 68 84 74 48 8 90 2 36 40 32 18 76 90 64 38 92 86 84 56 84 74 90 4 2 50 34 18 28 30 2 18 80 52 34 10 86 96 76 30 64 88 76 74 4 50 22 20 96 90 12 42", "output": "0" }, { "input": "99\n58 100 2 54 80 84 74 46 92 74 90 4 92 92 18 88 100 80 42 34 80 62 92 94 8 48 98 44 4 74 48 22 26 90 98 44 14 54 80 24 60 50 58 62 94 18 20 4 56 58 52 80 88 82 10 40 36 46 14 22 54 10 36 10 20 76 48 98 2 68 26 96 16 92 50 78 28 8 80 84 82 26 62 20 60 84 2 80 70 98 50 30 64 6 92 58 16 88 27", "output": "5353" }, { "input": "42\n26 24 14 18 96 30 56 72 10 32 94 62 68 11 75 45 39 49 37 29 9 1 63 47 81 67 79 81 93 31 69 61 73 67 81 7 37 87 61 17 21 65", "output": "2085" }, { "input": "42\n62 46 24 100 68 48 6 4 16 60 48 52 26 56 52 20 100 14 72 80 72 52 76 15 17 23 1 91 71 39 93 5 93 47 59 77 37 17 33 51 39 85", "output": "2047" }, { "input": "50\n88 68 16 44 72 6 2 50 2 36 26 98 16 30 6 10 88 76 50 90 44 28 84 28 100 57 59 91 51 37 19 79 69 79 95 81 75 89 19 87 31 49 77 35 79 7 85 41 83 91", "output": "2723" }, { "input": "1\n31", "output": "31" }, { "input": "1\n44", "output": "0" }, { "input": "2\n21 63", "output": "63" }, { "input": "2\n90 95", "output": "185" }, { "input": "2\n54 28", "output": "0" }, { "input": "10\n68 96 32 50 55 67 27 93 81 77", "output": "619" }, { "input": "5\n36 56 38 6 28", "output": "0" }, { "input": "6\n34 72 80 5 47 9", "output": "247" }, { "input": "100\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "output": "9801" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "9999" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100", "output": "9899" }, { "input": "100\n100 100 100 100 100 100 100 100 100 1 100 100 100 100 100 100 100 100 100 100 100 1 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 3 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "9705" }, { "input": "5\n6 6 6 6 6", "output": "0" }, { "input": "4\n2 3 5 8", "output": "15" }, { "input": "4\n2 4 6 8", "output": "0" }, { "input": "4\n2 3 5 4", "output": "11" }, { "input": "3\n5 7 9", "output": "21" } ]
1,551,330,652
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
218
0
n=int(input()) a=list(map(int,input().split())) a=sorted(a) a=list(reversed(a)) s=0 b=[] for i in range(n): s+=a[i] b.append(s) i=n-1 while i>=0: if b[i]%2==0: i-=1 else: print(b[i]) exit(0) print(0)
Title: Fortune Telling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Marina loves Sasha. But she keeps wondering whether Sasha loves her. Of course, the best way to know it is fortune telling. There are many ways of telling fortune, but Marina has picked the easiest one. She takes in her hand one or several camomiles and tears off the petals one by one. After each petal she pronounces alternatively "Loves" and "Doesn't love", at that Marina always starts with "Loves". There are *n* camomiles growing in the field, possessing the numbers of petals equal to *a*1,<=*a*2,<=... *a**n*. Marina wants to pick a bouquet with the maximal possible total number of petals so that the result would still be "Loves". Help her do that; find the maximal number of petals possible in the bouquet. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100), which is the number of flowers growing in the field. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100) which represent the number of petals on a given *i*-th camomile. Output Specification: Print a single number which is the maximal number of petals in the bouquet, the fortune telling on which would result in "Loves". If there are no such bouquet, print 0 instead. The bouquet may consist of a single flower. Demo Input: ['1\n1\n', '1\n2\n', '3\n5 6 7\n'] Demo Output: ['1\n', '0\n', '13\n'] Note: none
```python n=int(input()) a=list(map(int,input().split())) a=sorted(a) a=list(reversed(a)) s=0 b=[] for i in range(n): s+=a[i] b.append(s) i=n-1 while i>=0: if b[i]%2==0: i-=1 else: print(b[i]) exit(0) print(0) ```
0
888
B
Buggy Robot
PROGRAMMING
1,000
[ "greedy" ]
null
null
Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!
The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R.
Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.
[ "4\nLDUR\n", "5\nRRRUU\n", "6\nLLRRRR\n" ]
[ "4\n", "0\n", "4\n" ]
none
0
[ { "input": "4\nLDUR", "output": "4" }, { "input": "5\nRRRUU", "output": "0" }, { "input": "6\nLLRRRR", "output": "4" }, { "input": "88\nLLUUULRDRRURDDLURRLRDRLLRULRUUDDLLLLRRDDURDURRLDURRLDRRRUULDDLRRRDDRRLUULLURDURUDDDDDLDR", "output": "76" }, { "input": "89\nLDLLLDRDUDURRRRRUDULDDDLLUDLRLRLRLDLDUULRDUDLRRDLUDLURRDDRRDLDUDUUURUUUDRLUDUDLURDLDLLDDU", "output": "80" }, { "input": "90\nRRRDUULLLRDUUDDRLDLRLUDURDRDUUURUURDDRRRURLDDDUUDRLLLULURDRDRURLDRRRRUULDULDDLLLRRLRDLLLLR", "output": "84" }, { "input": "91\nRLDRLRRLLDLULULLURULLRRULUDUULLUDULDUULURUDRUDUURDULDUDDUUUDRRUUDLLRULRULURLDRDLDRURLLLRDDD", "output": "76" }, { "input": "92\nRLRDDLULRLLUURRDDDLDDDLDDUURRRULLRDULDULLLUUULDUDLRLRRDRDRDDULDRLUDRDULDRURUDUULLRDRRLLDRLRR", "output": "86" }, { "input": "93\nRLLURLULRURDDLUURLUDDRDLUURLRDLRRRDUULLRDRRLRLDURRDLLRDDLLLDDDLDRRURLLDRUDULDDRRULRRULRLDRDLR", "output": "84" }, { "input": "94\nRDULDDDLULRDRUDRUUDUUDRRRULDRRUDURUULRDUUDLULLLUDURRDRDLUDRULRRRULUURUDDDDDUDLLRDLDRLLRUUURLUL", "output": "86" }, { "input": "95\nRDLUUULLUURDDRLDLLRRRULRLRDULULRULRUDURLULDDDRLURLDRULDUDUUULLRDDURUULULLDDLDRDRLLLURLRDLLDDDDU", "output": "86" }, { "input": "96\nRDDRLRLLDDULRLRURUDLRLDUDRURLLUUDLLURDLRRUURDRRUDRURLLDLLRDURDURLRLUDURULLLRDUURULUUULRRURRDLURL", "output": "84" }, { "input": "97\nRURDDLRLLRULUDURDLRLLUUDURRLLUDLLLDUDRUULDRUUURURULRDLDRRLLUUUDLLLDDLLLLRLLDUDRRDLLUDLRURUDULRLUR", "output": "82" }, { "input": "98\nRUDURLULLDDLLRDLLRDDLLLLRLDDDDRRRDDRRURLDRLLRUUUDLUUUDDDUDRUURLURUUDUUDRULRRULLRRLRULLULDLUURLULRD", "output": "92" }, { "input": "99\nRRULLDULRRDRULLDUDRUDDDRLLUUDRDDUDURLDDRUUDRRUUURRRURDDLDUURDLRLURRDDLUDDLUDURDRUDDURLURURLRUDRURLD", "output": "86" }, { "input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL", "output": "88" }, { "input": "1\nU", "output": "0" }, { "input": "5\nUUULD", "output": "2" }, { "input": "1\nD", "output": "0" }, { "input": "5\nURLUL", "output": "2" }, { "input": "5\nDDDRU", "output": "2" }, { "input": "2\nLR", "output": "2" }, { "input": "8\nDDRDLDUR", "output": "4" }, { "input": "6\nLLLLUD", "output": "2" }, { "input": "13\nRRRLLLLLLLLLL", "output": "6" } ]
1,546,249,275
2,147,483,647
Python 3
OK
TESTS
25
124
0
n = int(input()) s = input() l,r,u,d = 0, 0, 0, 0 for x in s: if x=='L': l+=1 if x=='R': r+=1 if x=='U': u+=1 if x=='D': d+=1 print(min(l,r)*2 + min(u,d)*2)
Title: Buggy Robot Time Limit: None seconds Memory Limit: None megabytes Problem Description: Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0,<=0). The robot can process commands. There are four types of commands it can perform: - U — move from the cell (*x*,<=*y*) to (*x*,<=*y*<=+<=1); - D — move from (*x*,<=*y*) to (*x*,<=*y*<=-<=1); - L — move from (*x*,<=*y*) to (*x*<=-<=1,<=*y*); - R — move from (*x*,<=*y*) to (*x*<=+<=1,<=*y*). Ivan entered a sequence of *n* commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0,<=0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations! Input Specification: The first line contains one number *n* — the length of sequence of commands entered by Ivan (1<=≤<=*n*<=≤<=100). The second line contains the sequence itself — a string consisting of *n* characters. Each character can be U, D, L or R. Output Specification: Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell. Demo Input: ['4\nLDUR\n', '5\nRRRUU\n', '6\nLLRRRR\n'] Demo Output: ['4\n', '0\n', '4\n'] Note: none
```python n = int(input()) s = input() l,r,u,d = 0, 0, 0, 0 for x in s: if x=='L': l+=1 if x=='R': r+=1 if x=='U': u+=1 if x=='D': d+=1 print(min(l,r)*2 + min(u,d)*2) ```
3
962
A
Equator
PROGRAMMING
1,300
[ "implementation" ]
null
null
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator.
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
Print the index of the day when Polycarp will celebrate the equator.
[ "4\n1 3 2 1\n", "6\n2 2 2 2 2 2\n" ]
[ "2\n", "3\n" ]
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
0
[ { "input": "4\n1 3 2 1", "output": "2" }, { "input": "6\n2 2 2 2 2 2", "output": "3" }, { "input": "1\n10000", "output": "1" }, { "input": "3\n2 1 1", "output": "1" }, { "input": "2\n1 3", "output": "2" }, { "input": "4\n2 1 1 3", "output": "3" }, { "input": "3\n1 1 3", "output": "3" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "2\n1 2", "output": "2" }, { "input": "3\n2 1 2", "output": "2" }, { "input": "5\n1 2 4 3 5", "output": "4" }, { "input": "5\n2 2 2 4 3", "output": "4" }, { "input": "4\n1 2 3 1", "output": "3" }, { "input": "6\n7 3 10 7 3 11", "output": "4" }, { "input": "2\n3 4", "output": "2" }, { "input": "5\n1 1 1 1 1", "output": "3" }, { "input": "4\n1 3 2 3", "output": "3" }, { "input": "2\n2 3", "output": "2" }, { "input": "3\n32 10 23", "output": "2" }, { "input": "7\n1 1 1 1 1 1 1", "output": "4" }, { "input": "3\n1 2 4", "output": "3" }, { "input": "6\n3 3 3 2 4 4", "output": "4" }, { "input": "9\n1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "5\n1 3 3 1 1", "output": "3" }, { "input": "4\n1 1 1 2", "output": "3" }, { "input": "4\n1 2 1 3", "output": "3" }, { "input": "3\n2 2 1", "output": "2" }, { "input": "4\n2 3 3 3", "output": "3" }, { "input": "4\n3 2 3 3", "output": "3" }, { "input": "4\n2 1 1 1", "output": "2" }, { "input": "3\n2 1 4", "output": "3" }, { "input": "2\n6 7", "output": "2" }, { "input": "4\n3 3 4 3", "output": "3" }, { "input": "4\n1 1 2 5", "output": "4" }, { "input": "4\n1 8 7 3", "output": "3" }, { "input": "6\n2 2 2 2 2 3", "output": "4" }, { "input": "3\n2 2 5", "output": "3" }, { "input": "4\n1 1 2 1", "output": "3" }, { "input": "5\n1 1 2 2 3", "output": "4" }, { "input": "5\n9 5 3 4 8", "output": "3" }, { "input": "3\n3 3 1", "output": "2" }, { "input": "4\n1 2 2 2", "output": "3" }, { "input": "3\n1 3 5", "output": "3" }, { "input": "4\n1 1 3 6", "output": "4" }, { "input": "6\n1 2 1 1 1 1", "output": "3" }, { "input": "3\n3 1 3", "output": "2" }, { "input": "5\n3 4 5 1 2", "output": "3" }, { "input": "11\n1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "5\n3 1 2 5 2", "output": "4" }, { "input": "4\n1 1 1 4", "output": "4" }, { "input": "4\n2 6 1 10", "output": "4" }, { "input": "4\n2 2 3 2", "output": "3" }, { "input": "4\n4 2 2 1", "output": "2" }, { "input": "6\n1 1 1 1 1 4", "output": "5" }, { "input": "3\n3 2 2", "output": "2" }, { "input": "6\n1 3 5 1 7 4", "output": "5" }, { "input": "5\n1 2 4 8 16", "output": "5" }, { "input": "5\n1 2 4 4 4", "output": "4" }, { "input": "6\n4 2 1 2 3 1", "output": "3" }, { "input": "4\n3 2 1 5", "output": "3" }, { "input": "1\n1", "output": "1" }, { "input": "3\n2 4 7", "output": "3" }, { "input": "5\n1 1 1 1 3", "output": "4" }, { "input": "3\n3 1 5", "output": "3" }, { "input": "4\n1 2 3 7", "output": "4" }, { "input": "3\n1 4 6", "output": "3" }, { "input": "4\n2 1 2 2", "output": "3" }, { "input": "2\n4 5", "output": "2" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "3\n2 3 6", "output": "3" }, { "input": "6\n1 1 4 1 1 5", "output": "4" }, { "input": "5\n2 2 2 2 1", "output": "3" }, { "input": "2\n5 6", "output": "2" }, { "input": "4\n2 2 1 4", "output": "3" }, { "input": "5\n2 2 3 4 4", "output": "4" }, { "input": "4\n3 1 1 2", "output": "2" }, { "input": "5\n3 4 1 4 5", "output": "4" }, { "input": "4\n1 3 1 6", "output": "4" }, { "input": "5\n1 1 1 2 2", "output": "4" }, { "input": "4\n1 4 2 4", "output": "3" }, { "input": "10\n1 1 1 1 1 1 1 1 1 8", "output": "9" }, { "input": "4\n1 4 5 1", "output": "3" }, { "input": "5\n1 1 1 1 5", "output": "5" }, { "input": "4\n1 3 4 1", "output": "3" }, { "input": "4\n2 2 2 3", "output": "3" }, { "input": "4\n2 3 2 4", "output": "3" }, { "input": "5\n2 2 1 2 2", "output": "3" }, { "input": "3\n4 3 2", "output": "2" }, { "input": "3\n6 5 2", "output": "2" }, { "input": "69\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 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 1 1 1 1 1 1 1 1 1 1", "output": "35" }, { "input": "6\n1 1 1 1 1 2", "output": "4" }, { "input": "5\n1 2 5 4 5", "output": "4" }, { "input": "2\n9 10", "output": "2" }, { "input": "3\n1 1 5", "output": "3" }, { "input": "4\n3 4 3 5", "output": "3" }, { "input": "4\n1 4 3 3", "output": "3" }, { "input": "4\n7 1 3 4", "output": "2" }, { "input": "3\n100 100 1", "output": "2" }, { "input": "4\n5 2 2 2", "output": "2" } ]
1,526,126,236
2,147,483,647
Python 3
OK
TESTS
106
186
20,480,000
input() l = [int(i) for i in input().split()] k = sum(l) s = 0 i = 0 while s < k/2: s+=l[i] i+=1 print(i)
Title: Equator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. Input Specification: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. Output Specification: Print the index of the day when Polycarp will celebrate the equator. Demo Input: ['4\n1 3 2 1\n', '6\n2 2 2 2 2 2\n'] Demo Output: ['2\n', '3\n'] Note: In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
```python input() l = [int(i) for i in input().split()] k = sum(l) s = 0 i = 0 while s < k/2: s+=l[i] i+=1 print(i) ```
3
169
B
Replacing Digits
PROGRAMMING
1,100
[ "greedy" ]
null
null
You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation. Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*.
The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain leading zeroes.
Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes.
[ "1024\n010\n", "987\n1234567\n" ]
[ "1124\n", "987\n" ]
none
1,000
[ { "input": "1024\n010", "output": "1124" }, { "input": "987\n1234567", "output": "987" }, { "input": "10\n1", "output": "11" }, { "input": "11\n1", "output": "11" }, { "input": "12\n2", "output": "22" }, { "input": "1\n0", "output": "1" }, { "input": "123456\n9999", "output": "999956" }, { "input": "909090\n000111", "output": "919191" }, { "input": "588\n24", "output": "588" }, { "input": "25206\n88", "output": "88206" }, { "input": "9776247464\n8629", "output": "9986647464" }, { "input": "3666566898\n3001", "output": "3666566898" }, { "input": "3338860467\n5848", "output": "8858864467" }, { "input": "9768757689\n1010", "output": "9768757689" }, { "input": "6669490269\n6240849376", "output": "9879696469" }, { "input": "1794210278\n50931901955213461294", "output": "9999965578" }, { "input": "6997854871\n15113453341706470344", "output": "7997876875" }, { "input": "8947769539\n22900332144661023400", "output": "9967769649" }, { "input": "9885783638\n20241242140301231211", "output": "9885784648" }, { "input": "1\n2", "output": "2" }, { "input": "1\n1234567890", "output": "9" }, { "input": "123\n987987", "output": "998" }, { "input": "1000\n32119", "output": "9321" }, { "input": "31\n4", "output": "41" }, { "input": "504\n91111", "output": "914" }, { "input": "100001\n23", "output": "320001" }, { "input": "87\n9", "output": "97" }, { "input": "786796787566545376\n00101", "output": "786796787566545376" }, { "input": "123456789012345678905764345\n00001", "output": "123456789112345678905764345" }, { "input": "111\n2222222299999999", "output": "999" }, { "input": "111\n789", "output": "987" }, { "input": "1\n99", "output": "9" }, { "input": "1099\n9", "output": "9099" }, { "input": "123\n456", "output": "654" } ]
1,617,705,143
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
a = list(map(int, input())) s = list(map(int, input())) s.sort() flag = 0 if(len(s) > 1): for j in range(len(s)): for i in range(len(a)): if(a[i] < s[j]): a[i] = s[j] flag += 1 if(flag == len(s) - 1): break print(a)
Title: Replacing Digits Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an integer *a* that consists of *n* digits. You are also given a sequence of digits *s* of length *m*. The digit in position *j* (1<=≤<=*j*<=≤<=*m*) of sequence *s* means that you can choose an arbitrary position *i* (1<=≤<=*i*<=≤<=*n*) in *a* and replace the digit in the chosen position *i* with *s**j*. Each element in the sequence *s* can participate in no more than one replacing operation. Your task is to perform such sequence of replacements, that the given number *a* gets maximum value. You are allowed to use not all elements from *s*. Input Specification: The first line contains positive integer *a*. Its length *n* is positive and doesn't exceed 105. The second line contains sequence of digits *s*. Its length *m* is positive and doesn't exceed 105. The digits in the sequence *s* are written consecutively without any separators. The given number *a* doesn't contain leading zeroes. Output Specification: Print the maximum value that can be obtained from *a* after a series of replacements. You are allowed to use not all elements from *s*. The printed number shouldn't contain any leading zeroes. Demo Input: ['1024\n010\n', '987\n1234567\n'] Demo Output: ['1124\n', '987\n'] Note: none
```python a = list(map(int, input())) s = list(map(int, input())) s.sort() flag = 0 if(len(s) > 1): for j in range(len(s)): for i in range(len(a)): if(a[i] < s[j]): a[i] = s[j] flag += 1 if(flag == len(s) - 1): break print(a) ```
0
0
none
none
none
0
[ "none" ]
null
null
The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*.
The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*.
In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them.
[ "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n", "1\n42\n", "2\n1 1 1 1\n" ]
[ "4 3 6 2", "42 ", "1 1 " ]
none
0
[ { "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 " }, { "input": "1\n42", "output": "42 " }, { "input": "2\n1 1 1 1", "output": "1 1 " }, { "input": "2\n54748096 1 641009859 1", "output": "54748096 641009859 " }, { "input": "3\n1 7 923264237 374288891 7 524125987 1 1 1", "output": "374288891 524125987 923264237 " }, { "input": "4\n1 1 1 1 1 702209411 496813081 673102149 1 1 561219907 1 1 1 1 1", "output": "496813081 561219907 673102149 702209411 " }, { "input": "5\n1 1 1 1 1 9 564718673 585325539 1 1 3 1 9 1 1 365329221 3 291882089 3 1 412106895 1 1 1 3", "output": "291882089 365329221 412106895 564718673 585325539 " }, { "input": "5\n1 161 1 534447872 161 233427865 1 7 7 73701396 1 401939237 4 1 1 1 1 1 7 115704211 1 4 1 7 1", "output": "73701396 115704211 233427865 401939237 534447872 " }, { "input": "5\n2 11 1 1 2 4 2 1 181951 4 345484316 2 4 4 4 2 1 140772746 1 634524 4 521302304 1 2 11", "output": "181951 634524 140772746 345484316 521302304 " }, { "input": "5\n27 675 1 1 347621274 5 2 13 189 738040275 5 1 189 13 1 959752125 770516962 769220855 5 5 2 675 1 1 27", "output": "347621274 738040275 769220855 770516962 959752125 " }, { "input": "5\n2029 6087 2029 2029 6087 2029 527243766 4058 2029 2029 2029 2029 2029 2029 2029 2029 165353355 4058 2029 731472761 739767313 2029 2029 2029 585281282", "output": "165353355 527243766 585281282 731472761 739767313 " }, { "input": "5\n537163 537163 537163 537163 537163 537163 1074326 537163 537163 537163 515139317 1074326 537163 537163 537163 539311652 321760637 170817834 537163 537163 537163 537163 537163 537163 392666153", "output": "170817834 321760637 392666153 515139317 539311652 " }, { "input": "4\n1 188110 607844 2 1 1 695147 1 1 1 143380513 1 1 1 1 2", "output": "188110 607844 695147 143380513 " }, { "input": "4\n3 1 96256522 120 360284388 3 3 2 2 2 3 12 12 2 1 198192381", "output": "120 96256522 198192381 360284388 " }, { "input": "4\n67025 13405 1915 1915 1915 1915 5745 676469920 53620 5745 660330300 67025 53620 380098775 533084295 13405", "output": "380098775 533084295 660330300 676469920 " }, { "input": "4\n700521 233507 759364764 467014 468181535 233507 233507 890362191 233507 700521 467014 233507 946637378 233507 233507 233507", "output": "468181535 759364764 890362191 946637378 " }, { "input": "3\n484799 1 1 744137 1 1 909312183 1 1", "output": "484799 744137 909312183 " }, { "input": "3\n1 716963379 1 1 205 1 1 964 1", "output": "205 964 716963379 " }, { "input": "3\n5993 781145599 54740062 5993 5993 267030101 5993 5993 5993", "output": "54740062 267030101 781145599 " }, { "input": "3\n121339 121339 121339 55451923 531222142 121339 121339 435485671 121339", "output": "55451923 435485671 531222142 " }, { "input": "5\n4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1", "output": "1 2 4 4 4 " }, { "input": "4\n1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3", "output": "1 1 3 3 " }, { "input": "6\n1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 6 6 6 6 6 6 6 6 6", "output": "1 3 3 6 6 6 " } ]
1,443,975,760
2,260
Python 3
WRONG_ANSWER
TESTS
2
46
0
n = int(input()) v = list(map(int, input().split())) s = sorted(set(v)) print(*s[:-5:-1])
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*. Input Specification: The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*. Output Specification: In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. Demo Input: ['4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2\n', '1\n42\n', '2\n1 1 1 1\n'] Demo Output: ['4 3 6 2', '42 ', '1 1 '] Note: none
```python n = int(input()) v = list(map(int, input().split())) s = sorted(set(v)) print(*s[:-5:-1]) ```
0
282
A
Bit++
PROGRAMMING
800
[ "implementation" ]
null
null
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
Print a single integer — the final value of *x*.
[ "1\n++X\n", "2\nX++\n--X\n" ]
[ "1\n", "0\n" ]
none
500
[ { "input": "1\n++X", "output": "1" }, { "input": "2\nX++\n--X", "output": "0" }, { "input": "3\n++X\n++X\n++X", "output": "3" }, { "input": "2\n--X\n--X", "output": "-2" }, { "input": "5\n++X\n--X\n++X\n--X\n--X", "output": "-1" }, { "input": "28\nX--\n++X\nX++\nX++\nX++\n--X\n--X\nX++\nX--\n++X\nX++\n--X\nX--\nX++\nX--\n++X\n++X\nX++\nX++\nX++\nX++\n--X\n++X\n--X\n--X\n--X\n--X\nX++", "output": "4" }, { "input": "94\nX++\nX++\n++X\n++X\nX--\n--X\nX++\n--X\nX++\n++X\nX++\n++X\n--X\n--X\n++X\nX++\n--X\nX--\nX--\n--X\nX--\nX--\n--X\n++X\n--X\nX--\nX--\nX++\n++X\n--X\nX--\n++X\n--X\n--X\nX--\nX--\nX++\nX++\nX--\nX++\nX--\nX--\nX--\n--X\nX--\nX--\nX--\nX++\n++X\nX--\n++X\nX++\n--X\n--X\n--X\n--X\n++X\nX--\n--X\n--X\n++X\nX--\nX--\nX++\n++X\nX++\n++X\n--X\n--X\nX--\n++X\nX--\nX--\n++X\n++X\n++X\n++X\nX++\n++X\n--X\nX++\n--X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\nX--\nX--\n--X\n++X\nX++", "output": "-10" }, { "input": "56\n--X\nX--\n--X\n--X\nX--\nX--\n--X\nX++\n++X\n--X\nX++\nX--\n--X\n++X\n--X\nX--\nX--\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n--X\nX++\n++X\nX++\n--X\n++X\nX++\nX++\n--X\nX++\nX--\n--X\nX--\n--X\nX++\n++X\n--X\n++X\nX++\nX--\n--X\n--X\n++X\nX--\nX--\n--X\nX--\n--X\nX++\n--X\n++X\n--X", "output": "-14" }, { "input": "59\nX--\n--X\nX++\n++X\nX--\n--X\n--X\n++X\n++X\n++X\n++X\nX++\n++X\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX++\n--X\n++X\nX++\n--X\n--X\nX++\nX++\n--X\nX++\nX++\nX++\nX--\nX--\n--X\nX++\nX--\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\nX--\n++X\n--X\nX++\nX++\nX--\nX++\n++X\nX--\nX++\nX--\nX--\n++X", "output": "3" }, { "input": "87\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\nX--\n++X\n--X\n--X\nX++\n--X\nX--\nX++\n++X\n--X\n++X\n++X\n--X\n++X\n--X\nX--\n++X\n++X\nX--\nX++\nX++\n--X\n--X\n++X\nX--\n--X\n++X\n--X\nX++\n--X\n--X\nX--\n++X\n++X\n--X\nX--\nX--\nX--\nX--\nX--\nX++\n--X\n++X\n--X\nX++\n++X\nX++\n++X\n--X\nX++\n++X\nX--\n--X\nX++\n++X\nX++\nX++\n--X\n--X\n++X\n--X\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX--\n--X\n++X\n++X", "output": "-5" }, { "input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X\n++X\n--X\n++X\n++X\n--X\nX++\n++X\nX--\n++X\nX--\n++X\nX++\nX--\n++X\nX++\n--X\nX++\nX++\n++X\n--X\n++X\n--X\nX++\n--X\nX--\n--X\n++X\n++X\n++X\n--X\nX--\nX--\nX--\nX--\n--X\n--X\n--X\n++X\n--X\n--X", "output": "1" }, { "input": "63\n--X\nX--\n++X\n--X\n++X\nX++\n--X\n--X\nX++\n--X\n--X\nX++\nX--\nX--\n--X\n++X\nX--\nX--\nX++\n++X\nX++\nX++\n--X\n--X\n++X\nX--\nX--\nX--\n++X\nX++\nX--\n--X\nX--\n++X\n++X\nX++\n++X\nX++\nX++\n--X\nX--\n++X\nX--\n--X\nX--\nX--\nX--\n++X\n++X\n++X\n++X\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n++X\nX--\n++X\n++X\nX--", "output": "1" }, { "input": "45\n--X\n++X\nX--\n++X\n++X\nX++\n--X\n--X\n--X\n--X\n--X\n--X\n--X\nX++\n++X\nX--\n++X\n++X\nX--\nX++\nX--\n--X\nX--\n++X\n++X\n--X\n--X\nX--\nX--\n--X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\nX--\n++X\n++X\nX++\nX++\n++X\n++X\nX++", "output": "-3" }, { "input": "21\n++X\nX++\n--X\nX--\nX++\n++X\n--X\nX--\nX++\nX--\nX--\nX--\nX++\n++X\nX++\n++X\n--X\nX--\n--X\nX++\n++X", "output": "1" }, { "input": "100\n--X\n++X\nX++\n++X\nX--\n++X\nX--\nX++\n--X\nX++\nX--\nX--\nX--\n++X\nX--\nX++\nX++\n++X\nX++\nX++\nX++\nX++\n++X\nX++\n++X\nX--\n--X\n++X\nX--\n--X\n++X\n++X\nX--\nX++\nX++\nX++\n++X\n--X\n++X\nX++\nX--\n++X\n++X\n--X\n++X\nX--\nX--\nX--\nX++\nX--\nX--\nX++\nX++\n--X\nX++\nX++\n--X\nX--\n--X\n++X\n--X\n++X\n++X\nX--\n--X\n++X\n++X\n--X\n--X\n++X\nX++\nX--\nX++\nX--\nX++\nX++\n--X\nX--\nX--\n++X\nX--\n--X\n--X\nX++\n--X\n--X\nX--\nX--\n++X\n++X\nX--\n++X\nX++\n--X\n++X\n++X\nX++\n--X\n--X\nX++", "output": "8" }, { "input": "17\nX++\nX++\n++X\n--X\n--X\n++X\n++X\n--X\nX--\nX++\nX--\n--X\n--X\nX--\n++X\nX--\nX++", "output": "-1" }, { "input": "77\n++X\nX++\n--X\nX--\n--X\n--X\nX--\nX++\nX--\nX++\nX--\n++X\n--X\n--X\n--X\n--X\n++X\nX--\nX++\nX--\n--X\nX--\n--X\nX--\n++X\n--X\n++X\n++X\nX++\nX++\nX--\n--X\nX--\nX--\nX++\n--X\n--X\n++X\nX--\nX--\n++X\nX++\nX--\n++X\n--X\nX++\nX--\n++X\n++X\n++X\nX--\nX--\nX--\n--X\n++X\n++X\n++X\nX++\n--X\n--X\n++X\n--X\nX--\nX++\n++X\nX++\n++X\nX--\nX++\nX++\n--X\nX++\nX++\nX++\n--X\nX++\nX--", "output": "-5" }, { "input": "21\nX--\n++X\n--X\nX--\n++X\nX--\n++X\nX--\n--X\n++X\nX++\n++X\nX++\n++X\nX--\n--X\nX++\nX++\nX--\n++X\nX--", "output": "1" }, { "input": "1\nX--", "output": "-1" } ]
1,699,538,675
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) for i in range(n): st=str(input()) cnt=0 if st[0]=='+ or st[len(st)-1]=='+': cnt+=1 elif st[0]=='-' or st[len(st)-1]=='-': cnt-=1 print(cnt)
Title: Bit++ Time Limit: None seconds Memory Limit: None megabytes Problem Description: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. Output Specification: Print a single integer — the final value of *x*. Demo Input: ['1\n++X\n', '2\nX++\n--X\n'] Demo Output: ['1\n', '0\n'] Note: none
```python n=int(input()) for i in range(n): st=str(input()) cnt=0 if st[0]=='+ or st[len(st)-1]=='+': cnt+=1 elif st[0]=='-' or st[len(st)-1]=='-': cnt-=1 print(cnt) ```
-1
92
A
Chips
PROGRAMMING
800
[ "implementation", "math" ]
A. Chips
2
256
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
[ "4 11\n", "17 107\n", "3 8\n" ]
[ "0\n", "2\n", "1\n" ]
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
500
[ { "input": "4 11", "output": "0" }, { "input": "17 107", "output": "2" }, { "input": "3 8", "output": "1" }, { "input": "46 7262", "output": "35" }, { "input": "32 6864", "output": "0" }, { "input": "36 6218", "output": "14" }, { "input": "25 9712", "output": "11" }, { "input": "9 7601", "output": "5" }, { "input": "1 9058", "output": "0" }, { "input": "29 7772", "output": "26" }, { "input": "45 9465", "output": "14" }, { "input": "46 866", "output": "5" }, { "input": "29 1241", "output": "20" }, { "input": "17 4248", "output": "12" }, { "input": "20 8082", "output": "11" }, { "input": "50 9555", "output": "0" }, { "input": "4 7455", "output": "2" }, { "input": "36 880", "output": "4" }, { "input": "24 7440", "output": "9" }, { "input": "44 7888", "output": "12" }, { "input": "1 1", "output": "0" }, { "input": "50 10000", "output": "40" }, { "input": "1 10000", "output": "0" }, { "input": "50 1", "output": "0" }, { "input": "50 50", "output": "5" } ]
1,515,720,119
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
124
5,632,000
n,k = map(int,input().split()) s=n*(n+1)/2 if k>s: k=k%s k=int(k) if k==0: print(0) else: y= -1+(1+8*k)**(0.5) y=y/2 y=int(y) k=k-(y*(y+1))//2 print(k)
Title: Chips Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. Output Specification: Print the number of chips the presenter ended up with. Demo Input: ['4 11\n', '17 107\n', '3 8\n'] Demo Output: ['0\n', '2\n', '1\n'] Note: In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes. In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number 2, that's why the presenter takes the last chip.
```python n,k = map(int,input().split()) s=n*(n+1)/2 if k>s: k=k%s k=int(k) if k==0: print(0) else: y= -1+(1+8*k)**(0.5) y=y/2 y=int(y) k=k-(y*(y+1))//2 print(k) ```
0
487
A
Fight the Monster
PROGRAMMING
1,800
[ "binary search", "brute force", "implementation" ]
null
null
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*). During the battle, every second the monster's HP decrease by *max*(0,<=*ATK**Y*<=-<=*DEF**M*), while Yang's HP decreases by *max*(0,<=*ATK**M*<=-<=*DEF**Y*), where index *Y* denotes Master Yang and index *M* denotes monster. Both decreases happen simultaneously Once monster's *HP*<=≤<=0 and the same time Master Yang's *HP*<=&gt;<=0, Master Yang wins. Master Yang can buy attributes from the magic shop of Cyberland: *h* bitcoins per *HP*, *a* bitcoins per *ATK*, and *d* bitcoins per *DEF*. Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.
The first line contains three integers *HP**Y*,<=*ATK**Y*,<=*DEF**Y*, separated by a space, denoting the initial *HP*, *ATK* and *DEF* of Master Yang. The second line contains three integers *HP**M*,<=*ATK**M*,<=*DEF**M*, separated by a space, denoting the *HP*, *ATK* and *DEF* of the monster. The third line contains three integers *h*,<=*a*,<=*d*, separated by a space, denoting the price of 1 *HP*, 1 *ATK* and 1 *DEF*. All numbers in input are integer and lie between 1 and 100 inclusively.
The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.
[ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n" ]
[ "99\n", "0\n" ]
For the first sample, prices for *ATK* and *DEF* are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left. For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
500
[ { "input": "1 2 1\n1 100 1\n1 100 100", "output": "99" }, { "input": "100 100 100\n1 1 1\n1 1 1", "output": "0" }, { "input": "50 80 92\n41 51 56\n75 93 12", "output": "0" }, { "input": "76 63 14\n89 87 35\n20 15 56", "output": "915" }, { "input": "12 59 66\n43 15 16\n12 18 66", "output": "0" }, { "input": "51 89 97\n18 25 63\n22 91 74", "output": "0" }, { "input": "72 16 49\n5 21 84\n48 51 88", "output": "3519" }, { "input": "74 89 5\n32 76 99\n62 95 36", "output": "3529" }, { "input": "39 49 78\n14 70 41\n3 33 23", "output": "0" }, { "input": "11 82 51\n90 84 72\n98 98 43", "output": "1376" }, { "input": "65 6 5\n70 78 51\n88 55 78", "output": "7027" }, { "input": "14 61 87\n11 78 14\n5 84 92", "output": "0" }, { "input": "1 28 47\n31 60 38\n14 51 77", "output": "1562" }, { "input": "99 32 20\n89 72 74\n1 100 39", "output": "5478" }, { "input": "1 10 29\n1 1 43\n1 1 100", "output": "34" }, { "input": "1 1 100\n1 1 1\n100 1 100", "output": "1" }, { "input": "79 1 1\n1 1 10\n1 1 100", "output": "10" }, { "input": "10 10 100\n1 100 100\n10 100 90", "output": "9100" }, { "input": "10 10 100\n1 10 1\n1 1 100", "output": "0" }, { "input": "1 100 1\n1 1 1\n1 1 1", "output": "0" }, { "input": "11 1 1\n100 1 1\n100 1 1", "output": "1" }, { "input": "1 100 100\n1 1 1\n87 100 43", "output": "0" }, { "input": "10 100 1\n1 100 100\n100 1 9", "output": "811" }, { "input": "10 100 55\n100 100 1\n1 1 1", "output": "37" }, { "input": "11 1 1\n10 1 10\n100 50 1", "output": "500" }, { "input": "10 100 1\n100 1 1\n1 100 1", "output": "0" }, { "input": "1 10 10\n1 10 100\n1 1 61", "output": "91" }, { "input": "1 1 1\n1 1 1\n1 1 1", "output": "1" }, { "input": "1 1 1\n1 1 1\n100 100 100", "output": "100" }, { "input": "1 1 1\n100 100 100\n100 100 100", "output": "19900" }, { "input": "100 100 100\n1 1 1\n1 1 1", "output": "0" }, { "input": "100 100 100\n100 100 100\n100 100 100", "output": "100" }, { "input": "1 1 1\n1 1 100\n100 100 1", "output": "10000" }, { "input": "50 100 51\n100 100 100\n1 100 100", "output": "1384" }, { "input": "1 1 1\n100 100 100\n1 2 3", "output": "496" }, { "input": "100 1 1\n100 100 100\n100 1 100", "output": "199" }, { "input": "1 100 1\n100 100 100\n1 100 100", "output": "1990" }, { "input": "100 100 1\n100 100 100\n1 100 100", "output": "1891" }, { "input": "1 1 1\n100 100 100\n1 100 100", "output": "11890" }, { "input": "20 1 1\n100 100 100\n1 100 100", "output": "11871" }, { "input": "25 38 49\n84 96 42\n3 51 92", "output": "1692" }, { "input": "2 1 1\n100 2 100\n100 1 100", "output": "199" }, { "input": "1 97 1\n100 99 98\n1 51 52", "output": "1498" }, { "input": "1 1 1\n100 100 100\n1 1 100", "output": "298" }, { "input": "1 100 1\n100 100 99\n1 100 100", "output": "1890" }, { "input": "100 1 1\n100 100 100\n1 100 100", "output": "11791" } ]
1,656,529,002
2,147,483,647
PyPy 3-64
OK
TESTS
46
171
2,764,800
from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt maxint=10**21 def ceil(a, b): if(b==0): return maxint a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) # n,m=map(int,input().split()) #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def strinp(testcases): k = 5 if (testcases == -1 or testcases == 1): k = 1 f = str(input()) f = f[2:len(f) - k] return f def main(): yh,ya,yd=map(int,input().split()) mh,ma,md=map(int,input().split()) h,a,d=map(int,input().split()) matt=mh+md+1 curr=maxint for att in range(ya,201): for de in range(yd,101): cc=(a*(att-ya))+(d*(de-yd)) ym=ceil(yh,max(ma-de,0)) mm=ceil(mh,max(att-md,0)) if(ym==maxint and mm==maxint): continue if(mm>=ym): cc+=(h*(((mm)*(ma-de))+1-yh)) curr=min(curr,cc) print(curr) main()
Title: Fight the Monster Time Limit: None seconds Memory Limit: None megabytes Problem Description: A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (*HP*), offensive power (*ATK*) and defensive power (*DEF*). During the battle, every second the monster's HP decrease by *max*(0,<=*ATK**Y*<=-<=*DEF**M*), while Yang's HP decreases by *max*(0,<=*ATK**M*<=-<=*DEF**Y*), where index *Y* denotes Master Yang and index *M* denotes monster. Both decreases happen simultaneously Once monster's *HP*<=≤<=0 and the same time Master Yang's *HP*<=&gt;<=0, Master Yang wins. Master Yang can buy attributes from the magic shop of Cyberland: *h* bitcoins per *HP*, *a* bitcoins per *ATK*, and *d* bitcoins per *DEF*. Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win. Input Specification: The first line contains three integers *HP**Y*,<=*ATK**Y*,<=*DEF**Y*, separated by a space, denoting the initial *HP*, *ATK* and *DEF* of Master Yang. The second line contains three integers *HP**M*,<=*ATK**M*,<=*DEF**M*, separated by a space, denoting the *HP*, *ATK* and *DEF* of the monster. The third line contains three integers *h*,<=*a*,<=*d*, separated by a space, denoting the price of 1 *HP*, 1 *ATK* and 1 *DEF*. All numbers in input are integer and lie between 1 and 100 inclusively. Output Specification: The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win. Demo Input: ['1 2 1\n1 100 1\n1 100 100\n', '100 100 100\n1 1 1\n1 1 1\n'] Demo Output: ['99\n', '0\n'] Note: For the first sample, prices for *ATK* and *DEF* are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left. For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.
```python from bisect import * from collections import * import sys import io, os import math import random from heapq import * gcd = math.gcd sqrt = math.sqrt maxint=10**21 def ceil(a, b): if(b==0): return maxint a = -a k = a // b k = -k return k # arr=list(map(int, input().split())) # n,m=map(int,input().split()) #input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def strinp(testcases): k = 5 if (testcases == -1 or testcases == 1): k = 1 f = str(input()) f = f[2:len(f) - k] return f def main(): yh,ya,yd=map(int,input().split()) mh,ma,md=map(int,input().split()) h,a,d=map(int,input().split()) matt=mh+md+1 curr=maxint for att in range(ya,201): for de in range(yd,101): cc=(a*(att-ya))+(d*(de-yd)) ym=ceil(yh,max(ma-de,0)) mm=ceil(mh,max(att-md,0)) if(ym==maxint and mm==maxint): continue if(mm>=ym): cc+=(h*(((mm)*(ma-de))+1-yh)) curr=min(curr,cc) print(curr) main() ```
3
231
A
Team
PROGRAMMING
800
[ "brute force", "greedy" ]
null
null
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution.
The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces.
Print a single integer — the number of problems the friends will implement on the contest.
[ "3\n1 1 0\n1 1 1\n1 0 0\n", "2\n1 0 0\n0 1 1\n" ]
[ "2\n", "1\n" ]
In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
500
[ { "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2" }, { "input": "2\n1 0 0\n0 1 1", "output": "1" }, { "input": "1\n1 0 0", "output": "0" }, { "input": "2\n1 0 0\n1 1 1", "output": "1" }, { "input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0", "output": "1" }, { "input": "10\n0 1 0\n0 1 0\n1 1 0\n1 0 0\n0 0 1\n0 1 1\n1 1 1\n1 1 0\n0 0 0\n0 0 0", "output": "4" }, { "input": "15\n0 1 0\n1 0 0\n1 1 0\n1 1 1\n0 1 0\n0 0 1\n1 0 1\n1 0 1\n1 0 1\n0 0 0\n1 1 1\n1 1 0\n0 1 1\n1 1 0\n1 1 1", "output": "10" }, { "input": "50\n0 0 0\n0 1 1\n1 1 1\n0 1 0\n1 0 1\n1 1 1\n0 0 1\n1 0 0\n1 1 0\n1 0 1\n0 1 0\n0 0 1\n1 1 0\n0 1 0\n1 1 0\n0 0 0\n1 1 1\n1 0 1\n0 0 1\n1 1 0\n1 1 1\n0 1 1\n1 1 0\n0 0 0\n0 0 0\n1 1 1\n0 0 0\n1 1 1\n0 1 1\n0 0 1\n0 0 0\n0 0 0\n1 1 0\n1 1 0\n1 0 1\n1 0 0\n1 0 1\n1 0 1\n0 1 1\n1 1 0\n1 1 0\n0 1 0\n1 0 1\n0 0 0\n0 0 0\n0 0 0\n0 0 1\n1 1 1\n0 1 1\n1 0 1", "output": "29" }, { "input": "1\n1 1 1", "output": "1" }, { "input": "8\n0 0 0\n0 0 1\n0 0 0\n0 1 1\n1 0 0\n1 0 1\n1 1 0\n1 1 1", "output": "4" }, { "input": "16\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1", "output": "16" } ]
1,699,424,022
2,147,483,647
PyPy 3-64
OK
TESTS
21
186
2,252,800
n = int(input()) cnt = 0 for i in range(n): x = [int(a) for a in input().split()] if sum(x) >= 2: cnt+=1 print(cnt)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. Input Specification: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. Output Specification: Print a single integer — the number of problems the friends will implement on the contest. Demo Input: ['3\n1 1 0\n1 1 1\n1 0 0\n', '2\n1 0 0\n0 1 1\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't take it. In the second sample the friends will only implement the second problem, as Vasya and Tonya are sure about the solution.
```python n = int(input()) cnt = 0 for i in range(n): x = [int(a) for a in input().split()] if sum(x) >= 2: cnt+=1 print(cnt) ```
3
919
B
Perfect Number
PROGRAMMING
1,100
[ "binary search", "brute force", "dp", "implementation", "number theory" ]
null
null
We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer.
A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$).
A single number, denoting the $k$-th smallest perfect integer.
[ "1\n", "2\n" ]
[ "19\n", "28\n" ]
The first perfect integer is $19$ and the second one is $28$.
750
[ { "input": "1", "output": "19" }, { "input": "2", "output": "28" }, { "input": "13", "output": "136" }, { "input": "101", "output": "1432" }, { "input": "1023", "output": "100270" }, { "input": "9999", "output": "10800010" }, { "input": "10000", "output": "10800100" }, { "input": "2333", "output": "310060" }, { "input": "9139", "output": "10134010" }, { "input": "9859", "output": "10422001" }, { "input": "5987", "output": "2221201" }, { "input": "3", "output": "37" }, { "input": "4", "output": "46" }, { "input": "5", "output": "55" }, { "input": "7", "output": "73" }, { "input": "9", "output": "91" }, { "input": "10", "output": "109" }, { "input": "15", "output": "154" }, { "input": "51", "output": "613" }, { "input": "99", "output": "1414" }, { "input": "138", "output": "2224" }, { "input": "233", "output": "5050" }, { "input": "666", "output": "27100" }, { "input": "1234", "output": "110206" }, { "input": "3567", "output": "1033003" }, { "input": "4445", "output": "1221301" }, { "input": "5689", "output": "2114002" }, { "input": "6666", "output": "3102004" }, { "input": "7777", "output": "5300200" }, { "input": "8888", "output": "10110061" }, { "input": "9411", "output": "10214200" }, { "input": "5539", "output": "2101114" }, { "input": "6259", "output": "2511100" }, { "input": "2387", "output": "312220" }, { "input": "8515", "output": "10030114" } ]
1,632,202,098
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
0
2,000
7,065,600
def solve(): n=int(input()) def f(x): s=str(x) ans=0 for i in s: ans+=int(i) return ans i=19 s=[] while len(s)<10000: if f(i)==10: s.append(i) i+=9 print(s[n-1]) solve()
Title: Perfect Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: We consider a positive integer perfect, if and only if the sum of its digits is exactly $10$. Given a positive integer $k$, your task is to find the $k$-th smallest perfect positive integer. Input Specification: A single line with a positive integer $k$ ($1 \leq k \leq 10\,000$). Output Specification: A single number, denoting the $k$-th smallest perfect integer. Demo Input: ['1\n', '2\n'] Demo Output: ['19\n', '28\n'] Note: The first perfect integer is $19$ and the second one is $28$.
```python def solve(): n=int(input()) def f(x): s=str(x) ans=0 for i in s: ans+=int(i) return ans i=19 s=[] while len(s)<10000: if f(i)==10: s.append(i) i+=9 print(s[n-1]) solve() ```
0
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and 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" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,691,806,388
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
4
2,000
307,200
k, l, m, n, d = int(input()), int(input()), int(input()), int(input()), int(input()) x = [] count = 0 if k == 1 or l == 1 or m == 1 or n == 1: print(d) else: for i in range(1, d + 1): if i % k == 0 and i not in x: x.append(i) count += 1 if i % l == 0 and i not in x: x.append(i) count += 1 if i % m == 0 and i not in x: x.append(i) count += 1 if i % n == 0 and i not in x: x.append(i) count += 1 print(count)
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, l, m, n, d = int(input()), int(input()), int(input()), int(input()), int(input()) x = [] count = 0 if k == 1 or l == 1 or m == 1 or n == 1: print(d) else: for i in range(1, d + 1): if i % k == 0 and i not in x: x.append(i) count += 1 if i % l == 0 and i not in x: x.append(i) count += 1 if i % m == 0 and i not in x: x.append(i) count += 1 if i % n == 0 and i not in x: x.append(i) count += 1 print(count) ```
0
669
A
Little Artem and Presents
PROGRAMMING
800
[ "math" ]
null
null
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha?
The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday.
Print the maximum possible number of times Artem can give presents to Masha.
[ "1\n", "2\n", "3\n", "4\n" ]
[ "1\n", "1\n", "2\n", "3\n" ]
In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
500
[ { "input": "1", "output": "1" }, { "input": "2", "output": "1" }, { "input": "3", "output": "2" }, { "input": "4", "output": "3" }, { "input": "100", "output": "67" }, { "input": "101", "output": "67" }, { "input": "102", "output": "68" }, { "input": "1000000000", "output": "666666667" }, { "input": "5", "output": "3" }, { "input": "6", "output": "4" }, { "input": "999999999", "output": "666666666" }, { "input": "999999998", "output": "666666665" }, { "input": "999999997", "output": "666666665" }, { "input": "999999996", "output": "666666664" }, { "input": "999999995", "output": "666666663" }, { "input": "999999994", "output": "666666663" }, { "input": "999999993", "output": "666666662" }, { "input": "999999992", "output": "666666661" }, { "input": "999999991", "output": "666666661" }, { "input": "1000", "output": "667" }, { "input": "10000", "output": "6667" }, { "input": "100000", "output": "66667" }, { "input": "1000000", "output": "666667" }, { "input": "10000000", "output": "6666667" }, { "input": "100000000", "output": "66666667" }, { "input": "7", "output": "5" } ]
1,553,901,187
2,147,483,647
Python 3
OK
TESTS
26
109
0
stones = int(input()) print(((stones*2)+1)//3) # HaPpY NoWrUz 1398 # UBCF # CodeForcesian # ♥ # نشکن دلمو
Title: Little Artem and Presents Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? Input Specification: The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. Output Specification: Print the maximum possible number of times Artem can give presents to Masha. Demo Input: ['1\n', '2\n', '3\n', '4\n'] Demo Output: ['1\n', '1\n', '2\n', '3\n'] Note: In the first sample, Artem can only give 1 stone to Masha. In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times. In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone. In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and finally 1 stone again.
```python stones = int(input()) print(((stones*2)+1)//3) # HaPpY NoWrUz 1398 # UBCF # CodeForcesian # ♥ # نشکن دلمو ```
3
267
A
Subtractions
PROGRAMMING
900
[ "math", "number theory" ]
null
null
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them?
The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109).
Print the sought number of operations for each pair on a single line.
[ "2\n4 17\n7 987654321\n" ]
[ "8\n141093479\n" ]
none
500
[ { "input": "2\n4 17\n7 987654321", "output": "8\n141093479" }, { "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479" }, { "input": "1\n536870912 32", "output": "16777216" }, { "input": "20\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999\n1000000000 999999999", "output": "1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000" }, { "input": "3\n1000000000 1\n1000000000 1\n1 100000000", "output": "1000000000\n1000000000\n100000000" } ]
1,635,035,676
2,147,483,647
Python 3
OK
TESTS
35
61
4,505,600
from sys import stdin, stdout def Subtractions(a, b): result = 0 while a > 0 and b > 0: if a > b: result += a // b a = a % b elif b > a: result += b // a b = b % a else: result += 1 a = a - b return result def main(): n = int(stdin.readline()) for i in range(n): arr = [int(x) for x in stdin.readline().split()] print(Subtractions(arr[0], arr[1])) # call the main method if __name__ == "__main__": main()
Title: Subtractions Time Limit: None seconds Memory Limit: None megabytes Problem Description: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? Input Specification: The first line contains the number of pairs *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≤<=<=*a**i*,<=<=*b**i*<=<=≤<=<=109). Output Specification: Print the sought number of operations for each pair on a single line. Demo Input: ['2\n4 17\n7 987654321\n'] Demo Output: ['8\n141093479\n'] Note: none
```python from sys import stdin, stdout def Subtractions(a, b): result = 0 while a > 0 and b > 0: if a > b: result += a // b a = a % b elif b > a: result += b // a b = b % a else: result += 1 a = a - b return result def main(): n = int(stdin.readline()) for i in range(n): arr = [int(x) for x in stdin.readline().split()] print(Subtractions(arr[0], arr[1])) # call the main method if __name__ == "__main__": main() ```
3
348
A
Mafia
PROGRAMMING
1,600
[ "binary search", "math", "sortings" ]
null
null
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want?
The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play.
In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3\n3 2 2\n", "4\n2 2 2 2\n" ]
[ "4\n", "3\n" ]
You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
500
[ { "input": "3\n3 2 2", "output": "4" }, { "input": "4\n2 2 2 2", "output": "3" }, { "input": "7\n9 7 7 8 8 7 8", "output": "9" }, { "input": "10\n13 12 10 13 13 14 10 10 12 12", "output": "14" }, { "input": "10\n94 96 91 95 99 94 96 92 95 99", "output": "106" }, { "input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430 262 71 415 586 532 562 419 615 732 658 108 315 268 574 86 12 23 429 640 995 342 305", "output": "1000" }, { "input": "3\n1 1 1", "output": "2" }, { "input": "30\n94 93 90 94 90 91 93 91 93 94 93 90 100 94 97 94 94 95 94 96 94 98 97 95 97 91 91 95 98 96", "output": "100" }, { "input": "5\n1000000000 5 5 4 4", "output": "1000000000" }, { "input": "3\n1 2 1", "output": "2" }, { "input": "3\n2 1 1", "output": "2" }, { "input": "4\n1 2 3 4", "output": "4" }, { "input": "3\n1000000000 1000000000 10000000", "output": "1005000000" }, { "input": "3\n677876423 834056477 553175531", "output": "1032554216" }, { "input": "5\n1000000000 1 1 1 1", "output": "1000000000" }, { "input": "4\n1000000000 1000000000 1000000000 1000000000", "output": "1333333334" }, { "input": "3\n4 10 11", "output": "13" }, { "input": "5\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "1250000000" } ]
1,620,302,023
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
186
20,172,800
import math n = int(input()) arr = list(map(int, input().split())) s = sum(arr) c = math.ceil(s/(n-1)) print(c)
Title: Mafia Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the *i*-th number in the list is the number of rounds the *i*-th person wants to play. Output Specification: In a single line print a single integer — the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3\n3 2 2\n', '4\n2 2 2 2\n'] Demo Output: ['4\n', '3\n'] Note: You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game).
```python import math n = int(input()) arr = list(map(int, input().split())) s = sum(arr) c = math.ceil(s/(n-1)) print(c) ```
0
895
A
Pizza Separation
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360.
Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.
[ "4\n90 90 90 90\n", "3\n100 100 160\n", "1\n360\n", "4\n170 30 150 10\n" ]
[ "0\n", "40\n", "360\n", "0\n" ]
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
500
[ { "input": "4\n90 90 90 90", "output": "0" }, { "input": "3\n100 100 160", "output": "40" }, { "input": "1\n360", "output": "360" }, { "input": "4\n170 30 150 10", "output": "0" }, { "input": "5\n10 10 10 10 320", "output": "280" }, { "input": "8\n45 45 45 45 45 45 45 45", "output": "0" }, { "input": "3\n120 120 120", "output": "120" }, { "input": "5\n110 90 70 50 40", "output": "40" }, { "input": "2\n170 190", "output": "20" }, { "input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10", "output": "10" }, { "input": "5\n30 60 180 60 30", "output": "0" }, { "input": "2\n359 1", "output": "358" }, { "input": "5\n100 100 30 100 30", "output": "40" }, { "input": "5\n36 34 35 11 244", "output": "128" }, { "input": "5\n96 94 95 71 4", "output": "18" }, { "input": "2\n85 275", "output": "190" }, { "input": "3\n281 67 12", "output": "202" }, { "input": "5\n211 113 25 9 2", "output": "62" }, { "input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1", "output": "212" }, { "input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "92" }, { "input": "50\n148 53 32 11 4 56 8 2 5 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 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n1 1 358", "output": "356" }, { "input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341", "output": "322" }, { "input": "33\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 1 1 328", "output": "296" }, { "input": "70\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 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 1 1 1 1 1 1 1 1 1 1 291", "output": "222" }, { "input": "130\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 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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 231", "output": "102" }, { "input": "200\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 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 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 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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 161", "output": "0" }, { "input": "222\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 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 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 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 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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139", "output": "0" }, { "input": "10\n8 3 11 4 1 10 10 1 8 304", "output": "248" }, { "input": "12\n8 7 7 3 11 2 10 1 10 8 10 283", "output": "206" }, { "input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275", "output": "190" }, { "input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280", "output": "200" }, { "input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275", "output": "190" }, { "input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189", "output": "18" }, { "input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189", "output": "18" }, { "input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168", "output": "0" }, { "input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5", "output": "0" }, { "input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68", "output": "0" }, { "input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 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 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 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 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 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 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 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 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", "output": "0" }, { "input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 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 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 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 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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "6\n27 15 28 34 41 215", "output": "70" }, { "input": "7\n41 38 41 31 22 41 146", "output": "14" }, { "input": "8\n24 27 34 23 29 23 30 170", "output": "20" }, { "input": "9\n11 11 20 20 33 32 35 26 172", "output": "6" }, { "input": "10\n36 13 28 13 33 34 23 25 34 121", "output": "0" }, { "input": "11\n19 37 13 41 37 15 32 12 19 35 100", "output": "10" }, { "input": "12\n37 25 34 38 21 24 34 38 11 29 28 41", "output": "2" }, { "input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28", "output": "2" }, { "input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44", "output": "4" }, { "input": "3\n95 91 174", "output": "12" }, { "input": "4\n82 75 78 125", "output": "46" }, { "input": "6\n87 75 88 94 15 1", "output": "4" }, { "input": "10\n27 52 58 64 45 64 1 19 2 28", "output": "12" }, { "input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1", "output": "0" }, { "input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3", "output": "0" }, { "input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1", "output": "0" }, { "input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2", "output": "0" }, { "input": "5\n35 80 45 100 100", "output": "40" }, { "input": "4\n90 179 90 1", "output": "2" }, { "input": "5\n50 50 20 160 80", "output": "0" }, { "input": "5\n30 175 30 5 120", "output": "10" }, { "input": "4\n170 30 10 150", "output": "20" }, { "input": "6\n90 30 90 30 90 30", "output": "60" }, { "input": "4\n70 80 110 100", "output": "20" }, { "input": "7\n35 45 70 100 10 10 90", "output": "0" }, { "input": "6\n50 90 10 90 20 100", "output": "20" }, { "input": "6\n10 155 162 1 26 6", "output": "18" }, { "input": "7\n80 90 80 45 10 10 45", "output": "20" }, { "input": "4\n18 36 162 144", "output": "36" }, { "input": "5\n20 50 50 160 80", "output": "40" }, { "input": "5\n10 30 140 20 160", "output": "0" }, { "input": "6\n90 80 60 50 40 40", "output": "20" }, { "input": "9\n40 20 20 20 20 20 20 40 160", "output": "40" }, { "input": "4\n90 54 90 126", "output": "72" }, { "input": "4\n150 170 30 10", "output": "20" }, { "input": "8\n130 12 13 85 41 67 5 7", "output": "26" }, { "input": "7\n70 170 20 10 30 30 30", "output": "20" }, { "input": "8\n100 100 50 50 15 15 15 15", "output": "40" }, { "input": "4\n100 70 80 110", "output": "20" }, { "input": "5\n160 130 40 20 10", "output": "20" }, { "input": "4\n20 149 151 40", "output": "22" }, { "input": "4\n100 10 100 150", "output": "60" }, { "input": "6\n19 64 105 168 1 3", "output": "16" }, { "input": "8\n10 10 70 70 90 90 10 10", "output": "0" } ]
1,565,687,706
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
0
n = input() a = map(int, input().split()) print(min(abs(360-2*sum(a[j:i]))for i in range(n+1)for j in range(i)))
Title: Pizza Separation Time Limit: None seconds Memory Limit: None megabytes Problem Description: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. Output Specification: Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. Demo Input: ['4\n90 90 90 90\n', '3\n100 100 160\n', '1\n360\n', '4\n170 30 150 10\n'] Demo Output: ['0\n', '40\n', '360\n', '0\n'] Note: In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: <img class="tex-graphics" src="https://espresso.codeforces.com/4bb3450aca241f92fedcba5479bf1b6d22cf813d.png" style="max-width: 100.0%;max-height: 100.0%;"/> Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
```python n = input() a = map(int, input().split()) print(min(abs(360-2*sum(a[j:i]))for i in range(n+1)for j in range(i))) ```
-1
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly.
The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
If the word *t* is a word *s*, written reversely, print YES, otherwise print NO.
[ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
500
[ { "input": "code\nedoc", "output": "YES" }, { "input": "abb\naba", "output": "NO" }, { "input": "code\ncode", "output": "NO" }, { "input": "abacaba\nabacaba", "output": "YES" }, { "input": "q\nq", "output": "YES" }, { "input": "asrgdfngfnmfgnhweratgjkk\nasrgdfngfnmfgnhweratgjkk", "output": "NO" }, { "input": "z\na", "output": "NO" }, { "input": "asd\ndsa", "output": "YES" }, { "input": "abcdef\nfecdba", "output": "NO" }, { "input": "ywjjbirapvskozubvxoemscfwl\ngnduubaogtfaiowjizlvjcu", "output": "NO" }, { "input": "mfrmqxtzvgaeuleubcmcxcfqyruwzenguhgrmkuhdgnhgtgkdszwqyd\nmfxufheiperjnhyczclkmzyhcxntdfskzkzdwzzujdinf", "output": "NO" }, { "input": "bnbnemvybqizywlnghlykniaxxxlkhftppbdeqpesrtgkcpoeqowjwhrylpsziiwcldodcoonpimudvrxejjo\ntiynnekmlalogyvrgptbinkoqdwzuiyjlrldxhzjmmp", "output": "NO" }, { "input": "pwlpubwyhzqvcitemnhvvwkmwcaawjvdiwtoxyhbhbxerlypelevasmelpfqwjk\nstruuzebbcenziscuoecywugxncdwzyfozhljjyizpqcgkyonyetarcpwkqhuugsqjuixsxptmbnlfupdcfigacdhhrzb", "output": "NO" }, { "input": "gdvqjoyxnkypfvdxssgrihnwxkeojmnpdeobpecytkbdwujqfjtxsqspxvxpqioyfagzjxupqqzpgnpnpxcuipweunqch\nkkqkiwwasbhezqcfeceyngcyuogrkhqecwsyerdniqiocjehrpkljiljophqhyaiefjpavoom", "output": "NO" }, { "input": "umeszdawsvgkjhlqwzents\nhxqhdungbylhnikwviuh", "output": "NO" }, { "input": "juotpscvyfmgntshcealgbsrwwksgrwnrrbyaqqsxdlzhkbugdyx\nibqvffmfktyipgiopznsqtrtxiijntdbgyy", "output": "NO" }, { "input": "zbwueheveouatecaglziqmudxemhrsozmaujrwlqmppzoumxhamwugedikvkblvmxwuofmpafdprbcftew\nulczwrqhctbtbxrhhodwbcxwimncnexosksujlisgclllxokrsbnozthajnnlilyffmsyko", "output": "NO" }, { "input": "nkgwuugukzcv\nqktnpxedwxpxkrxdvgmfgoxkdfpbzvwsduyiybynbkouonhvmzakeiruhfmvrktghadbfkmwxduoqv", "output": "NO" }, { "input": "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd", "output": "NO" }, { "input": "w\nw", "output": "YES" }, { "input": "vz\nzv", "output": "YES" }, { "input": "ry\nyr", "output": "YES" }, { "input": "xou\nuox", "output": "YES" }, { "input": "axg\ngax", "output": "NO" }, { "input": "zdsl\nlsdz", "output": "YES" }, { "input": "kudl\nldku", "output": "NO" }, { "input": "zzlzwnqlcl\nlclqnwzlzz", "output": "YES" }, { "input": "vzzgicnzqooejpjzads\nsdazjpjeooqzncigzzv", "output": "YES" }, { "input": "raqhmvmzuwaykjpyxsykr\nxkysrypjkyawuzmvmhqar", "output": "NO" }, { "input": "ngedczubzdcqbxksnxuavdjaqtmdwncjnoaicvmodcqvhfezew\nwezefhvqcdomvciaonjcnwdmtqajdvauxnskxbqcdzbuzcdegn", "output": "YES" }, { "input": "muooqttvrrljcxbroizkymuidvfmhhsjtumksdkcbwwpfqdyvxtrlymofendqvznzlmim\nmimlznzvqdnefomylrtxvydqfpwwbckdskmutjshhmfvdiumykziorbxcjlrrvttqooum", "output": "YES" }, { "input": "vxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaivg\ngviayyikkitmuomcpiakhbxszgbnhvwyzkftwoagzixaearxpjacrnvpvbuzenvovehkmmxvblqyxvctroddksdsgebcmlluqpxv", "output": "YES" }, { "input": "mnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfdc\ncdfmkdgrdptkpewbsqvszipgxvgvuiuzbkkwuowbafkikgvnqdkxnayzdjygvezmtsgywnupocdntipiyiorblqkrzjpzatxahnm", "output": "NO" }, { "input": "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolvsatbblsrxabzrpszoiecpwhfjmwuhqrapvtcgvikuxtzbftydkw\nwkdytfbztxukivgctvparqhuwmjfhwpceiozsprzbaxrslbbqasvlocjirbnntajphenipthvwocowbweabhtgdcztsfoqbzmxgd", "output": "NO" }, { "input": "gxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwgeh\nhegwxvocotmzstqfbmpjvijgkcyodlxyjawrpkczpmdspsuhoiruavnnnuwvtwohglkdxjetshkboalvzqbgjgthoteceixioxg", "output": "YES" }, { "input": "sihxuwvmaambplxvjfoskinghzicyfqebjtkysotattkahssumfcgrkheotdxwjckpvapbkaepqrxseyfrwtyaycmrzsrsngkh\nhkgnsrszrmcyaytwrfyesxrqpeakbpavpkcjwxdtoehkrgcfmusshakttatosyktjbeqfycizhgniksofjvxlpbmaamvwuxhis", "output": "YES" }, { "input": "ycnahksbughnonldzrhkysujmylcgcfuludjvjiahtkyzqvkopzqcnwhltbzfugzojqkjjlggmvnultascmygelkiktmfieok\nkoeifmtkiklegkmcsatlunvmggkjjlqjozgufzbtlhwncqzpokvqzykthaijvjdulufcgclymjusyyhrzdlnonhgubskhancy", "output": "NO" }, { "input": "wbqasaehtkfojruzyhrlgwmtyiovmzyfifslvlemhqheyaelzwnthrenjsbmntwaoryzwfbxmscmypvxlfmzpnkkjlvwvmtz\nztmvwvljkknpzmflxvpymcsmxbfwzyroawtnmbsjnerhtnwzleayehqhmelvlsfifyzmvoiytmwglrhyzurjofktheasaqbw", "output": "YES" }, { "input": "imippqurprbhfugngtgifelytadegwrgaefnfhbjjnmzikvjaccotqzemufqieqldgnbmviisgkynzeldlhqxuqphjfmyij\njiymfjhpquxqhldleznykgsiivmbngdlqeiqfumezqtoccajvkizmnjjbhfnfeagrwgedatylefigtgngufhbrpruqppimi", "output": "YES" }, { "input": "bikydffiuisckpvzqlteqfhegsagimodb\nbdomigasgehfqetlqzvpkcsiuiffdykib", "output": "YES" } ]
1,649,993,479
2,147,483,647
Python 3
OK
TESTS
40
92
0
s=input();r=input() txts = [x for x in str(s)]; txtr = [x for x in str(r)] h=0 for i in range(len(txts)): if txts[i] != txtr[-(i+1)]: print("NO") h+=1 break if h==0: print("YES")
Title: Translation Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. Input Specification: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. Output Specification: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Demo Input: ['code\nedoc\n', 'abb\naba\n', 'code\ncode\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python s=input();r=input() txts = [x for x in str(s)]; txtr = [x for x in str(r)] h=0 for i in range(len(txts)): if txts[i] != txtr[-(i+1)]: print("NO") h+=1 break if h==0: print("YES") ```
3.977
769
C
Cycle In Maze
PROGRAMMING
1,700
[ "*special", "dfs and similar", "graphs", "greedy", "shortest paths" ]
null
null
The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. Initially, the Robot is in the empty cell. Your task is to find lexicographically minimal Robot's cycle with length exactly *k*, which begins and ends in the cell where the Robot was initially. It is allowed to the Robot to visit any cell many times (including starting). Consider that Robot's way is given as a line which consists of symbols "L", "R", "U" and "D". For example, if firstly the Robot goes down, then left, then right and up, it means that his way is written as "DLRU". In this task you don't need to minimize the length of the way. Find the minimum lexicographical (in alphabet order as in the dictionary) line which satisfies requirements above.
The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=106) — the size of the maze and the length of the cycle. Each of the following *n* lines contains *m* symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occupied by an obstacle. If the symbol equals to "X" then initially the Robot is in this cell and it is empty. It is guaranteed that the symbol "X" is found in the maze exactly once.
Print the lexicographically minimum Robot's way with the length exactly *k*, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
[ "2 3 2\n.**\nX..\n", "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.\n", "3 3 4\n***\n*X*\n***\n" ]
[ "RL\n", "DLDDLLLRRRUURU\n", "IMPOSSIBLE\n" ]
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't move to the neighboring cells, because they are occupied by obstacles.
1,500
[ { "input": "2 3 2\n.**\nX..", "output": "RL" }, { "input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU" }, { "input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE" }, { "input": "1 1 1\nX", "output": "IMPOSSIBLE" }, { "input": "1 2 2\nX.", "output": "RL" }, { "input": "1 5 4\n.X**.", "output": "LRLR" }, { "input": "1 10 1\n........X.", "output": "IMPOSSIBLE" }, { "input": "1 20 10\n*.*..............*.X", "output": "LRLRLRLRLR" }, { "input": "2 1 1\nX\n.", "output": "IMPOSSIBLE" }, { "input": "2 2 2\nX*\n.*", "output": "DU" }, { "input": "2 5 2\n.....\n*.*.X", "output": "LR" }, { "input": "2 10 4\n******....\n*.****.*X*", "output": "UDUD" }, { "input": "2 20 26\n.****..*.**.**.*....\n.*.*.*.*...*.****..X", "output": "LLRLRLRLRLRLRLRLRLRLRLRLRR" }, { "input": "2 25 46\n.*...***X....*..*........\n.....*...**.**.*....*...*", "output": "DLLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRRU" }, { "input": "5 1 2\n*\n.\nX\n*\n.", "output": "UD" }, { "input": "5 2 8\n..\n.*\nX.\n..\n*.", "output": "DRDUDULU" }, { "input": "5 5 12\n..**.\n***..\n..X*.\n....*\n**..*", "output": "DDRLRLRLRLUU" }, { "input": "5 10 42\n..**.**.**\n......*..*\n..**...X..\n*.......*.\n......*.**", "output": "DDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUU" }, { "input": "10 1 8\n.\n*\n*\n.\n.\nX\n*\n.\n*\n*", "output": "UDUDUDUD" }, { "input": "10 2 16\n.*\n*.\n*.\n..\n**\nX.\n..\n*.\n..\n.*", "output": "DRDDLDUDUDURUULU" }, { "input": "10 10 4\n*..*...***\nX...*.....\n***...**..\n..********\n.*.*......\n*.**..*...\n.**.**..**\n*.**.**..*\n**.****.*.\n...**..*.*", "output": "RLRL" }, { "input": "20 1 12\n.\n.\n.\n*\n.\nX\n.\n.\n.\n.\n.\n.\n*\n*\n.\n.\n.\n.\n.\n.", "output": "DDDDDDUUUUUU" }, { "input": "20 2 22\n.*\n**\n..\n**\n**\n..\n.*\n.*\n..\n..\n**\n**\n.*\n**\n..\n.*\n..\n..\nX*\n..", "output": "DRLRLRLRLRLRLRLRLRLRLU" }, { "input": "20 10 116\n..........\n....*.....\n.......*..\n*.........\n*....*....\n*........*\n..........\n*.........\n.......*..\n...*..*...\n..........\n...*......\n..*.......\n.....**..*\n........*.\n........*.\n...*......\n.........*\n.....*.X..\n*......*.*", "output": "LDLLLLLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRRRRRUR" }, { "input": "25 1 22\n.\n*\n*\n.\n*\n.\n.\n.\n.\n.\n.\n.\n.\n*\n.\n.\n.\n*\n.\n.\n.\n*\n.\nX\n.", "output": "DUDUDUDUDUDUDUDUDUDUDU" }, { "input": "25 2 26\n.*\n*.\n..\n.*\n..\n*.\n.*\n.*\n.*\n..\n*.\n..\n..\n..\n..\n..\n*.\n.*\n.*\n..\n..\n.*\nX*\n..\n..", "output": "DDRLRLRLRLRLRLRLRLRLRLRLUU" }, { "input": "25 5 22\n.....\n.....\n.....\n**...\n...*.\n...*.\n*..*.\n.....\n...**\n.*...\n.....\n*....\n*....\n*....\n*...X\n.....\n.*...\n...*.\n.*..*\n....*\n.....\n.....\n*....\n.....\n..*..", "output": "DDDUDUDUDUDUDUDUDUDUUU" }, { "input": "25 10 38\n....*...**\n.........*\n.........*\n**...*....\n..........\n.*.....*.*\n***.*....*\n..*****.**\n*........*\n*.........\n.*..*.**.*\n.*....*...\n..*..**...\n...*.*.*.*\n.*.*.....*\n.*.X.*...*\n*...**...*\n..........\n.*..*.*.**\n*.*..**.*.\n*.....*..*\n...**.*...\n...*...*..\n...*......\n...*.....*", "output": "DDDDDLDDDDLLRLRLRLRLRLRLRLRRUUUURUUUUU" }, { "input": "1 2 2\n.X", "output": "LR" }, { "input": "2 1 2\n.\nX", "output": "UD" }, { "input": "2 1 2\nX\n.", "output": "DU" }, { "input": "2 1 2\n*\nX", "output": "IMPOSSIBLE" }, { "input": "2 1 2\nX\n*", "output": "IMPOSSIBLE" }, { "input": "1 2 2\nX*", "output": "IMPOSSIBLE" }, { "input": "1 2 2\n*X", "output": "IMPOSSIBLE" }, { "input": "1 1 1000000\nX", "output": "IMPOSSIBLE" }, { "input": "1 1 1\nX", "output": "IMPOSSIBLE" }, { "input": "1 1 2\nX", "output": "IMPOSSIBLE" } ]
1,545,306,170
2,147,483,647
PyPy 3
MEMORY_LIMIT_EXCEEDED
TESTS
7
530
268,390,400
n, m, length = list(map(int,input().split())) x, y = 0, 0 arr = [] for i in range(n): arr.append(list(input())) if "X" in arr[i]: x, y = i, arr[i].index("X") arr[x][y] = "." def dfs(x, y, length): stack = [] stack.append([x, y, 0, ""]) while stack: now = stack.pop() x2, y2, ltg, word = now if ltg == length//2: return word if len(arr) > x2-1 >= 0: if arr[x2-1][y2] == ".": stack.append([x2-1, y2, ltg+1, word+"U"]) if len(arr[0]) > y2+1 >= 0: if arr[x2][y2+1] == ".": stack.append([x2, y2+1, ltg+1, word+"R"]) if len(arr[0]) > y2 - 1 >= 0: if arr[x2][y2-1] == ".": stack.append([x2, y2-1, ltg+1, word+"L"]) if len(arr) > x2 + 1 >= 0: if arr[x2+1][y2] == ".": stack.append([x2+1, y2, ltg+1, word+"D"]) if length %2 == 0: mapping = {"U":"D", "D":"U", "R":"L", "L": "R"} word1 = dfs(x, y, length) if word1: print(word1, end="") for char in word1[::-1]: print(mapping[char],end="") else: print("IMPOSSIBLE") else: print("IMPOSSIBLE")
Title: Cycle In Maze Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Robot is in a rectangular maze of size *n*<=×<=*m*. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. Initially, the Robot is in the empty cell. Your task is to find lexicographically minimal Robot's cycle with length exactly *k*, which begins and ends in the cell where the Robot was initially. It is allowed to the Robot to visit any cell many times (including starting). Consider that Robot's way is given as a line which consists of symbols "L", "R", "U" and "D". For example, if firstly the Robot goes down, then left, then right and up, it means that his way is written as "DLRU". In this task you don't need to minimize the length of the way. Find the minimum lexicographical (in alphabet order as in the dictionary) line which satisfies requirements above. Input Specification: The first line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=106) — the size of the maze and the length of the cycle. Each of the following *n* lines contains *m* symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occupied by an obstacle. If the symbol equals to "X" then initially the Robot is in this cell and it is empty. It is guaranteed that the symbol "X" is found in the maze exactly once. Output Specification: Print the lexicographically minimum Robot's way with the length exactly *k*, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes). Demo Input: ['2 3 2\n.**\nX..\n', '5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.\n', '3 3 4\n***\n*X*\n***\n'] Demo Output: ['RL\n', 'DLDDLLLRRRUURU\n', 'IMPOSSIBLE\n'] Note: In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't move to the neighboring cells, because they are occupied by obstacles.
```python n, m, length = list(map(int,input().split())) x, y = 0, 0 arr = [] for i in range(n): arr.append(list(input())) if "X" in arr[i]: x, y = i, arr[i].index("X") arr[x][y] = "." def dfs(x, y, length): stack = [] stack.append([x, y, 0, ""]) while stack: now = stack.pop() x2, y2, ltg, word = now if ltg == length//2: return word if len(arr) > x2-1 >= 0: if arr[x2-1][y2] == ".": stack.append([x2-1, y2, ltg+1, word+"U"]) if len(arr[0]) > y2+1 >= 0: if arr[x2][y2+1] == ".": stack.append([x2, y2+1, ltg+1, word+"R"]) if len(arr[0]) > y2 - 1 >= 0: if arr[x2][y2-1] == ".": stack.append([x2, y2-1, ltg+1, word+"L"]) if len(arr) > x2 + 1 >= 0: if arr[x2+1][y2] == ".": stack.append([x2+1, y2, ltg+1, word+"D"]) if length %2 == 0: mapping = {"U":"D", "D":"U", "R":"L", "L": "R"} word1 = dfs(x, y, length) if word1: print(word1, end="") for char in word1[::-1]: print(mapping[char],end="") else: print("IMPOSSIBLE") else: print("IMPOSSIBLE") ```
0
181
A
Series of Crimes
PROGRAMMING
800
[ "brute force", "geometry", "implementation" ]
null
null
The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed.
The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements.
Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right.
[ "3 2\n.*\n..\n**\n", "3 3\n*.*\n*..\n...\n" ]
[ "1 1\n", "2 3\n" ]
none
500
[ { "input": "3 2\n.*\n..\n**", "output": "1 1" }, { "input": "2 5\n*....\n*...*", "output": "1 5" }, { "input": "7 2\n..\n**\n..\n..\n..\n..\n.*", "output": "7 1" }, { "input": "7 2\n*.\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "2 10\n*......*..\n.......*..", "output": "2 1" }, { "input": "10 3\n*..\n...\n...\n...\n...\n...\n...\n...\n...\n**.", "output": "1 2" }, { "input": "100 2\n*.\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n..\n**", "output": "1 2" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "99 3\n**.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n*..", "output": "99 2" }, { "input": "98 3\n...\n.*.\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n...\n.**", "output": "2 3" }, { "input": "2 100\n...................................................................................................*\n*..................................................................................................*", "output": "1 1" }, { "input": "2 2\n*.\n**", "output": "1 2" }, { "input": "2 2\n**\n.*", "output": "2 1" }, { "input": "2 3\n*.*\n..*", "output": "2 1" } ]
1,695,477,644
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
62
0
n, m = map(int, input().split()) map = [] for i in range(n): map.append(input()) print(map) pos = [] for i in range(n): for j in range(m): if map[i][j] == '*': pos.append((i+1, j+1)) a = b = 0 if pos[0][0] != pos[1][0] and pos[0][0] != pos[2][0]: a = pos[0][0] elif pos[1][0] != pos[0][0] and pos[1][0] != pos[2][0]: a = pos[1][0] else: a = pos[2][0] if pos[0][1] != pos[1][1] and pos[0][1] != pos[2][1]: b = pos[0][1] elif pos[1][1] != pos[0][0] and pos[1][1] != pos[2][1]: b = pos[1][1] else: b = pos[2][1] print(a, b)
Title: Series of Crimes Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. Input Specification: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. Output Specification: Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Demo Input: ['3 2\n.*\n..\n**\n', '3 3\n*.*\n*..\n...\n'] Demo Output: ['1 1\n', '2 3\n'] Note: none
```python n, m = map(int, input().split()) map = [] for i in range(n): map.append(input()) print(map) pos = [] for i in range(n): for j in range(m): if map[i][j] == '*': pos.append((i+1, j+1)) a = b = 0 if pos[0][0] != pos[1][0] and pos[0][0] != pos[2][0]: a = pos[0][0] elif pos[1][0] != pos[0][0] and pos[1][0] != pos[2][0]: a = pos[1][0] else: a = pos[2][0] if pos[0][1] != pos[1][1] and pos[0][1] != pos[2][1]: b = pos[0][1] elif pos[1][1] != pos[0][0] and pos[1][1] != pos[2][1]: b = pos[1][1] else: b = pos[2][1] print(a, b) ```
0
61
D
Eternal Victory
PROGRAMMING
1,800
[ "dfs and similar", "graphs", "greedy", "shortest paths", "trees" ]
D. Eternal Victory
2
256
Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these *n* cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities. All cities are numbered 1 to *n*. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city. Help Shapur find how much He should travel.
First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities. Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road.
A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).
[ "3\n1 2 3\n2 3 4\n", "3\n1 2 3\n1 3 3\n" ]
[ "7\n", "9\n" ]
none
2,000
[ { "input": "3\n1 2 3\n2 3 4", "output": "7" }, { "input": "3\n1 2 3\n1 3 3", "output": "9" }, { "input": "5\n5 3 60\n4 3 63\n2 1 97\n3 1 14", "output": "371" }, { "input": "3\n2 1 63\n3 1 78", "output": "204" }, { "input": "13\n8 2 58\n2 1 49\n13 10 41\n11 9 67\n6 4 18\n7 1 79\n3 2 58\n9 7 92\n10 6 62\n4 3 5\n12 4 87\n5 3 66", "output": "1126" }, { "input": "2\n2 1 89", "output": "89" }, { "input": "12\n3 1 31\n5 2 94\n9 8 37\n10 9 45\n7 5 75\n4 2 77\n6 3 31\n11 6 14\n8 7 19\n2 1 68\n12 1 60", "output": "764" }, { "input": "2\n2 1 5", "output": "5" }, { "input": "12\n3 2 52\n4 1 2\n5 2 68\n6 1 93\n8 5 60\n2 1 88\n9 8 44\n7 5 48\n11 2 31\n10 4 45\n12 7 58", "output": "916" }, { "input": "15\n12 1 52\n3 2 10\n4 1 45\n11 7 20\n10 3 54\n13 9 44\n15 2 8\n14 5 55\n9 3 32\n2 1 32\n8 4 14\n6 5 24\n5 3 74\n7 6 88", "output": "856" }, { "input": "1", "output": "0" }, { "input": "3\n1 2 0\n2 3 0", "output": "0" }, { "input": "6\n1 2 3\n1 3 1\n3 4 1\n4 5 1\n5 6 1", "output": "10" } ]
1,435,628,772
2,147,483,647
PyPy 3
OK
TESTS
56
1,372
25,804,800
g = [[] for _ in range(100005)] sumx = 0 n = int(input()) for i in range(n-1): x, y, w = map(int, input().split(' ')) g[x].append([y, w]) g[y].append([x, w]) sumx += 2*w visited = [0] * 100005 dist = [10**18] * 100005 dist[1] = 0 def dfs(s): visited[s] = 1 for i in g[s]: if visited[i[0]] == 0: dist[i[0]] = dist[s] + i[1] dfs(i[0]) m = -1 dfs(1) for i in dist: if i != 10**18: m = max(m, i) print(sumx - m)
Title: Eternal Victory Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all *n* cities of Persia to find the best available mountain, but after the recent war he was too tired and didn't want to traverse a lot. So he wanted to visit each of these *n* cities at least once with smallest possible traverse. Persian cities are connected with bidirectional roads. You can go from any city to any other one using these roads and there is a unique path between each two cities. All cities are numbered 1 to *n*. Shapur is currently in the city 1 and he wants to visit all other cities with minimum possible traverse. He can finish his travels in any city. Help Shapur find how much He should travel. Input Specification: First line contains a single natural number *n* (1<=≤<=*n*<=≤<=105) — the amount of cities. Next *n*<=-<=1 lines contain 3 integer numbers each *x**i*, *y**i* and *w**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=0<=≤<=*w**i*<=≤<=2<=×<=104). *x**i* and *y**i* are two ends of a road and *w**i* is the length of that road. Output Specification: A single integer number, the minimal length of Shapur's travel. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Demo Input: ['3\n1 2 3\n2 3 4\n', '3\n1 2 3\n1 3 3\n'] Demo Output: ['7\n', '9\n'] Note: none
```python g = [[] for _ in range(100005)] sumx = 0 n = int(input()) for i in range(n-1): x, y, w = map(int, input().split(' ')) g[x].append([y, w]) g[y].append([x, w]) sumx += 2*w visited = [0] * 100005 dist = [10**18] * 100005 dist[1] = 0 def dfs(s): visited[s] = 1 for i in g[s]: if visited[i[0]] == 0: dist[i[0]] = dist[s] + i[1] dfs(i[0]) m = -1 dfs(1) for i in dist: if i != 10**18: m = max(m, i) print(sumx - m) ```
3.608935
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", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,660,247,825
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
0
n,m,a = input().split() x = int((n+a-1)/a) y = int((m+a-1)/a) print(x*y)
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 n,m,a = input().split() x = int((n+a-1)/a) y = int((m+a-1)/a) print(x*y) ```
-1
393
A
Nineteen
PROGRAMMING
0
[]
null
null
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string.
The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100.
Print a single integer — the maximum number of "nineteen"s that she can get in her string.
[ "nniinneetteeeenn\n", "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n", "nineteenineteen\n" ]
[ "2", "2", "2" ]
none
500
[ { "input": "nniinneetteeeenn", "output": "2" }, { "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2" }, { "input": "nineteenineteen", "output": "2" }, { "input": "nssemsnnsitjtihtthij", "output": "0" }, { "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1" }, { "input": "rrrteiehtesisntnjirtitijnjjjthrsmhtneirjimniemmnrhirssjnhetmnmjejjnjjritjttnnrhnjs", "output": "2" }, { "input": "mmrehtretseihsrjmtsenemniehssnisijmsnntesismmtmthnsieijjjnsnhisi", "output": "2" }, { "input": "hshretttnntmmiertrrnjihnrmshnthirnnirrheinnnrjiirshthsrsijtrrtrmnjrrjnresnintnmtrhsnjrinsseimn", "output": "1" }, { "input": "snmmensntritetnmmmerhhrmhnehehtesmhthseemjhmnrti", "output": "2" }, { "input": "rmeetriiitijmrenmeiijt", "output": "0" }, { "input": "ihimeitimrmhriemsjhrtjtijtesmhemnmmrsetmjttthtjhnnmirtimne", "output": "1" }, { "input": "rhtsnmnesieernhstjnmmirthhieejsjttsiierhihhrrijhrrnejsjer", "output": "2" }, { "input": "emmtjsjhretehmiiiestmtmnmissjrstnsnjmhimjmststsitemtttjrnhsrmsenjtjim", "output": "2" }, { "input": "nmehhjrhirniitshjtrrtitsjsntjhrstjehhhrrerhemehjeermhmhjejjesnhsiirheijjrnrjmminneeehtm", "output": "3" }, { "input": "hsntijjetmehejtsitnthietssmeenjrhhetsnjrsethisjrtrhrierjtmimeenjnhnijeesjttrmn", "output": "3" }, { "input": "jnirirhmirmhisemittnnsmsttesjhmjnsjsmntisheneiinsrjsjirnrmnjmjhmistntersimrjni", "output": "1" }, { "input": "neithjhhhtmejjnmieishethmtetthrienrhjmjenrmtejerernmthmsnrthhtrimmtmshm", "output": "2" }, { "input": "sithnrsnemhijsnjitmijjhejjrinejhjinhtisttteermrjjrtsirmessejireihjnnhhemiirmhhjeet", "output": "3" }, { "input": "jrjshtjstteh", "output": "0" }, { "input": "jsihrimrjnnmhttmrtrenetimemjnshnimeiitmnmjishjjneisesrjemeshjsijithtn", "output": "2" }, { "input": "hhtjnnmsemermhhtsstejehsssmnesereehnnsnnremjmmieethmirjjhn", "output": "2" }, { "input": "tmnersmrtsehhntsietttrehrhneiireijnijjejmjhei", "output": "1" }, { "input": "mtstiresrtmesritnjriirehtermtrtseirtjrhsejhhmnsineinsjsin", "output": "2" }, { "input": "ssitrhtmmhtnmtreijteinimjemsiiirhrttinsnneshintjnin", "output": "1" }, { "input": "rnsrsmretjiitrjthhritniijhjmm", "output": "0" }, { "input": "hntrteieimrimteemenserntrejhhmijmtjjhnsrsrmrnsjseihnjmehtthnnithirnhj", "output": "3" }, { "input": "nmmtsmjrntrhhtmimeresnrinstjnhiinjtnjjjnthsintmtrhijnrnmtjihtinmni", "output": "0" }, { "input": "eihstiirnmteejeehimttrijittjsntjejmessstsemmtristjrhenithrrsssihnthheehhrnmimssjmejjreimjiemrmiis", "output": "2" }, { "input": "srthnimimnemtnmhsjmmmjmmrsrisehjseinemienntetmitjtnnneseimhnrmiinsismhinjjnreehseh", "output": "3" }, { "input": "etrsmrjehntjjimjnmsresjnrthjhehhtreiijjminnheeiinseenmmethiemmistsei", "output": "3" }, { "input": "msjeshtthsieshejsjhsnhejsihisijsertenrshhrthjhiirijjneinjrtrmrs", "output": "1" }, { "input": "mehsmstmeejrhhsjihntjmrjrihssmtnensttmirtieehimj", "output": "1" }, { "input": "mmmsermimjmrhrhejhrrejermsneheihhjemnehrhihesnjsehthjsmmjeiejmmnhinsemjrntrhrhsmjtttsrhjjmejj", "output": "2" }, { "input": "rhsmrmesijmmsnsmmhertnrhsetmisshriirhetmjihsmiinimtrnitrseii", "output": "1" }, { "input": "iihienhirmnihh", "output": "0" }, { "input": "ismtthhshjmhisssnmnhe", "output": "0" }, { "input": "rhsmnrmhejshinnjrtmtsssijimimethnm", "output": "0" }, { "input": "eehnshtiriejhiirntminrirnjihmrnittnmmnjejjhjtennremrnssnejtntrtsiejjijisermj", "output": "3" }, { "input": "rnhmeesnhttrjintnhnrhristjrthhrmehrhjmjhjehmstrijemjmmistes", "output": "2" }, { "input": "ssrmjmjeeetrnimemrhimes", "output": "0" }, { "input": "n", "output": "0" }, { "input": "ni", "output": "0" }, { "input": "nine", "output": "0" }, { "input": "nineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteenineteen", "output": "13" }, { "input": "ninetee", "output": "0" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwynd", "output": "0" }, { "input": "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdch", "output": "0" }, { "input": "rtzxovxqfapkdmelxiyjroohufhbakpmmvaxq", "output": "0" }, { "input": "zninetneeineteeniwnteeennieteenineteenineteenineteenineteenineteenineteenineteenineteeninetzeenz", "output": "13" }, { "input": "nnnnnnniiiiiiiiiiiitttttttttteeeeeeeeeeeeeeeeee", "output": "3" }, { "input": "ttttiiiieeeeeeeeeeeennnnnnnnn", "output": "4" }, { "input": "ttttttttteeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiinnnnnnn", "output": "3" }, { "input": "nnnnnnnnnneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiiiiitttttttttttttttttttt", "output": "4" }, { "input": "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiittttttttttttttttnnnnnnn", "output": "3" }, { "input": "nineeen", "output": "0" }, { "input": "nineteeeeeeeeeeeeeeeeettttttttttttttttttiiiiiiiiiiiiiiiiii", "output": "0" }, { "input": "nineteenieteenieteenieteenieteenieteenieteen", "output": "4" }, { "input": "nineteenineteenineteenineteenineteen", "output": "5" } ]
1,550,078,290
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
93
0
s = input() numN = 3 numI = 1 numE = 3 numT = 1 countN = s.count('n') countI = s.count('i') countE = s.count('e') countT = s.count('t') print(min([countN//numN, countI//numI, countE//numE, countT//numT]))
Title: Nineteen Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. Input Specification: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. Output Specification: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Demo Input: ['nniinneetteeeenn\n', 'nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n', 'nineteenineteen\n'] Demo Output: ['2', '2', '2'] Note: none
```python s = input() numN = 3 numI = 1 numE = 3 numT = 1 countN = s.count('n') countI = s.count('i') countE = s.count('e') countT = s.count('t') print(min([countN//numN, countI//numI, countE//numE, countT//numT])) ```
0
33
A
What is for dinner?
PROGRAMMING
1,200
[ "greedy", "implementation" ]
A. What is for dinner?
2
256
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one.
The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth.
In the first line output the maximum amount of crucians that Valerie can consume for dinner.
[ "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "2 2 13\n1 13\n2 12\n" ]
[ "11\n", "13\n" ]
none
500
[ { "input": "4 3 18\n2 3\n1 2\n3 6\n2 3", "output": "11" }, { "input": "2 2 13\n1 13\n2 12", "output": "13" }, { "input": "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3", "output": "8" }, { "input": "1 1 0\n1 3", "output": "0" }, { "input": "7 1 30\n1 8\n1 15\n1 5\n1 17\n1 9\n1 16\n1 16", "output": "5" }, { "input": "4 2 8\n1 9\n1 10\n1 4\n2 6", "output": "8" }, { "input": "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0", "output": "8" }, { "input": "54 22 1009\n15 7\n17 7\n11 9\n5 11\n12 9\n13 8\n13 12\n22 11\n20 9\n20 7\n16 11\n19 12\n3 12\n15 9\n1 12\n2 10\n16 10\n16 10\n14 10\n9 11\n9 9\n14 8\n10 10\n16 12\n1 8\n3 8\n21 11\n18 12\n2 6\n9 11\n11 7\n15 9\n20 11\n6 8\n8 8\n19 11\n15 7\n9 9\n22 7\n12 9\n17 9\n17 11\n12 7\n15 9\n5 11\n11 6\n18 8\n7 10\n4 10\n13 12\n4 8\n20 6\n15 12\n9 7", "output": "180" }, { "input": "1 1 1000000\n1 1000000", "output": "1000000" }, { "input": "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278", "output": "4136" }, { "input": "50 50 0\n33 0\n26 0\n30 0\n41 0\n38 0\n36 0\n16 0\n7 0\n23 0\n5 0\n39 0\n29 0\n40 0\n47 0\n24 0\n43 0\n14 0\n10 0\n20 0\n3 0\n6 0\n34 0\n13 0\n18 0\n21 0\n9 0\n8 0\n22 0\n25 0\n4 0\n11 0\n17 0\n32 0\n44 0\n49 0\n50 0\n27 0\n28 0\n45 0\n12 0\n35 0\n15 0\n42 0\n31 0\n2 0\n1 0\n48 0\n19 0\n37 0\n46 0", "output": "0" }, { "input": "19 12 199\n7 1\n8 6\n6 14\n1 7\n4 1\n6 6\n3 4\n1 5\n9 2\n5 3\n11 3\n9 4\n1 12\n4 7\n7 3\n12 14\n2 1\n10 8\n6 12", "output": "54" } ]
1,564,335,549
2,147,483,647
Python 3
OK
TESTS
31
248
0
n, m, k = [int(i) for i in input().split()] lst = [1000000] * m for j in range(n): r, c = [int(y) for y in input().split()] lst[r - 1] = min(lst[r - 1], c) print(min(sum(lst), k))
Title: What is for dinner? Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". For a long time our heroine had been searching the sea for crucians, but a great misfortune happened. Her teeth started to ache, and she had to see the local dentist, lobster Ashot. As a professional, Ashot quickly relieved Valerie from her toothache. Moreover, he managed to determine the cause of Valerie's developing caries (for what he was later nicknamed Cap). It turned that Valerie eats too many crucians. To help Valerie avoid further reoccurrence of toothache, Ashot found for each Valerie's tooth its residual viability. Residual viability of a tooth is a value equal to the amount of crucians that Valerie can eat with this tooth. Every time Valerie eats a crucian, viability of all the teeth used for it will decrease by one. When the viability of at least one tooth becomes negative, the shark will have to see the dentist again. Unhappy, Valerie came back home, where a portion of crucians was waiting for her. For sure, the shark couldn't say no to her favourite meal, but she had no desire to go back to the dentist. That's why she decided to eat the maximum amount of crucians from the portion but so that the viability of no tooth becomes negative. As Valerie is not good at mathematics, she asked you to help her to find out the total amount of crucians that she can consume for dinner. We should remind you that while eating one crucian Valerie uses exactly one row of teeth and the viability of each tooth from this row decreases by one. Input Specification: The first line contains three integers *n*, *m*, *k* (1<=≤<=*m*<=≤<=*n*<=≤<=1000,<=0<=≤<=*k*<=≤<=106) — total amount of Valerie's teeth, amount of tooth rows and amount of crucians in Valerie's portion for dinner. Then follow *n* lines, each containing two integers: *r* (1<=≤<=*r*<=≤<=*m*) — index of the row, where belongs the corresponding tooth, and *c* (0<=≤<=*c*<=≤<=106) — its residual viability. It's guaranteed that each tooth row has positive amount of teeth. Output Specification: In the first line output the maximum amount of crucians that Valerie can consume for dinner. Demo Input: ['4 3 18\n2 3\n1 2\n3 6\n2 3\n', '2 2 13\n1 13\n2 12\n'] Demo Output: ['11\n', '13\n'] Note: none
```python n, m, k = [int(i) for i in input().split()] lst = [1000000] * m for j in range(n): r, c = [int(y) for y in input().split()] lst[r - 1] = min(lst[r - 1], c) print(min(sum(lst), k)) ```
3.938
122
A
Lucky Division
PROGRAMMING
1,000
[ "brute force", "number theory" ]
null
null
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky.
The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked.
In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes).
[ "47\n", "16\n", "78\n" ]
[ "YES\n", "YES\n", "NO\n" ]
Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
500
[ { "input": "47", "output": "YES" }, { "input": "16", "output": "YES" }, { "input": "78", "output": "NO" }, { "input": "48", "output": "YES" }, { "input": "100", "output": "YES" }, { "input": "107", "output": "NO" }, { "input": "77", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "480", "output": "YES" }, { "input": "1", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "49", "output": "YES" }, { "input": "56", "output": "YES" }, { "input": "124", "output": "YES" }, { "input": "1000", "output": "YES" }, { "input": "999", "output": "NO" }, { "input": "298", "output": "NO" }, { "input": "274", "output": "NO" }, { "input": "998", "output": "NO" }, { "input": "42", "output": "YES" }, { "input": "788", "output": "YES" }, { "input": "70", "output": "YES" }, { "input": "444", "output": "YES" }, { "input": "777", "output": "YES" }, { "input": "799", "output": "YES" }, { "input": "25", "output": "NO" }, { "input": "882", "output": "YES" }, { "input": "88", "output": "YES" }, { "input": "11", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "7", "output": "YES" }, { "input": "8", "output": "YES" }, { "input": "94", "output": "YES" }, { "input": "477", "output": "YES" }, { "input": "141", "output": "YES" } ]
1,694,781,656
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
92
0
n=int(input()) x={4,7} d=str(n) d=list(d) d=list(map(int,d)) c=set(d) if n%4==0 or n%7==0 or c==x: print("YES") else: print("NO")
Title: Lucky Division Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. Input Specification: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. Output Specification: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Demo Input: ['47\n', '16\n', '78\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: Note that all lucky numbers are almost lucky as any number is evenly divisible by itself. In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4.
```python n=int(input()) x={4,7} d=str(n) d=list(d) d=list(map(int,d)) c=set(d) if n%4==0 or n%7==0 or c==x: print("YES") else: print("NO") ```
0
500
A
New Year Transportation
PROGRAMMING
1,000
[ "dfs and similar", "graphs", "implementation" ]
null
null
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system.
The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World.
If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO".
[ "8 4\n1 2 1 2 1 2 1\n", "8 5\n1 2 1 2 1 1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
500
[ { "input": "8 4\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "8 5\n1 2 1 2 1 1 1", "output": "NO" }, { "input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1", "output": "YES" }, { "input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 22 8 8 9 1 7 5 12 5 6 13 6 11 2 6 3 1 5 1 1 2 2 1", "output": "YES" }, { "input": "120 104\n41 15 95 85 34 11 25 42 65 39 77 80 74 17 66 73 21 14 36 63 63 79 45 24 65 7 63 80 51 21 2 19 78 28 71 2 15 23 17 68 62 18 54 39 43 70 3 46 34 23 41 65 32 10 13 18 10 3 16 48 54 18 57 28 3 24 44 50 15 2 20 22 45 44 3 29 2 27 11 2 12 25 25 31 1 2 32 4 11 30 13 16 26 21 1 13 21 8 15 5 18 13 5 15 3 8 13 6 5 1 9 7 1 2 4 1 1 2 1", "output": "NO" }, { "input": "10 3\n8 3 5 4 2 3 2 2 1", "output": "NO" }, { "input": "10 9\n8 3 5 4 2 3 2 2 1", "output": "YES" }, { "input": "3 2\n1 1", "output": "YES" }, { "input": "3 2\n2 1", "output": "NO" }, { "input": "4 2\n2 1 1", "output": "NO" }, { "input": "4 4\n2 2 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 2 1", "output": "YES" }, { "input": "3 3\n1 1", "output": "YES" }, { "input": "8 8\n1 2 1 2 1 1 1", "output": "YES" }, { "input": "3 3\n2 1", "output": "YES" }, { "input": "4 4\n1 1 1", "output": "YES" }, { "input": "8 8\n1 1 1 1 1 1 1", "output": "YES" }, { "input": "5 5\n1 1 1 1", "output": "YES" } ]
1,641,702,603
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
12
93
3,584,000
n,t=map(int,input().split()) a=list(map(int,input().split())) i=1 while i<n: if i==t: print("YES") exit() i+=(a[i-1]) print("NO")
Title: New Year Transportation Time Limit: None seconds Memory Limit: None megabytes Problem Description: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. Input Specification: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. Output Specification: If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". Demo Input: ['8 4\n1 2 1 2 1 2 1\n', '8 5\n1 2 1 2 1 1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4. In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.
```python n,t=map(int,input().split()) a=list(map(int,input().split())) i=1 while i<n: if i==t: print("YES") exit() i+=(a[i-1]) print("NO") ```
0
96
B
Lucky Numbers (easy)
PROGRAMMING
1,300
[ "binary search", "bitmasks", "brute force" ]
B. Lucky Numbers (easy)
2
256
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*.
The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=109). This number doesn't have leading zeroes.
Output the least super lucky number that is more than or equal to *n*. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.
[ "4500\n", "47\n" ]
[ "4747\n", "47\n" ]
none
1,000
[ { "input": "4500", "output": "4747" }, { "input": "47", "output": "47" }, { "input": "1", "output": "47" }, { "input": "12", "output": "47" }, { "input": "4587", "output": "4747" }, { "input": "100", "output": "4477" }, { "input": "1007", "output": "4477" }, { "input": "99999999", "output": "4444477777" }, { "input": "491020945", "output": "4444477777" }, { "input": "1000000000", "output": "4444477777" }, { "input": "777777", "output": "44447777" }, { "input": "99999999", "output": "4444477777" }, { "input": "474", "output": "4477" }, { "input": "85469", "output": "444777" }, { "input": "7474747", "output": "44447777" }, { "input": "2145226", "output": "44447777" }, { "input": "5556585", "output": "44447777" }, { "input": "87584777", "output": "4444477777" }, { "input": "77777777", "output": "4444477777" }, { "input": "999999999", "output": "4444477777" }, { "input": "74477744", "output": "74477744" }, { "input": "444444444", "output": "4444477777" }, { "input": "467549754", "output": "4444477777" }, { "input": "147474747", "output": "4444477777" }, { "input": "555", "output": "4477" }, { "input": "100000", "output": "444777" }, { "input": "74777443", "output": "74777444" }, { "input": "4700007", "output": "44447777" }, { "input": "70070077", "output": "74444777" }, { "input": "123", "output": "4477" }, { "input": "7474", "output": "7474" }, { "input": "3696", "output": "4477" }, { "input": "888999577", "output": "4444477777" }, { "input": "10", "output": "47" }, { "input": "7", "output": "47" }, { "input": "50", "output": "74" }, { "input": "70", "output": "74" }, { "input": "74700", "output": "444777" }, { "input": "1024", "output": "4477" }, { "input": "73", "output": "74" }, { "input": "74710000", "output": "74744477" }, { "input": "444000000", "output": "4444477777" }, { "input": "4", "output": "47" }, { "input": "1", "output": "47" }, { "input": "9", "output": "47" }, { "input": "99", "output": "4477" }, { "input": "48", "output": "74" }, { "input": "47474749", "output": "47474774" }, { "input": "47474774", "output": "47474774" }, { "input": "77777777", "output": "4444477777" }, { "input": "4777", "output": "7447" }, { "input": "7748", "output": "444777" }, { "input": "7773", "output": "444777" }, { "input": "19", "output": "47" }, { "input": "447777", "output": "474477" } ]
1,662,698,011
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
1
60
0
n = int(input()) for e in [47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 747744, 774447, 774474, 774744, 777444, 44447777, 44474777, 44477477, 44477747, 44477774, 44744777, 44747477, 44747747, 44747774, 44774477, 44774747, 44774774, 44777447, 44777474, 44777744, 47444777, 47447477, 47447747, 47447774, 47474477, 47474747, 47474774, 47477447, 47477474, 47477744, 47744477, 47744747, 47744774, 47747447, 47747474, 47747744, 47774447, 47774474, 47774744, 47777444, 74444777, 74447477, 74447747, 74447774, 74474477, 74474747, 74474774, 74477447, 74477474, 74477744, 74744477, 74744747, 74744774, 74747447, 74747474, 74747744, 74774447, 74774474, 74774744, 74777444, 77444477, 77444747, 77444774, 77447447, 77447474, 77447744, 77474447, 77474474, 77474744, 77477444, 77744447, 77744474, 77744744, 77747444, 77774444, 4444477777, 4444747777, 4444774777, 4444777477, 4444777747, 4444777774, 4447447777, 4447474777, 4447477477, 4447477747, 4447477774, 4447744777, 4447747477, 4447747747, 4447747774, 4447774477, 4447774747, 4447774774, 4447777447, 4447777474, 4447777744, 4474447777, 4474474777, 4474477477, 4474477747, 4474477774, 4474744777, 4474747477, 4474747747, 4474747774, 4474774477, 4474774747, 4474774774, 4474777447, 4474777474, 4474777744, 4477444777, 4477447477, 4477447747, 4477447774, 4477474477, 4477474747, 4477474774, 4477477447, 4477477474, 4477477744, 4477744477, 4477744747, 4477744774, 4477747447, 4477747474, 4477747744, 4477774447, 4477774474, 4477774744, 4477777444, 4744447777, 4744474777, 4744477477, 4744477747, 4744477774, 4744744777, 4744747477, 4744747747, 4744747774, 4744774477, 4744774747, 4744774774, 4744777447, 4744777474, 4744777744, 4747444777, 4747447477, 4747447747, 4747447774, 4747474477, 4747474747, 4747474774, 4747477447, 4747477474, 4747477744, 4747744477, 4747744747, 4747744774, 4747747447, 4747747474, 4747747744, 4747774447, 4747774474, 4747774744, 4747777444, 4774444777, 4774447477, 4774447747, 4774447774, 4774474477, 4774474747, 4774474774, 4774477447, 4774477474, 4774477744, 4774744477, 4774744747, 4774744774, 4774747447, 4774747474, 4774747744, 4774774447, 4774774474, 4774774744, 4774777444, 4777444477, 4777444747, 4777444774, 4777447447, 4777447474, 4777447744, 4777474447, 4777474474, 4777474744, 4777477444, 4777744447, 4777744474, 4777744744, 4777747444, 4777774444, 7444447777, 7444474777, 7444477477, 7444477747, 7444477774, 7444744777, 7444747477, 7444747747, 7444747774, 7444774477, 7444774747, 7444774774, 7444777447, 7444777474, 7444777744, 7447444777, 7447447477, 7447447747, 7447447774, 7447474477, 7447474747, 7447474774, 7447477447, 7447477474, 7447477744, 7447744477, 7447744747, 7447744774, 7447747447, 7447747474, 7447747744, 7447774447, 7447774474, 7447774744, 7447777444, 7474444777, 7474447477, 7474447747, 7474447774, 7474474477, 7474474747, 7474474774, 7474477447, 7474477474, 7474477744, 7474744477, 7474744747, 7474744774, 7474747447, 7474747474, 7474747744, 7474774447, 7474774474, 7474774744, 7474777444, 7477444477, 7477444747, 7477444774, 7477447447, 7477447474, 7477447744, 7477474447, 7477474474, 7477474744, 7477477444, 7477744447, 7477744474, 7477744744, 7477747444, 7477774444, 7744444777, 7744447477, 7744447747, 7744447774, 7744474477, 7744474747, 7744474774, 7744477447, 7744477474, 7744477744, 7744744477, 7744744747, 7744744774, 7744747447, 7744747474, 7744747744, 7744774447, 7744774474, 7744774744, 7744777444, 7747444477, 7747444747, 7747444774, 7747447447, 7747447474, 7747447744, 7747474447, 7747474474, 7747474744, 7747477444, 7747744447, 7747744474, 7747744744, 7747747444, 7747774444, 7774444477, 7774444747, 7774444774, 7774447447, 7774447474, 7774447744, 7774474447, 7774474474, 7774474744, 7774477444, 7774744447, 7774744474, 7774744744, 7774747444, 7774774444, 7777444447, 7777444474, 7777444744, 7777447444, 7777474444, 7777744444]: if e > n: print(e) quit()
Title: Lucky Numbers (easy) Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer *n*. Help him to find the least super lucky number which is not less than *n*. Input Specification: The only line contains a positive integer *n* (1<=≤<=*n*<=≤<=109). This number doesn't have leading zeroes. Output Specification: Output the least super lucky number that is more than or equal to *n*. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Demo Input: ['4500\n', '47\n'] Demo Output: ['4747\n', '47\n'] Note: none
```python n = int(input()) for e in [47, 74, 4477, 4747, 4774, 7447, 7474, 7744, 444777, 447477, 447747, 447774, 474477, 474747, 474774, 477447, 477474, 477744, 744477, 744747, 744774, 747447, 747474, 747744, 774447, 774474, 774744, 777444, 44447777, 44474777, 44477477, 44477747, 44477774, 44744777, 44747477, 44747747, 44747774, 44774477, 44774747, 44774774, 44777447, 44777474, 44777744, 47444777, 47447477, 47447747, 47447774, 47474477, 47474747, 47474774, 47477447, 47477474, 47477744, 47744477, 47744747, 47744774, 47747447, 47747474, 47747744, 47774447, 47774474, 47774744, 47777444, 74444777, 74447477, 74447747, 74447774, 74474477, 74474747, 74474774, 74477447, 74477474, 74477744, 74744477, 74744747, 74744774, 74747447, 74747474, 74747744, 74774447, 74774474, 74774744, 74777444, 77444477, 77444747, 77444774, 77447447, 77447474, 77447744, 77474447, 77474474, 77474744, 77477444, 77744447, 77744474, 77744744, 77747444, 77774444, 4444477777, 4444747777, 4444774777, 4444777477, 4444777747, 4444777774, 4447447777, 4447474777, 4447477477, 4447477747, 4447477774, 4447744777, 4447747477, 4447747747, 4447747774, 4447774477, 4447774747, 4447774774, 4447777447, 4447777474, 4447777744, 4474447777, 4474474777, 4474477477, 4474477747, 4474477774, 4474744777, 4474747477, 4474747747, 4474747774, 4474774477, 4474774747, 4474774774, 4474777447, 4474777474, 4474777744, 4477444777, 4477447477, 4477447747, 4477447774, 4477474477, 4477474747, 4477474774, 4477477447, 4477477474, 4477477744, 4477744477, 4477744747, 4477744774, 4477747447, 4477747474, 4477747744, 4477774447, 4477774474, 4477774744, 4477777444, 4744447777, 4744474777, 4744477477, 4744477747, 4744477774, 4744744777, 4744747477, 4744747747, 4744747774, 4744774477, 4744774747, 4744774774, 4744777447, 4744777474, 4744777744, 4747444777, 4747447477, 4747447747, 4747447774, 4747474477, 4747474747, 4747474774, 4747477447, 4747477474, 4747477744, 4747744477, 4747744747, 4747744774, 4747747447, 4747747474, 4747747744, 4747774447, 4747774474, 4747774744, 4747777444, 4774444777, 4774447477, 4774447747, 4774447774, 4774474477, 4774474747, 4774474774, 4774477447, 4774477474, 4774477744, 4774744477, 4774744747, 4774744774, 4774747447, 4774747474, 4774747744, 4774774447, 4774774474, 4774774744, 4774777444, 4777444477, 4777444747, 4777444774, 4777447447, 4777447474, 4777447744, 4777474447, 4777474474, 4777474744, 4777477444, 4777744447, 4777744474, 4777744744, 4777747444, 4777774444, 7444447777, 7444474777, 7444477477, 7444477747, 7444477774, 7444744777, 7444747477, 7444747747, 7444747774, 7444774477, 7444774747, 7444774774, 7444777447, 7444777474, 7444777744, 7447444777, 7447447477, 7447447747, 7447447774, 7447474477, 7447474747, 7447474774, 7447477447, 7447477474, 7447477744, 7447744477, 7447744747, 7447744774, 7447747447, 7447747474, 7447747744, 7447774447, 7447774474, 7447774744, 7447777444, 7474444777, 7474447477, 7474447747, 7474447774, 7474474477, 7474474747, 7474474774, 7474477447, 7474477474, 7474477744, 7474744477, 7474744747, 7474744774, 7474747447, 7474747474, 7474747744, 7474774447, 7474774474, 7474774744, 7474777444, 7477444477, 7477444747, 7477444774, 7477447447, 7477447474, 7477447744, 7477474447, 7477474474, 7477474744, 7477477444, 7477744447, 7477744474, 7477744744, 7477747444, 7477774444, 7744444777, 7744447477, 7744447747, 7744447774, 7744474477, 7744474747, 7744474774, 7744477447, 7744477474, 7744477744, 7744744477, 7744744747, 7744744774, 7744747447, 7744747474, 7744747744, 7744774447, 7744774474, 7744774744, 7744777444, 7747444477, 7747444747, 7747444774, 7747447447, 7747447474, 7747447744, 7747474447, 7747474474, 7747474744, 7747477444, 7747744447, 7747744474, 7747744744, 7747747444, 7747774444, 7774444477, 7774444747, 7774444774, 7774447447, 7774447474, 7774447744, 7774474447, 7774474474, 7774474744, 7774477444, 7774744447, 7774744474, 7774744744, 7774747444, 7774774444, 7777444447, 7777444474, 7777444744, 7777447444, 7777474444, 7777744444]: if e > n: print(e) quit() ```
0
999
A
Mishka and Contest
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve?
The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Print one integer — the maximum number of problems Mishka can solve.
[ "8 4\n4 2 3 1 5 1 6 4\n", "5 2\n3 1 2 1 3\n", "5 100\n12 34 55 43 21\n" ]
[ "5\n", "0\n", "5\n" ]
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
0
[ { "input": "8 4\n4 2 3 1 5 1 6 4", "output": "5" }, { "input": "5 2\n3 1 2 1 3", "output": "0" }, { "input": "5 100\n12 34 55 43 21", "output": "5" }, { "input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 18 54 19 71 2 25 33 65 49 53 5 95 90 100 68 25 5 87 48 45 72 34 14 100 44 94 75 80 26 25 7 57 82 49 73 55 43 42 60 34 8 51 11 71 41 81 23 20 89 12 72 68 26 96 92 32 63 13 47 19 9 35 56 79 62", "output": "100" }, { "input": "100 99\n84 82 43 4 71 3 30 92 15 47 76 43 2 17 76 4 1 33 24 96 44 98 75 99 59 11 73 27 67 17 8 88 69 41 44 22 91 48 4 46 42 21 21 67 85 51 57 84 11 100 100 59 39 72 89 82 74 19 98 14 37 97 20 78 38 52 44 83 19 83 69 32 56 6 93 13 98 80 80 2 33 71 11 15 55 51 98 58 16 91 39 32 83 58 77 79 88 81 17 98", "output": "98" }, { "input": "100 69\n80 31 12 89 16 35 8 28 39 12 32 51 42 67 64 53 17 88 63 97 29 41 57 28 51 33 82 75 93 79 57 86 32 100 83 82 99 33 1 27 86 22 65 15 60 100 42 37 38 85 26 43 90 62 91 13 1 92 16 20 100 19 28 30 23 6 5 69 24 22 9 1 10 14 28 14 25 9 32 8 67 4 39 7 10 57 15 7 8 35 62 6 53 59 62 13 24 7 53 2", "output": "39" }, { "input": "100 2\n2 2 2 2 1 1 1 2 1 2 2 2 1 2 2 2 2 1 2 1 2 1 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 16", "output": "99" }, { "input": "100 3\n86 53 82 40 2 20 59 2 46 63 75 49 24 81 70 22 9 9 93 72 47 23 29 77 78 51 17 59 19 71 35 3 20 60 70 9 11 96 71 94 91 19 88 93 50 49 72 19 53 30 38 67 62 71 81 86 5 26 5 32 63 98 1 97 22 32 87 65 96 55 43 85 56 37 56 67 12 100 98 58 77 54 18 20 33 53 21 66 24 64 42 71 59 32 51 69 49 79 10 1", "output": "1" }, { "input": "13 7\n1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "13" }, { "input": "1 5\n4", "output": "1" }, { "input": "3 2\n1 4 1", "output": "2" }, { "input": "1 2\n100", "output": "0" }, { "input": "7 4\n4 2 3 4 4 2 3", "output": "7" }, { "input": "1 2\n1", "output": "1" }, { "input": "1 2\n15", "output": "0" }, { "input": "2 1\n1 1", "output": "2" }, { "input": "5 3\n3 4 3 2 1", "output": "4" }, { "input": "1 1\n2", "output": "0" }, { "input": "1 5\n1", "output": "1" }, { "input": "6 6\n7 1 1 1 1 1", "output": "5" }, { "input": "5 5\n6 5 5 5 5", "output": "4" }, { "input": "1 4\n2", "output": "1" }, { "input": "9 4\n1 2 1 2 4 2 1 2 1", "output": "9" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 10\n5", "output": "1" }, { "input": "5 5\n1 1 1 1 1", "output": "5" }, { "input": "100 10\n2 5 1 10 10 2 7 7 9 4 1 8 1 1 8 4 7 9 10 5 7 9 5 6 7 2 7 5 3 2 1 82 4 80 9 8 6 1 10 7 5 7 1 5 6 7 19 4 2 4 6 2 1 8 31 6 2 2 57 42 3 2 7 1 9 5 10 8 5 4 10 8 3 5 8 7 2 7 6 5 3 3 4 10 6 7 10 8 7 10 7 2 4 6 8 10 10 2 6 4", "output": "71" }, { "input": "100 90\n17 16 5 51 17 62 24 45 49 41 90 30 19 78 67 66 59 34 28 47 42 8 33 77 90 41 61 16 86 33 43 71 90 95 23 9 56 41 24 90 31 12 77 36 90 67 47 15 92 50 79 88 42 19 21 79 86 60 41 26 47 4 70 62 44 90 82 89 84 91 54 16 90 53 29 69 21 44 18 28 88 74 56 43 12 76 10 22 34 24 27 52 28 76 90 75 5 29 50 90", "output": "63" }, { "input": "100 10\n6 4 8 4 1 9 4 8 5 2 2 5 2 6 10 2 2 5 3 5 2 3 10 5 2 9 1 1 6 1 5 9 16 42 33 49 26 31 81 27 53 63 81 90 55 97 70 51 87 21 79 62 60 91 54 95 26 26 30 61 87 79 47 11 59 34 40 82 37 40 81 2 7 1 8 4 10 7 1 10 8 7 3 5 2 8 3 3 9 2 1 1 5 7 8 7 1 10 9 8", "output": "61" }, { "input": "100 90\n45 57 52 69 17 81 85 60 59 39 55 14 87 90 90 31 41 57 35 89 74 20 53 4 33 49 71 11 46 90 71 41 71 90 63 74 51 13 99 92 99 91 100 97 93 40 93 96 100 99 100 92 98 96 78 91 91 91 91 100 94 97 95 97 96 95 17 13 45 35 54 26 2 74 6 51 20 3 73 90 90 42 66 43 86 28 84 70 37 27 90 30 55 80 6 58 57 51 10 22", "output": "72" }, { "input": "100 10\n10 2 10 10 10 10 10 10 10 7 10 10 10 10 10 10 9 10 10 10 10 10 10 10 10 7 9 10 10 10 37 10 4 10 10 10 59 5 95 10 10 10 10 39 10 10 10 10 10 10 10 5 10 10 10 10 10 10 10 10 10 10 10 10 66 10 10 10 10 10 5 10 10 10 10 10 10 44 10 10 10 10 10 10 10 10 10 10 10 7 10 10 10 10 10 10 10 10 10 2", "output": "52" }, { "input": "100 90\n57 90 90 90 90 90 90 90 81 90 3 90 39 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 92 90 90 90 90 90 90 90 90 98 90 90 90 90 90 90 90 90 90 90 90 90 90 54 90 90 90 90 90 62 90 90 91 90 90 90 90 90 90 91 90 90 90 90 90 90 90 3 90 90 90 90 90 90 90 2 90 90 90 90 90 90 90 90 90 2 90 90 90 90 90", "output": "60" }, { "input": "100 10\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 78 90 61 40 87 39 91 50 64 30 10 24 10 55 28 11 28 35 26 26 10 57 45 67 14 99 96 51 67 79 59 11 21 55 70 33 10 16 92 70 38 50 66 52 5 10 10 10 2 4 10 10 10 10 10 10 10 10 10 6 10 10 10 10 10 10 10 10 10 10 8 10 10 10 10 10", "output": "56" }, { "input": "100 90\n90 90 90 90 90 90 55 21 90 90 90 90 90 90 90 90 90 90 69 83 90 90 90 90 90 90 90 90 93 95 92 98 92 97 91 92 92 91 91 95 94 95 100 100 96 97 94 93 90 90 95 95 97 99 90 95 98 91 94 96 99 99 94 95 95 97 99 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 12 90 3 90 90 90 90 90 90 90", "output": "61" }, { "input": "100 49\n71 25 14 36 36 48 36 49 28 40 49 49 49 38 40 49 33 22 49 49 14 46 8 44 49 11 37 49 40 49 2 49 3 49 37 49 49 11 25 49 49 32 49 11 49 30 16 21 49 49 23 24 30 49 49 49 49 49 49 27 49 42 49 49 20 32 30 29 35 49 30 49 9 49 27 25 5 49 49 42 49 20 49 35 49 22 15 49 49 49 19 49 29 28 13 49 22 7 6 24", "output": "99" }, { "input": "100 50\n38 68 9 6 50 18 19 50 50 20 33 34 43 50 24 50 50 2 50 50 50 50 50 21 30 50 41 40 50 50 50 50 50 7 50 21 19 23 1 50 24 50 50 50 25 50 50 50 50 50 50 50 7 24 28 18 50 5 43 50 20 50 13 50 50 16 50 3 2 24 50 50 18 5 50 4 50 50 38 50 33 49 12 33 11 14 50 50 50 33 50 50 50 50 50 50 7 4 50 50", "output": "99" }, { "input": "100 48\n8 6 23 47 29 48 48 48 48 48 48 26 24 48 48 48 3 48 27 28 41 45 9 29 48 48 48 48 48 48 48 48 48 48 47 23 48 48 48 5 48 22 40 48 48 48 20 48 48 57 48 32 19 48 33 2 4 19 48 48 39 48 16 48 48 44 48 48 48 48 29 14 25 43 46 7 48 19 30 48 18 8 39 48 30 47 35 18 48 45 48 48 30 13 48 48 48 17 9 48", "output": "99" }, { "input": "100 57\n57 9 57 4 43 57 57 57 57 26 57 18 57 57 57 57 57 57 57 47 33 57 57 43 57 57 55 57 14 57 57 4 1 57 57 57 57 57 46 26 57 57 57 57 57 57 57 39 57 57 57 5 57 12 11 57 57 57 25 37 34 57 54 18 29 57 39 57 5 57 56 34 57 24 7 57 57 57 2 57 57 57 57 1 55 39 19 57 57 57 57 21 3 40 13 3 57 57 62 57", "output": "99" }, { "input": "100 51\n51 51 38 51 51 45 51 51 51 18 51 36 51 19 51 26 37 51 11 51 45 34 51 21 51 51 33 51 6 51 51 51 21 47 51 13 51 51 30 29 50 51 51 51 51 51 51 45 14 51 2 51 51 23 9 51 50 23 51 29 34 51 40 32 1 36 31 51 11 51 51 47 51 51 51 51 51 51 51 50 39 51 14 4 4 12 3 11 51 51 51 51 41 51 51 51 49 37 5 93", "output": "99" }, { "input": "100 50\n87 91 95 73 50 50 16 97 39 24 58 50 33 89 42 37 50 50 12 71 3 55 50 50 80 10 76 50 52 36 88 44 66 69 86 71 77 50 72 50 21 55 50 50 78 61 75 89 65 2 50 69 62 47 11 92 97 77 41 31 55 29 35 51 36 48 50 91 92 86 50 36 50 94 51 74 4 27 55 63 50 36 87 50 67 7 65 75 20 96 88 50 41 73 35 51 66 21 29 33", "output": "3" }, { "input": "100 50\n50 37 28 92 7 76 50 50 50 76 100 57 50 50 50 32 76 50 8 72 14 8 50 91 67 50 55 82 50 50 24 97 88 50 59 61 68 86 44 15 61 67 88 50 40 50 36 99 1 23 63 50 88 59 76 82 99 76 68 50 50 30 31 68 57 98 71 12 15 60 35 79 90 6 67 50 50 50 50 68 13 6 50 50 16 87 84 50 67 67 50 64 50 58 50 50 77 51 50 51", "output": "3" }, { "input": "100 50\n43 50 50 91 97 67 6 50 86 50 76 60 50 59 4 56 11 38 49 50 37 50 50 20 60 47 33 54 95 58 22 50 77 77 72 9 57 40 81 57 95 50 81 63 62 76 13 87 50 39 74 69 50 99 63 1 11 62 84 31 97 99 56 73 70 36 45 100 28 91 93 9 19 52 73 50 83 58 84 52 86 12 50 44 64 52 97 50 12 71 97 52 87 66 83 66 86 50 9 49", "output": "6" }, { "input": "88 10\n10 8 1 10 10 1 3 7 10 5 8 8 10 2 7 10 10 10 10 10 1 10 10 10 10 1 2 9 10 9 10 10 10 64 100 25 10 12 9 52 13 8 10 56 10 4 10 7 10 3 10 79 74 8 73 10 10 10 9 10 3 5 10 10 10 5 1 10 10 4 3 10 10 10 4 10 6 4 10 10 10 10 3 3 8 5 6 8", "output": "66" }, { "input": "100 50\n80 39 33 69 75 50 23 88 50 50 67 90 87 50 29 15 55 32 60 50 50 50 38 95 62 50 50 88 8 97 45 50 42 12 22 93 49 50 24 50 50 71 60 4 50 72 57 57 50 50 50 83 69 17 1 31 72 55 50 11 50 80 93 41 91 94 20 60 50 50 51 48 53 56 76 73 50 72 19 98 50 50 50 50 50 28 48 45 62 11 16 67 93 88 63 50 50 66 48 95", "output": "0" }, { "input": "100 50\n70 50 38 50 38 50 32 30 50 31 26 42 50 33 34 50 50 50 28 21 50 44 50 47 50 50 9 40 50 50 50 50 50 42 50 50 16 50 50 3 24 50 50 50 4 26 50 2 50 50 33 1 27 50 50 50 8 29 50 23 33 50 6 29 50 50 15 50 50 50 32 50 43 50 50 50 31 50 4 50 50 31 50 50 31 16 50 17 50 17 31 13 25 16 50 10 50 47 50 66", "output": "0" }, { "input": "2 8\n8 8", "output": "2" }, { "input": "1 6\n3", "output": "1" }, { "input": "1 5\n5", "output": "1" } ]
1,639,727,660
2,147,483,647
Python 3
OK
TESTS
48
46
0
n,m=map(int,input().split()) l=list(map(int,input().split())) n=0 c=0 for i in l: if i<=m: n+=1 else: c=i break if c==0: print(n) else: s=l.index(c) for j in range(len(l)-1,s-1,-1): if l[j]<=m: n+=1 else: print(n) break
Title: Mishka and Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$. Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list. Mishka cannot solve a problem with difficulty greater than $k$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $1$. Mishka stops when he is unable to solve any problem from any end of the list. How many problems can Mishka solve? Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) — the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are given in order from the leftmost to the rightmost in the list. Output Specification: Print one integer — the maximum number of problems Mishka can solve. Demo Input: ['8 4\n4 2 3 1 5 1 6 4\n', '5 2\n3 1 2 1 3\n', '5 100\n12 34 55 43 21\n'] Demo Output: ['5\n', '0\n', '5\n'] Note: In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$. In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$. In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
```python n,m=map(int,input().split()) l=list(map(int,input().split())) n=0 c=0 for i in l: if i<=m: n+=1 else: c=i break if c==0: print(n) else: s=l.index(c) for j in range(len(l)-1,s-1,-1): if l[j]<=m: n+=1 else: print(n) break ```
3
716
B
Complete the Word
PROGRAMMING
1,300
[ "greedy", "two pointers" ]
null
null
ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him?
The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember.
If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them.
[ "ABC??FGHIJK???OPQR?TUVWXY?\n", "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n", "??????????????????????????\n", "AABCDEFGHIJKLMNOPQRSTUVW??M\n" ]
[ "ABCDEFGHIJKLMNOPQRZTUVWXYS", "-1", "MNBVCXZLKJHGFDSAQPWOEIRUYT", "-1" ]
In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
1,000
[ { "input": "ABC??FGHIJK???OPQR?TUVWXY?", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO", "output": "-1" }, { "input": "??????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AABCDEFGHIJKLMNOPQRSTUVW??M", "output": "-1" }, { "input": "QWERTYUIOPASDFGHJKL???????", "output": "QWERTYUIOPASDFGHJKLBCMNVXZ" }, { "input": "ABABABBAB????????????ABABABABA???????????ABABABABA?????????KLCSJB?????????Z", "output": "ABABABBABAAAAAAAAAAAAABABABABAAAAAAAAAAAAABABABABADEFGHIMNOKLCSJBPQRTUVWXYZ" }, { "input": "Q?E?T?U?O?A?D?G?J?L?X?V?MMQ?E?T?U?O?A?D?G?J?L?X?V?N", "output": "QAEATAUAOAAADAGAJALAXAVAMMQBECTFUHOIAKDPGRJSLWXYVZN" }, { "input": "???????????????????????????", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZA" }, { "input": "EJMGJAXCHXYIKZSQKUGRCLSTWDLNCVZIGXGWILAVFBEIGOHWGVEPRJTHWEDQRPOVZUQOSRVTIHFFHJMCLOWGHCIGJBCAAVBJFMJEFTEGFXZFVRZOXAFOFVXRAIZEWIKILFLYDZVDADYWYWYJXAGDFGNZBQKKKTGWPINLCDBZVULROGAKEKXXTWNYKQBMLQMQRUYOWUTWMNTJVGUXENHXWMFWMSBKVNGXSNFFTRTTGEGBBHMFZTKNJQDYUQOXVDWTDHZCCQNYYIOFPMKYQIGEEYBCKBAYVCTWARVMHIENKXKFXNXEFUHUNRQPEDFUBMKNQOYCQHGTLRHLWUAVZJDRBRTSVQHBKRDJFKKYEZAJWJKATRFZLNELPYGFUIWBXLIWVTHUILJHTQKDGRNCFTFELCOQPJDBYSPYJOUDKIFRCKEMJPUXTTAMHVENEVMNTZLUYSUALQOUPPRLZHCYICXAQFFRQZAAJNFKVRJDMDXFTBRJSAAHTSVG", "output": "-1" }, { "input": "SVBWLLLPMPJUQVIGVXPCKMPEBPWMYORVTYELJOQGKEOJVCRBUJOOKQZQBYJIBCSHGSDBTIIMNGAXAQJRHHKQFAJSOJLAYRKWBASMLBQVUPPQWDGAVKDLFHEHVVWGSYQHYCPDIECHBTOIFYUFGKWIIMCKEBLECHCETBQMJPBPPGDHRLJIIMVJBZDRSDWWEJASQFRSCLOBAOLZQDPEZWDLMYTGDLUHCJMTXVURWQFCFDIGSUADTFMNGVHRYHQKWBGWWLQJQSFSWXGWIYUTSBUNZFDONBCFTGWTTQIISXJZUWSZWXXFMNB?UWPOWVWIWMBAPXYMGTRSGWMQRXULCMDTUKZS?CNMBRIYDZCUQWAKYQLLJLTXSVMUAYZHVBZFYBABBECIADQPUPZVVYHTGKOWKDNEUYPBTNUSQLLQRODUXFMSYUYIQGERINAPZWL?VKBVQJQLUJGDPFHNVXXSNOWHBZPMLOXVC?IEUMVLIBYLEATFUTILPPTP", "output": "-1" }, { "input": "DMWSBHPGSJJD?EEV?CYAXQCCGNNQWNN?OMEDD?VC?CTKNQQPYXKKJFAYMJ?FMPXXCLKOL?OTRCE", "output": "-1" }, { "input": "EOYJRKFABJIUOZILSHHCXIFQTXAVXJOVTQCDHXPNYPW?RVRKTB?OVXEL?NQHMZZXJLGSA?OTFSZQBV?SBHGKPJPCIQMLRSYDCFPYMEMXUEVHANXELHKSKNLGHGDCYMURXQRWMHEYXXCMGMUFZIPVOZQQBJGVKESTCDZCWFUCSGGIRWMXYXJLFLGUXQAWLZIKFUTVYDGKBVKBKXTICIKHXWFVJRHNMYRJZYNNYXMUOFERZPY?AJKSMUCTLOFH?LV?EHHCHKBHOJZAHFKJHHZJKZIEYAOAPDQRIUWDBMJGOOSNWN?CBKUXJCTEWVTRBDCNFMGBJUAODCCZVPZBQJNIRJVVF?QBWBV?AXOVOYNAWSKUVPHWJK?YPYOKTVFBWAGCC?JOWPPCAZDOYETAYYECWWURYHY?SJHMSJXDIMXFOTUWJLYDKCHOAPLFYPMFYFRNRKWY?CBPLQJJJ?BJYGBJT?FV?VDQEQAUFWZSOJHZFBVEALMMT?XP", "output": "-1" }, { "input": "E?BIVQUPQQEJNMINFD?NKV?IROHPTGUIPMEVYPII?LZJMRI?FTKKKBHPOVQZZSAPDDWVSPVHOBT", "output": "-1" }, { "input": "FDQHJSNDDXHJLWVZVXJZUGKVHWCZVRWVZTIURLMJNGAMCUBDGVSIDEYRJZOLDISDNTOEKLSNLBSOQZLJVPAMLEBAVUNBXNKMLZBGJJQCGCSKBFSEEDXEVSWGZHFJIZJESPZIKIONJWTFFYYZKIDBSDNPJVAUHQMRFKIJWCEGTBVZHWZEKLPHGZVKZFAFAQRNKHGACNRTSXQKKCYBMEMKNKKSURKHOSMEVUXNGOCVCLVVSKULGBKFPCEKVRAJMBWCFFFSCCNDOSEKXEFFZETTUZHMQETWCVZASTTULYOPBNMOMXMVUEEEYZHSMRPAEIHUKNPNJTARJKQKIOXDJASSQPQQHEQIQJQLVPIJRCFVOVECHBOCRYWQEDXZLJXUDZUBFTRWEWNYTSKGDBEBWFFLMUYWELNVAAXSMKYEZXQFKKHJTZKMKMYOBTVXAOVBRMAMHTBDDYMDGQYEEBYZUBMUCKLKXCZGTWVZAYJOXZVGUYNXOVAPXQVE", "output": "-1" }, { "input": "KMNTIOJTLEKZW?JALAZYWYMKWRXTLAKNMDJLICZMETAKHVPTDOLAPCGHOEYSNIUJZVLPBTZ?YSR", "output": "-1" }, { "input": "?MNURVAKIVSOGITVJZEZCAOZEFVNZERAHVNCVCYKTJVEHK?ZMDL?CROLIDFSG?EIFHYKELMQRBVLE?CERELHDVFODJ?LBGJVFPO?CVMPBW?DPGZMVA?BKPXQQCRMKHJWDNAJSGOTGLBNSWMXMKAQ?MWMXCNRSGHTL?LGLAHSDHAGZRGTNDFI?KJ?GSAWOEPOENXTJCVJGMYOFIQKKDWOCIKPGCMFEKNEUPFGBCBYQCM?EQSAX?HZ?MFKAUHOHRKZZSIVZCAKYIKBDJYOCZJRYNLSOKGAEGQRQ?TBURXXLHAFCNVGAUVWBXZILMHWSBYJTIMWPNEGATPURPTJYFWKHRL?QPYUQ?HKDDHWAHOWUSONQKSZFIYFMFUJAMIYAMPNBGVPJSDFDFSAHDWWGEAKXLHBURNTIMCUZIAFAOCVNKPJRNLNGSJVMGKQ?IFQSRHTZGKHGXFJBDGPLCUUMEWNOSCONIVCLAOAPPSFFLCPRIXTKNBSSOVM", "output": "-1" }, { "input": "MRHKVVRBFEIFWIZGWCATJPBSZWNYANEWSSEVFQUUVNJKQOKVIGYBPFSZFTBUCNQEJEYVOWSPYER", "output": "-1" }, { "input": "CNRFBWKRTQTDFOMIGPPGDBHPRNRXFASDDBCZXHORGXDRSIORLJEROJBLLEHLNBILBPX?KHQLCOUPTKUADCDNHNBWMVNUUVUFPIRXSPNUCCRLJTDSUIUDLBKNKMXSAVBJDUGWIMNBIUWJX?TCBDEBNDYUGPS?MQSSEIIUGEE?XXKW?CMFQMWUAEXTSZNNOCPHBAEAKWALYBBMUMQZXUKTQPWNMZKIDECWIZFHKQIUJZRSBZPQFUQNVKQZMYJDHXZWXFHIZ?HWPIPIWV?JMIYKEJDNPMKTTOY?NTOMZZXTNMWQENYRWFYM?WLJJFCIJSETZSJORBZZHAFWYKGQJAPYQQXUWROOZUDOJJLNCDRSGUKYAZLLENGUICGOYPLJQ?POSKHPMOFJMAOXCITWWL?LOEDKHZPQFZZCTB?JYZNXZSDREAMGGXHMCFTQNOUALEYHULSDQVOXZIWFHNNHHG?FYUOCQNKBLFGGZ?YNFNVLRMENYBDWMDSP", "output": "-1" }, { "input": "KSRVTPFVRJWNPYUZMXBRLKVXIQPPBYVSYKRQPNGKTKRPFMKLIYFACFKBIQGPAXLEUESVGPBBXLY", "output": "-1" }, { "input": "LLVYUOXHBHUZSAPUMQEKWSQAFRKSMEENXDQYOPQFXNNFXSRBGXFUIRBFJDSDKQIDMCPPTWRJOZCRHZYZPBVUJPQXHNALAOCJDTTBDZWYDBVPMNSQNVMLHHUJAOIWFSEJEJSRBYREOZKHEXTBAXPTISPGIPOYBFFEJNAKKXAEPNGKWYGEJTNEZIXAWRSCEIRTKNEWSKSGKNIKDEOVXGYVEVFRGTNDFNWIFDRZQEJQZYIWNZXCONVZAKKKETPTPPXZMIVDWPGXOFODRNJZBATKGXAPXYHTUUFFASCHOLSMVSWBIJBAENEGNQTWKKOJUYQNXWDCDXBXBJOOWETWLQMGKHAJEMGXMYNVEHRAEGZOJJQPZGYRHXRNKMSWFYDIZLIBUTSKIKGQJZLGZQFJVIMNOHNZJKWVVPFMFACVXKJKTBZRXRZDJKSWSXBBKWIKEICSZEIPTOJCKJQYYPNUPRNPQNNCVITNXPLAKQBYAIQGNAHXDUQWQLYN", "output": "-1" }, { "input": "PVCKCT?KLTFPIBBIHODCAABEQLJKQECRUJUSHSXPMBEVBKHQTIKQLBLTIRQZPOGPWMMNWWCUKAD", "output": "-1" }, { "input": "BRTYNUVBBWMFDSRXAMLNSBIN???WDDQVPCSWGJTHLRAKTPFKGVLHAKNRIEYIDDRDZLLTBRKXRVRSPBSLXIZRRBEVMHJSAFPLZAIHFVTTEKDO?DYWKILEYRM?VHSEQCBYZZRZMICVZRYA?ONCSZOPGZUMIHJQJPIFX?YJMIERCMKTSFTDZIKEZPLDEOOCJLQIZ?RPHUEQHPNNSBRQRTDGLWNSCZ?WQVIZPTOETEXYI?DRQUOMREPUTOAJKFNBGYNWMGCAOELXEPLLZEYHTVLT?ETJJXLHJMAUDQESNQ?ZCGNDGI?JSGUXQV?QAWQIYKXBKCCSWNRTGHPZF?CSWDQSAZIWQNHOWHYAEZNXRMPAZEQQPPIBQQJEDHJEDHVXNEDETEN?ZHEPJJ?VVDYGPJUWGCBMB?ANFJHJXQVAJWCAZEZXZX?BACPPXORNENMCRMQPIYKNPHX?NSKGEABWWVLHQ?ESWLJUPQJSFIUEGMGHEYVLYEDWJG?L", "output": "-1" }, { "input": "TESTEIGHTYFOUR", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "-1" }, { "input": "?????????????????????????", "output": "-1" }, { "input": "Q?RYJPGLNQ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYS" }, { "input": "AACDEFGHIJKLMNOPQRZTUVWXYS", "output": "-1" }, { "input": "ZA?ABCDEFGHIJKLMNOPQRSTUVWXY", "output": "ZAZABCDEFGHIJKLMNOPQRSTUVWXY" }, { "input": "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPPQQRRSSTTUUVVWWXXYYZZ", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYYYZABC", "output": "-1" }, { "input": "????", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRZTUVWXYS??", "output": "ABCDEFGHIJKLMNOPQRZTUVWXYSAA" }, { "input": "A", "output": "-1" }, { "input": "NKBDABACEFGGGIJLLLLMMMOMPQWZSSRHHTTUWUWVXYY", "output": "-1" }, { "input": "AA", "output": "-1" }, { "input": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXA?CDEFGHIJKLMNOPQRSTUVWXYZ", "output": "BAAAAAAAAAAAAAAAAAAAAAAAAAAAXABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "???DEFGHIJKL??L?PQRSTUVW???", "output": "-1" }, { "input": "?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A?A", "output": "-1" }, { "input": "A?AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA???????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????", "output": "-1" }, { "input": "ZXXCVBNMLKJHGFDSAQWWERTYUIOP", "output": "-1" }, { "input": "ABCA???????????????????????", "output": "ABCADEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "AB", "output": "-1" }, { "input": "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "ABCDEFGHIJKLMNOPQRSTUVWXYZ" }, { "input": "BCDEFGHIAJKLMNOPQARSTUVWXYZ", "output": "-1" }, { "input": "AABBCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "-1" }, { "input": "???AA????????????????????BB???", "output": "-1" }, { "input": "ABC??FGAHIJ??MNOPQRST??WXYZ", "output": "ABCDEFGAHIJKLMNOPQRSTUVWXYZ" }, { "input": "QWERTYUIOPASDFGHJKLZXCVBN", "output": "-1" }, { "input": "??????AAAAAAAAAAAAAAAAAAAABBBBB??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBB????????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA??????????AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAASSSSSSSSFFFFFFF?????????DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD??????WWWWWWWWWWEEEEEEEEEEERRRRRRRRRRRRRRRRRRRRRRRRRHHHHHHHHHH?????", "output": "-1" } ]
1,693,807,280
2,147,483,647
PyPy 3-64
RUNTIME_ERROR
TESTS
36
171
9,318,400
def solve(s,n): if n < 26: print(-1) else: used = [False] * 26 alphas = {'?':0} for i in range(26): if alphas.get(s[i]): alphas[s[i]] += 1 else: alphas[s[i]] = 1 #print(s[i],used) if s[i] != '?': used[ord(s[i])-65] = True found = 0 if sum(used) == 26 or sum(used)+alphas['?'] >=26: #print('here') found = 1 return 25,used for i in range(26,len(s)): alphas[s[i-26]] -= 1 if alphas[s[i-26]] == 0: used[ord(s[i-26])-65] = False if alphas.get(s[i]): alphas[s[i]] += 1 else: alphas[s[i]] = 1 if s[i] != '?': used[ord(s[i])-65] = True total = sum(used) if total == 26 or total+alphas['?'] >=26: return i,used break s = input().strip() n = len(s) if solve(s,n): index,used = solve(s,n) new = "" #print(index,used) for i in range(0,index-26+1): if s[i] =='?': new+='A' else: new += s[i] for j in range(len(used)): if not used[j]: break for i in range(index-26+1,index+1): if s[i] == '?': new += chr(j+65) for k in range(j+1,26): if not used[k]: break j = k else: new += s[i] for i in range(index+1,len(s)): if s[i] == '?': new+='A' else: new += s[i] print(new) # Check if it's impossible to form a nice word else: print(-1)
Title: Complete the Word Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segment of letters) of it of length 26 where each letter of English alphabet appears exactly once. In particular, if the string has length strictly less than 26, no such substring exists and thus it is not nice. Now, ZS the Coder tells you a word, where some of its letters are missing as he forgot them. He wants to determine if it is possible to fill in the missing letters so that the resulting word is nice. If it is possible, he needs you to find an example of such a word as well. Can you help him? Input Specification: The first and only line of the input contains a single string *s* (1<=≤<=|*s*|<=≤<=50<=000), the word that ZS the Coder remembers. Each character of the string is the uppercase letter of English alphabet ('A'-'Z') or is a question mark ('?'), where the question marks denotes the letters that ZS the Coder can't remember. Output Specification: If there is no way to replace all the question marks with uppercase letters such that the resulting word is nice, then print <=-<=1 in the only line. Otherwise, print a string which denotes a possible nice word that ZS the Coder learned. This string should match the string from the input, except for the question marks replaced with uppercase English letters. If there are multiple solutions, you may print any of them. Demo Input: ['ABC??FGHIJK???OPQR?TUVWXY?\n', 'WELCOMETOCODEFORCESROUNDTHREEHUNDREDANDSEVENTYTWO\n', '??????????????????????????\n', 'AABCDEFGHIJKLMNOPQRSTUVW??M\n'] Demo Output: ['ABCDEFGHIJKLMNOPQRZTUVWXYS', '-1', 'MNBVCXZLKJHGFDSAQPWOEIRUYT', '-1'] Note: In the first sample case, ABCDEFGHIJKLMNOPQRZTUVWXYS is a valid answer beacuse it contains a substring of length 26 (the whole string in this case) which contains all the letters of the English alphabet exactly once. Note that there are many possible solutions, such as ABCDEFGHIJKLMNOPQRSTUVWXYZ or ABCEDFGHIJKLMNOPQRZTUVWXYS. In the second sample case, there are no missing letters. In addition, the given string does not have a substring of length 26 that contains all the letters of the alphabet, so the answer is  - 1. In the third sample case, any string of length 26 that contains all letters of the English alphabet fits as an answer.
```python def solve(s,n): if n < 26: print(-1) else: used = [False] * 26 alphas = {'?':0} for i in range(26): if alphas.get(s[i]): alphas[s[i]] += 1 else: alphas[s[i]] = 1 #print(s[i],used) if s[i] != '?': used[ord(s[i])-65] = True found = 0 if sum(used) == 26 or sum(used)+alphas['?'] >=26: #print('here') found = 1 return 25,used for i in range(26,len(s)): alphas[s[i-26]] -= 1 if alphas[s[i-26]] == 0: used[ord(s[i-26])-65] = False if alphas.get(s[i]): alphas[s[i]] += 1 else: alphas[s[i]] = 1 if s[i] != '?': used[ord(s[i])-65] = True total = sum(used) if total == 26 or total+alphas['?'] >=26: return i,used break s = input().strip() n = len(s) if solve(s,n): index,used = solve(s,n) new = "" #print(index,used) for i in range(0,index-26+1): if s[i] =='?': new+='A' else: new += s[i] for j in range(len(used)): if not used[j]: break for i in range(index-26+1,index+1): if s[i] == '?': new += chr(j+65) for k in range(j+1,26): if not used[k]: break j = k else: new += s[i] for i in range(index+1,len(s)): if s[i] == '?': new+='A' else: new += s[i] print(new) # Check if it's impossible to form a nice word else: print(-1) ```
-1
23
A
You're Given a String...
PROGRAMMING
1,200
[ "brute force", "greedy" ]
A. You're Given a String...
2
256
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.
Output one number — length of the longest substring that can be met in the string at least twice.
[ "abcd\n", "ababa\n", "zzz\n" ]
[ "0", "3", "2" ]
none
0
[ { "input": "abcd", "output": "0" }, { "input": "ababa", "output": "3" }, { "input": "zzz", "output": "2" }, { "input": "kmmm", "output": "2" }, { "input": "wzznz", "output": "1" }, { "input": "qlzazaaqll", "output": "2" }, { "input": "lzggglgpep", "output": "2" }, { "input": "iegdlraaidefgegiagrdfhihe", "output": "2" }, { "input": "esxpqmdrtidgtkxojuxyrcwxlycywtzbjzpxvbngnlepgzcaeg", "output": "1" }, { "input": "garvpaimjdjiivamusjdwfcaoswuhxyyxvrxzajoyihggvuxumaadycfphrzbprraicvjjlsdhojihaw", "output": "2" }, { "input": "ckvfndqgkmhcyojaqgdkenmbexufryhqejdhctxujmtrwkpbqxufxamgoeigzfyzbhevpbkvviwntdhqscvkmphnkkljizndnbjt", "output": "3" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "output": "99" }, { "input": "ikiikiikikiiikkkkkikkkkiiiiikkiiikkiikiikkkkikkkikikkikiiikkikikiiikikkkiiikkkikkikkikkkkiiikkiiiiii", "output": "10" }, { "input": "ovovhoovvhohhhvhhvhhvhovoohovhhoooooovohvooooohvvoooohvvovhhvhovhhvoovhvhvoovovvhooovhhooovohvhhovhv", "output": "8" }, { "input": "ccwckkkycccccckwckwkwkwkkkkyycykcccycyckwywcckwykcycykkkwcycwwcykcwkwkwwykwkwcykywwwyyykckkyycckwcwk", "output": "5" }, { "input": "ttketfkefktfztezzkzfkkeetkkfktftzktezekkeezkeeetteeteefetefkzzzetekfftkeffzkktffzkzzeftfeezfefzffeef", "output": "4" }, { "input": "rtharczpfznrgdnkltchafduydgbgkdjqrmjqyfmpwjwphrtsjbmswkanjlprbnduaqbcjqxlxmkspkhkcnzbqwxonzxxdmoigti", "output": "2" }, { "input": "fplrkfklvwdeiynbjgaypekambmbjfnoknlhczhkdmljicookdywdgpnlnqlpunnkebnikgcgcjefeqhknvlynmvjcegvcdgvvdb", "output": "2" }, { "input": "txbciieycswqpniwvzipwlottivvnfsysgzvzxwbctcchfpvlbcjikdofhpvsknptpjdbxemtmjcimetkemdbettqnbvzzbdyxxb", "output": "2" }, { "input": "fmubmfwefikoxtqvmaavwjxmoqltapexkqxcsztpezfcltqavuicefxovuswmqimuikoppgqpiapqutkczgcvxzutavkujxvpklv", "output": "3" }, { "input": "ipsrjylhpkjvlzncfixipstwcicxqygqcfrawpzzvckoveyqhathglblhpkjvlzncfixipfajaqobtzvthmhgbuawoxoknirclxg", "output": "15" }, { "input": "kcnjsntjzcbgzjscrsrjkrbytqsrptzspzctjrorsyggrtkcnjsntjzcbgzjscrsrjyqbrtpcgqirsrrjbbbrnyqstnrozcoztt", "output": "20" }, { "input": "unhcfnrhsqetuerjqcetrhlsqgfnqfntvkgxsscquolxxroqgtchffyccetrhlsqgfnqfntvkgxsscquolxxroqgtchffhfqvx", "output": "37" }, { "input": "kkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckkkkkcckkccckkcckcccckcckkkkcckkkkckkkcckckkkkkckckckkc", "output": "46" }, { "input": "mlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydbrxdmlhsyijxeydqxhtkmpdeqwzogjvxahmssyhfhqessbxzvydik", "output": "47" }, { "input": "abcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "tttttbttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttmttttttt", "output": "85" }, { "input": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffbfffffffffffffffffffffffffffffffffffff", "output": "61" }, { "input": "cccccccccccccccccccccccwcccccccccccccccccccccuccccccccccccccnccccccccccccccccccccccccccccccccccccccc", "output": "38" }, { "input": "ffffffffffffffffffffffffffufffgfffffffffffffffffffffffffffffffffffffffgffffffftffffffgffffffffffffff", "output": "38" }, { "input": "rrrrrrrrrrrrrrrrrrrlhbrrrrrrrrurrrrrrrfrrqrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrewrrrrrrryrrxrrrrrrrrrrr", "output": "33" }, { "input": "vyvvvvvvvvzvvvvvzvvvwvvvvrvvvvvvvvvvvvvvvrvvvvvvvvvpkvvpvgvvvvvvvvvvvvvgvvvvvvvvvvvvvvvvvvysvvvbvvvv", "output": "17" }, { "input": "cbubbbbbbbbbbfbbbbbbbbjbobbbbbbbbbbibbubbbbjbbbnzgbbzbbfbbbbbbbbbbbfbpbbbbbbbbbbygbbbgbabbbbbbbhibbb", "output": "12" }, { "input": "lrqrrrrrrrjrrrrrcdrrgrrmwvrrrrrrrrrxfzrmrmrryrrrurrrdrrrrrrrrrrererrrsrrrrrrrrrrrqrrrrcrrwjsrrlrrrrr", "output": "10" }, { "input": "ssssusisisosscssssztzessssyspskjssvosiissussszsosssslsssdsssvssvsssslsssmsfjasjsssssowscsjsssszsspss", "output": "8" }, { "input": "uukuuuumueuuuujuukgdhbztuuuubbguuocuozfaunqufjujuguyuuvkuuauubuubuucuvtjuuuuuusduduuuuuuuueunuuuuuzu", "output": "7" }, { "input": "jpkkgwklngwqcfzmwkkpcwkkkkkekkkekkkdsykqwjkkkhkkkxdnukkkkkkmkqykkkxqklkskkrkkkkkqqjikkkkkkpknkkkkkoh", "output": "7" }, { "input": "bmzbbfbbhqxwthtbbisbbbbbtbbfbbpbfbbpbkbjfbcbbbbzbbbdwmbbbrnvqdbbtbbuglrnbbbbvmbyblebbabibrevaxbbjbqb", "output": "6" }, { "input": "qqqmqqqsbteqqopsuqiqumrqzpqnqgqeniqqkyqqyqqqpxzqeqqquhdqquhqqqfqjirqaqqaquxqoqqjqqqqbjbgqcqqqqicnkqc", "output": "4" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasaaaavaaaaaaauaaeaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "44" }, { "input": "a", "output": "0" }, { "input": "fg", "output": "0" }, { "input": "yy", "output": "1" }, { "input": "abcabcabc", "output": "6" }, { "input": "qwerqwedqwes", "output": "3" } ]
1,680,955,097
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
62
0
s = input() n = len(s) ans = 0 for i in range(n): for j in range(i+1, n): substr = s[i:j+1] if s.count(substr) >= 2: ans = max(ans, len(substr)) print(ans)
Title: You're Given a String... Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). Input Specification: The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. Output Specification: Output one number — length of the longest substring that can be met in the string at least twice. Demo Input: ['abcd\n', 'ababa\n', 'zzz\n'] Demo Output: ['0', '3', '2'] Note: none
```python s = input() n = len(s) ans = 0 for i in range(n): for j in range(i+1, n): substr = s[i:j+1] if s.count(substr) >= 2: ans = max(ans, len(substr)) print(ans) ```
0
281
A
Word Capitalization
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged.
A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.
Output the given word after capitalization.
[ "ApPLe\n", "konjac\n" ]
[ "ApPLe\n", "Konjac\n" ]
none
500
[ { "input": "ApPLe", "output": "ApPLe" }, { "input": "konjac", "output": "Konjac" }, { "input": "a", "output": "A" }, { "input": "A", "output": "A" }, { "input": "z", "output": "Z" }, { "input": "ABACABA", "output": "ABACABA" }, { "input": "xYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX", "output": "XYaPxPxHxGePfGtQySlNrLxSjDtNnTaRaEpAhPaQpWnDzMqGgRgEwJxGiBdZnMtHxFbObCaGiCeZkUqIgBhHtNvAqAlHpMnQhNeQbMyZrCdElVwHtKrPpJjIaHuIlYwHaRkAkUpPlOhNlBtXwDsKzPyHrPiUwNlXtTaPuMwTqYtJySgFoXvLiHbQwMjSvXsQfKhVlOxGdQkWjBhEyQvBjPoFkThNeRhTuIzFjInJtEfPjOlOsJpJuLgLzFnZmKvFgFrNsOnVqFcNiMfCqTpKnVyLwNqFiTySpWeTdFnWuTwDkRjVxNyQvTrOoEiExYiFaIrLoFmJfZcDkHuWjYfCeEqCvEsZiWnJaEmFbMjDvYwEeJeGcKbVbChGsIzNlExHzHiTlHcSaKxLuZxX" }, { "input": "rZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO", "output": "RZhIcQlXpNcPgXrOjTiOlMoTgXgIhCfMwZfWoFzGhEkQlOoMjIuShPlZfWkNnMyQfYdUhVgQuSmYoElEtZpDyHtOxXgCpWbZqSbYnPqBcNqRtPgCnJnAyIvNsAhRbNeVlMwZyRyJnFgIsCnSbOdLvUyIeOzQvRpMoMoHfNhHwKvTcHuYnYySfPmAiNwAiWdZnWlLvGfBbRbRrCrBqIgIdWkWiBsNyYkKdNxZdGaToSsDnXpRaGrKxBpQsCzBdQgZzBkGeHgGxNrIyQlSzWsTmSnZwOcHqQpNcQvJlPvKaPiQaMaYsQjUeCqQdCjPgUbDmWiJmNiXgExLqOcCtSwSePnUxIuZfIfBeWbEiVbXnUsPwWyAiXyRbZgKwOqFfCtQuKxEmVeRlAkOeXkO" }, { "input": "hDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD", "output": "HDgZlUmLhYbLkLcNcKeOwJwTePbOvLaRvNzQbSbLsPeHqLhUqWtUbNdQfQqFfXeJqJwWuOrFnDdZiPxIkDyVmHbHvXfIlFqSgAcSyWbOlSlRuPhWdEpEzEeLnXwCtWuVcHaUeRgCiYsIvOaIgDnFuDbRnMoCmPrZfLeFpSjQaTfHgZwZvAzDuSeNwSoWuJvLqKqAuUxFaCxFfRcEjEsJpOfCtDiVrBqNsNwPuGoRgPzRpLpYnNyQxKaNnDnYiJrCrVcHlOxPiPcDbEgKfLwBjLhKcNeMgJhJmOiJvPfOaPaEuGqWvRbErKrIpDkEoQnKwJnTlStLyNsHyOjZfKoIjXwUvRrWpSyYhRpQdLqGmErAiNcGqAqIrTeTiMuPmCrEkHdBrLyCxPtYpRqD" }, { "input": "qUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW", "output": "QUdLgGrJeGmIzIeZrCjUtBpYfRvNdXdRpGsThIsEmJjTiMqEwRxBeBaSxEuWrNvExKePjPnXhPzBpWnHiDhTvZhBuIjDnZpTcEkCvRkAcTmMuXhGgErWgFyGyToOyVwYlCuQpTfJkVdWmFyBqQhJjYtXrBbFdHzDlGsFbHmHbFgXgFhIyDhZyEqEiEwNxSeByBwLiVeSnCxIdHbGjOjJrZeVkOzGeMmQrJkVyGhDtCzOlPeAzGrBlWwEnAdUfVaIjNrRyJjCnHkUvFuKuKeKbLzSbEmUcXtVkZzXzKlOrPgQiDmCcCvIyAdBwOeUuLbRmScNcWxIkOkJuIsBxTrIqXhDzLcYdVtPgZdZfAxTmUtByGiTsJkSySjXdJvEwNmSmNoWsChPdAzJrBoW" }, { "input": "kHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL", "output": "KHbApGoBcLmIwUlXkVgUmWzYeLoDbGaOkWbIuXoRwMfKuOoMzAoXrBoTvYxGrMbRjDuRxAbGsTnErIiHnHoLeRnTbFiRfDdOkNlWiAcOsChLdLqFqXlDpDoDtPxXqAmSvYgPvOcCpOlWtOjYwFkGkHuCaHwZcFdOfHjBmIxTeSiHkWjXyFcCtOlSuJsZkDxUgPeZkJwMmNpErUlBcGuMlJwKkWnOzFeFiSiPsEvMmQiCsYeHlLuHoMgBjFoZkXlObDkSoQcVyReTmRsFzRhTuIvCeBqVsQdQyTyZjStGrTyDcEcAgTgMiIcVkLbZbGvWeHtXwEqWkXfTcPyHhHjYwIeVxLyVmHmMkUsGiHmNnQuMsXaFyPpVqNrBhOiWmNkBbQuHvQdOjPjKiZcL" }, { "input": "aHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC", "output": "AHmRbLgNuWkLxLnWvUbYwTeZeYiOlLhTuOvKfLnVmCiPcMkSgVrYjZiLuRjCiXhAnVzVcTlVeJdBvPdDfFvHkTuIhCdBjEsXbVmGcLrPfNvRdFsZkSdNpYsJeIhIcNqSoLkOjUlYlDmXsOxPbQtIoUxFjGnRtBhFaJvBeEzHsAtVoQbAfYjJqReBiKeUwRqYrUjPjBoHkOkPzDwEwUgTxQxAvKzUpMhKyOhPmEhYhItQwPeKsKaKlUhGuMcTtSwFtXfJsDsFlTtOjVvVfGtBtFlQyIcBaMsPaJlPqUcUvLmReZiFbXxVtRhTzJkLkAjVqTyVuFeKlTyQgUzMsXjOxQnVfTaWmThEnEoIhZeZdStBkKeLpAhJnFoJvQyGwDiStLjEwGfZwBuWsEfC" }, { "input": "sLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN", "output": "SLlZkDiDmEdNaXuUuJwHqYvRtOdGfTiTpEpAoSqAbJaChOiCvHgSwZwEuPkMmXiLcKdXqSsEyViEbZpZsHeZpTuXoGcRmOiQfBfApPjDqSqElWeSeOhUyWjLyNoRuYeGfGwNqUsQoTyVvWeNgNdZfDxGwGfLsDjIdInSqDlMuNvFaHbScZkTlVwNcJpEjMaPaOtFgJjBjOcLlLmDnQrShIrJhOcUmPnZhTxNeClQsZaEaVaReLyQpLwEqJpUwYhLiRzCzKfOoFeTiXzPiNbOsZaZaLgCiNnMkBcFwGgAwPeNyTxJcCtBgXcToKlWaWcBaIvBpNxPeClQlWeQqRyEtAkJdBtSrFdDvAbUlKyLdCuTtXxFvRcKnYnWzVdYqDeCmOqPxUaFjQdTdCtN" }, { "input": "iRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE", "output": "IRuStKvVhJdJbQwRoIuLiVdTpKaOqKfYlYwAzIpPtUwUtMeKyCaOlXmVrKwWeImYmVuXdLkRlHwFxKqZbZtTzNgOzDbGqTfZnKmUzAcIjDcEmQgYyFbEfWzRpKvCkDmAqDiIiRcLvMxWaJqCgYqXgIcLdNaZlBnXtJyKaMnEaWfXfXwTbDnAiYnWqKbAtDpYdUbZrCzWgRnHzYxFgCdDbOkAgTqBuLqMeStHcDxGnVhSgMzVeTaZoTfLjMxQfRuPcFqVlRyYdHyOdJsDoCeWrUuJyIiAqHwHyVpEeEoMaJwAoUfPtBeJqGhMaHiBjKwAlXoZpUsDhHgMxBkVbLcEvNtJbGnPsUwAvXrAkTlXwYvEnOpNeWyIkRnEnTrIyAcLkRgMyYcKrGiDaAyE" }, { "input": "cRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP", "output": "CRtJkOxHzUbJcDdHzJtLbVmSoWuHoTkVrPqQaVmXeBrHxJbQfNrQbAaMrEhVdQnPxNyCjErKxPoEdWkVrBbDeNmEgBxYiBtWdAfHiLuSwIxJuHpSkAxPoYdNkGoLySsNhUmGoZhDzAfWhJdPlJzQkZbOnMtTkClIoCqOlIcJcMlGjUyOiEmHdYfIcPtTgQhLlLcPqQjAnQnUzHpCaQsCnYgQsBcJrQwBnWsIwFfSfGuYgTzQmShFpKqEeRlRkVfMuZbUsDoFoPrNuNwTtJqFkRiXxPvKyElDzLoUnIwAaBaOiNxMpEvPzSpGpFhMtGhGdJrFnZmNiMcUfMtBnDuUnXqDcMsNyGoLwLeNnLfRsIwRfBtXkHrFcPsLdXaAoYaDzYnZuQeVcZrElWmP" }, { "input": "wVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG", "output": "WVaCsGxZrBbFnTbKsCoYlAvUkIpBaYpYmJkMlPwCaFvUkDxAiJgIqWsFqZlFvTtAnGzEwXbYiBdFfFxRiDoUkLmRfAwOlKeOlKgXdUnVqLkTuXtNdQpBpXtLvZxWoBeNePyHcWmZyRiUkPlRqYiQdGeXwOhHbCqVjDcEvJmBkRwWnMqPjXpUsIyXqGjHsEsDwZiFpIbTkQaUlUeFxMwJzSaHdHnDhLaLdTuYgFuJsEcMmDvXyPjKsSeBaRwNtPuOuBtNeOhQdVgKzPzOdYtPjPfDzQzHoWcYjFbSvRgGdGsCmGnQsErToBkCwGeQaCbBpYkLhHxTbUvRnJpZtXjKrHdRiUmUbSlJyGaLnWsCrJbBnSjFaZrIzIrThCmGhQcMsTtOxCuUcRaEyPaG" }, { "input": "kEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV", "output": "KEiLxLmPjGzNoGkJdBlAfXhThYhMsHmZoZbGyCvNiUoLoZdAxUbGyQiEfXvPzZzJrPbEcMpHsMjIkRrVvDvQtHuKmXvGpQtXbPzJpFjJdUgWcPdFxLjLtXgVpEiFhImHnKkGiWnZbJqRjCyEwHsNbYfYfTyBaEuKlCtWnOqHmIgGrFmQiYrBnLiFcGuZxXlMfEuVoCxPkVrQvZoIpEhKsYtXrPxLcSfQqXsWaDgVlOnAzUvAhOhMrJfGtWcOwQfRjPmGhDyAeXrNqBvEiDfCiIvWxPjTwPlXpVsMjVjUnCkXgBuWnZaDyJpWkCfBrWnHxMhJgItHdRqNrQaEeRjAuUwRkUdRhEeGlSqVqGmOjNcUhFfXjCmWzBrGvIuZpRyWkWiLyUwFpYjNmNfV" }, { "input": "eIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI", "output": "EIhDoLmDeReKqXsHcVgFxUqNfScAiQnFrTlCgSuTtXiYvBxKaPaGvUeYfSgHqEaWcHxKpFaSlCxGqAmNeFcIzFcZsBiVoZhUjXaDaIcKoBzYdIlEnKfScRqSkYpPtVsVhXsBwUsUfAqRoCkBxWbHgDiCkRtPvUwVgDjOzObYwNiQwXlGnAqEkHdSqLgUkOdZiWaHqQnOhUnDhIzCiQtVcJlGoRfLuVlFjWqSuMsLgLwOdZvKtWdRuRqDoBoInKqPbJdXpIqLtFlMlDaWgSiKbFpCxOnQeNeQzXeKsBzIjCyPxCmBnYuHzQoYxZgGzSgGtZiTeQmUeWlNzZeKiJbQmEjIiDhPeSyZlNdHpZnIkPdJzSeJpPiXxToKyBjJfPwNzZpWzIzGySqPxLtI" }, { "input": "uOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX", "output": "UOoQzIeTwYeKpJtGoUdNiXbPgEwVsZkAnJcArHxIpEnEhZwQhZvAiOuLeMkVqLeDsAyKeYgFxGmRoLaRsZjAeXgNfYhBkHeDrHdPuTuYhKmDlAvYzYxCdYgYfVaYlGeVqTeSfBxQePbQrKsTaIkGzMjFrQlJuYaMxWpQkLdEcDsIiMnHnDtThRvAcKyGwBsHqKdXpJfIeTeZtYjFbMeUoXoXzGrShTwSwBpQlKeDrZdCjRqNtXoTsIzBkWbMsObTtDvYaPhUeLeHqHeMpZmTaCcIqXzAmGnPfNdDaFhOqWqDrWuFiBpRjZrQmAdViOuMbFfRyXyWfHgRkGpPnDrEqQcEmHcKpEvWlBrOtJbUaXbThJaSxCbVoGvTmHvZrHvXpCvLaYbRiHzYuQyX" }, { "input": "lZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ", "output": "LZqBqKeGvNdSeYuWxRiVnFtYbKuJwQtUcKnVtQhAlOeUzMaAuTaEnDdPfDcNyHgEoBmYjZyFePeJrRiKyAzFnBfAuGiUyLrIeLrNhBeBdVcEeKgCcBrQzDsPwGcNnZvTsEaYmFfMeOmMdNuZbUtDoQoNcGwDqEkEjIdQaPwAxJbXeNxOgKgXoEbZiIsVkRrNpNyAkLeHkNfEpLuQvEcMbIoGaDzXbEtNsLgGfOkZaFiUsOvEjVeCaMcZqMzKeAdXxJsVeCrZaFpJtZxInQxFaSmGgSsVyGeLlFgFqTpIbAvPkIfJrVcJeBxSdEvPyVwIjHpYrLrKqLnAmCuGmPoZrSbOtGaLaTmBmSuUyAmAsRiMqOtRjJhPhAfXaJnTpLbFqPmJgFcBxImTqIiJ" }, { "input": "P", "output": "P" }, { "input": "Xyzzy", "output": "Xyzzy" }, { "input": "Zzz", "output": "Zzz" }, { "input": "Zp", "output": "Zp" } ]
1,699,205,878
2,147,483,647
Python 3
OK
TESTS
25
92
0
n=input() res = n[0].upper() + n[1:] print(res)
Title: Word Capitalization Time Limit: None seconds Memory Limit: None megabytes Problem Description: Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word. Note, that during capitalization all the letters except the first one remains unchanged. Input Specification: A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. Output Specification: Output the given word after capitalization. Demo Input: ['ApPLe\n', 'konjac\n'] Demo Output: ['ApPLe\n', 'Konjac\n'] Note: none
```python n=input() res = n[0].upper() + n[1:] print(res) ```
3
104
A
Blackjack
PROGRAMMING
800
[ "implementation" ]
A. Blackjack
2
256
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*.
The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points.
Print the numbers of ways to get the second card in the required way if the first card is the queen of spades.
[ "12\n", "20\n", "10\n" ]
[ "4", "15", "0" ]
In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
500
[ { "input": "12", "output": "4" }, { "input": "20", "output": "15" }, { "input": "10", "output": "0" }, { "input": "11", "output": "4" }, { "input": "15", "output": "4" }, { "input": "18", "output": "4" }, { "input": "25", "output": "0" }, { "input": "22", "output": "0" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "5", "output": "0" }, { "input": "6", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "0" }, { "input": "9", "output": "0" }, { "input": "13", "output": "4" }, { "input": "14", "output": "4" }, { "input": "16", "output": "4" }, { "input": "17", "output": "4" }, { "input": "19", "output": "4" }, { "input": "21", "output": "4" }, { "input": "23", "output": "0" }, { "input": "24", "output": "0" } ]
1,599,653,254
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
436
2,150,400
n=int(input("")) r=n-10 if(r<1 or r>11): print('0') elif(r==10): print('15') else: pritn('4')
Title: Blackjack Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. Input Specification: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. Output Specification: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Demo Input: ['12\n', '20\n', '10\n'] Demo Output: ['4', '15', '0'] Note: In the first sample only four two's of different suits can earn the required sum of points. In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use. In the third sample there is no card, that would add a zero to the current ten points.
```python n=int(input("")) r=n-10 if(r<1 or r>11): print('0') elif(r==10): print('15') else: pritn('4') ```
-1
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 586975278", "output": "1" }, { "input": "259504825 377489979 588153796 377489979", "output": "1" }, { "input": "652588203 931100304 931100304 652588203", "output": "2" }, { "input": "391958720 651507265 391958720 651507265", "output": "2" }, { "input": "90793237 90793237 90793237 90793237", "output": "3" }, { "input": "551651653 551651653 551651653 551651653", "output": "3" }, { "input": "156630260 609654355 668943582 973622757", "output": "0" }, { "input": "17061017 110313588 434481173 796661222", "output": "0" }, { "input": "24975422 256716298 337790533 690960249", "output": "0" }, { "input": "255635360 732742923 798648949 883146723", "output": "0" }, { "input": "133315691 265159773 734556507 265159773", "output": "1" }, { "input": "28442865 741657755 978106882 978106882", "output": "1" }, { "input": "131245479 174845575 497483467 131245479", "output": "1" }, { "input": "139159884 616215581 958341883 616215581", "output": "1" }, { "input": "147784432 947653080 947653080 947653080", "output": "2" }, { "input": "94055790 756126496 756126496 94055790", "output": "2" }, { "input": "240458500 511952208 240458500 511952208", "output": "2" }, { "input": "681828506 972810624 972810624 681828506", "output": "2" }, { "input": "454961014 454961014 454961014 454961014", "output": "3" }, { "input": "915819430 915819430 915819430 915819430", "output": "3" }, { "input": "671645142 671645142 671645142 671645142", "output": "3" }, { "input": "132503558 132503558 132503558 132503558", "output": "3" }, { "input": "5 5 999999 6", "output": "1" }, { "input": "1 1 2 5", "output": "1" }, { "input": "2 1 2 3", "output": "1" }, { "input": "1 1 3 5", "output": "1" }, { "input": "1 1 3 3", "output": "2" }, { "input": "2 2 2 1", "output": "2" }, { "input": "3 1 1 1", "output": "2" }, { "input": "1 2 2 2", "output": "2" } ]
1,698,000,256
2,147,483,647
Python 3
OK
TESTS
34
92
0
print(4-(len(set(input().split(" ")))))
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 print(4-(len(set(input().split(" "))))) ```
3
208
A
Dubstep
PROGRAMMING
900
[ "strings" ]
null
null
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song.
The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word.
Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space.
[ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ]
[ "ABC ", "WE ARE THE CHAMPIONS MY FRIEND " ]
In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
500
[ { "input": "WUBWUBABCWUB", "output": "ABC " }, { "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND " }, { "input": "WUBWUBWUBSR", "output": "SR " }, { "input": "RWUBWUBWUBLWUB", "output": "R L " }, { "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L " }, { "input": "CWUBBWUBWUBWUBEWUBWUBWUBQWUBWUBWUB", "output": "C B E Q " }, { "input": "WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB", "output": "JKD WBIRAQKF YE WV " }, { "input": "WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB", "output": "KSDHEMIXUJ R S H " }, { "input": "OGWUBWUBWUBXWUBWUBWUBIWUBWUBWUBKOWUBWUB", "output": "OG X I KO " }, { "input": "QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH", "output": "Q QQ I WW JOPJPBRH " }, { "input": "VSRNVEATZTLGQRFEGBFPWUBWUBWUBAJWUBWUBWUBPQCHNWUBCWUB", "output": "VSRNVEATZTLGQRFEGBFP AJ PQCHN C " }, { "input": "WUBWUBEWUBWUBWUBIQMJNIQWUBWUBWUBGZZBQZAUHYPWUBWUBWUBPMRWUBWUBWUBDCV", "output": "E IQMJNIQ GZZBQZAUHYP PMR DCV " }, { "input": "WUBWUBWUBFVWUBWUBWUBBPSWUBWUBWUBRXNETCJWUBWUBWUBJDMBHWUBWUBWUBBWUBWUBVWUBWUBB", "output": "FV BPS RXNETCJ JDMBH B V B " }, { "input": "WUBWUBWUBFBQWUBWUBWUBIDFSYWUBWUBWUBCTWDMWUBWUBWUBSXOWUBWUBWUBQIWUBWUBWUBL", "output": "FBQ IDFSY CTWDM SXO QI L " }, { "input": "IWUBWUBQLHDWUBYIIKZDFQWUBWUBWUBCXWUBWUBUWUBWUBWUBKWUBWUBWUBNL", "output": "I QLHD YIIKZDFQ CX U K NL " }, { "input": "KWUBUPDYXGOKUWUBWUBWUBAGOAHWUBIZDWUBWUBWUBIYWUBWUBWUBVWUBWUBWUBPWUBWUBWUBE", "output": "K UPDYXGOKU AGOAH IZD IY V P E " }, { "input": "WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWUBXHDKCPYKCTWWYWUBWUBWUBVWUBWUBWUBFZWUBWUB", "output": "O IPVCQAFWY Q XHDKCPYKCTWWY V FZ " }, { "input": "PAMJGYWUBWUBWUBXGPQMWUBWUBWUBTKGSXUYWUBWUBWUBEWUBWUBWUBNWUBWUBWUBHWUBWUBWUBEWUBWUB", "output": "PAMJGY XGPQM TKGSXUY E N H E " }, { "input": "WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB", "output": "YYRTSMNWU C C FSYUINDWOBV F AU V JB " }, { "input": "WUBWUBYGPYEYBNRTFKOQCWUBWUBWUBUYGRTQEGWLFYWUBWUBWUBFVWUBHPWUBWUBWUBXZQWUBWUBWUBZDWUBWUBWUBM", "output": "YGPYEYBNRTFKOQC UYGRTQEGWLFY FV HP XZQ ZD M " }, { "input": "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRADWUBWUBWUBCHQVWUBWUBWUBKFTWUBWUBWUBW", "output": "ZVMJ FOIMJQWKNZUBOFOFYCC AUW RDRAD CHQV KFT W " }, { "input": "WUBWUBZBKOKHQLGKRVIMZQMQNRWUBWUBWUBDACWUBWUBNZHFJMPEYKRVSWUBWUBWUBPPHGAVVPRZWUBWUBWUBQWUBWUBAWUBG", "output": "ZBKOKHQLGKRVIMZQMQNR DAC NZHFJMPEYKRVS PPHGAVVPRZ Q A G " }, { "input": "WUBWUBJWUBWUBWUBNFLWUBWUBWUBGECAWUBYFKBYJWTGBYHVSSNTINKWSINWSMAWUBWUBWUBFWUBWUBWUBOVWUBWUBLPWUBWUBWUBN", "output": "J NFL GECA YFKBYJWTGBYHVSSNTINKWSINWSMA F OV LP N " }, { "input": "WUBWUBLCWUBWUBWUBZGEQUEATJVIXETVTWUBWUBWUBEXMGWUBWUBWUBRSWUBWUBWUBVWUBWUBWUBTAWUBWUBWUBCWUBWUBWUBQG", "output": "LC ZGEQUEATJVIXETVT EXMG RS V TA C QG " }, { "input": "WUBMPWUBWUBWUBORWUBWUBDLGKWUBWUBWUBVVZQCAAKVJTIKWUBWUBWUBTJLUBZJCILQDIFVZWUBWUBYXWUBWUBWUBQWUBWUBWUBLWUB", "output": "MP OR DLGK VVZQCAAKVJTIK TJLUBZJCILQDIFVZ YX Q L " }, { "input": "WUBNXOLIBKEGXNWUBWUBWUBUWUBGITCNMDQFUAOVLWUBWUBWUBAIJDJZJHFMPVTPOXHPWUBWUBWUBISCIOWUBWUBWUBGWUBWUBWUBUWUB", "output": "NXOLIBKEGXN U GITCNMDQFUAOVL AIJDJZJHFMPVTPOXHP ISCIO G U " }, { "input": "WUBWUBNMMWCZOLYPNBELIYVDNHJUNINWUBWUBWUBDXLHYOWUBWUBWUBOJXUWUBWUBWUBRFHTGJCEFHCGWARGWUBWUBWUBJKWUBWUBSJWUBWUB", "output": "NMMWCZOLYPNBELIYVDNHJUNIN DXLHYO OJXU RFHTGJCEFHCGWARG JK SJ " }, { "input": "SGWLYSAUJOJBNOXNWUBWUBWUBBOSSFWKXPDPDCQEWUBWUBWUBDIRZINODWUBWUBWUBWWUBWUBWUBPPHWUBWUBWUBRWUBWUBWUBQWUBWUBWUBJWUB", "output": "SGWLYSAUJOJBNOXN BOSSFWKXPDPDCQE DIRZINOD W PPH R Q J " }, { "input": "TOWUBWUBWUBGBTBNWUBWUBWUBJVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSAWUBWUBWUBSWUBWUBWUBTOLVXWUBWUBWUBNHWUBWUBWUBO", "output": "TO GBTBN JVIOJBIZFUUYHUAIEBQLQXPQKZJMPTCWBKPOSA S TOLVX NH O " }, { "input": "WUBWUBWSPLAYSZSAUDSWUBWUBWUBUWUBWUBWUBKRWUBWUBWUBRSOKQMZFIYZQUWUBWUBWUBELSHUWUBWUBWUBUKHWUBWUBWUBQXEUHQWUBWUBWUBBWUBWUBWUBR", "output": "WSPLAYSZSAUDS U KR RSOKQMZFIYZQU ELSHU UKH QXEUHQ B R " }, { "input": "WUBXEMWWVUHLSUUGRWUBWUBWUBAWUBXEGILZUNKWUBWUBWUBJDHHKSWUBWUBWUBDTSUYSJHWUBWUBWUBPXFWUBMOHNJWUBWUBWUBZFXVMDWUBWUBWUBZMWUBWUB", "output": "XEMWWVUHLSUUGR A XEGILZUNK JDHHKS DTSUYSJH PXF MOHNJ ZFXVMD ZM " }, { "input": "BMBWUBWUBWUBOQKWUBWUBWUBPITCIHXHCKLRQRUGXJWUBWUBWUBVWUBWUBWUBJCWUBWUBWUBQJPWUBWUBWUBBWUBWUBWUBBMYGIZOOXWUBWUBWUBTAGWUBWUBHWUB", "output": "BMB OQK PITCIHXHCKLRQRUGXJ V JC QJP B BMYGIZOOX TAG H " }, { "input": "CBZNWUBWUBWUBNHWUBWUBWUBYQSYWUBWUBWUBMWUBWUBWUBXRHBTMWUBWUBWUBPCRCWUBWUBWUBTZUYLYOWUBWUBWUBCYGCWUBWUBWUBCLJWUBWUBWUBSWUBWUBWUB", "output": "CBZN NH YQSY M XRHBTM PCRC TZUYLYO CYGC CLJ S " }, { "input": "DPDWUBWUBWUBEUQKWPUHLTLNXHAEKGWUBRRFYCAYZFJDCJLXBAWUBWUBWUBHJWUBOJWUBWUBWUBNHBJEYFWUBWUBWUBRWUBWUBWUBSWUBWWUBWUBWUBXDWUBWUBWUBJWUB", "output": "DPD EUQKWPUHLTLNXHAEKG RRFYCAYZFJDCJLXBA HJ OJ NHBJEYF R S W XD J " }, { "input": "WUBWUBWUBISERPQITVIYERSCNWUBWUBWUBQWUBWUBWUBDGSDIPWUBWUBWUBCAHKDZWEXBIBJVVSKKVQJWUBWUBWUBKIWUBWUBWUBCWUBWUBWUBAWUBWUBWUBPWUBWUBWUBHWUBWUBWUBF", "output": "ISERPQITVIYERSCN Q DGSDIP CAHKDZWEXBIBJVVSKKVQJ KI C A P H F " }, { "input": "WUBWUBWUBIWUBWUBLIKNQVWUBWUBWUBPWUBWUBWUBHWUBWUBWUBMWUBWUBWUBDPRSWUBWUBWUBBSAGYLQEENWXXVWUBWUBWUBXMHOWUBWUBWUBUWUBWUBWUBYRYWUBWUBWUBCWUBWUBWUBY", "output": "I LIKNQV P H M DPRS BSAGYLQEENWXXV XMHO U YRY C Y " }, { "input": "WUBWUBWUBMWUBWUBWUBQWUBWUBWUBITCFEYEWUBWUBWUBHEUWGNDFNZGWKLJWUBWUBWUBMZPWUBWUBWUBUWUBWUBWUBBWUBWUBWUBDTJWUBHZVIWUBWUBWUBPWUBFNHHWUBWUBWUBVTOWUB", "output": "M Q ITCFEYE HEUWGNDFNZGWKLJ MZP U B DTJ HZVI P FNHH VTO " }, { "input": "WUBWUBNDNRFHYJAAUULLHRRDEDHYFSRXJWUBWUBWUBMUJVDTIRSGYZAVWKRGIFWUBWUBWUBHMZWUBWUBWUBVAIWUBWUBWUBDDKJXPZRGWUBWUBWUBSGXWUBWUBWUBIFKWUBWUBWUBUWUBWUBWUBW", "output": "NDNRFHYJAAUULLHRRDEDHYFSRXJ MUJVDTIRSGYZAVWKRGIF HMZ VAI DDKJXPZRG SGX IFK U W " }, { "input": "WUBOJMWRSLAXXHQRTPMJNCMPGWUBWUBWUBNYGMZIXNLAKSQYWDWUBWUBWUBXNIWUBWUBWUBFWUBWUBWUBXMBWUBWUBWUBIWUBWUBWUBINWUBWUBWUBWDWUBWUBWUBDDWUBWUBWUBD", "output": "OJMWRSLAXXHQRTPMJNCMPG NYGMZIXNLAKSQYWD XNI F XMB I IN WD DD D " }, { "input": "WUBWUBWUBREHMWUBWUBWUBXWUBWUBWUBQASNWUBWUBWUBNLSMHLCMTICWUBWUBWUBVAWUBWUBWUBHNWUBWUBWUBNWUBWUBWUBUEXLSFOEULBWUBWUBWUBXWUBWUBWUBJWUBWUBWUBQWUBWUBWUBAWUBWUB", "output": "REHM X QASN NLSMHLCMTIC VA HN N UEXLSFOEULB X J Q A " }, { "input": "WUBWUBWUBSTEZTZEFFIWUBWUBWUBSWUBWUBWUBCWUBFWUBHRJPVWUBWUBWUBDYJUWUBWUBWUBPWYDKCWUBWUBWUBCWUBWUBWUBUUEOGCVHHBWUBWUBWUBEXLWUBWUBWUBVCYWUBWUBWUBMWUBWUBWUBYWUB", "output": "STEZTZEFFI S C F HRJPV DYJU PWYDKC C UUEOGCVHHB EXL VCY M Y " }, { "input": "WPPNMSQOQIWUBWUBWUBPNQXWUBWUBWUBHWUBWUBWUBNFLWUBWUBWUBGWSGAHVJFNUWUBWUBWUBFWUBWUBWUBWCMLRICFSCQQQTNBWUBWUBWUBSWUBWUBWUBKGWUBWUBWUBCWUBWUBWUBBMWUBWUBWUBRWUBWUB", "output": "WPPNMSQOQI PNQX H NFL GWSGAHVJFNU F WCMLRICFSCQQQTNB S KG C BM R " }, { "input": "YZJOOYITZRARKVFYWUBWUBRZQGWUBWUBWUBUOQWUBWUBWUBIWUBWUBWUBNKVDTBOLETKZISTWUBWUBWUBWLWUBQQFMMGSONZMAWUBZWUBWUBWUBQZUXGCWUBWUBWUBIRZWUBWUBWUBLTTVTLCWUBWUBWUBY", "output": "YZJOOYITZRARKVFY RZQG UOQ I NKVDTBOLETKZIST WL QQFMMGSONZMA Z QZUXGC IRZ LTTVTLC Y " }, { "input": "WUBCAXNCKFBVZLGCBWCOAWVWOFKZVQYLVTWUBWUBWUBNLGWUBWUBWUBAMGDZBDHZMRMQMDLIRMIWUBWUBWUBGAJSHTBSWUBWUBWUBCXWUBWUBWUBYWUBZLXAWWUBWUBWUBOHWUBWUBWUBZWUBWUBWUBGBWUBWUBWUBE", "output": "CAXNCKFBVZLGCBWCOAWVWOFKZVQYLVT NLG AMGDZBDHZMRMQMDLIRMI GAJSHTBS CX Y ZLXAW OH Z GB E " }, { "input": "WUBWUBCHXSOWTSQWUBWUBWUBCYUZBPBWUBWUBWUBSGWUBWUBWKWORLRRLQYUUFDNWUBWUBWUBYYGOJNEVEMWUBWUBWUBRWUBWUBWUBQWUBWUBWUBIHCKWUBWUBWUBKTWUBWUBWUBRGSNTGGWUBWUBWUBXCXWUBWUBWUBS", "output": "CHXSOWTSQ CYUZBPB SG WKWORLRRLQYUUFDN YYGOJNEVEM R Q IHCK KT RGSNTGG XCX S " }, { "input": "WUBWUBWUBHJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQWUBWUBWUBXTZKGIITWUBWUBWUBAWUBWUBWUBVNCXPUBCQWUBWUBWUBIDPNAWUBWUBWUBOWUBWUBWUBYGFWUBWUBWUBMQOWUBWUBWUBKWUBWUBWUBAZVWUBWUBWUBEP", "output": "HJHMSBURXTHXWSCHNAIJOWBHLZGJZDHEDSPWBWACCGQ XTZKGIIT A VNCXPUBCQ IDPNA O YGF MQO K AZV EP " }, { "input": "WUBKYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTVWUBWUBWUBLRMIIWUBWUBWUBGWUBWUBWUBADPSWUBWUBWUBANBWUBWUBPCWUBWUBWUBPWUBWUBWUBGPVNLSWIRFORYGAABUXMWUBWUBWUBOWUBWUBWUBNWUBWUBWUBYWUBWUB", "output": "KYDZOYWZSNGMKJSWAXFDFLTHDHEOGTDBNZMSMKZTV LRMII G ADPS ANB PC P GPVNLSWIRFORYGAABUXM O N Y " }, { "input": "REWUBWUBWUBJDWUBWUBWUBNWUBWUBWUBTWWUBWUBWUBWZDOCKKWUBWUBWUBLDPOVBFRCFWUBWUBAKZIBQKEUAZEEWUBWUBWUBLQYPNPFWUBYEWUBWUBWUBFWUBWUBWUBBPWUBWUBWUBAWWUBWUBWUBQWUBWUBWUBBRWUBWUBWUBXJL", "output": "RE JD N TW WZDOCKK LDPOVBFRCF AKZIBQKEUAZEE LQYPNPF YE F BP AW Q BR XJL " }, { "input": "CUFGJDXGMWUBWUBWUBOMWUBWUBWUBSIEWUBWUBWUBJJWKNOWUBWUBWUBYBHVNRNORGYWUBWUBWUBOAGCAWUBWUBWUBSBLBKTPFKPBIWUBWUBWUBJBWUBWUBWUBRMFCJPGWUBWUBWUBDWUBWUBWUBOJOWUBWUBWUBZPWUBWUBWUBMWUBRWUBWUBWUBFXWWUBWUBWUBO", "output": "CUFGJDXGM OM SIE JJWKNO YBHVNRNORGY OAGCA SBLBKTPFKPBI JB RMFCJPG D OJO ZP M R FXW O " }, { "input": "WUBJZGAEXFMFEWMAKGQLUWUBWUBWUBICYTPQWGENELVYWANKUOJYWUBWUBWUBGWUBWUBWUBHYCJVLPHTUPNEGKCDGQWUBWUBWUBOFWUBWUBWUBCPGSOGZBRPRPVJJEWUBWUBWUBDQBCWUBWUBWUBHWUBWUBWUBMHOHYBMATWUBWUBWUBVWUBWUBWUBSWUBWUBWUBKOWU", "output": "JZGAEXFMFEWMAKGQLU ICYTPQWGENELVYWANKUOJY G HYCJVLPHTUPNEGKCDGQ OF CPGSOGZBRPRPVJJE DQBC H MHOHYBMAT V S KOWU " }, { "input": "A", "output": "A " }, { "input": "WUBA", "output": "A " }, { "input": "WUBWUBA", "output": "A " }, { "input": "AWUBWUBWUB", "output": "A " }, { "input": "AWUBBWUBCWUBD", "output": "A B C D " }, { "input": "WUBWWUBWUBWUBUWUBWUBBWUB", "output": "W U B " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWUBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA " }, { "input": "WUWUBBWWUBUB", "output": "WU BW UB " }, { "input": "WUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUABWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUBWUB", "output": "WUAB " }, { "input": "ZWUB", "output": "Z " }, { "input": "WU", "output": "WU " }, { "input": "UB", "output": "UB " }, { "input": "U", "output": "U " }, { "input": "WUBW", "output": "W " }, { "input": "WUBWU", "output": "WU " }, { "input": "WUWUB", "output": "WU " }, { "input": "UBWUB", "output": "UB " }, { "input": "WUWUBUBWUBUWUB", "output": "WU UB U " }, { "input": "WUBWWUBAWUB", "output": "W A " }, { "input": "WUUUUU", "output": "WUUUUU " } ]
1,682,516,648
2,147,483,647
PyPy 3-64
OK
TESTS
71
216
0
s = input() s = s.replace("WUB", " ") c = s.split() for i in range(len(c)): print(c[i], end = ' ')
Title: Dubstep Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. Input Specification: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. Output Specification: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Demo Input: ['WUBWUBABCWUB\n', 'WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n'] Demo Output: ['ABC ', 'WE ARE THE CHAMPIONS MY FRIEND '] Note: In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya. In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE" and "THE" — between them Vasya added two "WUB".
```python s = input() s = s.replace("WUB", " ") c = s.split() for i in range(len(c)): print(c[i], end = ' ') ```
3
937
A
Olympiad
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score.
Print a single integer — the desired number of ways.
[ "4\n1 3 3 2\n", "3\n1 1 1\n", "4\n42 0 0 42\n" ]
[ "3\n", "1\n", "1\n" ]
There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
500
[ { "input": "4\n1 3 3 2", "output": "3" }, { "input": "3\n1 1 1", "output": "1" }, { "input": "4\n42 0 0 42", "output": "1" }, { "input": "10\n1 0 1 0 1 0 0 0 0 1", "output": "1" }, { "input": "10\n572 471 540 163 50 30 561 510 43 200", "output": "10" }, { "input": "100\n122 575 426 445 172 81 247 429 97 202 175 325 382 384 417 356 132 502 328 537 57 339 518 211 479 306 140 168 268 16 140 263 593 249 391 310 555 468 231 180 157 18 334 328 276 155 21 280 322 545 111 267 467 274 291 304 235 34 365 180 21 95 501 552 325 331 302 353 296 22 289 399 7 466 32 302 568 333 75 192 284 10 94 128 154 512 9 480 243 521 551 492 420 197 207 125 367 117 438 600", "output": "94" }, { "input": "100\n600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600 600", "output": "1" }, { "input": "78\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12", "output": "13" }, { "input": "34\n220 387 408 343 184 447 197 307 337 414 251 319 426 322 347 242 208 412 188 185 241 235 216 259 331 372 322 284 444 384 214 297 389 391", "output": "33" }, { "input": "100\n1 2 1 0 3 0 2 0 0 1 2 0 1 3 0 3 3 1 3 0 0 2 1 2 2 1 3 3 3 3 3 2 0 0 2 1 2 3 2 3 0 1 1 3 3 2 0 3 1 0 2 2 2 1 2 3 2 1 0 3 0 2 0 3 0 2 1 0 3 1 0 2 2 1 3 1 3 0 2 3 3 1 1 3 1 3 0 3 2 0 2 3 3 0 2 0 2 0 1 3", "output": "3" }, { "input": "100\n572 471 540 163 50 30 561 510 43 200 213 387 500 424 113 487 357 333 294 337 435 202 447 494 485 465 161 344 470 559 104 356 393 207 224 213 511 514 60 386 149 216 392 229 429 173 165 401 395 150 127 579 344 390 529 296 225 425 318 79 465 447 177 110 367 212 459 270 41 500 277 567 125 436 178 9 214 342 203 112 144 24 79 155 495 556 40 549 463 281 241 316 2 246 1 396 510 293 332 55", "output": "93" }, { "input": "99\n5 4 13 2 5 6 2 10 10 1 2 6 7 9 6 3 5 7 1 10 2 2 7 0 2 11 11 3 1 13 3 10 6 2 0 3 0 5 0 1 4 11 1 1 7 0 12 7 5 12 0 2 12 9 8 3 4 3 4 11 4 10 2 3 10 12 5 6 1 11 2 0 8 7 9 1 3 12 2 3 9 3 7 13 7 13 0 11 8 12 2 5 9 4 0 6 6 2 13", "output": "13" }, { "input": "99\n1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 0 0 0 0 0 1", "output": "1" }, { "input": "99\n21 74 25 44 71 80 46 28 96 1 74 24 81 83 16 55 31 1 27 36 56 38 17 10 78 5 39 67 67 15 39 62 92 48 90 9 54 67 30 79 56 17 33 27 75 54 20 79 21 44 10 66 66 73 90 3 34 33 64 79 20 94 0 51 24 30 1 52 95 21 88 98 6 65 31 1 67 32 74 91 83 9 93 27 53 11 8 79 42 20 50 91 19 96 6 24 66 16 37", "output": "61" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n0 600", "output": "1" }, { "input": "4\n1 1 1 2", "output": "2" }, { "input": "4\n0 0 1 2", "output": "2" }, { "input": "1\n5", "output": "1" }, { "input": "2\n0 5", "output": "1" }, { "input": "5\n1 0 0 1 2", "output": "2" } ]
1,596,063,674
2,147,483,647
Python 3
OK
TESTS
21
109
6,656,000
def solution(): n = int(input()) arr = [int(i) for i in input().split(' ') if int(i) != 0] print(len(set(arr))) if __name__ == "__main__": solution()
Title: Olympiad Time Limit: None seconds Memory Limit: None megabytes Problem Description: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. Output Specification: Print a single integer — the desired number of ways. Demo Input: ['4\n1 3 3 2\n', '3\n1 1 1\n', '4\n42 0 0 42\n'] Demo Output: ['3\n', '1\n', '1\n'] Note: There are three ways to choose a subset in sample case one. 1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma! The only option in sample case two is to award everyone. Note that in sample case three participants with zero scores cannot get anything.
```python def solution(): n = int(input()) arr = [int(i) for i in input().split(' ') if int(i) != 0] print(len(set(arr))) if __name__ == "__main__": solution() ```
3
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": "6" }, { "input": "5 1\n998 997 985 937 998", "output": "0" }, { "input": "2 2\n-742 -187", "output": "929" }, { "input": "3 3\n522 597 384", "output": "0" }, { "input": "4 2\n-215 -620 192 647", "output": "835" }, { "input": "10 6\n557 605 685 231 910 633 130 838 -564 -85", "output": "649" }, { "input": "20 14\n932 442 960 943 624 624 955 998 631 910 850 517 715 123 1000 155 -10 961 966 59", "output": "10" }, { "input": "30 5\n991 997 996 967 977 999 991 986 1000 965 984 997 998 1000 958 983 974 1000 991 999 1000 978 961 992 990 998 998 978 998 1000", "output": "0" }, { "input": "50 20\n-815 -947 -946 -993 -992 -846 -884 -954 -963 -733 -940 -746 -766 -930 -821 -937 -937 -999 -914 -938 -936 -975 -939 -981 -977 -952 -925 -901 -952 -978 -994 -957 -946 -896 -905 -836 -994 -951 -887 -939 -859 -953 -985 -988 -946 -829 -956 -842 -799 -886", "output": "19441" }, { "input": "88 64\n999 999 1000 1000 999 996 995 1000 1000 999 1000 997 998 1000 999 1000 997 1000 993 998 994 999 998 996 1000 997 1000 1000 1000 997 1000 998 997 1000 1000 998 1000 998 999 1000 996 999 999 999 996 995 999 1000 998 999 1000 999 999 1000 1000 1000 996 1000 1000 1000 997 1000 1000 997 999 1000 1000 1000 1000 1000 999 999 1000 1000 996 999 1000 1000 995 999 1000 996 1000 998 999 999 1000 999", "output": "0" }, { "input": "99 17\n-993 -994 -959 -989 -991 -995 -976 -997 -990 -1000 -996 -994 -999 -995 -1000 -983 -979 -1000 -989 -968 -994 -992 -962 -993 -999 -983 -991 -979 -995 -993 -973 -999 -995 -995 -999 -993 -995 -992 -947 -1000 -999 -998 -982 -988 -979 -993 -963 -988 -980 -990 -979 -976 -995 -999 -981 -988 -998 -999 -970 -1000 -983 -994 -943 -975 -998 -977 -973 -997 -959 -999 -983 -985 -950 -977 -977 -991 -998 -973 -987 -985 -985 -986 -984 -994 -978 -998 -989 -989 -988 -970 -985 -974 -997 -981 -962 -972 -995 -988 -993", "output": "16984" }, { "input": "100 37\n205 19 -501 404 912 -435 -322 -469 -655 880 -804 -470 793 312 -108 586 -642 -928 906 605 -353 -800 745 -440 -207 752 -50 -28 498 -800 -62 -195 602 -833 489 352 536 404 -775 23 145 -512 524 759 651 -461 -427 -557 684 -366 62 592 -563 -811 64 418 -881 -308 591 -318 -145 -261 -321 -216 -18 595 -202 960 -4 219 226 -238 -882 -963 425 970 -434 -160 243 -672 -4 873 8 -633 904 -298 -151 -377 -61 -72 -677 -66 197 -716 3 -870 -30 152 -469 981", "output": "21743" }, { "input": "100 99\n-931 -806 -830 -828 -916 -962 -660 -867 -952 -966 -820 -906 -724 -982 -680 -717 -488 -741 -897 -613 -986 -797 -964 -939 -808 -932 -810 -860 -641 -916 -858 -628 -821 -929 -917 -976 -664 -985 -778 -665 -624 -928 -940 -958 -884 -757 -878 -896 -634 -526 -514 -873 -990 -919 -988 -878 -650 -973 -774 -783 -733 -648 -756 -895 -833 -974 -832 -725 -841 -748 -806 -613 -924 -867 -881 -943 -864 -991 -809 -926 -777 -817 -998 -682 -910 -996 -241 -722 -964 -904 -821 -920 -835 -699 -805 -632 -779 -317 -915 -654", "output": "81283" }, { "input": "100 14\n995 994 745 684 510 737 984 690 979 977 542 933 871 603 758 653 962 997 747 974 773 766 975 770 527 960 841 989 963 865 974 967 950 984 757 685 986 809 982 959 931 880 978 867 805 562 970 900 834 782 616 885 910 608 974 918 576 700 871 980 656 941 978 759 767 840 573 859 841 928 693 853 716 927 976 851 962 962 627 797 707 873 869 988 993 533 665 887 962 880 929 980 877 887 572 790 721 883 848 782", "output": "0" }, { "input": "100 84\n768 946 998 752 931 912 826 1000 991 910 875 962 901 952 958 733 959 908 872 840 923 826 952 980 974 980 947 955 959 822 997 963 966 933 829 923 971 999 926 932 865 984 974 858 994 855 949 941 992 861 951 949 991 711 763 728 935 485 716 907 869 952 960 859 909 963 978 942 968 933 923 909 997 962 687 764 924 774 875 1000 961 951 987 974 848 921 966 859 995 997 974 931 886 941 974 986 906 978 998 823", "output": "0" }, { "input": "100 80\n-795 -994 -833 -930 -974 -980 -950 -940 -788 -927 -583 -956 -945 -949 -809 -974 -957 -736 -967 -908 -975 -961 -986 -983 -963 -771 -952 -847 -751 -741 -982 -959 -925 -931 -839 -937 -880 -914 -858 -998 -812 -911 -862 -965 -943 -984 -738 -920 -950 -998 -909 -998 -781 -901 -677 -940 -985 -951 -675 -952 -967 -949 -882 -641 -969 -937 -975 -993 -913 -941 -807 -851 -832 -960 -939 -943 -895 -929 -528 -880 -823 -930 -888 -862 -948 -966 -962 -857 -799 -969 -833 -998 -952 -878 -946 -971 -976 -974 -723 -992", "output": "75068" }, { "input": "1 1\n0", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 1\n555", "output": "0" }, { "input": "1 1\n-1", "output": "1" }, { "input": "1 1\n-24", "output": "24" } ]
1,671,662,112
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
122
0
a,b=[int(x) for x in input().split(" ")] arr=[int(x) for x in input().split(" ")] arr.sort() ans=0 for i in range(a): if i == b: break if arr[i] < 0: ans+=arr[i]*-1 else: ans+=arr[i] print(ans)
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 a,b=[int(x) for x in input().split(" ")] arr=[int(x) for x in input().split(" ")] arr.sort() ans=0 for i in range(a): if i == b: break if arr[i] < 0: ans+=arr[i]*-1 else: ans+=arr[i] print(ans) ```
0
312
B
Archer
PROGRAMMING
1,300
[ "math", "probabilities" ]
null
null
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match.
A single line contains four integers .
Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6.
[ "1 2 1 2\n" ]
[ "0.666666666667" ]
none
1,000
[ { "input": "1 2 1 2", "output": "0.666666666667" }, { "input": "1 3 1 3", "output": "0.600000000000" }, { "input": "1 3 2 3", "output": "0.428571428571" }, { "input": "3 4 3 4", "output": "0.800000000000" }, { "input": "1 2 10 11", "output": "0.523809523810" }, { "input": "4 5 4 5", "output": "0.833333333333" }, { "input": "466 701 95 721", "output": "0.937693791148" }, { "input": "268 470 444 885", "output": "0.725614009325" }, { "input": "632 916 713 821", "output": "0.719292895126" }, { "input": "269 656 918 992", "output": "0.428937461623" }, { "input": "71 657 187 695", "output": "0.310488463257" }, { "input": "435 852 973 978", "output": "0.511844133157" }, { "input": "518 816 243 359", "output": "0.719734031025" }, { "input": "882 962 311 811", "output": "0.966386645447" }, { "input": "684 774 580 736", "output": "0.906051574446" }, { "input": "486 868 929 999", "output": "0.577723252958" }, { "input": "132 359 996 998", "output": "0.368154532345" }, { "input": "933 977 266 450", "output": "0.972879407907" }, { "input": "298 833 615 872", "output": "0.441270817024" }, { "input": "34 554 14 958", "output": "0.817324099167" }, { "input": "836 934 800 905", "output": "0.906105535462" }, { "input": "482 815 69 509", "output": "0.914365577772" }, { "input": "284 423 137 521", "output": "0.885974839378" }, { "input": "648 881 486 703", "output": "0.800911421248" }, { "input": "450 885 755 836", "output": "0.533901011176" }, { "input": "533 773 823 998", "output": "0.729222130525" }, { "input": "897 957 92 898", "output": "0.993193806364" }, { "input": "699 925 441 928", "output": "0.866816866175" }, { "input": "64 704 148 603", "output": "0.289486317811" }, { "input": "719 735 626 990", "output": "0.986124079764" }, { "input": "1 1000 1 1000", "output": "0.500250125063" } ]
1,692,386,343
2,147,483,647
Python 3
OK
TESTS
31
46
0
prob = input().split() a = int(prob[0]) b = int(prob[1]) c = int(prob[2]) d = int(prob[3]) prob1 = a/b prob2 = c/d ptotal = prob1/(1 - ((1-prob1)*(1-prob2))) print(round(ptotal, 12))
Title: Archer Time Limit: None seconds Memory Limit: None megabytes Problem Description: SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner. Output the probability that SmallR will win the match. Input Specification: A single line contains four integers . Output Specification: Print a single real number, the probability that SmallR will win the match. The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. Demo Input: ['1 2 1 2\n'] Demo Output: ['0.666666666667'] Note: none
```python prob = input().split() a = int(prob[0]) b = int(prob[1]) c = int(prob[2]) d = int(prob[3]) prob1 = a/b prob2 = c/d ptotal = prob1/(1 - ((1-prob1)*(1-prob2))) print(round(ptotal, 12)) ```
3
955
A
Feed the cat
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts. Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero.
The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening. The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102).
Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if .
[ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n" ]
[ "25200.0000\n", "1365.0000\n" ]
In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.
500
[ { "input": "19 00\n255 1 100 1", "output": "25200.0000" }, { "input": "17 41\n1000 6 15 11", "output": "1365.0000" }, { "input": "16 34\n61066 14 50 59", "output": "43360.0000" }, { "input": "18 18\n23331 86 87 41", "output": "49590.0000" }, { "input": "10 48\n68438 8 18 29", "output": "36187.2000" }, { "input": "08 05\n63677 9 83 25", "output": "186252.0000" }, { "input": "00 00\n100000 100 100 100", "output": "100000.0000" }, { "input": "20 55\n100000 100 100 100", "output": "80000.0000" }, { "input": "23 59\n100000 100 100 100", "output": "80000.0000" }, { "input": "00 00\n1 100 100 100", "output": "100.0000" }, { "input": "21 26\n33193 54 97 66", "output": "39032.8000" }, { "input": "20 45\n33756 24 21 1", "output": "567100.8000" }, { "input": "14 33\n92062 59 89 72", "output": "110146.4000" }, { "input": "01 24\n92730 5 35 29", "output": "94920.0000" }, { "input": "20 58\n93398 43 86 99", "output": "64947.2000" }, { "input": "23 04\n37170 81 32 64", "output": "14873.6000" }, { "input": "01 38\n70542 27 74 26", "output": "200836.0000" }, { "input": "04 28\n38505 65 25 95", "output": "10150.0000" }, { "input": "00 10\n33077 21 40 22", "output": "60160.0000" }, { "input": "10 44\n66449 67 90 83", "output": "72090.0000" }, { "input": "05 51\n10220 5 33 48", "output": "7029.0000" }, { "input": "20 19\n68886 28 48 94", "output": "28147.2000" }, { "input": "01 49\n11621 55 78 46", "output": "19734.0000" }, { "input": "21 28\n78549 91 4 98", "output": "2566.4000" }, { "input": "18 06\n88580 22 35 59", "output": "43232.0000" }, { "input": "22 28\n55507 53 61 11", "output": "246293.6000" }, { "input": "18 58\n22434 84 91 59", "output": "34143.2000" }, { "input": "15 36\n32466 27 22 15", "output": "46464.0000" }, { "input": "17 31\n9603 53 73 74", "output": "9490.0000" }, { "input": "14 53\n76530 92 4 22", "output": "13916.0000" }, { "input": "18 31\n10753 23 30 74", "output": "4152.0000" }, { "input": "17 43\n16290 46 90 94", "output": "15660.0000" }, { "input": "18 38\n3652 11 53 94", "output": "2067.0000" }, { "input": "19 57\n3 4 7 6", "output": "7.0000" } ]
1,521,838,133
2,147,483,647
Python 3
OK
TESTS
34
77
7,065,600
from math import ceil hh,mm=map(int,input().split()) h,d,c,n=map(int,input().split()) mins=0 if hh<20: mins=(60*(19-hh)+(60-mm)) new_h=h+mins*d print(min((ceil(h/n))*c,ceil(new_h/n)*c*0.8))
Title: Feed the cat Time Limit: None seconds Memory Limit: None megabytes Problem Description: After waking up at *hh*:*mm*, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is *H* points, moreover each minute without food increases his hunger by *D* points. At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs *C* roubles and decreases hunger by *N* points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts. Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero. Input Specification: The first line contains two integers *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59) — the time of Andrew's awakening. The second line contains four integers *H*, *D*, *C* and *N* (1<=≤<=*H*<=≤<=105,<=1<=≤<=*D*,<=*C*,<=*N*<=≤<=102). Output Specification: Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10<=-<=4. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Demo Input: ['19 00\n255 1 100 1\n', '17 41\n1000 6 15 11\n'] Demo Output: ['25200.0000\n', '1365.0000\n'] Note: In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles.
```python from math import ceil hh,mm=map(int,input().split()) h,d,c,n=map(int,input().split()) mins=0 if hh<20: mins=(60*(19-hh)+(60-mm)) new_h=h+mins*d print(min((ceil(h/n))*c,ceil(new_h/n)*c*0.8)) ```
3
1,004
C
Sonya and Robots
PROGRAMMING
1,400
[ "constructive algorithms", "implementation" ]
null
null
Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet.
The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row.
Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet.
[ "5\n1 5 4 1 3\n", "7\n1 2 1 1 1 3 2\n" ]
[ "9\n", "7\n" ]
In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
1,500
[ { "input": "5\n1 5 4 1 3", "output": "9" }, { "input": "7\n1 2 1 1 1 3 2", "output": "7" }, { "input": "10\n2 2 4 4 3 1 1 2 3 2", "output": "14" }, { "input": "15\n1 2 2 1 2 4 2 1 1 6 6 4 2 5 4", "output": "20" }, { "input": "1\n1", "output": "0" } ]
1,530,849,607
2,707
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
1,000
7,065,600
n=int(input()) a=[int(x) for x in input().split()] tried=set([]) ans=0 for i in range(n-1): if(not(a[i] in tried)): tried.add(a[i]) tested=set([]) for j in range(i+1,n): tested.add(a[j]) ans+=len(tested) print(ans)
Title: Sonya and Robots Time Limit: None seconds Memory Limit: None megabytes Problem Description: Since Sonya is interested in robotics too, she decided to construct robots that will read and recognize numbers. Sonya has drawn $n$ numbers in a row, $a_i$ is located in the $i$-th position. She also has put a robot at each end of the row (to the left of the first number and to the right of the last number). Sonya will give a number to each robot (they can be either same or different) and run them. When a robot is running, it is moving toward to another robot, reading numbers in the row. When a robot is reading a number that is equal to the number that was given to that robot, it will turn off and stay in the same position. Sonya does not want robots to break, so she will give such numbers that robots will stop before they meet. That is, the girl wants them to stop at different positions so that the first robot is to the left of the second one. For example, if the numbers $[1, 5, 4, 1, 3]$ are written, and Sonya gives the number $1$ to the first robot and the number $4$ to the second one, the first robot will stop in the $1$-st position while the second one in the $3$-rd position. In that case, robots will not meet each other. As a result, robots will not be broken. But if Sonya gives the number $4$ to the first robot and the number $5$ to the second one, they will meet since the first robot will stop in the $3$-rd position while the second one is in the $2$-nd position. Sonya understands that it does not make sense to give a number that is not written in the row because a robot will not find this number and will meet the other robot. Sonya is now interested in finding the number of different pairs that she can give to robots so that they will not meet. In other words, she wants to know the number of pairs ($p$, $q$), where she will give $p$ to the first robot and $q$ to the second one. Pairs ($p_i$, $q_i$) and ($p_j$, $q_j$) are different if $p_i\neq p_j$ or $q_i\neq q_j$. Unfortunately, Sonya is busy fixing robots that broke after a failed launch. That is why she is asking you to find the number of pairs that she can give to robots so that they will not meet. Input Specification: The first line contains a single integer $n$ ($1\leq n\leq 10^5$) — the number of numbers in a row. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\leq a_i\leq 10^5$) — the numbers in a row. Output Specification: Print one number — the number of possible pairs that Sonya can give to robots so that they will not meet. Demo Input: ['5\n1 5 4 1 3\n', '7\n1 2 1 1 1 3 2\n'] Demo Output: ['9\n', '7\n'] Note: In the first example, Sonya can give pairs ($1$, $1$), ($1$, $3$), ($1$, $4$), ($1$, $5$), ($4$, $1$), ($4$, $3$), ($5$, $1$), ($5$, $3$), and ($5$, $4$). In the second example, Sonya can give pairs ($1$, $1$), ($1$, $2$), ($1$, $3$), ($2$, $1$), ($2$, $2$), ($2$, $3$), and ($3$, $2$).
```python n=int(input()) a=[int(x) for x in input().split()] tried=set([]) ans=0 for i in range(n-1): if(not(a[i] in tried)): tried.add(a[i]) tested=set([]) for j in range(i+1,n): tested.add(a[j]) ans+=len(tested) print(ans) ```
0
149
D
Coloring Brackets
PROGRAMMING
1,900
[ "dp" ]
null
null
Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a correct mathematical expression from it, inserting numbers and operators between the brackets. For example, such sequences as "(())()" and "()" are correct bracket sequences and such sequences as ")()" and "(()" are not. In a correct bracket sequence each bracket corresponds to the matching bracket (an opening bracket corresponds to the matching closing bracket and vice versa). For example, in a bracket sequence shown of the figure below, the third bracket corresponds to the matching sixth one and the fifth bracket corresponds to the fourth one. You are allowed to color some brackets in the bracket sequence so as all three conditions are fulfilled: - Each bracket is either not colored any color, or is colored red, or is colored blue. - For any pair of matching brackets exactly one of them is colored. In other words, for any bracket the following is true: either it or the matching bracket that corresponds to it is colored. - No two neighboring colored brackets have the same color. Find the number of different ways to color the bracket sequence. The ways should meet the above-given conditions. Two ways of coloring are considered different if they differ in the color of at least one bracket. As the result can be quite large, print it modulo 1000000007 (109<=+<=7).
The first line contains the single string *s* (2<=≤<=|*s*|<=≤<=700) which represents a correct bracket sequence.
Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109<=+<=7).
[ "(())\n", "(()())\n", "()\n" ]
[ "12\n", "40\n", "4\n" ]
Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
2,500
[ { "input": "(())", "output": "12" }, { "input": "(()())", "output": "40" }, { "input": "()", "output": "4" }, { "input": "((()))", "output": "36" }, { "input": "()(())", "output": "42" }, { "input": "()()()", "output": "48" }, { "input": "(())(())", "output": "126" }, { "input": "()()()()()()()()()()()(())", "output": "9085632" }, { "input": "()(())()((()))", "output": "4428" }, { "input": "()()(())()(())", "output": "5040" }, { "input": "()()()()()()()()()()()()()()()()", "output": "411525376" }, { "input": "(()()())", "output": "136" }, { "input": "()(()())()", "output": "480" }, { "input": "(())()(())()", "output": "1476" }, { "input": "()()(()())(())()()()", "output": "195840" }, { "input": "()()()((((())))())()()()()()((()))()()(())()(((())))()(()())((())())((()())(((((()()()())()()())))))", "output": "932124942" }, { "input": "((()(((((()(()(())))()((((((((())))()(((((())()((((())())(()(()(())())((()))()((()))))))))))))))))))))", "output": "90824888" }, { "input": "((()))((())())((()()))()(())(()())(())()()()((()(((()())))()())()((((()((()((())))(())(()(())())))((()())()()()((())()))()(())(())))()(((((()())))))))", "output": "100627207" }, { "input": "()(((()((((()())))())(())(((((()(()()))))()()))((())))()())((())))(())()((()())())()(()(()())())(()())()(()(((((()))()((()()(())()(())(()((()((()))))()(())()()(()()()((((()())()))))()(((()(((((()()((((())(())))()())(()))(((())((()())(()))())(((()()()(()(())())())(()()()))))())))()((()(()()(()))())((())(()()()(())()))()()(((())))((()))(()((()(((()))((((()())))())(((())()(()((())))))))))))))))))))))", "output": "306199947" }, { "input": "(())(((((()()()()())(())))(()()((()(()(((((())(()())))())(()()(()((())()(()()))))))(())()())))()((()()())))()()(()(())())()())()(())(((((()(()()(((()())()))((())((((()()()))())(((())(((())))))))))))))", "output": "270087235" }, { "input": "()()()((()))(())(((())()(())(())))()()(((()((()()()))(()()(())(())))(()()((()((())(()()(()(())))))))(((())()((((()())))()(((()()())))()))()())))()(()(()())((()((()))))())(((((()())()((((()))(((((()())()))(((()()()((((((()()(())(()))((()(()(()((()((((()(((()(()()(()()((((()))()()()(()((((()(((())(((()()()(())()))((()()()(()))))())()))))(((((((()))())))(((()(()())(())))())))((((())(())())(((()()()))((()()))())(()))(())((()(()))(()()((()(()((()(())(()))()()))))))))))))))))))))))))))))))))))))))))))", "output": "461776571" }, { "input": "()()(((((()((()(())()(()))(()(()(()(()(())(())(())(()(()((())))()))())((()((()(()(((()(()))()(()())(()()()()(((((()(((()))((((())())(((()((((()((((((())())))()))))))))(())())))(((()((()))))((())(()()))()(()(()((()())())()))))((()))))()((())())(()())()())))())())())())()((()((())((()()())()())())()(())()))(()(()))())))(()()()())()())))))))((((()())))((((()()()))())((()(())))))()((()(((())()()()(()()()()()))))(((()())()))()()(((())(()())(()()))))))", "output": "66338682" }, { "input": "(()())()()()((((()(()()(())()((())(((()((()()(()))()))()()))))()(()(())(()))))))", "output": "639345575" }, { "input": "()((()))((((()((())((()()((((()))()()((())((()(((((()(()))((())()))((((())()(()(()))()))))))))))))))))))", "output": "391997323" }, { "input": "(((((()())))))()()()()()(())()()()((()()))()()()()()(((()(())))())(((()())))", "output": "422789312" }, { "input": "((()((()))()((()(()))())))()((()())())()(()())((()))(()())(())()(())()(())(())((()()))((()))()()()()(())()", "output": "140121189" }, { "input": "()()", "output": "14" } ]
1,696,387,753
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
60
0
# LUOGU_RID: 127442379 print("4")
Title: Coloring Brackets Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it. You are given string *s*. It represents a correct bracket sequence. A correct bracket sequence is the sequence of opening ("(") and closing (")") brackets, such that it is possible to obtain a correct mathematical expression from it, inserting numbers and operators between the brackets. For example, such sequences as "(())()" and "()" are correct bracket sequences and such sequences as ")()" and "(()" are not. In a correct bracket sequence each bracket corresponds to the matching bracket (an opening bracket corresponds to the matching closing bracket and vice versa). For example, in a bracket sequence shown of the figure below, the third bracket corresponds to the matching sixth one and the fifth bracket corresponds to the fourth one. You are allowed to color some brackets in the bracket sequence so as all three conditions are fulfilled: - Each bracket is either not colored any color, or is colored red, or is colored blue. - For any pair of matching brackets exactly one of them is colored. In other words, for any bracket the following is true: either it or the matching bracket that corresponds to it is colored. - No two neighboring colored brackets have the same color. Find the number of different ways to color the bracket sequence. The ways should meet the above-given conditions. Two ways of coloring are considered different if they differ in the color of at least one bracket. As the result can be quite large, print it modulo 1000000007 (109<=+<=7). Input Specification: The first line contains the single string *s* (2<=≤<=|*s*|<=≤<=700) which represents a correct bracket sequence. Output Specification: Print the only number — the number of ways to color the bracket sequence that meet the above given conditions modulo 1000000007 (109<=+<=7). Demo Input: ['(())\n', '(()())\n', '()\n'] Demo Output: ['12\n', '40\n', '4\n'] Note: Let's consider the first sample test. The bracket sequence from the sample can be colored, for example, as is shown on two figures below. The two ways of coloring shown below are incorrect.
```python # LUOGU_RID: 127442379 print("4") ```
0
911
B
Two Cakes
PROGRAMMING
1,200
[ "binary search", "brute force", "implementation" ]
null
null
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*!
The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake.
[ "5 2 3\n", "4 7 10\n" ]
[ "1\n", "3\n" ]
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
0
[ { "input": "5 2 3", "output": "1" }, { "input": "4 7 10", "output": "3" }, { "input": "100 100 100", "output": "2" }, { "input": "10 100 3", "output": "3" }, { "input": "2 9 29", "output": "9" }, { "input": "4 6 10", "output": "3" }, { "input": "3 70 58", "output": "35" }, { "input": "5 7 10", "output": "3" }, { "input": "5 30 22", "output": "10" }, { "input": "5 5 6", "output": "2" }, { "input": "2 4 3", "output": "3" }, { "input": "10 10 31", "output": "3" }, { "input": "2 1 1", "output": "1" }, { "input": "10 98 99", "output": "19" }, { "input": "4 10 16", "output": "5" }, { "input": "11 4 8", "output": "1" }, { "input": "5 10 14", "output": "4" }, { "input": "6 7 35", "output": "7" }, { "input": "5 6 7", "output": "2" }, { "input": "4 15 3", "output": "3" }, { "input": "7 48 77", "output": "16" }, { "input": "4 4 10", "output": "3" }, { "input": "4 7 20", "output": "6" }, { "input": "5 2 8", "output": "2" }, { "input": "3 2 3", "output": "1" }, { "input": "14 95 1", "output": "1" }, { "input": "99 82 53", "output": "1" }, { "input": "10 71 27", "output": "9" }, { "input": "5 7 8", "output": "2" }, { "input": "11 77 77", "output": "12" }, { "input": "10 5 28", "output": "3" }, { "input": "7 3 12", "output": "2" }, { "input": "10 15 17", "output": "3" }, { "input": "7 7 7", "output": "1" }, { "input": "4 11 18", "output": "6" }, { "input": "3 3 4", "output": "2" }, { "input": "9 2 10", "output": "1" }, { "input": "100 90 20", "output": "1" }, { "input": "3 2 2", "output": "1" }, { "input": "12 45 60", "output": "8" }, { "input": "3 94 79", "output": "47" }, { "input": "41 67 34", "output": "2" }, { "input": "9 3 23", "output": "2" }, { "input": "10 20 57", "output": "7" }, { "input": "55 27 30", "output": "1" }, { "input": "100 100 10", "output": "1" }, { "input": "20 8 70", "output": "3" }, { "input": "3 3 3", "output": "1" }, { "input": "4 9 15", "output": "5" }, { "input": "3 1 3", "output": "1" }, { "input": "2 94 94", "output": "94" }, { "input": "5 3 11", "output": "2" }, { "input": "4 3 2", "output": "1" }, { "input": "12 12 100", "output": "9" }, { "input": "6 75 91", "output": "25" }, { "input": "3 4 3", "output": "2" }, { "input": "3 2 5", "output": "2" }, { "input": "6 5 15", "output": "3" }, { "input": "4 3 6", "output": "2" }, { "input": "3 9 9", "output": "4" }, { "input": "26 93 76", "output": "6" }, { "input": "41 34 67", "output": "2" }, { "input": "6 12 6", "output": "3" }, { "input": "5 20 8", "output": "5" }, { "input": "2 1 3", "output": "1" }, { "input": "35 66 99", "output": "4" }, { "input": "30 7 91", "output": "3" }, { "input": "5 22 30", "output": "10" }, { "input": "8 19 71", "output": "10" }, { "input": "3 5 6", "output": "3" }, { "input": "5 3 8", "output": "2" }, { "input": "2 4 2", "output": "2" }, { "input": "4 3 7", "output": "2" }, { "input": "5 20 10", "output": "5" }, { "input": "5 100 50", "output": "25" }, { "input": "6 3 10", "output": "2" }, { "input": "2 90 95", "output": "90" }, { "input": "4 8 6", "output": "3" }, { "input": "6 10 3", "output": "2" }, { "input": "3 3 5", "output": "2" }, { "input": "5 33 33", "output": "11" }, { "input": "5 5 8", "output": "2" }, { "input": "19 24 34", "output": "3" }, { "input": "5 5 12", "output": "3" }, { "input": "8 7 10", "output": "2" }, { "input": "5 56 35", "output": "17" }, { "input": "4 3 5", "output": "1" }, { "input": "18 100 50", "output": "8" }, { "input": "5 6 8", "output": "2" }, { "input": "5 98 100", "output": "33" }, { "input": "6 5 8", "output": "2" }, { "input": "3 40 80", "output": "40" }, { "input": "4 8 11", "output": "4" }, { "input": "66 100 99", "output": "3" }, { "input": "17 100 79", "output": "10" }, { "input": "3 2 10", "output": "2" }, { "input": "99 100 99", "output": "2" }, { "input": "21 100 5", "output": "5" }, { "input": "3 10 2", "output": "2" }, { "input": "4 100 63", "output": "33" }, { "input": "2 2 10", "output": "2" }, { "input": "5 94 79", "output": "31" }, { "input": "4 12 5", "output": "4" }, { "input": "5 5 40", "output": "5" }, { "input": "99 99 99", "output": "1" }, { "input": "8 97 44", "output": "16" }, { "input": "11 4 10", "output": "1" }, { "input": "6 3 3", "output": "1" }, { "input": "7 3 4", "output": "1" }, { "input": "8 4 4", "output": "1" }, { "input": "9 4 5", "output": "1" }, { "input": "12 6 6", "output": "1" }, { "input": "4 48 89", "output": "29" }, { "input": "8 3 6", "output": "1" }, { "input": "4 6 3", "output": "2" }, { "input": "5 5 1", "output": "1" }, { "input": "11 6 5", "output": "1" }, { "input": "4 5 4", "output": "2" }, { "input": "6 6 4", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "4 1 3", "output": "1" }, { "input": "3 3 1", "output": "1" }, { "input": "9 4 6", "output": "1" }, { "input": "6 5 6", "output": "1" }, { "input": "2 2 3", "output": "2" }, { "input": "4 5 1", "output": "1" }, { "input": "13 6 7", "output": "1" }, { "input": "14 7 7", "output": "1" }, { "input": "12 97 13", "output": "8" }, { "input": "4 2 9", "output": "2" }, { "input": "10 20 59", "output": "7" }, { "input": "12 34 56", "output": "7" }, { "input": "4 5 9", "output": "3" }, { "input": "2 2 2", "output": "2" }, { "input": "4 66 41", "output": "22" } ]
1,579,887,035
2,147,483,647
PyPy 3
OK
TESTS
135
156
0
n,a,b=map(int,input().split()) l1=[] for x in range(1,n): l1.append(min(a//x , b//(n-x))) print(max(l1))
Title: Two Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*! Input Specification: The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. Output Specification: Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. Demo Input: ['5 2 3\n', '4 7 10\n'] Demo Output: ['1\n', '3\n'] Note: In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it. In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
```python n,a,b=map(int,input().split()) l1=[] for x in range(1,n): l1.append(min(a//x , b//(n-x))) print(max(l1)) ```
3
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "10000220" }, { "input": ".", "output": "0" }, { "input": "-.", "output": "1" }, { "input": "--", "output": "2" }, { "input": "..", "output": "00" }, { "input": "--.", "output": "20" }, { "input": ".--.", "output": "020" }, { "input": ".-.-..", "output": "0110" }, { "input": "----.-.", "output": "2201" }, { "input": "-..--.-.", "output": "10201" }, { "input": "..--..--.", "output": "0020020" }, { "input": "-.-.---.--..-..-.-.-..-..-.--.", "output": "112120010111010120" }, { "input": "---.-.-.------..-..-..-..-.-..-.--.-.-..-.-.-----..-.-.", "output": "21112220010101011012011011221011" }, { "input": "-.-..--.-.-.-.-.-..-.-.-.---------.--.---..--...--.-----.-.-.-...--.-.-.---.------.--..-.--.-----.-...-..------", "output": "11020111110111222212021020002022111100201121222020012022110010222" }, { "input": "-.-..-.--.---..---.-..---.-...-.-.----..-.---.-.---..-.--.---.-.-------.---.--....----.-.---.---.---.----.-----..---.-.-.-.-----.--.-------.-..", "output": "110120210211021100112200121121012021122212120000220121212122022102111122120222110" }, { "input": ".-..-.-.---.-----.--.---...-.--.-.-....-..", "output": "01011212212021001201100010" }, { "input": ".------.-.---..--...-..-..-.-.-.--.--.-..-.--...-.-.---.-.-.------..--..-.---..----.-..-.--.---.-.----.-.---...-.-.-.-----.-.-.---.---.-.....-.-...-----.-...-.---.-..-.-----.--...---.-.-..-.--.-.---..", "output": "022201210200010101112020101200011211122200200121022010120211220121001112211121211000011002211001211012212000211101201210" }, { "input": ".-.--.---.-----.-.-----.-.-..-----..-..----..--.-.--.----..---.---..-.-.-----..-------.----..----.-..---...-----..-..-----...-..-.-.-----....---..---..-.-----...-.--...--.-.---.-.-.-.-.-...---..----.", "output": "01202122112211102210102200201202200212101122102221220022010210022101022100101122100021021012210012000201211111100210220" }, { "input": "..-.-.-.---.-.-.-..-.-..-.-.---.-------.---..-----.---....-.---.--.--.-.---.---------.-..---.-.-.--..---.---.-.---.-.-..-.-..-.-.-.----.--.-....--------.-.---..----.------.-.-.--.--.-----.-----.----", "output": "0011121111011011212221210221210001212020121222211021112002121121110110111220201000222201210220222011202022122122" }, { "input": "-..-------.------.-..--.-.-..--.-.-..-----..-.-.-..-..-..--.---..-----..---..-..--.-..-.-.---...-.....-------.---.-----.-...-.-...-.-.---.---.-----.--.--...-.--..-.-..-...-.-.-.-.---..---.-..-.-.-.-..", "output": "102221222010201102011022101110101020210221021010201011210010000222121221100110011212122120200012001101001111210211011110" }, { "input": ".-.----.-.--..-.-.-.-..----..-.-...--.-.---.---.-------..-.--..-......--.------.--.----.--...-.--.--..-----..-.....--.--.-.-.------..--------.----------..-.---.----.---.-..--..-.....-..------.--.", "output": "012201200111102200110020121212221012001000002022202022020001202002210100002020112220022220222220012122021102001000010222020" }, { "input": "------.-----.-....--.-.----.-.---.-.-..---.-.---.-----..-...-.-.---..-.-.-..-.-.-...-.-.-.----..--.------.----.-..-.--...-.-------...-.-..-.-.--.--.---..--..--------.--.-.-.---.-.-.-...----.--..-.--..", "output": "222022110002012201211102112122101001121011101110011122002022202201012000122210011011202021020022220201121111002202001200" }, { "input": "-.---...----...--.--...-.--.----", "output": "121002200020200012022" }, { "input": "--.--.--.---.--.-.---.-.-..-..--.-..---.-.....-..---.-----.--...-.-.-------.-.--.-.----.-..-.------.", "output": "202020212012111010201021100001021221200011222112012201012220" } ]
1,691,166,072
2,147,483,647
PyPy 3-64
OK
TESTS
30
154
0
import sys def input(): return sys.stdin.readline().strip() def getints(): return map(int, sys.stdin.readline().strip().split()) import bisect left = lambda l,a : bisect.bisect_left(l,a) right = lambda l,a: bisect.bisect_right(l,a) s = input() i = 0 ans = "" while i < len(s): if s[i] == '.' : ans += '0'; i += 1 elif s[i] == '-' : if s[i+1] == '-': ans += '2' else: ans += '1' i += 2 print(ans)
Title: Borze Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. Input Specification: The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). Output Specification: Output the decoded ternary number. It can have leading zeroes. Demo Input: ['.-.--\n', '--.\n', '-..-.--\n'] Demo Output: ['012', '20', '1012'] Note: none
```python import sys def input(): return sys.stdin.readline().strip() def getints(): return map(int, sys.stdin.readline().strip().split()) import bisect left = lambda l,a : bisect.bisect_left(l,a) right = lambda l,a: bisect.bisect_right(l,a) s = input() i = 0 ans = "" while i < len(s): if s[i] == '.' : ans += '0'; i += 1 elif s[i] == '-' : if s[i+1] == '-': ans += '2' else: ans += '1' i += 2 print(ans) ```
3.9615
716
A
Crazy Computer
PROGRAMMING
800
[ "implementation" ]
null
null
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything.
The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word.
Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*.
[ "6 5\n1 3 8 14 19 20\n", "6 1\n1 3 5 7 9 10\n" ]
[ "3", "2" ]
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
500
[ { "input": "6 5\n1 3 8 14 19 20", "output": "3" }, { "input": "6 1\n1 3 5 7 9 10", "output": "2" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "5 5\n1 7 12 13 14", "output": "4" }, { "input": "2 1000000000\n1 1000000000", "output": "2" }, { "input": "3 5\n1 10 20", "output": "1" }, { "input": "3 10\n1 2 3", "output": "3" }, { "input": "2 1\n1 100", "output": "1" }, { "input": "3 1\n1 2 10", "output": "1" }, { "input": "2 1\n1 2", "output": "2" } ]
1,690,560,317
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
n, c = [int(i) for i in input().split()] t = [int(i) for i in input().split()] answer = 1 for i in range(n): if t[i] - t[i-1] > c: answer = 0 answer += 1 print(answer)
Title: Crazy Computer Time Limit: None seconds Memory Limit: None megabytes Problem Description: ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear! More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=≤<=*c*, just the new word is appended to other words on the screen. If *b*<=-<=*a*<=&gt;<=*c*, then everything on the screen disappears and after that the word you have typed appears on the screen. For example, if *c*<==<=5 and you typed words at seconds 1,<=3,<=8,<=14,<=19,<=20 then at the second 8 there will be 3 words on the screen. After that, everything disappears at the second 13 because nothing was typed. At the seconds 14 and 19 another two words are typed, and finally, at the second 20, one more word is typed, and a total of 3 words remain on the screen. You're given the times when ZS the Coder typed the words. Determine how many words remain on the screen after he finished typing everything. Input Specification: The first line contains two integers *n* and *c* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*c*<=≤<=109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=&lt;<=*t*2<=&lt;<=...<=&lt;<=*t**n*<=≤<=109), where *t**i* denotes the second when ZS the Coder typed the *i*-th word. Output Specification: Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. Demo Input: ['6 5\n1 3 8 14 19 20\n', '6 1\n1 3 5 7 9 10\n'] Demo Output: ['3', '2'] Note: The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 &gt; 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be two words on the screen, as the old word won't disappear because 10 - 9 ≤ 1.
```python n, c = [int(i) for i in input().split()] t = [int(i) for i in input().split()] answer = 1 for i in range(n): if t[i] - t[i-1] > c: answer = 0 answer += 1 print(answer) ```
0
0
none
none
none
0
[ "none" ]
null
null
The Little Elephant has two permutations *a* and *b* of length *n*, consisting of numbers from 1 to *n*, inclusive. Let's denote the *i*-th (1<=≤<=*i*<=≤<=*n*) element of the permutation *a* as *a**i*, the *j*-th (1<=≤<=*j*<=≤<=*n*) element of the permutation *b* — as *b**j*. The distance between permutations *a* and *b* is the minimum absolute value of the difference between the positions of the occurrences of some number in *a* and in *b*. More formally, it's such minimum |*i*<=-<=*j*|, that *a**i*<==<=*b**j*. A cyclic shift number *i* (1<=≤<=*i*<=≤<=*n*) of permutation *b* consisting from *n* elements is a permutation *b**i**b**i*<=+<=1... *b**n**b*1*b*2... *b**i*<=-<=1. Overall a permutation has *n* cyclic shifts. The Little Elephant wonders, for all cyclic shifts of permutation *b*, what is the distance between the cyclic shift and permutation *a*?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the permutations. The second line contains permutation *a* as *n* distinct numbers from 1 to *n*, inclusive. The numbers are separated with single spaces. The third line contains permutation *b* in the same format.
In *n* lines print *n* integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation *b*, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on.
[ "2\n1 2\n2 1\n", "4\n2 1 3 4\n3 4 2 1\n" ]
[ "1\n0\n", "2\n1\n0\n1\n" ]
none
0
[]
1,691,759,388
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
60
0
print("_RANDOM_GUESS_1691759388.7838838")# 1691759388.7839005
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has two permutations *a* and *b* of length *n*, consisting of numbers from 1 to *n*, inclusive. Let's denote the *i*-th (1<=≤<=*i*<=≤<=*n*) element of the permutation *a* as *a**i*, the *j*-th (1<=≤<=*j*<=≤<=*n*) element of the permutation *b* — as *b**j*. The distance between permutations *a* and *b* is the minimum absolute value of the difference between the positions of the occurrences of some number in *a* and in *b*. More formally, it's such minimum |*i*<=-<=*j*|, that *a**i*<==<=*b**j*. A cyclic shift number *i* (1<=≤<=*i*<=≤<=*n*) of permutation *b* consisting from *n* elements is a permutation *b**i**b**i*<=+<=1... *b**n**b*1*b*2... *b**i*<=-<=1. Overall a permutation has *n* cyclic shifts. The Little Elephant wonders, for all cyclic shifts of permutation *b*, what is the distance between the cyclic shift and permutation *a*? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the permutations. The second line contains permutation *a* as *n* distinct numbers from 1 to *n*, inclusive. The numbers are separated with single spaces. The third line contains permutation *b* in the same format. Output Specification: In *n* lines print *n* integers — the answers for cyclic shifts. Print the answers to the shifts in the order of the shifts' numeration in permutation *b*, that is, first for the 1-st cyclic shift, then for the 2-nd, and so on. Demo Input: ['2\n1 2\n2 1\n', '4\n2 1 3 4\n3 4 2 1\n'] Demo Output: ['1\n0\n', '2\n1\n0\n1\n'] Note: none
```python print("_RANDOM_GUESS_1691759388.7838838")# 1691759388.7839005 ```
0
976
A
Minimum Binary Number
PROGRAMMING
800
[ "implementation" ]
null
null
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).
The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct.
Print one string — the minimum correct string that you can obtain from the given one.
[ "4\n1001\n", "1\n1\n" ]
[ "100\n", "1\n" ]
In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
0
[ { "input": "4\n1001", "output": "100" }, { "input": "1\n1", "output": "1" }, { "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000" }, { "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10" }, { "input": "1\n0", "output": "0" }, { "input": "8\n10101010", "output": "10000" }, { "input": "2\n10", "output": "10" }, { "input": "3\n111", "output": "1" }, { "input": "5\n11100", "output": "100" }, { "input": "2\n11", "output": "1" }, { "input": "3\n110", "output": "10" }, { "input": "50\n10010010000000000000000000000000000000001000000000", "output": "10000000000000000000000000000000000000000000000" } ]
1,545,756,744
2,147,483,647
Python 3
OK
TESTS
14
124
0
n = int(input()) s = [x for x in input()] if s.count('1') > 0: print('1', '0'*s.count('0'), sep='') else: print('0')
Title: Minimum Binary Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. Output Specification: Print one string — the minimum correct string that you can obtain from the given one. Demo Input: ['4\n1001\n', '1\n1\n'] Demo Output: ['100\n', '1\n'] Note: In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1100" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "100". In the second example you can't obtain smaller answer no matter what operations you use.
```python n = int(input()) s = [x for x in input()] if s.count('1') > 0: print('1', '0'*s.count('0'), sep='') else: print('0') ```
3
1,005
B
Delete from the Left
PROGRAMMING
900
[ "brute force", "implementation", "strings" ]
null
null
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal.
The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive.
Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings.
[ "test\nwest\n", "codeforces\nyes\n", "test\nyes\n", "b\nab\n" ]
[ "2\n", "9\n", "7\n", "1\n" ]
In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
0
[ { "input": "test\nwest", "output": "2" }, { "input": "codeforces\nyes", "output": "9" }, { "input": "test\nyes", "output": "7" }, { "input": "b\nab", "output": "1" }, { "input": "z\nz", "output": "0" }, { "input": "abacabadabacaba\nabacabadacaba", "output": "18" }, { "input": "z\na", "output": "2" }, { "input": "ama\nsama", "output": "1" }, { "input": "aaabc\nbc", "output": "3" }, { "input": "lxuyspmieeuyxluv\ndfwxqvavzxctblaa", "output": "32" }, { "input": "ahmedaly\naly", "output": "5" }, { "input": "aa\na", "output": "1" }, { "input": "aa\nba", "output": "2" }, { "input": "cccba\nba", "output": "3" }, { "input": "a\nab", "output": "3" }, { "input": "dadc\ndddc", "output": "4" }, { "input": "aacaaab\nb", "output": "6" }, { "input": "dddc\ncdcde", "output": "9" }, { "input": "bbdab\ndab", "output": "2" }, { "input": "a\naa", "output": "1" }, { "input": "aa\nab", "output": "4" }, { "input": "codeforces\nces", "output": "7" } ]
1,639,910,088
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
139
2,355,200
s1 = list(input()) s2 = list(input()) count = 0 i,j =len(s1)-1,len(s2)-1 while i >= 0 and j>=0: if s1[i] == s2[j]: count +=1 i-=1 j-=1 print(len(s1)+len(s2)-2*count)
Title: Delete from the Left Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. Input Specification: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. Output Specification: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Demo Input: ['test\nwest\n', 'codeforces\nyes\n', 'test\nyes\n', 'b\nab\n'] Demo Output: ['2\n', '9\n', '7\n', '1\n'] Note: In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est". In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The move should be applied to the string "yes" once. The result is the same string "yes" $\to$ "es". In the third example, you can make the strings equal only by completely deleting them. That is, in the end, both strings will be empty. In the fourth example, the first character of the second string should be deleted.
```python s1 = list(input()) s2 = list(input()) count = 0 i,j =len(s1)-1,len(s2)-1 while i >= 0 and j>=0: if s1[i] == s2[j]: count +=1 i-=1 j-=1 print(len(s1)+len(s2)-2*count) ```
0
443
A
Anton and Letters
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.
The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.
Print a single number — the number of distinct letters in Anton's set.
[ "{a, b, c}\n", "{b, a, b, a}\n", "{}\n" ]
[ "3\n", "2\n", "0\n" ]
none
500
[ { "input": "{a, b, c}", "output": "3" }, { "input": "{b, a, b, a}", "output": "2" }, { "input": "{}", "output": "0" }, { "input": "{a, a, c, b, b, b, c, c, c, c}", "output": "3" }, { "input": "{a, c, b, b}", "output": "3" }, { "input": "{a, b}", "output": "2" }, { "input": "{a}", "output": "1" }, { "input": "{b, a, b, a, b, c, c, b, c, b}", "output": "3" }, { "input": "{e, g, c, e}", "output": "3" }, { "input": "{a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a}", "output": "1" }, { "input": "{a, a, b}", "output": "2" }, { "input": "{a, b, b, b, a, b, a, a, a, a, a, a, b, a, b, a, a, a, a, a, b, a, b, a}", "output": "2" }, { "input": "{j, u, a, c, f, w, e, w, x, t, h, p, v, n, i, l, x, n, i, b, u, c, a, a}", "output": "16" }, { "input": "{x, i, w, c, p, e, h, z, k, i}", "output": "9" }, { "input": "{t, k, o, x, r, d, q, j, k, e, z, w, y, r, z, s, s, e, s, b, k, i}", "output": "15" }, { "input": "{y}", "output": "1" }, { "input": "{x}", "output": "1" }, { "input": "{b, z, a, z}", "output": "3" }, { "input": "{z}", "output": "1" }, { "input": "{a, z}", "output": "2" }, { "input": "{a, b, z}", "output": "3" }, { "input": "{s, q, z, r, t, a, b, h, j, i, o, z, r, q}", "output": "11" } ]
1,698,297,632
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
a = input() if a == "{}": print(0) else: a.replace('{', "") a.replace('}', '') a= list(map(str, a.split(","))) print(len(a))
Title: Anton and Letters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set. Input Specification: The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. Output Specification: Print a single number — the number of distinct letters in Anton's set. Demo Input: ['{a, b, c}\n', '{b, a, b, a}\n', '{}\n'] Demo Output: ['3\n', '2\n', '0\n'] Note: none
```python a = input() if a == "{}": print(0) else: a.replace('{', "") a.replace('}', '') a= list(map(str, a.split(","))) print(len(a)) ```
0
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": "Anton" }, { "input": "200\nDDDDDDDADDDDDDAADADAADAAADAADADAAADDDADDDDDDADDDAADDDAADADDDDDADDDAAAADAAADDDDDAAADAADDDAAAADDADADDDAADDAADAAADAADAAAADDAADDADAAAADADDDAAAAAADDAADAADAADADDDAAADAAAADADDADAAAAAADADADDDADDDAADDADDDAAAAD", "output": "Friendship" }, { "input": "1\nA", "output": "Anton" }, { "input": "1\nD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "4\nDADA", "output": "Friendship" }, { "input": "4\nDAAD", "output": "Friendship" }, { "input": "3\nADD", "output": "Danik" }, { "input": "3\nDAD", "output": "Danik" }, { "input": "2\nDA", "output": "Friendship" }, { "input": "379\nAADAAAAAADDAAAAAADAADADADDAAAAADADDAADAAAADDDADAAAAAAADAADAAAAAAADAAAAAAAAADAAAAAAADAAAAAAAAAAADDDADAAAAAAAADAADADAAAADAAAAAAAAAAAAAAAAADAAAADDDAADAAAAAAADAAADAAADAADDDADDAAADAAAAAADDDADDDAAADAAAADAAAAAAAAADAAADAAAAAAAAADAAAAAAAAAAAAAAAAAADADAAAAAAAAAAADAAAAADAAAADAAAAAAAAAAAAADADAADAAAAAAAADAADAAAAAAAADAAAAAAAADDDAAAAAADAAADAAAAAADAADAAAAAADAAAADADAADAAAAAADAAAADAADDAADAADAAA", "output": "Anton" } ]
1,691,383,641
2,147,483,647
Python 3
OK
TESTS
25
31
921,600
n=int(input()) str1=input().upper() str1=list(str1) if str1.count('A')>str1.count('D'): print("Anton") elif str1.count('A')<str1.count('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=int(input()) str1=input().upper() str1=list(str1) if str1.count('A')>str1.count('D'): print("Anton") elif str1.count('A')<str1.count('D'): print("Danik") else: print("Friendship") ```
3
981
D
Bookshelves
PROGRAMMING
1,900
[ "bitmasks", "dp", "greedy" ]
null
null
Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.
The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 &lt; a_i &lt; 2^{50}$) — the prices of the books in the order they stand on the old shelf.
Print the maximum possible beauty of $k$ shelves in the new office.
[ "10 4\n9 14 28 1 7 13 15 29 2 31\n", "7 3\n3 14 15 92 65 35 89\n" ]
[ "24\n", "64\n" ]
In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \&amp; (13 + 15) \&amp; (29 + 2) \&amp; (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \&amp; (65) \&amp; (35 + 89) = 64.$$
1,750
[ { "input": "10 4\n9 14 28 1 7 13 15 29 2 31", "output": "24" }, { "input": "7 3\n3 14 15 92 65 35 89", "output": "64" }, { "input": "40 5\n6 18 24 5 14 16 31 9 15 5 25 2 18 12 19 27 10 23 23 18 22 14 1 14 6 14 17 28 11 21 8 23 10 30 21 5 17 11 26 16", "output": "80" }, { "input": "20 15\n927353279298143 655102800384382 40376603048780 1008958973042960 1123049780860278 853122601026128 154596679092462 200013924385343 591199113039915 140875624438732 924096460433635 609326666846280 639191601375336 868486002971126 338452290857190 947205016908287 1091731324024232 315465850740682 804685495436596 1102057294815123", "output": "16777216" }, { "input": "10 4\n318346909478488 165408439052762 201407789817026 481299976321209 960738945073700 249445428976993 1096588610084096 605348669136305 817617728356976 256799633127974", "output": "563104572248080" }, { "input": "50 15\n10 30 15 11 9 5 7 16 4 3 29 28 14 20 9 10 21 16 1 7 30 19 16 25 12 29 12 5 3 23 27 16 11 25 21 18 22 12 23 16 24 27 19 7 11 12 30 1 24 11", "output": "32" }, { "input": "20 8\n29 25 19 16 26 18 25 9 5 2 17 16 19 16 3 16 4 17 7 20", "output": "16" }, { "input": "30 4\n893642632982367 772277951746295 510759449350295 826812150840579 1060893142351815 525992742241552 154832018679993 645715002371268 27232975419720 475004229372388 200177708355593 810661468479466 49618609534806 301608930846726 97042172725806 441637617418914 594900693592862 626510702147446 653604971179679 51832188158797 771139366286148 604472775724297 543106972286801 854107321252442 958411818162963 419377189839607 595529582510881 663396887427244 543023709380824 1078875721144944", "output": "3940649673949202" }, { "input": "40 5\n22 16 24 23 3 18 20 12 25 26 29 4 10 31 31 30 2 7 11 16 24 8 2 24 19 17 5 17 20 7 15 26 1 16 26 21 27 4 19 25", "output": "106" }, { "input": "20 9\n162679258761381 497029570950369 441562370676165 658883349839306 803660720071652 397337645985983 1098171846564844 578539182000384 612361670323974 773464823371908 133451479483291 1053028311550002 812258927376098 1012522114357354 692621870999109 73882870347249 783703450776904 897456103589081 217535031946368 318888756116976", "output": "571746046443520" }, { "input": "50 12\n22 12 31 3 3 12 19 19 21 15 24 25 31 18 9 3 8 5 3 24 6 26 30 25 14 25 9 25 3 29 9 6 11 3 12 12 15 6 1 28 28 28 26 9 15 12 17 2 18 18", "output": "36" }, { "input": "16 7\n1103813397013349 727264530801741 378049079598082 630901233315595 518569339136212 532452143552615 428093804691193 371529237344587 940308912730366 704551472087683 631663816743474 29306660032804 583388823624504 1109142272484691 257363549141980 1089402363164001", "output": "572020924350465" }, { "input": "30 2\n26 8 26 25 27 18 6 13 10 22 25 19 7 14 20 4 10 22 9 10 30 30 11 7 27 8 23 13 17 21", "output": "125" }, { "input": "10 3\n30 15 26 16 21 13 25 5 27 11", "output": "33" }, { "input": "10 6\n977831009728918 953593140925615 784863715891337 774777129376154 384491823368699 788094311512692 223966626677969 1066171741163060 119044778274639 876388748099519", "output": "562949953683460" }, { "input": "20 9\n2 3 15 8 17 7 23 12 30 23 4 23 16 21 11 6 7 16 3 3", "output": "16" }, { "input": "20 8\n483137921056907 768218083275243 207834138817392 354531452905166 963403044757413 833232873786483 582872528360258 514660235281883 1011861985723061 459485641216220 942598735621775 873490204734628 649359794076787 543622431653711 10411517577635 91729283882125 291509560140622 287260200844128 879410314598283 206118644453476", "output": "562951027164160" }, { "input": "30 9\n21 6 19 18 27 3 14 18 1 5 7 9 11 13 9 26 8 12 14 31 21 6 9 3 3 10 2 24 22 24", "output": "36" }, { "input": "30 22\n73306162994949 868677001959133 1106639997936963 879122920975808 161227935543926 760034092541884 1120594333824270 1054807665792407 476276883119188 271363692993319 440885048025850 7074457876332 636209225974410 221086579024023 1009685779703594 647498280909980 816934931718733 452863796888983 1061332951888385 942660914590384 365185997676754 112920162715865 178172288962138 810584030647354 923637556325003 1102808429103893 1118229467600088 1074261154123678 839042706865637 352292698714231", "output": "2097152" }, { "input": "23 10\n935459645688325 899894863244863 776172843769766 986122540485649 248016433194357 475375806620409 20513751182830 421086691387167 247543829168446 155673663632778 415875856906302 128486751653325 849753391760463 1083573552851049 244133940871958 934119204927643 1085966359617308 577156229051957 1081049229814148 935408354841926 1093470105244215 288440615891778 467185550898222", "output": "562950087639040" }, { "input": "40 5\n2 20 10 21 4 30 27 12 17 20 5 21 11 12 28 12 24 20 20 31 19 2 1 27 31 1 14 8 1 21 10 2 29 22 29 9 12 29 21 7", "output": "80" }, { "input": "10 4\n22 21 18 7 16 14 12 11 18 5", "output": "16" }, { "input": "50 24\n19 14 27 12 29 18 26 24 16 23 23 22 3 28 18 11 27 14 24 19 25 23 14 7 25 31 20 7 23 10 21 9 30 3 25 17 11 16 27 28 3 25 8 19 17 27 21 19 26 31", "output": "16" }, { "input": "10 4\n23 12 4 5 7 10 22 18 1 6", "output": "4" }, { "input": "4 2\n158042378809438 929800196167200 663932725437382 1056705514263205", "output": "594152991508074" }, { "input": "20 8\n8 29 23 29 3 24 21 4 2 8 12 17 22 8 14 15 21 18 2 22", "output": "16" }, { "input": "1 1\n1", "output": "1" }, { "input": "50 50\n1 3 7 15 31 63 127 255 511 1023 2047 4095 8191 16383 32767 65535 131071 262143 524287 1048575 2097151 4194303 8388607 16777215 33554431 67108863 134217727 268435455 536870911 1073741823 2147483647 4294967295 8589934591 17179869183 34359738367 68719476735 137438953471 274877906943 549755813887 1099511627775 2199023255551 4398046511103 8796093022207 17592186044415 35184372088831 70368744177663 140737488355327 281474976710655 562949953421311 1125899906842623", "output": "1" }, { "input": "1 1\n847523811295364", "output": "847523811295364" }, { "input": "16 4\n874317845770206 387621540079007 155991277344382 691438508026243 930771471405935 572771476513435 743983828305226 4504492981600 163201683368400 839227763533133 66330553316499 1019586586453035 361344913793137 983404846165187 1054785536664003 328380935299964", "output": "1214153029059594" }, { "input": "8 3\n1091780344011621 940196424994342 1122602056403610 446348279968546 844618893669060 630726534256806 583591612685392 410152590972252", "output": "633396032195072" }, { "input": "4 2\n162835105872970 116592879151848 139965176195127 395498533500931", "output": "392680337115137" }, { "input": "2 1\n209353646212060 198207100745412", "output": "407560746957472" }, { "input": "16 14\n104025519164115 388661629481441 867118235830760 833392737978583 446248951095413 1075527144295046 1065273356416483 60098918081731 29503418096534 995667681082455 1087347063175248 131807733936246 235096689659338 202086293947852 889771265698655 384926479287439", "output": "0" }, { "input": "8 5\n173728498114277 92445238671418 136142198208213 974561146026363 1099401507969061 180377338638143 458779251007513 55384960555288", "output": "140737555464192" }, { "input": "4 3\n266761283825161 255669386891250 772637301427796 659604966525743", "output": "19928690198528" }, { "input": "8 1\n562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312", "output": "4503599627370496" }, { "input": "16 1\n562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312 562949953421312", "output": "9007199254740992" }, { "input": "17 1\n1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 1125899906842623 16", "output": "18014398509481984" } ]
1,689,213,154
2,147,483,647
PyPy 3-64
OK
TESTS
64
108
5,939,200
import os import sys from io import BytesIO, IOBase BUFSIZE = 4096 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin = IOWrapper(sys.stdin) sys.stdout = IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def LII(): return list(map(int, input().split())) def count_bit(num): cnt = 0 while num != 0: cnt += 1 num //= 2 return cnt n, k = LII() a = LII() s = [0] * (n + 1) for i in range(1, n + 1): s[i] = s[i - 1] + a[i - 1] ans = 0 for i in range(count_bit(s[n]) - 1, -1, -1): target = ans | (1 << i) f = [[False] * (n + 1) for _ in range(k + 1)] f[0][0] = True for j in range(1, k + 1): for r in range(1, n + 1): for l, ok in enumerate(f[j - 1][:r]): if ok and (s[r] - s[l]) & target == target: f[j][r] = True break if f[k][n]: ans = target print(ans)
Title: Bookshelves Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr Keks is a typical white-collar in Byteland. He has a bookshelf in his office with some books on it, each book has an integer positive price. Mr Keks defines the value of a shelf as the sum of books prices on it. Miraculously, Mr Keks was promoted and now he is moving into a new office. He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the values of all the shelves. He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty. Input Specification: The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office. The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 &lt; a_i &lt; 2^{50}$) — the prices of the books in the order they stand on the old shelf. Output Specification: Print the maximum possible beauty of $k$ shelves in the new office. Demo Input: ['10 4\n9 14 28 1 7 13 15 29 2 31\n', '7 3\n3 14 15 92 65 35 89\n'] Demo Output: ['24\n', '64\n'] Note: In the first example you can split the books as follows: $$(9 + 14 + 28 + 1 + 7) \&amp; (13 + 15) \&amp; (29 + 2) \&amp; (31) = 24.$$ In the second example you can split the books as follows: $$(3 + 14 + 15 + 92) \&amp; (65) \&amp; (35 + 89) = 64.$$
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 4096 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin = IOWrapper(sys.stdin) sys.stdout = IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def LII(): return list(map(int, input().split())) def count_bit(num): cnt = 0 while num != 0: cnt += 1 num //= 2 return cnt n, k = LII() a = LII() s = [0] * (n + 1) for i in range(1, n + 1): s[i] = s[i - 1] + a[i - 1] ans = 0 for i in range(count_bit(s[n]) - 1, -1, -1): target = ans | (1 << i) f = [[False] * (n + 1) for _ in range(k + 1)] f[0][0] = True for j in range(1, k + 1): for r in range(1, n + 1): for l, ok in enumerate(f[j - 1][:r]): if ok and (s[r] - s[l]) & target == target: f[j][r] = True break if f[k][n]: ans = target print(ans) ```
3
245
A
System Administrator
PROGRAMMING
800
[ "implementation" ]
null
null
Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.
In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format.
[ "2\n1 5 5\n2 6 4\n", "3\n1 0 10\n2 0 10\n1 10 0\n" ]
[ "LIVE\nLIVE\n", "LIVE\nDEAD\n" ]
Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
0
[ { "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE" }, { "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD" }, { "input": "12\n1 5 5\n1 0 10\n1 4 6\n1 2 8\n1 2 8\n1 5 5\n1 9 1\n2 9 1\n1 5 5\n1 1 9\n2 9 1\n2 7 3", "output": "DEAD\nLIVE" }, { "input": "13\n1 8 2\n1 4 6\n1 5 5\n1 5 5\n2 10 0\n2 9 1\n1 3 7\n2 6 4\n2 6 4\n2 5 5\n1 7 3\n2 3 7\n2 9 1", "output": "LIVE\nLIVE" }, { "input": "14\n1 7 3\n1 0 10\n1 7 3\n1 1 9\n2 2 8\n2 0 10\n1 1 9\n2 8 2\n2 6 4\n1 3 7\n1 3 7\n2 6 4\n2 1 9\n2 7 3", "output": "DEAD\nDEAD" } ]
1,561,669,740
2,147,483,647
Python 3
OK
TESTS
13
218
0
n = int(input()) k = [0] * 3 for _ in range(n): t, x, y = map(int, input().split()) k[t] += x - y for i in range(1, 3): print('LIVE' if k[i] >= 0 else 'DEAD')
Title: System Administrator Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus is a system administrator. There are two servers under his strict guidance — *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10; *x*,<=*y*<=≥<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=1000) — the number of commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers — the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≤<=*t**i*<=≤<=2; *x**i*,<=*y**i*<=≥<=0; *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. Output Specification: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Demo Input: ['2\n1 5 5\n2 6 4\n', '3\n1 0 10\n2 0 10\n1 10 0\n'] Demo Output: ['LIVE\nLIVE\n', 'LIVE\nDEAD\n'] Note: Consider the first test case. There 10 packets were sent to server *a*, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server *b*, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Consider the second test case. There were overall 20 packages sent to server *a*, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server *b*, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
```python n = int(input()) k = [0] * 3 for _ in range(n): t, x, y = map(int, input().split()) k[t] += x - y for i in range(1, 3): print('LIVE' if k[i] >= 0 else 'DEAD') ```
3
803
A
Maximal Binary Matrix
PROGRAMMING
1,400
[ "constructive algorithms" ]
null
null
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1.
The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106).
If the answer exists then output resulting matrix. Otherwise output -1.
[ "2 1\n", "3 2\n", "2 5\n" ]
[ "1 0 \n0 0 \n", "1 0 0 \n0 1 0 \n0 0 0 \n", "-1\n" ]
none
0
[ { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "2 5", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "20 398", "output": "1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 \n1 1 1 1..." }, { "input": "20 401", "output": "-1" }, { "input": "100 3574", "output": "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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 \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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 \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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "1 1000000", "output": "-1" }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "1 2", "output": "-1" }, { "input": "1 0", "output": "0 " }, { "input": "1 1", "output": "1 " }, { "input": "1 2", "output": "-1" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "-1" }, { "input": "1 5", "output": "-1" }, { "input": "1 6", "output": "-1" }, { "input": "1 7", "output": "-1" }, { "input": "1 8", "output": "-1" }, { "input": "1 9", "output": "-1" }, { "input": "1 10", "output": "-1" }, { "input": "1 11", "output": "-1" }, { "input": "1 12", "output": "-1" }, { "input": "1 13", "output": "-1" }, { "input": "1 14", "output": "-1" }, { "input": "1 15", "output": "-1" }, { "input": "1 16", "output": "-1" }, { "input": "1 17", "output": "-1" }, { "input": "1 18", "output": "-1" }, { "input": "1 19", "output": "-1" }, { "input": "1 20", "output": "-1" }, { "input": "1 21", "output": "-1" }, { "input": "1 22", "output": "-1" }, { "input": "1 23", "output": "-1" }, { "input": "1 24", "output": "-1" }, { "input": "1 25", "output": "-1" }, { "input": "1 26", "output": "-1" }, { "input": "2 0", "output": "0 0 \n0 0 " }, { "input": "2 1", "output": "1 0 \n0 0 " }, { "input": "2 2", "output": "1 0 \n0 1 " }, { "input": "2 3", "output": "1 1 \n1 0 " }, { "input": "2 4", "output": "1 1 \n1 1 " }, { "input": "2 5", "output": "-1" }, { "input": "2 6", "output": "-1" }, { "input": "2 7", "output": "-1" }, { "input": "2 8", "output": "-1" }, { "input": "2 9", "output": "-1" }, { "input": "2 10", "output": "-1" }, { "input": "2 11", "output": "-1" }, { "input": "2 12", "output": "-1" }, { "input": "2 13", "output": "-1" }, { "input": "2 14", "output": "-1" }, { "input": "2 15", "output": "-1" }, { "input": "2 16", "output": "-1" }, { "input": "2 17", "output": "-1" }, { "input": "2 18", "output": "-1" }, { "input": "2 19", "output": "-1" }, { "input": "2 20", "output": "-1" }, { "input": "2 21", "output": "-1" }, { "input": "2 22", "output": "-1" }, { "input": "2 23", "output": "-1" }, { "input": "2 24", "output": "-1" }, { "input": "2 25", "output": "-1" }, { "input": "2 26", "output": "-1" }, { "input": "3 0", "output": "0 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 1", "output": "1 0 0 \n0 0 0 \n0 0 0 " }, { "input": "3 2", "output": "1 0 0 \n0 1 0 \n0 0 0 " }, { "input": "3 3", "output": "1 1 0 \n1 0 0 \n0 0 0 " }, { "input": "3 4", "output": "1 1 0 \n1 1 0 \n0 0 0 " }, { "input": "3 5", "output": "1 1 1 \n1 0 0 \n1 0 0 " }, { "input": "3 6", "output": "1 1 1 \n1 1 0 \n1 0 0 " }, { "input": "3 7", "output": "1 1 1 \n1 1 0 \n1 0 1 " }, { "input": "3 8", "output": "1 1 1 \n1 1 1 \n1 1 0 " }, { "input": "3 9", "output": "1 1 1 \n1 1 1 \n1 1 1 " }, { "input": "3 10", "output": "-1" }, { "input": "3 11", "output": "-1" }, { "input": "3 12", "output": "-1" }, { "input": "3 13", "output": "-1" }, { "input": "3 14", "output": "-1" }, { "input": "3 15", "output": "-1" }, { "input": "3 16", "output": "-1" }, { "input": "3 17", "output": "-1" }, { "input": "3 18", "output": "-1" }, { "input": "3 19", "output": "-1" }, { "input": "3 20", "output": "-1" }, { "input": "3 21", "output": "-1" }, { "input": "3 22", "output": "-1" }, { "input": "3 23", "output": "-1" }, { "input": "3 24", "output": "-1" }, { "input": "3 25", "output": "-1" }, { "input": "3 26", "output": "-1" }, { "input": "4 0", "output": "0 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 1", "output": "1 0 0 0 \n0 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 2", "output": "1 0 0 0 \n0 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 3", "output": "1 1 0 0 \n1 0 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 4", "output": "1 1 0 0 \n1 1 0 0 \n0 0 0 0 \n0 0 0 0 " }, { "input": "4 5", "output": "1 1 1 0 \n1 0 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 6", "output": "1 1 1 0 \n1 1 0 0 \n1 0 0 0 \n0 0 0 0 " }, { "input": "4 7", "output": "1 1 1 1 \n1 0 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 8", "output": "1 1 1 1 \n1 1 0 0 \n1 0 0 0 \n1 0 0 0 " }, { "input": "4 9", "output": "1 1 1 1 \n1 1 0 0 \n1 0 1 0 \n1 0 0 0 " }, { "input": "4 10", "output": "1 1 1 1 \n1 1 1 0 \n1 1 0 0 \n1 0 0 0 " }, { "input": "4 11", "output": "1 1 1 1 \n1 1 1 0 \n1 1 1 0 \n1 0 0 0 " }, { "input": "4 12", "output": "1 1 1 1 \n1 1 1 1 \n1 1 0 0 \n1 1 0 0 " }, { "input": "4 13", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 0 " }, { "input": "4 14", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 0 \n1 1 0 1 " }, { "input": "4 15", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 0 " }, { "input": "4 16", "output": "1 1 1 1 \n1 1 1 1 \n1 1 1 1 \n1 1 1 1 " }, { "input": "4 17", "output": "-1" }, { "input": "4 18", "output": "-1" }, { "input": "4 19", "output": "-1" }, { "input": "4 20", "output": "-1" }, { "input": "4 21", "output": "-1" }, { "input": "4 22", "output": "-1" }, { "input": "4 23", "output": "-1" }, { "input": "4 24", "output": "-1" }, { "input": "4 25", "output": "-1" }, { "input": "4 26", "output": "-1" }, { "input": "5 0", "output": "0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 1", "output": "1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 2", "output": "1 0 0 0 0 \n0 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 3", "output": "1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 4", "output": "1 1 0 0 0 \n1 1 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 5", "output": "1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 6", "output": "1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 7", "output": "1 1 1 1 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 8", "output": "1 1 1 1 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n0 0 0 0 0 " }, { "input": "5 9", "output": "1 1 1 1 1 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 10", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 11", "output": "1 1 1 1 1 \n1 1 0 0 0 \n1 0 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 12", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 13", "output": "1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 \n1 0 0 0 0 \n1 0 0 0 0 " }, { "input": "5 14", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 0 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 15", "output": "1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 \n1 0 0 0 0 " }, { "input": "5 16", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 0 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 17", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 0 0 \n1 1 0 0 0 " }, { "input": "5 18", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 0 1 0 \n1 1 0 0 0 " }, { "input": "5 19", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 \n1 1 0 0 0 " }, { "input": "5 20", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 1 0 \n1 1 0 0 0 " }, { "input": "5 21", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 0 0 \n1 1 1 0 0 " }, { "input": "5 22", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 0 " }, { "input": "5 23", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 \n1 1 1 0 1 " }, { "input": "5 24", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 0 " }, { "input": "5 25", "output": "1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 \n1 1 1 1 1 " }, { "input": "5 26", "output": "-1" }, { "input": "100 0", "output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 2", "output": "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 3", "output": "1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 99", "output": "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 100", "output": "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 101", "output": "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 9999", "output": "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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 \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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10000", "output": "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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 \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 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 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 1 1 1 1 1 1 1 1 1 1 1 1 \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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1..." }, { "input": "100 10001", "output": "-1" } ]
1,699,955,492
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
n,m = map(int,(input().split())) A = [[0]*n for _ in range(n)] B = [[0]*n for _ in range(n)] L = [[0]*n for _ in range(n)] ls = [] for _ in range(m): i,j = map(int,(input().split())) A[i][j] = 1 A[j][i] = 1 ls.append(i) ls.append(j) for x in range(n): B[x][x] = ls.count(x) for i in range(n): for j in range(n): L[i][j] = B[i][j] - A[i][j] for row in L: print(' '.join(map(str,row)))
Title: Maximal Binary Matrix Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal. One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one. If there exists no such matrix then output -1. Input Specification: The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). Output Specification: If the answer exists then output resulting matrix. Otherwise output -1. Demo Input: ['2 1\n', '3 2\n', '2 5\n'] Demo Output: ['1 0 \n0 0 \n', '1 0 0 \n0 1 0 \n0 0 0 \n', '-1\n'] Note: none
```python n,m = map(int,(input().split())) A = [[0]*n for _ in range(n)] B = [[0]*n for _ in range(n)] L = [[0]*n for _ in range(n)] ls = [] for _ in range(m): i,j = map(int,(input().split())) A[i][j] = 1 A[j][i] = 1 ls.append(i) ls.append(j) for x in range(n): B[x][x] = ls.count(x) for i in range(n): for j in range(n): L[i][j] = B[i][j] - A[i][j] for row in L: print(' '.join(map(str,row))) ```
-1
46
B
T-shirts from Sponsor
PROGRAMMING
1,100
[ "implementation" ]
B. T-shirts from Sponsor
2
256
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size.
The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*.
For each contestant, print a line containing the size of the T-shirt he/she got.
[ "1 0 2 0 1\n3\nXL\nXXL\nM\n" ]
[ "XXL\nL\nL\n" ]
none
0
[ { "input": "1 0 2 0 1\n3\nXL\nXXL\nM", "output": "XXL\nL\nL" }, { "input": "0 0 0 0 1\n1\nS", "output": "XXL" }, { "input": "1 0 1 0 1\n1\nS", "output": "S" }, { "input": "1 0 0 0 1\n2\nS\nL", "output": "S\nXXL" }, { "input": "1 1 1 1 1\n2\nXL\nM", "output": "XL\nM" }, { "input": "1 0 1 1 1\n3\nS\nXXL\nL", "output": "S\nXXL\nL" }, { "input": "1 0 2 1 1\n4\nS\nXXL\nL\nM", "output": "S\nXXL\nL\nL" }, { "input": "1 0 3 0 1\n5\nS\nS\nS\nXL\nL", "output": "S\nL\nL\nXXL\nL" }, { "input": "2 1 0 1 3\n4\nXL\nM\nS\nS", "output": "XL\nM\nS\nS" }, { "input": "2 2 0 2 1\n6\nS\nXXL\nM\nXL\nXXL\nXL", "output": "S\nXXL\nM\nXL\nXL\nM" }, { "input": "3 1 1 4 1\n10\nXL\nL\nL\nXXL\nXXL\nXL\nL\nXXL\nS\nM", "output": "XL\nL\nXL\nXXL\nXL\nXL\nM\nS\nS\nS" }, { "input": "14 3 1 0 2\n10\nS\nXL\nM\nXL\nS\nXXL\nL\nXXL\nS\nL", "output": "S\nXXL\nM\nXXL\nS\nL\nM\nM\nS\nS" }, { "input": "44 314 100 272 270\n10\nXXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL", "output": "XXL\nXL\nXXL\nXXL\nS\nS\nS\nS\nL\nL" }, { "input": "2 22 11 9 6\n20\nXL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nS\nXL", "output": "XL\nXXL\nXL\nL\nXL\nXXL\nXXL\nL\nS\nL\nXXL\nXL\nXXL\nXXL\nL\nM\nL\nS\nM\nXL" }, { "input": "13 0 2 4 41\n20\nS\nXXL\nXXL\nL\nXXL\nM\nL\nM\nXXL\nM\nXXL\nL\nXXL\nXL\nM\nXL\nXL\nL\nL\nM", "output": "S\nXXL\nXXL\nL\nXXL\nL\nXL\nS\nXXL\nS\nXXL\nXL\nXXL\nXL\nS\nXL\nXXL\nXXL\nXXL\nS" }, { "input": "5 7 2 9 7\n30\nS\nM\nS\nXL\nXXL\nL\nXL\nL\nL\nXXL\nS\nM\nXXL\nXXL\nS\nL\nXL\nS\nL\nXXL\nXXL\nS\nM\nM\nM\nXXL\nS\nXXL\nS\nL", "output": "S\nM\nS\nXL\nXXL\nL\nXL\nL\nXL\nXXL\nS\nM\nXXL\nXXL\nS\nXL\nXL\nS\nXL\nXXL\nXXL\nM\nM\nM\nM\nXXL\nM\nXL\nXL\nXL" }, { "input": "3 17 3 21 16\n50\nL\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nS\nXXL\nXXL\nXL\nM\nL\nS\nXL\nS\nM\nS\nL\nXL\nM\nXL\nL\nXL\nXL\nL\nL\nM\nXL\nS\nXXL\nL\nL\nM\nL\nS\nM\nL\nXXL\nXL\nS\nL", "output": "L\nXL\nXXL\nM\nXXL\nXL\nM\nS\nXL\nXXL\nXL\nM\nS\nS\nM\nM\nXXL\nXXL\nXL\nM\nL\nM\nXL\nM\nM\nM\nL\nXL\nM\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL\nM\nXXL\nXL\nXL\nM\nXL\nM\nM\nXL\nXXL\nXL\nM\nXL" }, { "input": "2 36 4 48 10\n50\nXXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nS\nXL\nXL\nS\nXXL\nS\nS\nS\nL\nM\nM\nXXL\nS\nS\nM\nXXL\nXL\nL\nS\nM\nXL\nXL\nS\nXXL\nM\nL\nXXL\nXL\nXXL\nXXL\nXL\nL\nL\nXXL\nXL\nXXL\nL\nL\nL\nS\nXL", "output": "XXL\nXXL\nS\nXXL\nXL\nXL\nS\nL\nXXL\nM\nXL\nXL\nM\nXXL\nM\nM\nM\nL\nM\nM\nXXL\nM\nM\nM\nXXL\nXL\nL\nM\nM\nXL\nXL\nM\nXXL\nM\nL\nXXL\nXL\nXXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nXL\nM\nXL" }, { "input": "450 65 82 309 94\n50\nM\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL", "output": "M\nXL\nXL\nXL\nM\nM\nS\nXL\nXXL\nXL\nM\nXL\nS\nXXL\nS\nXL\nM\nXL\nM\nS\nS\nM\nXL\nS\nL\nS\nXL\nXL\nL\nL\nXL\nXL\nXL\nXXL\nXXL\nL\nXXL\nM\nXXL\nM\nXXL\nXL\nM\nXL\nL\nS\nXL\nS\nM\nXXL" }, { "input": "200 910 49 294 547\n50\nXXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL", "output": "XXL\nL\nXXL\nS\nXL\nXXL\nL\nXXL\nM\nM\nM\nM\nXXL\nS\nXXL\nXL\nL\nXXL\nL\nL\nXL\nXL\nXL\nXL\nS\nXL\nL\nXXL\nM\nXXL\nS\nXXL\nS\nXXL\nS\nS\nL\nS\nL\nXL\nXXL\nL\nL\nS\nS\nS\nS\nXXL\nXL\nXXL" }, { "input": "85 80 1 27 7\n100\nXXL\nM\nM\nS\nL\nL\nXL\nM\nXXL\nXXL\nXL\nL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nL\nM\nXL\nM\nS\nL\nM\nXXL\nL\nXXL\nS\nM\nS\nM\nL\nXXL\nXXL\nM\nS\nS\nL\nXXL\nM\nXXL\nM\nS\nM\nXXL\nM\nM\nXL\nXXL\nL\nXXL\nXL\nXXL\nS\nL\nL\nS\nS\nS\nL\nM\nL\nXXL\nL\nL\nXXL\nS\nS\nS\nXL\nXXL\nXL\nS\nL\nXXL\nS\nS\nM\nL\nXXL\nXL\nXL\nL\nXXL", "output": "XXL\nM\nM\nS\nL\nXL\nXL\nM\nXXL\nXXL\nXL\nXL\nM\nXL\nM\nXL\nXL\nS\nM\nS\nXXL\nXL\nXL\nM\nS\nXL\nS\nXL\nS\nXL\nS\nM\nXXL\nXL\nM\nXL\nM\nS\nXL\nM\nXXL\nXL\nXXL\nS\nM\nS\nM\nXL\nXL\nXL\nM\nS\nS\nXL\nXL\nM\nXL\nM\nS\nM\nXL\nM\nM\nXL\nXL\nXL\nXL\nM\nM\nS\nM\nM\nS\nS\nS\nM\nM\nM\nM\nM\nM\nM\nS\nS\nS\nM\nM\nM\nS\nM\nM\nS\nS\nM\nM\nM\nM\nM\nM\nM" }, { "input": "302 143 40 63 452\n100\nXXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL", "output": "XXL\nM\nXL\nS\nXXL\nS\nL\nXL\nXL\nXL\nXXL\nS\nXXL\nS\nXXL\nXL\nXL\nXXL\nXL\nXXL\nM\nS\nS\nS\nS\nXXL\nS\nL\nXL\nXXL\nXXL\nS\nXXL\nL\nXXL\nM\nS\nL\nL\nXL\nXL\nS\nXL\nL\nXL\nM\nXL\nL\nM\nS\nXL\nXXL\nXL\nL\nXL\nXL\nXL\nM\nM\nXL\nL\nS\nS\nXL\nS\nXXL\nXXL\nXL\nS\nXL\nXXL\nS\nS\nL\nL\nXXL\nXL\nL\nXL\nM\nS\nM\nM\nXL\nXXL\nS\nXL\nXL\nM\nXL\nXXL\nXXL\nXL\nL\nS\nM\nXXL\nM\nL\nXXL" } ]
1,569,529,880
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
10
248
0
l = input().split() for i in range(len(l)): l[i]= int(l[i]) n_sizes = ["S","M","L","XL","XXL"] s_sizes = { "S" : 0, "M" : 1, "L": 2, "XL": 3, "XXL":4, } n = int(input()) ans = "" for i in range(n): k = 10 size = s_sizes[input()] for j in range(len(l)): if l[j]>0: k = min(abs(size-j),k) if size+k>4: ans += n_sizes[size-k]+" " l[size-k]+=-1 else: ans += n_sizes[size+k]+" " l[size+k]+=-1 print(ans)
Title: T-shirts from Sponsor Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other hand, one doesn't want to order too many T-shirts (and we do not exactly paper the walls with the oversupply). After considerable brain racking and some pre-estimating, the sponsor representatives ordered a certain number of T-shirts of sizes S, M, L, XL and XXL. The T-shirts turned out to bring good luck, that's why on the contest day there built up a line of *K* participants willing to get one. Every contestant is characterized by his/her desired T-shirt size (so it happens that for all the participants it is also one of the sizes S, M, L, XL and XXL). The participants come up to get a T-shirt one by one and try to choose the most suitable one, choosing it like this. If there is still a T-shirt of the optimal size left, that he/she takes it without further ado. Otherwise the contestant would prefer to choose a T-shirt with the size as close to the optimal one as possible (the distance between neighboring sizes is considered equal to one). If the variant of choice is not unique, the contestant will take a T-shirt of a bigger size (in case he/she grows more). For example, for a person whose optimal size is L the preference list looks like this: L, XL, M, XXL, S. Using the data on how many T-shirts of every size had been ordered by the organizers, on the size of contestants in the line determine who got a T-shirt of what size. Input Specification: The first line contains five non-negative integers *N**S*,<=*N**M*,<=*N**L*,<=*N**XL*,<=*N**XXL* not exceeding 1000 which represent the number of T-shirts of the corresponding sizes. The second line contains an integer *K* (1<=≤<=*K*<=≤<=1000) which represents the number of participants. The next *K* lines contain the optimal T-shirt sizes for the contestants. The sizes are given in the order in which the participants stand in the line. It is guaranteed that *N**S*<=+<=*N**M*<=+<=*N**L*<=+<=*N**XL*<=+<=*N**XXL*<=≥<=*K*. Output Specification: For each contestant, print a line containing the size of the T-shirt he/she got. Demo Input: ['1 0 2 0 1\n3\nXL\nXXL\nM\n'] Demo Output: ['XXL\nL\nL\n'] Note: none
```python l = input().split() for i in range(len(l)): l[i]= int(l[i]) n_sizes = ["S","M","L","XL","XXL"] s_sizes = { "S" : 0, "M" : 1, "L": 2, "XL": 3, "XXL":4, } n = int(input()) ans = "" for i in range(n): k = 10 size = s_sizes[input()] for j in range(len(l)): if l[j]>0: k = min(abs(size-j),k) if size+k>4: ans += n_sizes[size-k]+" " l[size-k]+=-1 else: ans += n_sizes[size+k]+" " l[size+k]+=-1 print(ans) ```
0
38
A
Army
PROGRAMMING
800
[ "implementation" ]
A. Army
2
256
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream.
The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated.
Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*.
[ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ]
[ "5\n", "11\n" ]
none
0
[ { "input": "3\n5 6\n1 2", "output": "5" }, { "input": "3\n5 6\n1 3", "output": "11" }, { "input": "2\n55\n1 2", "output": "55" }, { "input": "3\n85 78\n1 3", "output": "163" }, { "input": "4\n63 4 49\n2 3", "output": "4" }, { "input": "5\n93 83 42 56\n2 5", "output": "181" }, { "input": "6\n22 9 87 89 57\n1 6", "output": "264" }, { "input": "7\n52 36 31 23 74 78\n2 7", "output": "242" }, { "input": "8\n82 14 24 5 91 49 94\n3 8", "output": "263" }, { "input": "9\n12 40 69 39 59 21 59 5\n4 6", "output": "98" }, { "input": "10\n95 81 32 59 71 30 50 61 100\n1 6", "output": "338" }, { "input": "15\n89 55 94 4 15 69 19 60 91 77 3 94 91 62\n3 14", "output": "617" }, { "input": "20\n91 1 41 51 95 67 92 35 23 70 44 91 57 50 21 8 9 71 40\n8 17", "output": "399" }, { "input": "25\n70 95 21 84 97 39 12 98 53 24 78 29 84 65 70 22 100 17 69 27 62 48 35 80\n8 23", "output": "846" }, { "input": "30\n35 69 50 44 19 56 86 56 98 24 21 2 61 24 85 30 2 22 57 35 59 84 12 77 92 53 50 92 9\n1 16", "output": "730" }, { "input": "35\n2 34 47 15 27 61 6 88 67 20 53 65 29 68 77 5 78 86 44 98 32 81 91 79 54 84 95 23 65 97 22 33 42 87\n8 35", "output": "1663" }, { "input": "40\n32 88 59 36 95 45 28 78 73 30 97 13 13 47 48 100 43 21 22 45 88 25 15 13 63 25 72 92 29 5 25 11 50 5 54 51 48 84 23\n7 26", "output": "862" }, { "input": "45\n83 74 73 95 10 31 100 26 29 15 80 100 22 70 31 88 9 56 19 70 2 62 48 30 27 47 52 50 94 44 21 94 23 85 15 3 95 72 43 62 94 89 68 88\n17 40", "output": "1061" }, { "input": "50\n28 8 16 29 19 82 70 51 96 84 74 72 17 69 12 21 37 21 39 3 18 66 19 49 86 96 94 93 2 90 96 84 59 88 58 15 61 33 55 22 35 54 51 29 64 68 29 38 40\n23 28", "output": "344" }, { "input": "60\n24 28 25 21 43 71 64 73 71 90 51 83 69 43 75 43 78 72 56 61 99 7 23 86 9 16 16 94 23 74 18 56 20 72 13 31 75 34 35 86 61 49 4 72 84 7 65 70 66 52 21 38 6 43 69 40 73 46 5\n28 60", "output": "1502" }, { "input": "70\n69 95 34 14 67 61 6 95 94 44 28 94 73 66 39 13 19 71 73 71 28 48 26 22 32 88 38 95 43 59 88 77 80 55 17 95 40 83 67 1 38 95 58 63 56 98 49 2 41 4 73 8 78 41 64 71 60 71 41 61 67 4 4 19 97 14 39 20 27\n9 41", "output": "1767" }, { "input": "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24", "output": "219" }, { "input": "90\n61 35 100 99 67 87 42 90 44 4 81 65 29 63 66 56 53 22 55 87 39 30 34 42 27 80 29 97 85 28 81 22 50 22 24 75 67 86 78 79 94 35 13 97 48 76 68 66 94 13 82 1 22 85 5 36 86 73 65 97 43 56 35 26 87 25 74 47 81 67 73 75 99 75 53 38 70 21 66 78 38 17 57 40 93 57 68 55 1\n12 44", "output": "1713" }, { "input": "95\n37 74 53 96 65 84 65 72 95 45 6 77 91 35 58 50 51 51 97 30 51 20 79 81 92 10 89 34 40 76 71 54 26 34 73 72 72 28 53 19 95 64 97 10 44 15 12 38 5 63 96 95 86 8 36 96 45 53 81 5 18 18 47 97 65 9 33 53 41 86 37 53 5 40 15 76 83 45 33 18 26 5 19 90 46 40 100 42 10 90 13 81 40 53\n6 15", "output": "570" }, { "input": "96\n51 32 95 75 23 54 70 89 67 3 1 51 4 100 97 30 9 35 56 38 54 77 56 98 43 17 60 43 72 46 87 61 100 65 81 22 74 38 16 96 5 10 54 22 23 22 10 91 9 54 49 82 29 73 33 98 75 8 4 26 24 90 71 42 90 24 94 74 94 10 41 98 56 63 18 43 56 21 26 64 74 33 22 38 67 66 38 60 64 76 53 10 4 65 76\n21 26", "output": "328" }, { "input": "97\n18 90 84 7 33 24 75 55 86 10 96 72 16 64 37 9 19 71 62 97 5 34 85 15 46 72 82 51 52 16 55 68 27 97 42 72 76 97 32 73 14 56 11 86 2 81 59 95 60 93 1 22 71 37 77 100 6 16 78 47 78 62 94 86 16 91 56 46 47 35 93 44 7 86 70 10 29 45 67 62 71 61 74 39 36 92 24 26 65 14 93 92 15 28 79 59\n6 68", "output": "3385" }, { "input": "98\n32 47 26 86 43 42 79 72 6 68 40 46 29 80 24 89 29 7 21 56 8 92 13 33 50 79 5 7 84 85 24 23 1 80 51 21 26 55 96 51 24 2 68 98 81 88 57 100 64 84 54 10 14 2 74 1 89 71 1 20 84 85 17 31 42 58 69 67 48 60 97 90 58 10 21 29 2 21 60 61 68 89 77 39 57 18 61 44 67 100 33 74 27 40 83 29 6\n8 77", "output": "3319" }, { "input": "99\n46 5 16 66 53 12 84 89 26 27 35 68 41 44 63 17 88 43 80 15 59 1 42 50 53 34 75 16 16 55 92 30 28 11 12 71 27 65 11 28 86 47 24 10 60 47 7 53 16 75 6 49 56 66 70 3 20 78 75 41 38 57 89 23 16 74 30 39 1 32 49 84 9 33 25 95 75 45 54 59 17 17 29 40 79 96 47 11 69 86 73 56 91 4 87 47 31 24\n23 36", "output": "514" }, { "input": "100\n63 65 21 41 95 23 3 4 12 23 95 50 75 63 58 34 71 27 75 31 23 94 96 74 69 34 43 25 25 55 44 19 43 86 68 17 52 65 36 29 72 96 84 25 84 23 71 54 6 7 71 7 21 100 99 58 93 35 62 47 36 70 68 9 75 13 35 70 76 36 62 22 52 51 2 87 66 41 54 35 78 62 30 35 65 44 74 93 78 37 96 70 26 32 71 27 85 85 63\n43 92", "output": "2599" }, { "input": "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 46 82 1 61 89 92 6 56 28 8 46 80 56 90 91 38 38 17 69 64 57 68 13 44 45 38 8 72 61 39 87 2 73 88\n15 27", "output": "618" }, { "input": "2\n3\n1 2", "output": "3" }, { "input": "5\n6 8 22 22\n2 3", "output": "8" }, { "input": "6\n3 12 27 28 28\n3 4", "output": "27" }, { "input": "9\n1 2 2 2 2 3 3 5\n3 7", "output": "9" }, { "input": "10\n1 1 1 1 1 1 1 1 1\n6 8", "output": "2" }, { "input": "20\n1 1 1 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 3\n5 17", "output": "23" }, { "input": "25\n1 1 1 4 5 6 8 11 11 11 11 12 13 14 14 14 15 16 16 17 17 17 19 19\n4 8", "output": "23" }, { "input": "35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\n30 31", "output": "2" }, { "input": "45\n1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 3 3 4 5 5 5 5 6 6 6 6 6 6 6 7 7 7 7 8 8 8 9 9 9 9 9 10 10 10\n42 45", "output": "30" }, { "input": "50\n1 8 8 13 14 15 15 16 19 21 22 24 26 31 32 37 45 47 47 47 50 50 51 54 55 56 58 61 61 61 63 63 64 66 66 67 67 70 71 80 83 84 85 92 92 94 95 95 100\n4 17", "output": "285" }, { "input": "60\n1 2 4 4 4 6 6 8 9 10 10 13 14 18 20 20 21 22 23 23 26 29 30 32 33 34 35 38 40 42 44 44 46 48 52 54 56 56 60 60 66 67 68 68 69 73 73 74 80 80 81 81 82 84 86 86 87 89 89\n56 58", "output": "173" }, { "input": "70\n1 2 3 3 4 5 5 7 7 7 8 8 8 8 9 9 10 12 12 12 12 13 16 16 16 16 16 16 17 17 18 18 20 20 21 23 24 25 25 26 29 29 29 29 31 32 32 34 35 36 36 37 37 38 39 39 40 40 40 40 41 41 42 43 44 44 44 45 45\n62 65", "output": "126" }, { "input": "80\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 5 5 5 5 5 5 5 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 9 9 9 9 9 10 10 10 10 10 10 10 10 10 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12\n17 65", "output": "326" }, { "input": "90\n1 1 3 5 8 9 10 11 11 11 11 12 13 14 15 15 15 16 16 19 19 20 22 23 24 25 25 28 29 29 30 31 33 34 35 37 37 38 41 43 43 44 45 47 51 54 55 56 58 58 59 59 60 62 66 67 67 67 68 68 69 70 71 72 73 73 76 77 77 78 78 78 79 79 79 82 83 84 85 85 87 87 89 93 93 93 95 99 99\n28 48", "output": "784" }, { "input": "95\n2 2 3 3 4 6 6 7 7 7 9 10 12 12 12 12 13 14 15 16 17 18 20 20 20 20 21 21 21 21 22 22 22 22 22 23 23 23 25 26 26 27 27 27 28 29 29 30 30 31 32 33 34 36 37 37 38 39 39 39 42 43 43 43 45 47 48 50 50 51 52 53 54 54 54 55 55 55 58 59 60 61 61 61 61 62 62 63 64 65 66 67 67 67\n64 93", "output": "1636" }, { "input": "96\n1 1 2 3 3 5 8 9 9 10 10 10 11 11 11 11 11 12 13 13 13 14 15 15 16 16 17 17 17 17 18 18 20 20 20 21 21 21 23 24 24 25 25 26 27 27 27 27 29 29 29 30 30 30 32 32 32 32 32 32 33 33 34 34 34 35 35 35 36 36 37 37 37 38 39 40 41 41 41 41 42 42 43 43 45 45 45 46 46 47 47 49 50 52 52\n76 96", "output": "898" }, { "input": "98\n2 3 4 4 5 7 8 10 10 10 11 11 12 12 12 12 13 14 15 15 16 16 18 19 19 20 21 21 21 21 22 23 24 25 26 26 27 27 27 27 29 29 30 30 31 31 37 40 40 40 41 41 41 42 43 44 44 44 46 46 47 49 49 50 50 50 51 53 55 55 56 56 56 56 56 57 57 58 59 60 60 60 62 62 63 64 64 64 65 66 66 67 68 70 70 71 71\n8 90", "output": "3016" }, { "input": "99\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 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 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 1 1 1 1 1 1 1 1 1 1\n66 95", "output": "29" }, { "input": "100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 13 13 13 13 13 13 13 13 13 13 14 14 14 14 14 14 15 15 15 15 15 15 16 16 16 17 17\n39 52", "output": "82" }, { "input": "51\n5 7 9 16 19 25 26 29 29 30 31 32 32 41 43 44 47 49 50 50 51 52 54 55 56 63 64 66 67 70 74 74 77 78 79 80 80 85 86 87 89 89 90 92 93 94 94 95 95 97\n3 44", "output": "2268" } ]
1,598,706,770
2,147,483,647
PyPy 3
OK
TESTS
50
312
0
def do(): n = int(input()) dat = list(map(int, input().split())) a,b = map(int, input().split()) res = 0 for i in range(a-1, b-1): res += dat[i] print(res) do() def resolve(): #input = sys.stdin.readline from pprint import pprint #import sys #sys.setrecursionlimit(100000) q = int(input()) for _ in range(q): s = input() n = int(input()) n, k = map(int, input().split()) dat = list(map(int, input().split())) dat = [1, 2, 3] print(" ".join(list(map(str, res)))) pass import math math.ceil(1.2) math.floor(1.2) round(1.2, 3)
Title: Army Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. Input Specification: The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated. Output Specification: Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. Demo Input: ['3\n5 6\n1 2\n', '3\n5 6\n1 3\n'] Demo Output: ['5\n', '11\n'] Note: none
```python def do(): n = int(input()) dat = list(map(int, input().split())) a,b = map(int, input().split()) res = 0 for i in range(a-1, b-1): res += dat[i] print(res) do() def resolve(): #input = sys.stdin.readline from pprint import pprint #import sys #sys.setrecursionlimit(100000) q = int(input()) for _ in range(q): s = input() n = int(input()) n, k = map(int, input().split()) dat = list(map(int, input().split())) dat = [1, 2, 3] print(" ".join(list(map(str, res)))) pass import math math.ceil(1.2) math.floor(1.2) round(1.2, 3) ```
3.922
746
A
Compote
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0.
The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has.
Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote.
[ "2\n5\n7\n", "4\n7\n13\n", "2\n3\n2\n" ]
[ "7\n", "21\n", "0\n" ]
In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
500
[ { "input": "2\n5\n7", "output": "7" }, { "input": "4\n7\n13", "output": "21" }, { "input": "2\n3\n2", "output": "0" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n4", "output": "7" }, { "input": "1000\n1000\n1000", "output": "1750" }, { "input": "1\n1\n4", "output": "0" }, { "input": "1\n2\n3", "output": "0" }, { "input": "1\n1000\n1000", "output": "7" }, { "input": "1000\n1\n1000", "output": "0" }, { "input": "1000\n2\n1000", "output": "7" }, { "input": "1000\n500\n1000", "output": "1750" }, { "input": "1000\n1000\n4", "output": "7" }, { "input": "1000\n1000\n3", "output": "0" }, { "input": "4\n8\n12", "output": "21" }, { "input": "10\n20\n40", "output": "70" }, { "input": "100\n200\n399", "output": "693" }, { "input": "200\n400\n800", "output": "1400" }, { "input": "199\n400\n800", "output": "1393" }, { "input": "201\n400\n800", "output": "1400" }, { "input": "200\n399\n800", "output": "1393" }, { "input": "200\n401\n800", "output": "1400" }, { "input": "200\n400\n799", "output": "1393" }, { "input": "200\n400\n801", "output": "1400" }, { "input": "139\n252\n871", "output": "882" }, { "input": "109\n346\n811", "output": "763" }, { "input": "237\n487\n517", "output": "903" }, { "input": "161\n331\n725", "output": "1127" }, { "input": "39\n471\n665", "output": "273" }, { "input": "9\n270\n879", "output": "63" }, { "input": "137\n422\n812", "output": "959" }, { "input": "15\n313\n525", "output": "105" }, { "input": "189\n407\n966", "output": "1323" }, { "input": "18\n268\n538", "output": "126" }, { "input": "146\n421\n978", "output": "1022" }, { "input": "70\n311\n685", "output": "490" }, { "input": "244\n405\n625", "output": "1092" }, { "input": "168\n454\n832", "output": "1176" }, { "input": "46\n344\n772", "output": "322" }, { "input": "174\n438\n987", "output": "1218" }, { "input": "144\n387\n693", "output": "1008" }, { "input": "22\n481\n633", "output": "154" }, { "input": "196\n280\n848", "output": "980" }, { "input": "190\n454\n699", "output": "1218" }, { "input": "231\n464\n928", "output": "1617" }, { "input": "151\n308\n616", "output": "1057" }, { "input": "88\n182\n364", "output": "616" }, { "input": "12\n26\n52", "output": "84" }, { "input": "204\n412\n824", "output": "1428" }, { "input": "127\n256\n512", "output": "889" }, { "input": "224\n446\n896", "output": "1561" }, { "input": "146\n291\n584", "output": "1015" }, { "input": "83\n164\n332", "output": "574" }, { "input": "20\n38\n80", "output": "133" }, { "input": "198\n393\n792", "output": "1372" }, { "input": "120\n239\n480", "output": "833" }, { "input": "208\n416\n831", "output": "1449" }, { "input": "130\n260\n517", "output": "903" }, { "input": "67\n134\n267", "output": "462" }, { "input": "245\n490\n979", "output": "1708" }, { "input": "182\n364\n727", "output": "1267" }, { "input": "104\n208\n413", "output": "721" }, { "input": "10\n2\n100", "output": "7" }, { "input": "2\n100\n100", "output": "14" }, { "input": "2\n3\n8", "output": "7" }, { "input": "1\n2\n8", "output": "7" }, { "input": "1\n2\n200", "output": "7" }, { "input": "5\n4\n16", "output": "14" }, { "input": "1\n10\n10", "output": "7" }, { "input": "1\n4\n8", "output": "7" }, { "input": "100\n4\n1000", "output": "14" }, { "input": "2\n6\n12", "output": "14" }, { "input": "10\n7\n4", "output": "7" }, { "input": "2\n10\n100", "output": "14" }, { "input": "2\n3\n4", "output": "7" }, { "input": "1\n2\n999", "output": "7" }, { "input": "1\n10\n20", "output": "7" }, { "input": "100\n18\n20", "output": "35" }, { "input": "100\n1\n100", "output": "0" }, { "input": "3\n7\n80", "output": "21" }, { "input": "2\n8\n24", "output": "14" }, { "input": "1\n100\n100", "output": "7" }, { "input": "2\n1\n8", "output": "0" }, { "input": "10\n5\n23", "output": "14" } ]
1,691,718,956
2,147,483,647
Python 3
OK
TESTS
84
61
0
a=int(input()) b=int(input()) c=int(input()) count=0 for i in range(1,a+1): if i<=a and 2*i<=b and 4*i<=c: count+=7 else: break print(count)
Title: Compote Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nikolay has *a* lemons, *b* apples and *c* pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1:<=2:<=4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. Input Specification: The first line contains the positive integer *a* (1<=≤<=*a*<=≤<=1000) — the number of lemons Nikolay has. The second line contains the positive integer *b* (1<=≤<=*b*<=≤<=1000) — the number of apples Nikolay has. The third line contains the positive integer *c* (1<=≤<=*c*<=≤<=1000) — the number of pears Nikolay has. Output Specification: Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. Demo Input: ['2\n5\n7\n', '4\n7\n13\n', '2\n3\n2\n'] Demo Output: ['7\n', '21\n', '0\n'] Note: In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0.
```python a=int(input()) b=int(input()) c=int(input()) count=0 for i in range(1,a+1): if i<=a and 2*i<=b and 4*i<=c: count+=7 else: break print(count) ```
3
633
B
A Trivial Problem
PROGRAMMING
1,300
[ "brute force", "constructive algorithms", "math", "number theory" ]
null
null
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem?
The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial.
First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order.
[ "1\n", "5\n" ]
[ "5\n5 6 7 8 9 ", "0" ]
The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
500
[ { "input": "1", "output": "5\n5 6 7 8 9 " }, { "input": "5", "output": "0" }, { "input": "2", "output": "5\n10 11 12 13 14 " }, { "input": "3", "output": "5\n15 16 17 18 19 " }, { "input": "7", "output": "5\n30 31 32 33 34 " }, { "input": "12", "output": "5\n50 51 52 53 54 " }, { "input": "15", "output": "5\n65 66 67 68 69 " }, { "input": "18", "output": "5\n75 76 77 78 79 " }, { "input": "38", "output": "5\n155 156 157 158 159 " }, { "input": "47", "output": "5\n195 196 197 198 199 " }, { "input": "58", "output": "5\n240 241 242 243 244 " }, { "input": "66", "output": "5\n270 271 272 273 274 " }, { "input": "70", "output": "5\n285 286 287 288 289 " }, { "input": "89", "output": "5\n365 366 367 368 369 " }, { "input": "417", "output": "5\n1675 1676 1677 1678 1679 " }, { "input": "815", "output": "5\n3265 3266 3267 3268 3269 " }, { "input": "394", "output": "5\n1585 1586 1587 1588 1589 " }, { "input": "798", "output": "0" }, { "input": "507", "output": "5\n2035 2036 2037 2038 2039 " }, { "input": "406", "output": "5\n1630 1631 1632 1633 1634 " }, { "input": "570", "output": "5\n2290 2291 2292 2293 2294 " }, { "input": "185", "output": "0" }, { "input": "765", "output": "0" }, { "input": "967", "output": "0" }, { "input": "112", "output": "5\n455 456 457 458 459 " }, { "input": "729", "output": "5\n2925 2926 2927 2928 2929 " }, { "input": "4604", "output": "5\n18425 18426 18427 18428 18429 " }, { "input": "8783", "output": "5\n35140 35141 35142 35143 35144 " }, { "input": "1059", "output": "0" }, { "input": "6641", "output": "5\n26575 26576 26577 26578 26579 " }, { "input": "9353", "output": "5\n37425 37426 37427 37428 37429 " }, { "input": "1811", "output": "5\n7250 7251 7252 7253 7254 " }, { "input": "2528", "output": "0" }, { "input": "8158", "output": "5\n32640 32641 32642 32643 32644 " }, { "input": "3014", "output": "5\n12070 12071 12072 12073 12074 " }, { "input": "7657", "output": "5\n30640 30641 30642 30643 30644 " }, { "input": "4934", "output": "0" }, { "input": "9282", "output": "5\n37140 37141 37142 37143 37144 " }, { "input": "2610", "output": "5\n10450 10451 10452 10453 10454 " }, { "input": "2083", "output": "5\n8345 8346 8347 8348 8349 " }, { "input": "26151", "output": "5\n104620 104621 104622 104623 104624 " }, { "input": "64656", "output": "5\n258640 258641 258642 258643 258644 " }, { "input": "46668", "output": "5\n186690 186691 186692 186693 186694 " }, { "input": "95554", "output": "5\n382235 382236 382237 382238 382239 " }, { "input": "37320", "output": "0" }, { "input": "52032", "output": "5\n208140 208141 208142 208143 208144 " }, { "input": "11024", "output": "5\n44110 44111 44112 44113 44114 " }, { "input": "63218", "output": "5\n252885 252886 252887 252888 252889 " }, { "input": "40095", "output": "5\n160390 160391 160392 160393 160394 " }, { "input": "42724", "output": "5\n170910 170911 170912 170913 170914 " }, { "input": "24381", "output": "5\n97530 97531 97532 97533 97534 " }, { "input": "73138", "output": "5\n292570 292571 292572 292573 292574 " }, { "input": "93346", "output": "5\n373400 373401 373402 373403 373404 " }, { "input": "18338", "output": "5\n73370 73371 73372 73373 73374 " }, { "input": "42662", "output": "5\n170660 170661 170662 170663 170664 " }, { "input": "81221", "output": "5\n324900 324901 324902 324903 324904 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "100000", "output": "5\n400005 400006 400007 400008 400009 " }, { "input": "99998", "output": "0" }, { "input": "30", "output": "0" }, { "input": "11", "output": "0" }, { "input": "780", "output": "0" }, { "input": "97656", "output": "5\n390625 390626 390627 390628 390629 " }, { "input": "12499", "output": "5\n50000 50001 50002 50003 50004 " }, { "input": "65", "output": "5\n265 266 267 268 269 " }, { "input": "41", "output": "5\n170 171 172 173 174 " }, { "input": "31", "output": "5\n125 126 127 128 129 " }, { "input": "86577", "output": "0" } ]
1,463,565,384
2,147,483,647
Python 3
OK
TESTS
68
77
5,120,000
def num5(n): r = 0 while n: n //= 5 r += n return r m = int(input()) lo = 0 hi = int(1e20) while lo < hi: mi = (lo + hi) // 2 if num5(mi) < m: lo = mi + 1 else: hi = mi r = [] while num5(lo) == m: r.append(lo) lo += 1 print(len(r)) if r: print(" ".join(map(str, r)))
Title: A Trivial Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? Input Specification: The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. Output Specification: First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. Demo Input: ['1\n', '5\n'] Demo Output: ['5\n5 6 7 8 9 ', '0'] Note: The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*! = 1·2·3·...·*n*. In the first sample, 5! = 120, 6! = 720, 7! = 5040, 8! = 40320 and 9! = 362880.
```python def num5(n): r = 0 while n: n //= 5 r += n return r m = int(input()) lo = 0 hi = int(1e20) while lo < hi: mi = (lo + hi) // 2 if num5(mi) < m: lo = mi + 1 else: hi = mi r = [] while num5(lo) == m: r.append(lo) lo += 1 print(len(r)) if r: print(" ".join(map(str, r))) ```
3
461
A
Appleman and Toastman
PROGRAMMING
1,200
[ "greedy", "sortings" ]
null
null
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman.
Print a single integer — the largest possible score.
[ "3\n3 1 5\n", "1\n10\n" ]
[ "26\n", "10\n" ]
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
500
[ { "input": "3\n3 1 5", "output": "26" }, { "input": "1\n10", "output": "10" }, { "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376" }, { "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082" }, { "input": "10\n1 2 2 2 4 5 6 7 8 10", "output": "376" }, { "input": "10\n161821 171308 228496 397870 431255 542924 718337 724672 888642 892002", "output": "40204082" }, { "input": "1\n397870", "output": "397870" }, { "input": "1\n1000000", "output": "1000000" }, { "input": "10\n10 8 7 6 5 4 2 2 2 1", "output": "376" }, { "input": "10\n892002 888642 724672 718337 542924 431255 397870 228496 171308 161821", "output": "40204082" }, { "input": "10\n5 2 6 10 10 10 10 2 2 5", "output": "485" }, { "input": "10\n431255 724672 228496 397870 397870 397870 397870 724672 888642 431255", "output": "36742665" }, { "input": "10\n2 2 2 5 5 6 10 10 10 10", "output": "485" }, { "input": "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 888642", "output": "36742665" }, { "input": "10\n10 10 10 10 6 5 5 2 2 2", "output": "485" }, { "input": "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496", "output": "36742665" }, { "input": "10\n10 10 10 10 10 10 10 10 10 10", "output": "640" }, { "input": "10\n1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "64000000" }, { "input": "1\n397870", "output": "397870" }, { "input": "2\n1 2", "output": "6" }, { "input": "2\n2 3", "output": "10" }, { "input": "2\n1 1", "output": "4" } ]
1,512,618,869
2,147,483,647
Python 3
MEMORY_LIMIT_EXCEEDED
TESTS
6
764
268,390,400
n = int(input()) a = input().split() b = [] for i in range(n): a[i] = int(a[i]) a = sorted(a)[::-1] b.extend(a) while True: if len(a) == 1: break b.extend(a) x = a.pop() print(sum(b))
Title: Appleman and Toastman Time Limit: None seconds Memory Limit: None megabytes Problem Description: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. Output Specification: Print a single integer — the largest possible score. Demo Input: ['3\n3 1 5\n', '1\n10\n'] Demo Output: ['26\n', '10\n'] Note: Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
```python n = int(input()) a = input().split() b = [] for i in range(n): a[i] = int(a[i]) a = sorted(a)[::-1] b.extend(a) while True: if len(a) == 1: break b.extend(a) x = a.pop() print(sum(b)) ```
0
432
A
Choosing Teams
PROGRAMMING
800
[ "greedy", "implementation", "sortings" ]
null
null
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times?
The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship.
Print a single number — the answer to the problem.
[ "5 2\n0 4 5 1 0\n", "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n" ]
[ "1\n", "0\n", "2\n" ]
In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
500
[ { "input": "5 2\n0 4 5 1 0", "output": "1" }, { "input": "6 4\n0 1 2 3 4 5", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "3 4\n0 1 0", "output": "1" }, { "input": "3 4\n0 2 0", "output": "0" }, { "input": "6 5\n0 0 0 0 0 0", "output": "2" }, { "input": "12 2\n0 1 2 3 4 0 1 2 3 4 0 1", "output": "3" }, { "input": "15 2\n0 1 2 3 4 0 1 2 3 4 0 1 2 3 4", "output": "4" }, { "input": "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1", "output": "3" }, { "input": "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0", "output": "5" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "20 2\n1 4 5 1 3 4 0 5 0 3 3 0 4 0 0 1 4 2 0 4", "output": "4" }, { "input": "6 3\n4 4 4 4 4 4", "output": "0" }, { "input": "1 4\n1", "output": "0" }, { "input": "1 1\n0", "output": "0" }, { "input": "2 3\n0 0", "output": "0" } ]
1,698,473,491
2,147,483,647
Python 3
OK
TESTS
35
46
0
n, k = map(int, input().split()) countCompetitions = list(map(int, input().split())) countMembers = 0 for countCompetition in countCompetitions: if countCompetition + k <= 5: countMembers += 1 print(countMembers//3)
Title: Choosing Teams Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least *k* times? Input Specification: The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. Output Specification: Print a single number — the answer to the problem. Demo Input: ['5 2\n0 4 5 1 0\n', '6 4\n0 1 2 3 4 5\n', '6 5\n0 0 0 0 0 0\n'] Demo Output: ['1\n', '0\n', '2\n'] Note: In the first sample only one team could be made: the first, the fourth and the fifth participants. In the second sample no teams could be created. In the third sample two teams could be created. Any partition into two teams fits.
```python n, k = map(int, input().split()) countCompetitions = list(map(int, input().split())) countMembers = 0 for countCompetition in countCompetitions: if countCompetition + k <= 5: countMembers += 1 print(countMembers//3) ```
3
368
B
Sereja and Suffixes
PROGRAMMING
1,100
[ "data structures", "dp" ]
null
null
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*.
The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*).
Print *m* lines — on the *i*-th line print the answer to the number *l**i*.
[ "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" ]
[ "6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n" ]
none
1,000
[ { "input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10", "output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1" }, { "input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2", "output": "3\n4\n5" }, { "input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4", "output": "3\n5\n2\n4\n3\n3\n2\n5\n1\n3" }, { "input": "10 2\n2 6 5 7 2 2 3 2 4 8\n1\n2", "output": "7\n7" }, { "input": "7 1\n68346 10956 76708 23018 84063 34833 80407\n1", "output": "7" }, { "input": "2 2\n8 4\n1\n1", "output": "2\n2" }, { "input": "1 5\n5\n1\n1\n1\n1\n1", "output": "1\n1\n1\n1\n1" }, { "input": "4 7\n3 1 4 2\n4\n1\n2\n3\n2\n4\n4", "output": "1\n4\n3\n2\n3\n1\n1" }, { "input": "4 3\n9 1 7 1\n1\n4\n2", "output": "3\n1\n2" }, { "input": "8 3\n9280 6676 2720 6172 8329 10413 3975 1394\n5\n6\n7", "output": "4\n3\n2" }, { "input": "1 1\n1\n1", "output": "1" } ]
1,693,023,311
2,147,483,647
PyPy 3
OK
TESTS
30
888
12,595,200
n, m = map(int, input().split()) array = list(map(int, input().split())) queries = [] for _ in range(m): queries.append(int(input())) ans=[] d=set() for i in range(n): d.add(array[-i-1]) ans.append(len(d)) for l in queries: print(ans[-l])
Title: Sereja and Suffixes Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are staying on the positions *l**i*, *l**i*<=+<=1, ..., *n*. Formally, he want to find the number of distinct numbers among *a**l**i*,<=*a**l**i*<=+<=1,<=...,<=*a**n*.? Sereja wrote out the necessary array elements but the array was so large and the boy was so pressed for time. Help him, find the answer for the described question for each *l**i*. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements. Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). Output Specification: Print *m* lines — on the *i*-th line print the answer to the number *l**i*. Demo Input: ['10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n'] Demo Output: ['6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n'] Note: none
```python n, m = map(int, input().split()) array = list(map(int, input().split())) queries = [] for _ in range(m): queries.append(int(input())) ans=[] d=set() for i in range(n): d.add(array[-i-1]) ans.append(len(d)) for l in queries: print(ans[-l]) ```
3
146
B
Lucky Mask
PROGRAMMING
1,300
[ "brute force", "implementation" ]
null
null
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer *n* the number that is obtained after successive writing of all lucky digits of number *n* from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number. Petya has two numbers — an arbitrary integer *a* and a lucky number *b*. Help him find the minimum number *c* (*c*<=&gt;<=*a*) such that the mask of number *c* equals *b*.
The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky.
In the only line print a single number — the number *c* that is sought by Petya.
[ "1 7\n", "100 47\n" ]
[ "7\n", "147\n" ]
none
1,000
[ { "input": "1 7", "output": "7" }, { "input": "100 47", "output": "147" }, { "input": "458 47", "output": "467" }, { "input": "7 7", "output": "17" }, { "input": "547 47", "output": "647" }, { "input": "77 77", "output": "177" }, { "input": "44 4", "output": "45" }, { "input": "740 4", "output": "804" }, { "input": "100000 77777", "output": "177777" }, { "input": "77777 77777", "output": "177777" }, { "input": "47 74", "output": "74" }, { "input": "74 77", "output": "77" }, { "input": "77 74", "output": "174" }, { "input": "98545 7474", "output": "107474" }, { "input": "99997 4", "output": "100004" }, { "input": "100000 7", "output": "100007" }, { "input": "99997 47", "output": "100047" }, { "input": "47774 774", "output": "50774" }, { "input": "47744 7", "output": "50007" }, { "input": "45896 4", "output": "45898" }, { "input": "45679 77777", "output": "77777" }, { "input": "99979 77", "output": "100077" }, { "input": "10 77777", "output": "77777" }, { "input": "1 47774", "output": "47774" }, { "input": "47774 47774", "output": "147774" }, { "input": "47580 47774", "output": "47774" }, { "input": "55557 74", "output": "55574" }, { "input": "59765 4774", "output": "64774" }, { "input": "76492 447", "output": "80447" }, { "input": "69700 77477", "output": "77477" }, { "input": "31975 74", "output": "32074" }, { "input": "369 47", "output": "407" }, { "input": "39999 4", "output": "40000" }, { "input": "39999 4774", "output": "40774" }, { "input": "474 74", "output": "574" }, { "input": "40007 74444", "output": "74444" }, { "input": "40007 74", "output": "50074" }, { "input": "1 4", "output": "4" }, { "input": "4 4", "output": "14" }, { "input": "700 74", "output": "704" }, { "input": "476 47", "output": "478" }, { "input": "99999 77", "output": "100077" }, { "input": "46 7", "output": "57" } ]
1,619,147,119
2,147,483,647
PyPy 3
OK
TESTS
43
218
2,048,000
a, b= input().split() hap= True x, dig=int(a)+1, int(0) # while(x!=0): # x/=10 # dig+=1 while (hap): mask="" for y in str(x): if(int(y)==4 or int(y)==7): mask+=y if(mask==b): hap=False print(x) x+=1 # a+=pow(10,dig)
Title: Lucky Mask Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer *n* the number that is obtained after successive writing of all lucky digits of number *n* from the left to the right. For example, the mask of number 72174994 is number 7744, the mask of 7 is 7, the mask of 9999047 is 47. Obviously, mask of any number is always a lucky number. Petya has two numbers — an arbitrary integer *a* and a lucky number *b*. Help him find the minimum number *c* (*c*<=&gt;<=*a*) such that the mask of number *c* equals *b*. Input Specification: The only line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=105). It is guaranteed that number *b* is lucky. Output Specification: In the only line print a single number — the number *c* that is sought by Petya. Demo Input: ['1 7\n', '100 47\n'] Demo Output: ['7\n', '147\n'] Note: none
```python a, b= input().split() hap= True x, dig=int(a)+1, int(0) # while(x!=0): # x/=10 # dig+=1 while (hap): mask="" for y in str(x): if(int(y)==4 or int(y)==7): mask+=y if(mask==b): hap=False print(x) x+=1 # a+=pow(10,dig) ```
3
918
A
Eleven
PROGRAMMING
800
[ "brute force", "implementation" ]
null
null
Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.
The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000).
Print Eleven's new name on the first and only line of output.
[ "8\n", "15\n" ]
[ "OOOoOooO\n", "OOOoOooOooooOoo\n" ]
none
500
[ { "input": "8", "output": "OOOoOooO" }, { "input": "15", "output": "OOOoOooOooooOoo" }, { "input": "85", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooo" }, { "input": "381", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooo" }, { "input": "805", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1000", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "1", "output": "O" }, { "input": "2", "output": "OO" }, { "input": "3", "output": "OOO" }, { "input": "5", "output": "OOOoO" }, { "input": "17", "output": "OOOoOooOooooOoooo" }, { "input": "49", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooo" }, { "input": "256", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooo" }, { "input": "512", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "933", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "61", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooo" }, { "input": "781", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." }, { "input": "999", "output": "OOOoOooOooooOoooooooOooooooooooooOooooooooooooooooooooOoooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooOooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooOoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo..." } ]
1,583,961,148
2,147,483,647
Python 3
OK
TESTS
18
109
409,600
# I make this just for fun because i'm done # Aimi Haraguni >> Konomi Suzuki >> Yui >> Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi. .. dude? # problems that involves any kind of persistent data structures are the best of the best, are not them? import random N=20 ar, br = [0]*1001, [0]*52 br[0], br[1], ar[1] = 1, 1, 1 for i in range(2, N, 1): br[i]=br[i-1]+br[i-2] if(br[i] <= 1000): ar[br[i]]=ar[br[i]]+1 n=int(input()) for i in range(1, n+1, 1): if(ar[i]!=0): print("O", end='') else: print("o", end='')
Title: Eleven Time Limit: None seconds Memory Limit: None megabytes Problem Description: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. Input Specification: The first and only line of input contains an integer *n* (1<=≤<=*n*<=≤<=1000). Output Specification: Print Eleven's new name on the first and only line of output. Demo Input: ['8\n', '15\n'] Demo Output: ['OOOoOooO\n', 'OOOoOooOooooOoo\n'] Note: none
```python # I make this just for fun because i'm done # Aimi Haraguni >> Konomi Suzuki >> Yui >> Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi. .. dude? # problems that involves any kind of persistent data structures are the best of the best, are not them? import random N=20 ar, br = [0]*1001, [0]*52 br[0], br[1], ar[1] = 1, 1, 1 for i in range(2, N, 1): br[i]=br[i-1]+br[i-2] if(br[i] <= 1000): ar[br[i]]=ar[br[i]]+1 n=int(input()) for i in range(1, n+1, 1): if(ar[i]!=0): print("O", end='') else: print("o", end='') ```
3
982
A
Row
PROGRAMMING
1,200
[ "brute force", "constructive algorithms" ]
null
null
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal". Note that the first and last seats are not adjacent (if $n \ne 2$).
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
[ "3\n101\n", "4\n1011\n", "5\n10001\n" ]
[ "Yes\n", "No\n", "No\n" ]
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
500
[ { "input": "3\n101", "output": "Yes" }, { "input": "4\n1011", "output": "No" }, { "input": "5\n10001", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010", "output": "Yes" }, { "input": "4\n0100", "output": "No" }, { "input": "42\n011000100101001001101011011010100010011010", "output": "No" }, { "input": "3\n001", "output": "No" }, { "input": "64\n1001001010010010100101010010010100100101001001001001010100101001", "output": "Yes" }, { "input": "3\n111", "output": "No" }, { "input": "4\n0000", "output": "No" }, { "input": "4\n0001", "output": "No" }, { "input": "4\n0010", "output": "No" }, { "input": "4\n0011", "output": "No" }, { "input": "4\n0101", "output": "Yes" }, { "input": "4\n0110", "output": "No" }, { "input": "4\n0111", "output": "No" }, { "input": "4\n1000", "output": "No" }, { "input": "4\n1001", "output": "Yes" }, { "input": "4\n1010", "output": "Yes" }, { "input": "4\n1100", "output": "No" }, { "input": "4\n1101", "output": "No" }, { "input": "4\n1110", "output": "No" }, { "input": "4\n1111", "output": "No" }, { "input": "2\n00", "output": "No" }, { "input": "2\n01", "output": "Yes" }, { "input": "2\n10", "output": "Yes" }, { "input": "2\n11", "output": "No" }, { "input": "3\n000", "output": "No" }, { "input": "3\n010", "output": "Yes" }, { "input": "3\n011", "output": "No" }, { "input": "3\n100", "output": "No" }, { "input": "3\n110", "output": "No" }, { "input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110", "output": "No" }, { "input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101", "output": "Yes" }, { "input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011", "output": "No" }, { "input": "3\n001", "output": "No" }, { "input": "4\n0010", "output": "No" }, { "input": "3\n111", "output": "No" }, { "input": "4\n0110", "output": "No" }, { "input": "2\n11", "output": "No" }, { "input": "2\n10", "output": "Yes" }, { "input": "2\n01", "output": "Yes" }, { "input": "4\n1101", "output": "No" }, { "input": "2\n00", "output": "No" }, { "input": "4\n1111", "output": "No" }, { "input": "15\n000010101010000", "output": "No" }, { "input": "8\n10010100", "output": "No" }, { "input": "5\n00100", "output": "No" }, { "input": "6\n100100", "output": "No" }, { "input": "7\n1000001", "output": "No" }, { "input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010", "output": "Yes" } ]
1,536,811,902
2,147,483,647
Python 3
OK
TESTS
55
124
0
n = int(input()) seq = list(input()) yes = True for i in range(len(seq)): if seq[i] == '1': if (i != 0 and seq[i-1] == '1') or (i != len(seq) - 1 and seq[i+1] == '1'): yes = False break if i != 0 and seq[i-1] == '0': seq[i-1] = 'x' if i != len(seq) - 1 and seq[i+1] == '0': seq[i+1] = 'x' if yes and '0' in seq: yes = False # print(seq) print("YES" if yes else "NO")
Title: Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal". Note that the first and last seats are not adjacent (if $n \ne 2$). Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. Output Specification: Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase). Demo Input: ['3\n101\n', '4\n1011\n', '5\n10001\n'] Demo Output: ['Yes\n', 'No\n', 'No\n'] Note: In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
```python n = int(input()) seq = list(input()) yes = True for i in range(len(seq)): if seq[i] == '1': if (i != 0 and seq[i-1] == '1') or (i != len(seq) - 1 and seq[i+1] == '1'): yes = False break if i != 0 and seq[i-1] == '0': seq[i-1] = 'x' if i != len(seq) - 1 and seq[i+1] == '0': seq[i+1] = 'x' if yes and '0' in seq: yes = False # print(seq) print("YES" if yes else "NO") ```
3
758
A
Holiday Of Equality
PROGRAMMING
800
[ "implementation", "math" ]
null
null
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them.
The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen.
In the only line print the integer *S* — the minimum number of burles which are had to spend.
[ "5\n0 1 2 3 4\n", "5\n1 1 0 1 1\n", "3\n1 3 1\n", "1\n12\n" ]
[ "10", "1", "4", "0" ]
In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
500
[ { "input": "5\n0 1 2 3 4", "output": "10" }, { "input": "5\n1 1 0 1 1", "output": "1" }, { "input": "3\n1 3 1", "output": "4" }, { "input": "1\n12", "output": "0" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "14\n52518 718438 358883 462189 853171 592966 225788 46977 814826 295697 676256 561479 56545 764281", "output": "5464380" }, { "input": "21\n842556 216391 427181 626688 775504 168309 851038 448402 880826 73697 593338 519033 135115 20128 424606 939484 846242 756907 377058 241543 29353", "output": "9535765" }, { "input": "3\n1 3 2", "output": "3" }, { "input": "3\n2 1 3", "output": "3" }, { "input": "3\n2 3 1", "output": "3" }, { "input": "3\n3 1 2", "output": "3" }, { "input": "3\n3 2 1", "output": "3" }, { "input": "1\n228503", "output": "0" }, { "input": "2\n32576 550340", "output": "517764" }, { "input": "3\n910648 542843 537125", "output": "741328" }, { "input": "4\n751720 572344 569387 893618", "output": "787403" }, { "input": "6\n433864 631347 597596 794426 713555 231193", "output": "1364575" }, { "input": "9\n31078 645168 695751 126111 375934 150495 838412 434477 993107", "output": "4647430" }, { "input": "30\n315421 772664 560686 654312 151528 356749 351486 707462 820089 226682 546700 136028 824236 842130 578079 337807 665903 764100 617900 822937 992759 591749 651310 742085 767695 695442 17967 515106 81059 186025", "output": "13488674" }, { "input": "45\n908719 394261 815134 419990 926993 383792 772842 277695 527137 655356 684956 695716 273062 550324 106247 399133 442382 33076 462920 294674 846052 817752 421365 474141 290471 358990 109812 74492 543281 169434 919692 786809 24028 197184 310029 801476 699355 429672 51343 374128 776726 850380 293868 981569 550763", "output": "21993384" }, { "input": "56\n100728 972537 13846 385421 756708 184642 259487 319707 376662 221694 675284 972837 499419 13846 38267 289898 901299 831197 954715 197515 514102 910423 127555 883934 362472 870788 538802 741008 973434 448124 391526 363321 947321 544618 68006 782313 955075 741981 815027 723297 585059 718114 700739 413489 454091 736144 308999 98065 3716 347323 9635 289003 986510 607065 60236 273351", "output": "26984185" }, { "input": "70\n644488 5444 150441 714420 602059 335330 510670 196555 546346 740011 509449 850947 692874 524857 750434 952985 223744 374727 896124 753037 367352 679050 560202 172728 569291 778616 332116 286927 843598 372698 244906 498046 900681 709791 420904 724593 864493 813094 791377 39998 296710 625656 403891 579231 706693 984045 16901 574259 562265 761104 930361 256045 124461 538980 573508 372148 988722 108592 784354 55302 232524 277205 782251 299943 436488 743389 324618 742543 266915 99642", "output": "32816391" }, { "input": "1\n0", "output": "0" }, { "input": "1\n1000000", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000", "output": "99000000" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "99000000" }, { "input": "3\n0 0 0", "output": "0" }, { "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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "3\n5 0 0", "output": "10" }, { "input": "5\n2 10 0 0 0", "output": "38" } ]
1,674,413,636
2,147,483,647
PyPy 3-64
OK
TESTS
41
62
0
_ = input() arr = list(map(int,input().split())) a = max(arr) * len(arr) - sum(arr) print(a)
Title: Holiday Of Equality Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. Input Specification: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. Output Specification: In the only line print the integer *S* — the minimum number of burles which are had to spend. Demo Input: ['5\n0 1 2 3 4\n', '5\n1 1 0 1 1\n', '3\n1 3 1\n', '1\n12\n'] Demo Output: ['10', '1', '4', '0'] Note: In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles.
```python _ = input() arr = list(map(int,input().split())) a = max(arr) * len(arr) - sum(arr) print(a) ```
3
520
A
Pangram
PROGRAMMING
800
[ "implementation", "strings" ]
null
null
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
Output "YES", if the string is a pangram and "NO" otherwise.
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n" ]
[ "NO\n", "YES\n" ]
none
500
[ { "input": "12\ntoosmallword", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLazyDog", "output": "YES" }, { "input": "1\na", "output": "NO" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "YES" }, { "input": "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "YES" }, { "input": "48\nthereisasyetinsufficientdataforameaningfulanswer", "output": "NO" }, { "input": "30\nToBeOrNotToBeThatIsTheQuestion", "output": "NO" }, { "input": "30\njackdawslovemybigsphinxofquarz", "output": "NO" }, { "input": "31\nTHEFIVEBOXINGWIZARDSJUMPQUICKLY", "output": "YES" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "NO" }, { "input": "26\nMGJYIZDKsbhpVeNFlquRTcWoAx", "output": "YES" }, { "input": "26\nfWMOhAPsbIVtyUEZrGNQXDklCJ", "output": "YES" }, { "input": "26\nngPMVFSThiRCwLEuyOAbKxQzDJ", "output": "YES" }, { "input": "25\nnxYTzLFwzNolAumjgcAboyxAj", "output": "NO" }, { "input": "26\npRWdodGdxUESvcScPGbUoooZsC", "output": "NO" }, { "input": "66\nBovdMlDzTaqKllZILFVfxbLGsRnzmtVVTmqiIDTYrossLEPlmsPrkUYtWEsGHVOnFj", "output": "NO" }, { "input": "100\nmKtsiDRJypUieHIkvJaMFkwaKxcCIbBszZQLIyPpCDCjhNpAnYFngLjRpnKWpKWtGnwoSteeZXuFHWQxxxOpFlNeYTwKocsXuCoa", "output": "YES" }, { "input": "26\nEoqxUbsLjPytUHMiFnvcGWZdRK", "output": "NO" }, { "input": "26\nvCUFRKElZOnjmXGylWQaHDiPst", "output": "NO" }, { "input": "26\nWtrPuaHdXLKJMsnvQfgOiJZBEY", "output": "NO" }, { "input": "26\npGiFluRteQwkaVoPszJyNBChxM", "output": "NO" }, { "input": "26\ncTUpqjPmANrdbzSFhlWIoKxgVY", "output": "NO" }, { "input": "26\nLndjgvAEuICHKxPwqYztosrmBN", "output": "NO" }, { "input": "26\nMdaXJrCipnOZLykfqHWEStevbU", "output": "NO" }, { "input": "26\nEjDWsVxfKTqGXRnUMOLYcIzPba", "output": "NO" }, { "input": "26\nxKwzRMpunYaqsdfaBgJcVElTHo", "output": "NO" }, { "input": "26\nnRYUQsTwCPLZkgshfEXvBdoiMa", "output": "NO" }, { "input": "26\nHNCQPfJutyAlDGsvRxZWMEbIdO", "output": "NO" }, { "input": "26\nDaHJIpvKznQcmUyWsTGObXRFDe", "output": "NO" }, { "input": "26\nkqvAnFAiRhzlJbtyuWedXSPcOG", "output": "NO" }, { "input": "26\nhlrvgdwsIOyjcmUZXtAKEqoBpF", "output": "NO" }, { "input": "26\njLfXXiMhBTcAwQVReGnpKzdsYu", "output": "NO" }, { "input": "26\nlNMcVuwItjxRBGAekjhyDsQOzf", "output": "NO" }, { "input": "26\nRkSwbNoYldUGtAZvpFMcxhIJFE", "output": "NO" }, { "input": "26\nDqspXZJTuONYieKgaHLMBwfVSC", "output": "NO" }, { "input": "26\necOyUkqNljFHRVXtIpWabGMLDz", "output": "NO" }, { "input": "26\nEKAvqZhBnPmVCDRlgWJfOusxYI", "output": "NO" }, { "input": "26\naLbgqeYchKdMrsZxIPFvTOWNjA", "output": "NO" }, { "input": "26\nxfpBLsndiqtacOCHGmeWUjRkYz", "output": "NO" }, { "input": "26\nXsbRKtqleZPNIVCdfUhyagAomJ", "output": "NO" }, { "input": "26\nAmVtbrwquEthZcjKPLiyDgSoNF", "output": "NO" }, { "input": "26\nOhvXDcwqAUmSEPRZGnjFLiKtNB", "output": "NO" }, { "input": "26\nEKWJqCFLRmstxVBdYuinpbhaOg", "output": "NO" }, { "input": "26\nmnbvcxxlkjhgfdsapoiuytrewq", "output": "NO" }, { "input": "26\naAbcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "30\nABCDEFGHTYRIOPLabcdefghtyriopl", "output": "NO" }, { "input": "25\nabcdefghijklmnopqrstuvwxy", "output": "NO" }, { "input": "26\nabcdefhijklmnopqrstVxyzABC", "output": "NO" }, { "input": "25\nqwertyuiopasdfghjklxcvbnm", "output": "NO" }, { "input": "34\nTheQuickBrownFoxJumpsOverTheLayDog", "output": "NO" }, { "input": "26\nabcdefghigklmnopqrstuvwxyz", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxyA", "output": "NO" }, { "input": "50\nqazwsxedcrfvtgbyhnujmikolQWERTYUIOASDFGHJKLZXCVBNM", "output": "NO" }, { "input": "35\nTheQuickBrownFoxJumpsOverTheLasyDog", "output": "NO" }, { "input": "25\nbcdefghijklmnopqrstuvwxyz", "output": "NO" }, { "input": "38\nAbCdEfGhIjKlMnOpQrStVwXyZzzzzzzaaaaaaa", "output": "NO" }, { "input": "26\nabcdefghiklmnopqrstvxyzABC", "output": "NO" }, { "input": "26\nabcdefghijklmnopqrstuvwxzZ", "output": "NO" }, { "input": "50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY", "output": "NO" } ]
1,695,574,898
2,147,483,647
PyPy 3
OK
TESTS
59
124
2,048,000
import string alp = list(string.ascii_lowercase) n = int(input()) w = input().lower() count = 0 alrd=[] for i in w: if i in alp and i not in alrd: count+=1 alrd.append(i) if count==len(alp): print("YES") else: print("NO")
Title: Pangram Time Limit: None seconds Memory Limit: None megabytes Problem Description: A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. Output Specification: Output "YES", if the string is a pangram and "NO" otherwise. Demo Input: ['12\ntoosmallword\n', '35\nTheQuickBrownFoxJumpsOverTheLazyDog\n'] Demo Output: ['NO\n', 'YES\n'] Note: none
```python import string alp = list(string.ascii_lowercase) n = int(input()) w = input().lower() count = 0 alrd=[] for i in w: if i in alp and i not in alrd: count+=1 alrd.append(i) if count==len(alp): print("YES") else: print("NO") ```
3
259
B
Little Elephant and Magic Square
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.
[ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n" ]
[ "1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n" ]
none
1,000
[ { "input": "0 1 1\n1 0 1\n1 1 0", "output": "1 1 1\n1 1 1\n1 1 1" }, { "input": "0 3 6\n5 0 5\n4 7 0", "output": "6 3 6\n5 5 5\n4 7 4" }, { "input": "0 4 4\n4 0 4\n4 4 0", "output": "4 4 4\n4 4 4\n4 4 4" }, { "input": "0 54 48\n36 0 78\n66 60 0", "output": "69 54 48\n36 57 78\n66 60 45" }, { "input": "0 17 14\n15 0 15\n16 13 0", "output": "14 17 14\n15 15 15\n16 13 16" }, { "input": "0 97 56\n69 0 71\n84 43 0", "output": "57 97 56\n69 70 71\n84 43 83" }, { "input": "0 1099 1002\n1027 0 1049\n1074 977 0", "output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063" }, { "input": "0 98721 99776\n99575 0 99123\n98922 99977 0", "output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148" }, { "input": "0 6361 2304\n1433 0 8103\n7232 3175 0", "output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897" }, { "input": "0 99626 99582\n99766 0 99258\n99442 99398 0", "output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696" }, { "input": "0 99978 99920\n99950 0 99918\n99948 99890 0", "output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964" }, { "input": "0 840 666\n612 0 948\n894 720 0", "output": "834 840 666\n612 780 948\n894 720 726" }, { "input": "0 28 10\n12 0 24\n26 8 0", "output": "16 28 10\n12 18 24\n26 8 20" }, { "input": "0 120 83\n98 0 90\n105 68 0", "output": "79 120 83\n98 94 90\n105 68 109" }, { "input": "0 86900 85807\n85836 0 86842\n86871 85778 0", "output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368" }, { "input": "0 74 78\n78 0 74\n74 78 0", "output": "76 74 78\n78 76 74\n74 78 76" }, { "input": "0 505 681\n605 0 657\n581 757 0", "output": "707 505 681\n605 631 657\n581 757 555" }, { "input": "0 662 918\n822 0 854\n758 1014 0", "output": "934 662 918\n822 838 854\n758 1014 742" }, { "input": "0 93 95\n93 0 97\n95 97 0", "output": "97 93 95\n93 95 97\n95 97 93" }, { "input": "0 709 712\n719 0 695\n702 705 0", "output": "700 709 712\n719 707 695\n702 705 714" }, { "input": "0 7 6\n9 0 1\n4 3 0", "output": "2 7 6\n9 5 1\n4 3 8" }, { "input": "0 9 2\n3 0 7\n8 1 0", "output": "4 9 2\n3 5 7\n8 1 6" }, { "input": "0 1 43\n13 0 61\n31 73 0", "output": "67 1 43\n13 37 61\n31 73 7" }, { "input": "0 100000 100000\n100000 0 100000\n100000 100000 0", "output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000" } ]
1,588,505,387
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
186
307,200
a=[] for i in range(3): a.append(list(map(int,input().split()))) m,n,o=a[0][1]+a[0][2],a[1][0]+a[1][2],a[2][0]+a[2][1] x,y,z=max(m,n,o)-m,max(m,n,o)-n,max(m,n,o)-o x+=1 y+=1 z+=1 a[0][0],a[1][1],a[2][2]=x,y,z for i in range(3): for j in range(3): print(a[i][j],end=" ") print("")
Title: Little Elephant and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input Specification: The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Specification: Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Demo Input: ['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n'] Demo Output: ['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n'] Note: none
```python a=[] for i in range(3): a.append(list(map(int,input().split()))) m,n,o=a[0][1]+a[0][2],a[1][0]+a[1][2],a[2][0]+a[2][1] x,y,z=max(m,n,o)-m,max(m,n,o)-n,max(m,n,o)-o x+=1 y+=1 z+=1 a[0][0],a[1][1],a[2][2]=x,y,z for i in range(3): for j in range(3): print(a[i][j],end=" ") print("") ```
0
82
A
Double Cola
PROGRAMMING
1,100
[ "implementation", "math" ]
A. Double Cola
1
256
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.
The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.
Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially.
[ "1\n", "6\n", "1802\n" ]
[ "Sheldon\n", "Sheldon\n", "Penny\n" ]
none
500
[ { "input": "1", "output": "Sheldon" }, { "input": "6", "output": "Sheldon" }, { "input": "1802", "output": "Penny" }, { "input": "1", "output": "Sheldon" }, { "input": "2", "output": "Leonard" }, { "input": "3", "output": "Penny" }, { "input": "4", "output": "Rajesh" }, { "input": "5", "output": "Howard" }, { "input": "10", "output": "Penny" }, { "input": "534", "output": "Rajesh" }, { "input": "5033", "output": "Howard" }, { "input": "10010", "output": "Howard" }, { "input": "500000000", "output": "Penny" }, { "input": "63", "output": "Rajesh" }, { "input": "841", "output": "Leonard" }, { "input": "3667", "output": "Penny" }, { "input": "38614", "output": "Howard" }, { "input": "282798", "output": "Rajesh" }, { "input": "9266286", "output": "Rajesh" }, { "input": "27385966", "output": "Leonard" }, { "input": "121580142", "output": "Penny" }, { "input": "5", "output": "Howard" }, { "input": "300", "output": "Howard" }, { "input": "1745", "output": "Leonard" }, { "input": "8302", "output": "Rajesh" }, { "input": "184518", "output": "Sheldon" }, { "input": "1154414", "output": "Rajesh" }, { "input": "28643950", "output": "Leonard" }, { "input": "159222638", "output": "Howard" }, { "input": "24", "output": "Penny" }, { "input": "505", "output": "Penny" }, { "input": "4425", "output": "Rajesh" }, { "input": "12079", "output": "Sheldon" }, { "input": "469726", "output": "Penny" }, { "input": "3961838", "output": "Penny" }, { "input": "57710446", "output": "Leonard" }, { "input": "80719470", "output": "Howard" }, { "input": "1000000000", "output": "Penny" }, { "input": "999999999", "output": "Penny" }, { "input": "999999998", "output": "Penny" }, { "input": "5", "output": "Howard" } ]
1,579,960,132
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
109
0
n = int(input()) l = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] if(n < len(l)): print(l[n-1]) else: print(l[n%(len(l)+1)])
Title: Double Cola Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. Input Specification: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. Output Specification: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Demo Input: ['1\n', '6\n', '1802\n'] Demo Output: ['Sheldon\n', 'Sheldon\n', 'Penny\n'] Note: none
```python n = int(input()) l = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"] if(n < len(l)): print(l[n-1]) else: print(l[n%(len(l)+1)]) ```
-1
0
none
none
none
0
[ "none" ]
null
null
For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions. He knows that this year *n* competitions will take place. During the *i*-th competition the participant must as quickly as possible complete a ride along a straight line from point *s**i* to point *f**i* (*s**i*<=&lt;<=*f**i*). Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius *r*. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius *r*. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle. At the beginning each participant can choose any point *b**i*, such that his bike is fully behind the starting line, that is, *b**i*<=&lt;<=*s**i*<=-<=*r*. After that, he starts the movement, instantly accelerates to his maximum speed and at time *ts**i*, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time *tf**i*), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time *tf**i*<=-<=*ts**i*. Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed *v*, but also on his choice of the initial point *b**i*. Now Maxim is asking you to calculate for each of *n* competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to *r*.
The first line contains three integers *n*, *r* and *v* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*r*,<=*v*<=≤<=109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively. Next *n* lines contain the descriptions of the contests. The *i*-th line contains two integers *s**i* and *f**i* (1<=≤<=*s**i*<=&lt;<=*f**i*<=≤<=109) — the coordinate of the start and the coordinate of the finish on the *i*-th competition.
Print *n* real numbers, the *i*-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=6. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if .
[ "2 1 2\n1 10\n5 9\n" ]
[ "3.849644710502\n1.106060157705\n" ]
none
0
[]
1,485,146,838
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
11
1,060
4,608,000
from math import cos, pi, sin TWO_PI = 2*pi def newton(x): t = x nt = t - (t + sin(t) - x)/(1 + cos(t)) while abs(nt - t) >= 1e-7: t = nt nt = t - (t + sin(t) - x)/(1 + cos(t)) return nt def min_time(d, r, v): k, x = divmod(d/r, TWO_PI) t = newton(x/2) return (2*t + k*TWO_PI) * r / v if __name__ == '__main__': n, r, v = map(int, input().split()) for _ in range(n): si, fi = map(int, input().split()) print(min_time(fi-si, r, v))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: For months Maxim has been coming to work on his favorite bicycle. And quite recently he decided that he is ready to take part in a cyclists' competitions. He knows that this year *n* competitions will take place. During the *i*-th competition the participant must as quickly as possible complete a ride along a straight line from point *s**i* to point *f**i* (*s**i*<=&lt;<=*f**i*). Measuring time is a complex process related to usage of a special sensor and a time counter. Think of the front wheel of a bicycle as a circle of radius *r*. Let's neglect the thickness of a tire, the size of the sensor, and all physical effects. The sensor is placed on the rim of the wheel, that is, on some fixed point on a circle of radius *r*. After that the counter moves just like the chosen point of the circle, i.e. moves forward and rotates around the center of the circle. At the beginning each participant can choose any point *b**i*, such that his bike is fully behind the starting line, that is, *b**i*<=&lt;<=*s**i*<=-<=*r*. After that, he starts the movement, instantly accelerates to his maximum speed and at time *ts**i*, when the coordinate of the sensor is equal to the coordinate of the start, the time counter starts. The cyclist makes a complete ride, moving with his maximum speed and at the moment the sensor's coordinate is equal to the coordinate of the finish (moment of time *tf**i*), the time counter deactivates and records the final time. Thus, the counter records that the participant made a complete ride in time *tf**i*<=-<=*ts**i*. Maxim is good at math and he suspects that the total result doesn't only depend on his maximum speed *v*, but also on his choice of the initial point *b**i*. Now Maxim is asking you to calculate for each of *n* competitions the minimum possible time that can be measured by the time counter. The radius of the wheel of his bike is equal to *r*. Input Specification: The first line contains three integers *n*, *r* and *v* (1<=≤<=*n*<=≤<=100<=000,<=1<=≤<=*r*,<=*v*<=≤<=109) — the number of competitions, the radius of the front wheel of Max's bike and his maximum speed, respectively. Next *n* lines contain the descriptions of the contests. The *i*-th line contains two integers *s**i* and *f**i* (1<=≤<=*s**i*<=&lt;<=*f**i*<=≤<=109) — the coordinate of the start and the coordinate of the finish on the *i*-th competition. Output Specification: Print *n* real numbers, the *i*-th number should be equal to the minimum possible time measured by the time counter. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=6. Namely: let's assume that your answer equals *a*, and the answer of the jury is *b*. The checker program will consider your answer correct if . Demo Input: ['2 1 2\n1 10\n5 9\n'] Demo Output: ['3.849644710502\n1.106060157705\n'] Note: none
```python from math import cos, pi, sin TWO_PI = 2*pi def newton(x): t = x nt = t - (t + sin(t) - x)/(1 + cos(t)) while abs(nt - t) >= 1e-7: t = nt nt = t - (t + sin(t) - x)/(1 + cos(t)) return nt def min_time(d, r, v): k, x = divmod(d/r, TWO_PI) t = newton(x/2) return (2*t + k*TWO_PI) * r / v if __name__ == '__main__': n, r, v = map(int, input().split()) for _ in range(n): si, fi = map(int, input().split()) print(min_time(fi-si, r, v)) ```
-1
455
A
Boredom
PROGRAMMING
1,500
[ "dp" ]
null
null
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105).
Print a single integer — the maximum number of points that Alex can earn.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n" ]
[ "2\n", "4\n", "10\n" ]
Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
500
[ { "input": "2\n1 2", "output": "2" }, { "input": "3\n1 2 3", "output": "4" }, { "input": "9\n1 2 1 3 2 2 2 2 3", "output": "10" }, { "input": "5\n3 3 4 5 4", "output": "11" }, { "input": "5\n5 3 5 3 4", "output": "16" }, { "input": "5\n4 2 3 2 5", "output": "9" }, { "input": "10\n10 5 8 9 5 6 8 7 2 8", "output": "46" }, { "input": "10\n1 1 1 1 1 1 2 3 4 4", "output": "14" }, { "input": "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10 7 1 1 10 7 7 7 2 3 4 2 8 4 7 4 4", "output": "296" }, { "input": "100\n6 1 5 7 10 10 2 7 3 7 2 10 7 6 3 5 5 5 3 7 2 4 2 7 7 4 2 8 2 10 4 7 9 1 1 7 9 7 1 10 10 9 5 6 10 1 7 5 8 1 1 5 3 10 2 4 3 5 2 7 4 9 5 10 1 3 7 6 6 9 3 6 6 10 1 10 6 1 10 3 4 1 7 9 2 7 8 9 3 3 2 4 6 6 1 2 9 4 1 2", "output": "313" }, { "input": "100\n7 6 3 8 8 3 10 5 3 8 6 4 6 9 6 7 3 9 10 7 5 5 9 10 7 2 3 8 9 5 4 7 9 3 6 4 9 10 7 6 8 7 6 6 10 3 7 4 5 7 7 5 1 5 4 8 7 3 3 4 7 8 5 9 2 2 3 1 6 4 6 6 6 1 7 10 7 4 5 3 9 2 4 1 5 10 9 3 9 6 8 5 2 1 10 4 8 5 10 9", "output": "298" }, { "input": "100\n2 10 9 1 2 6 7 2 2 8 9 9 9 5 6 2 5 1 1 10 7 4 5 5 8 1 9 4 10 1 9 3 1 8 4 10 8 8 2 4 6 5 1 4 2 2 1 2 8 5 3 9 4 10 10 7 8 6 1 8 2 6 7 1 6 7 3 10 10 3 7 7 6 9 6 8 8 10 4 6 4 3 3 3 2 3 10 6 8 5 5 10 3 7 3 1 1 1 5 5", "output": "312" }, { "input": "100\n4 9 7 10 4 7 2 6 1 9 1 8 7 5 5 7 6 7 9 8 10 5 3 5 7 10 3 2 1 3 8 9 4 10 4 7 6 4 9 6 7 1 9 4 3 5 8 9 2 7 10 5 7 5 3 8 10 3 8 9 3 4 3 10 6 5 1 8 3 2 5 8 4 7 5 3 3 2 6 9 9 8 2 7 6 3 2 2 8 8 4 5 6 9 2 3 2 2 5 2", "output": "287" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n4 8 10 1 8 8 8 1 10 3 1 8 6 8 6 1 10 3 3 3 3 7 2 1 1 6 10 1 7 9 8 10 3 8 6 2 1 6 5 6 10 8 9 7 4 3 10 5 3 9 10 5 10 8 8 5 7 8 9 5 3 9 9 2 7 8 1 10 4 9 2 8 10 10 5 8 5 1 7 3 4 5 2 5 9 3 2 5 6 2 3 10 1 5 9 6 10 4 10 8", "output": "380" }, { "input": "100\n10 5 8 4 4 4 1 4 5 8 3 10 2 4 1 10 8 1 1 6 8 4 2 9 1 3 1 7 7 9 3 5 5 8 6 9 9 4 8 1 3 3 2 6 1 5 4 5 3 5 5 6 7 5 7 9 3 5 4 9 2 6 8 1 1 7 7 3 8 9 8 7 3 2 4 1 6 1 3 9 4 2 2 8 5 10 1 8 8 5 1 5 6 9 4 5 6 5 10 2", "output": "265" }, { "input": "100\n7 5 1 8 5 6 6 2 6 2 7 7 3 6 2 4 4 2 10 2 2 2 10 6 6 1 5 10 9 1 5 9 8 9 4 1 10 5 7 5 7 6 4 8 8 1 7 8 3 8 2 1 8 4 10 3 5 6 6 10 9 6 5 1 10 7 6 9 9 2 10 10 9 1 2 1 7 7 4 10 1 10 5 5 3 8 9 8 1 4 10 2 4 5 4 4 1 6 2 9", "output": "328" }, { "input": "100\n5 6 10 7 1 7 10 1 9 1 5 1 4 1 3 3 7 9 1 6 1 6 5 7 1 6 3 1 3 6 3 8 2 4 1 5 2 10 7 3 10 4 10 1 5 4 2 9 7 9 5 7 10 4 1 4 8 9 3 1 3 7 7 4 3 7 7 10 6 9 5 5 6 5 3 9 8 8 5 5 4 10 9 4 10 4 1 8 3 5 4 10 9 3 10 4 10 7 10 9", "output": "324" }, { "input": "10\n7 4 5 3 9 1 10 3 4 5", "output": "34" }, { "input": "10\n8 9 6 5 6 4 10 9 1 4", "output": "39" }, { "input": "10\n1 7 1 4 9 10 8 2 9 9", "output": "40" }, { "input": "1\n100000", "output": "100000" } ]
1,687,423,967
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
31
0
n = int(input()) tmp = map( int , input().split()) d = {} for ele in tmp: if ele not in d : d[ele] = 1 else : d[ele] += 1 arr = sorted(list(d.keys())) print( d ) # print( d.keys()) print( arr ) def func( d, arr, n , ptr = 0 , prev = -1 ): if n==ptr: return 0 ele = arr[ptr] sum = ele * d[ele] if n == ptr +1: return sum if prev + 1 == ele : return func(d , arr , n , ptr+1 , prev = prev ) a = func(d , arr , n , ptr+1 , prev = ele ) b = func(d , arr , n , ptr+1 , prev = prev ) return max( a , b+ sum ) abc = func( d, arr , n) print( abc)
Title: Boredom Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). Output Specification: Print a single integer — the maximum number of points that Alex can earn. Demo Input: ['2\n1 2\n', '3\n1 2 3\n', '9\n1 2 1 3 2 2 2 2 3\n'] Demo Output: ['2\n', '4\n', '10\n'] Note: Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
```python n = int(input()) tmp = map( int , input().split()) d = {} for ele in tmp: if ele not in d : d[ele] = 1 else : d[ele] += 1 arr = sorted(list(d.keys())) print( d ) # print( d.keys()) print( arr ) def func( d, arr, n , ptr = 0 , prev = -1 ): if n==ptr: return 0 ele = arr[ptr] sum = ele * d[ele] if n == ptr +1: return sum if prev + 1 == ele : return func(d , arr , n , ptr+1 , prev = prev ) a = func(d , arr , n , ptr+1 , prev = ele ) b = func(d , arr , n , ptr+1 , prev = prev ) return max( a , b+ sum ) abc = func( d, arr , n) print( abc) ```
0
799
A
Carrot Cakes
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.
The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven.
If it is reasonable to build the second oven, print "YES". Otherwise print "NO".
[ "8 6 4 5\n", "8 6 4 6\n", "10 3 11 4\n", "4 2 1 4\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n" ]
In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
500
[ { "input": "8 6 4 5", "output": "YES" }, { "input": "8 6 4 6", "output": "NO" }, { "input": "10 3 11 4", "output": "NO" }, { "input": "4 2 1 4", "output": "YES" }, { "input": "28 17 16 26", "output": "NO" }, { "input": "60 69 9 438", "output": "NO" }, { "input": "599 97 54 992", "output": "YES" }, { "input": "11 22 18 17", "output": "NO" }, { "input": "1 13 22 11", "output": "NO" }, { "input": "1 1 1 1", "output": "NO" }, { "input": "3 1 1 1", "output": "YES" }, { "input": "1000 1000 1000 1000", "output": "NO" }, { "input": "1000 1000 1 1", "output": "YES" }, { "input": "1000 1000 1 400", "output": "YES" }, { "input": "1000 1000 1 1000", "output": "YES" }, { "input": "1000 1000 1 999", "output": "YES" }, { "input": "53 11 3 166", "output": "YES" }, { "input": "313 2 3 385", "output": "NO" }, { "input": "214 9 9 412", "output": "NO" }, { "input": "349 9 5 268", "output": "YES" }, { "input": "611 16 8 153", "output": "YES" }, { "input": "877 13 3 191", "output": "YES" }, { "input": "340 9 9 10", "output": "YES" }, { "input": "31 8 2 205", "output": "NO" }, { "input": "519 3 2 148", "output": "YES" }, { "input": "882 2 21 219", "output": "NO" }, { "input": "982 13 5 198", "output": "YES" }, { "input": "428 13 6 272", "output": "YES" }, { "input": "436 16 14 26", "output": "YES" }, { "input": "628 10 9 386", "output": "YES" }, { "input": "77 33 18 31", "output": "YES" }, { "input": "527 36 4 8", "output": "YES" }, { "input": "128 18 2 169", "output": "YES" }, { "input": "904 4 2 288", "output": "YES" }, { "input": "986 4 3 25", "output": "YES" }, { "input": "134 8 22 162", "output": "NO" }, { "input": "942 42 3 69", "output": "YES" }, { "input": "894 4 9 4", "output": "YES" }, { "input": "953 8 10 312", "output": "YES" }, { "input": "43 8 1 121", "output": "YES" }, { "input": "12 13 19 273", "output": "NO" }, { "input": "204 45 10 871", "output": "YES" }, { "input": "342 69 50 425", "output": "NO" }, { "input": "982 93 99 875", "output": "NO" }, { "input": "283 21 39 132", "output": "YES" }, { "input": "1000 45 83 686", "output": "NO" }, { "input": "246 69 36 432", "output": "NO" }, { "input": "607 93 76 689", "output": "NO" }, { "input": "503 21 24 435", "output": "NO" }, { "input": "1000 45 65 989", "output": "NO" }, { "input": "30 21 2 250", "output": "YES" }, { "input": "1000 49 50 995", "output": "NO" }, { "input": "383 69 95 253", "output": "YES" }, { "input": "393 98 35 999", "output": "YES" }, { "input": "1000 22 79 552", "output": "NO" }, { "input": "268 294 268 154", "output": "NO" }, { "input": "963 465 706 146", "output": "YES" }, { "input": "304 635 304 257", "output": "NO" }, { "input": "4 2 1 6", "output": "NO" }, { "input": "1 51 10 50", "output": "NO" }, { "input": "5 5 4 4", "output": "YES" }, { "input": "3 2 1 1", "output": "YES" }, { "input": "3 4 3 3", "output": "NO" }, { "input": "7 3 4 1", "output": "YES" }, { "input": "101 10 1 1000", "output": "NO" }, { "input": "5 1 1 1", "output": "YES" }, { "input": "5 10 5 5", "output": "NO" }, { "input": "19 1 7 1", "output": "YES" }, { "input": "763 572 745 262", "output": "YES" }, { "input": "1 2 1 1", "output": "NO" }, { "input": "5 1 1 3", "output": "YES" }, { "input": "170 725 479 359", "output": "NO" }, { "input": "6 2 1 7", "output": "YES" }, { "input": "6 2 5 1", "output": "YES" }, { "input": "1 2 2 1", "output": "NO" }, { "input": "24 2 8 3", "output": "YES" }, { "input": "7 3 3 3", "output": "YES" }, { "input": "5 2 2 2", "output": "YES" }, { "input": "3 2 1 2", "output": "YES" }, { "input": "1000 2 200 8", "output": "NO" }, { "input": "3 100 2 100", "output": "NO" }, { "input": "2 999 1 1000", "output": "NO" }, { "input": "2 1 1 1", "output": "NO" }, { "input": "2 3 5 1", "output": "NO" }, { "input": "100 1 5 1", "output": "YES" }, { "input": "7 2 3 3", "output": "YES" }, { "input": "4 1 1 3", "output": "NO" }, { "input": "3 2 2 1", "output": "YES" }, { "input": "1 1 1 2", "output": "NO" }, { "input": "91 8 7 13", "output": "YES" }, { "input": "3 1 2 1", "output": "NO" }, { "input": "5 3 2 3", "output": "YES" }, { "input": "9 6 6 3", "output": "YES" } ]
1,697,658,076
2,147,483,647
PyPy 3
OK
TESTS
93
93
0
n,t,k,d=map(int, input().split()) from math import ceil time = ceil(n/k) * t if time <= (d + t): print("NO") else: print("YES")
Title: Carrot Cakes Time Limit: None seconds Memory Limit: None megabytes Problem Description: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. Input Specification: The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. Output Specification: If it is reasonable to build the second oven, print "YES". Otherwise print "NO". Demo Input: ['8 6 4 5\n', '8 6 4 6\n', '10 3 11 4\n', '4 2 1 4\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n', 'YES\n'] Note: In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven. In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven.
```python n,t,k,d=map(int, input().split()) from math import ceil time = ceil(n/k) * t if time <= (d + t): print("NO") else: print("YES") ```
3
472
A
Design Tutorial: Learn from Math
PROGRAMMING
800
[ "math", "number theory" ]
null
null
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers.
The only line contains an integer *n* (12<=≤<=*n*<=≤<=106).
Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them.
[ "12\n", "15\n", "23\n", "1000000\n" ]
[ "4 8\n", "6 9\n", "8 15\n", "500000 500000\n" ]
In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
500
[ { "input": "12", "output": "4 8" }, { "input": "15", "output": "6 9" }, { "input": "23", "output": "8 15" }, { "input": "1000000", "output": "500000 500000" }, { "input": "63874", "output": "4 63870" }, { "input": "14568", "output": "4 14564" }, { "input": "192", "output": "4 188" }, { "input": "86", "output": "4 82" }, { "input": "46220", "output": "4 46216" }, { "input": "57114", "output": "4 57110" }, { "input": "869", "output": "4 865" }, { "input": "738457", "output": "4 738453" }, { "input": "58113", "output": "6 58107" }, { "input": "4864", "output": "4 4860" }, { "input": "15", "output": "6 9" }, { "input": "74752", "output": "4 74748" }, { "input": "6073", "output": "4 6069" }, { "input": "1289", "output": "4 1285" }, { "input": "20", "output": "4 16" }, { "input": "58134", "output": "4 58130" }, { "input": "57756", "output": "4 57752" }, { "input": "765", "output": "6 759" }, { "input": "59", "output": "4 55" }, { "input": "991666", "output": "4 991662" }, { "input": "70761", "output": "4 70757" }, { "input": "13", "output": "4 9" }, { "input": "999999", "output": "4 999995" }, { "input": "17", "output": "8 9" }, { "input": "21", "output": "6 15" }, { "input": "19", "output": "4 15" }, { "input": "100007", "output": "6 100001" }, { "input": "999987", "output": "6 999981" }, { "input": "22", "output": "4 18" } ]
1,661,301,939
2,147,483,647
Python 3
OK
TESTS
33
46
0
num = int(input()) if num % 2 == 0: print(4) print(num - 4) else: print(9) print(num - 9)
Title: Design Tutorial: Learn from Math Time Limit: None seconds Memory Limit: None megabytes Problem Description: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem. You are given an integer *n* no less than 12, express it as a sum of two composite numbers. Input Specification: The only line contains an integer *n* (12<=≤<=*n*<=≤<=106). Output Specification: Output two composite integers *x* and *y* (1<=&lt;<=*x*,<=*y*<=&lt;<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. Demo Input: ['12\n', '15\n', '23\n', '1000000\n'] Demo Output: ['4 8\n', '6 9\n', '8 15\n', '500000 500000\n'] Note: In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well. In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.
```python num = int(input()) if num % 2 == 0: print(4) print(num - 4) else: print(9) print(num - 9) ```
3
856
C
Eleventh Birthday
PROGRAMMING
2,400
[ "combinatorics", "dp", "math" ]
null
null
It is Borya's eleventh birthday, and he has got a great present: *n* cards with numbers. The *i*-th card has the number *a**i* written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112. He is only 11, but he already knows that there are *n*! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112<==<=1192<=×<=11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there. Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways. Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353.
Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100). The descriptions of test cases follow. Each test is described by two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of cards in Borya's present. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — numbers written on the cards. It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000.
For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353.
[ "4\n2\n1 1\n3\n1 31 12\n3\n12345 67 84\n9\n1 2 3 4 5 6 7 8 9\n" ]
[ "2\n2\n2\n31680\n" ]
none
0
[]
1,693,661,901
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
0
15
0
print("_RANDOM_GUESS_1693661901.0046923")# 1693661901.0047073
Title: Eleventh Birthday Time Limit: None seconds Memory Limit: None megabytes Problem Description: It is Borya's eleventh birthday, and he has got a great present: *n* cards with numbers. The *i*-th card has the number *a**i* written on it. Borya wants to put his cards in a row to get one greater number. For example, if Borya has cards with numbers 1, 31, and 12, and he puts them in a row in this order, he would get a number 13112. He is only 11, but he already knows that there are *n*! ways to put his cards in a row. But today is a special day, so he is only interested in such ways that the resulting big number is divisible by eleven. So, the way from the previous paragraph is good, because 13112<==<=1192<=×<=11, but if he puts the cards in the following order: 31, 1, 12, he would get a number 31112, it is not divisible by 11, so this way is not good for Borya. Help Borya to find out how many good ways to put the cards are there. Borya considers all cards different, even if some of them contain the same number. For example, if Borya has two cards with 1 on it, there are two good ways. Help Borya, find the number of good ways to put the cards. This number can be large, so output it modulo 998244353. Input Specification: Input data contains multiple test cases. The first line of the input data contains an integer *t* — the number of test cases (1<=≤<=*t*<=≤<=100). The descriptions of test cases follow. Each test is described by two lines. The first line contains an integer *n* (1<=≤<=*n*<=≤<=2000) — the number of cards in Borya's present. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — numbers written on the cards. It is guaranteed that the total number of cards in all tests of one input data doesn't exceed 2000. Output Specification: For each test case output one line: the number of ways to put the cards to the table so that the resulting big number was divisible by 11, print the number modulo 998244353. Demo Input: ['4\n2\n1 1\n3\n1 31 12\n3\n12345 67 84\n9\n1 2 3 4 5 6 7 8 9\n'] Demo Output: ['2\n2\n2\n31680\n'] Note: none
```python print("_RANDOM_GUESS_1693661901.0046923")# 1693661901.0047073 ```
0
510
A
Fox And Snake
PROGRAMMING
800
[ "implementation" ]
null
null
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern.
The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number.
Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces.
[ "3 3\n", "3 4\n", "5 3\n", "9 9\n" ]
[ "###\n..#\n###\n", "####\n...#\n####\n", "###\n..#\n###\n#..\n###\n", "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n" ]
none
500
[ { "input": "3 3", "output": "###\n..#\n###" }, { "input": "3 4", "output": "####\n...#\n####" }, { "input": "5 3", "output": "###\n..#\n###\n#..\n###" }, { "input": "9 9", "output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########" }, { "input": "3 5", "output": "#####\n....#\n#####" }, { "input": "3 6", "output": "######\n.....#\n######" }, { "input": "7 3", "output": "###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "7 4", "output": "####\n...#\n####\n#...\n####\n...#\n####" }, { "input": "49 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "43 27", "output": "###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n..........................#\n###########################\n#..........................\n###########################\n....................." }, { "input": "11 15", "output": "###############\n..............#\n###############\n#..............\n###############\n..............#\n###############\n#..............\n###############\n..............#\n###############" }, { "input": "11 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "19 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###" }, { "input": "23 50", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................................." }, { "input": "49 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "33 43", "output": "###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#..........................................\n###########################################\n..........................................#\n###########################################\n#.................." }, { "input": "33 44", "output": "############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#...........................................\n############################################\n...........................................#\n############################################\n#......." }, { "input": "45 45", "output": "#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#############################################\n#............................................\n#############################################\n............................................#\n#########################################..." }, { "input": "45 49", "output": "#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#################################################\n#................................................\n#################################################\n................................................#\n#..." }, { "input": "45 3", "output": "###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###\n..#\n###\n#..\n###" }, { "input": "45 4", "output": "####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####\n...#\n####\n#...\n####" }, { "input": "5 4", "output": "####\n...#\n####\n#...\n####" }, { "input": "5 5", "output": "#####\n....#\n#####\n#....\n#####" }, { "input": "5 6", "output": "######\n.....#\n######\n#.....\n######" }, { "input": "7 5", "output": "#####\n....#\n#####\n#....\n#####\n....#\n#####" }, { "input": "7 6", "output": "######\n.....#\n######\n#.....\n######\n.....#\n######" }, { "input": "7 7", "output": "#######\n......#\n#######\n#......\n#######\n......#\n#######" } ]
1,693,464,625
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n, m = map(int, input().split()) snake = [['#'] * m for _ in range(n)] for i in range(1, n, 2): if i % 4 == 1: snake[i][-1] = '.' else: snake[i][0] = '.' for row in snake: print(''.join(row)) ``` You can run this code and input the values of `n` and `m` to get the snake pattern output.
Title: Fox And Snake Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern. Input Specification: The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number. Output Specification: Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. Demo Input: ['3 3\n', '3 4\n', '5 3\n', '9 9\n'] Demo Output: ['###\n..#\n###\n', '####\n...#\n####\n', '###\n..#\n###\n#..\n###\n', '#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n'] Note: none
```python n, m = map(int, input().split()) snake = [['#'] * m for _ in range(n)] for i in range(1, n, 2): if i % 4 == 1: snake[i][-1] = '.' else: snake[i][0] = '.' for row in snake: print(''.join(row)) ``` You can run this code and input the values of `n` and `m` to get the snake pattern output. ```
-1
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,655,536,133
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
a,b=input("").split(" ") a=float(a);b=float(b) def GCD(x, y): while(y): x, y = y, x % y return abs(x) print(int(GCD(a,b)))
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python a,b=input("").split(" ") a=float(a);b=float(b) def GCD(x, y): while(y): x, y = y, x % y return abs(x) print(int(GCD(a,b))) ```
0
272
A
Dima and Friends
PROGRAMMING
1,000
[ "implementation", "math" ]
null
null
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment. For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place. Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space.
In a single line print the answer to the problem.
[ "1\n1\n", "1\n2\n", "2\n3 5\n" ]
[ "3\n", "2\n", "3\n" ]
In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
500
[ { "input": "1\n1", "output": "3" }, { "input": "1\n2", "output": "2" }, { "input": "2\n3 5", "output": "3" }, { "input": "2\n3 5", "output": "3" }, { "input": "1\n5", "output": "3" }, { "input": "5\n4 4 3 5 1", "output": "4" }, { "input": "6\n2 3 2 2 1 3", "output": "4" }, { "input": "8\n2 2 5 3 4 3 3 2", "output": "4" }, { "input": "7\n4 1 3 2 2 4 5", "output": "4" }, { "input": "3\n3 5 1", "output": "4" }, { "input": "95\n4 2 3 4 4 5 2 2 4 4 3 5 3 3 3 5 4 2 5 4 2 1 1 3 4 2 1 3 5 4 2 1 1 5 1 1 2 2 4 4 5 4 5 5 2 1 2 2 2 4 5 5 2 4 3 4 4 3 5 2 4 1 5 4 5 1 3 2 4 2 2 1 5 3 1 5 3 4 3 3 2 1 2 2 1 3 1 5 2 3 1 1 2 5 2", "output": "5" }, { "input": "31\n3 2 3 3 3 3 4 4 1 5 5 4 2 4 3 2 2 1 4 4 1 2 3 1 1 5 5 3 4 4 1", "output": "4" }, { "input": "42\n3 1 2 2 5 1 2 2 4 5 4 5 2 5 4 5 4 4 1 4 3 3 4 4 4 4 3 2 1 3 4 5 5 2 1 2 1 5 5 2 4 4", "output": "5" }, { "input": "25\n4 5 5 5 3 1 1 4 4 4 3 5 4 4 1 4 4 1 2 4 2 5 4 5 3", "output": "5" }, { "input": "73\n3 4 3 4 5 1 3 4 2 1 4 2 2 3 5 3 1 4 2 3 2 1 4 5 3 5 2 2 4 3 2 2 5 3 2 3 5 1 3 1 1 4 5 2 4 2 5 1 4 3 1 3 1 4 2 3 3 3 3 5 5 2 5 2 5 4 3 1 1 5 5 2 3", "output": "4" }, { "input": "46\n1 4 4 5 4 5 2 3 5 5 3 2 5 4 1 3 2 2 1 4 3 1 5 5 2 2 2 2 4 4 1 1 4 3 4 3 1 4 2 2 4 2 3 2 5 2", "output": "4" }, { "input": "23\n5 2 1 1 4 2 5 5 3 5 4 5 5 1 1 5 2 4 5 3 4 4 3", "output": "5" }, { "input": "6\n4 2 3 1 3 5", "output": "4" }, { "input": "15\n5 5 5 3 5 4 1 3 3 4 3 4 1 4 4", "output": "5" }, { "input": "93\n1 3 1 4 3 3 5 3 1 4 5 4 3 2 2 4 3 1 4 1 2 3 3 3 2 5 1 3 1 4 5 1 1 1 4 2 1 2 3 1 1 1 5 1 5 5 1 2 5 4 3 2 2 4 4 2 5 4 5 5 3 1 3 1 2 1 3 1 1 2 3 4 4 5 5 3 2 1 3 3 5 1 3 5 4 4 1 3 3 4 2 3 2", "output": "5" }, { "input": "96\n1 5 1 3 2 1 2 2 2 2 3 4 1 1 5 4 4 1 2 3 5 1 4 4 4 1 3 3 1 4 5 4 1 3 5 3 4 4 3 2 1 1 4 4 5 1 1 2 5 1 2 3 1 4 1 2 2 2 3 2 3 3 2 5 2 2 3 3 3 3 2 1 2 4 5 5 1 5 3 2 1 4 3 5 5 5 3 3 5 3 4 3 4 2 1 3", "output": "5" }, { "input": "49\n1 4 4 3 5 2 2 1 5 1 2 1 2 5 1 4 1 4 5 2 4 5 3 5 2 4 2 1 3 4 2 1 4 2 1 1 3 3 2 3 5 4 3 4 2 4 1 4 1", "output": "5" }, { "input": "73\n4 1 3 3 3 1 5 2 1 4 1 1 3 5 1 1 4 5 2 1 5 4 1 5 3 1 5 2 4 5 1 4 3 3 5 2 2 3 3 2 5 1 4 5 2 3 1 4 4 3 5 2 3 5 1 4 3 5 1 2 4 1 3 3 5 4 2 4 2 4 1 2 5", "output": "5" }, { "input": "41\n5 3 5 4 2 5 4 3 1 1 1 5 4 3 4 3 5 4 2 5 4 1 1 3 2 4 5 3 5 1 5 5 1 1 1 4 4 1 2 4 3", "output": "5" }, { "input": "100\n3 3 1 4 2 4 4 3 1 5 1 1 4 4 3 4 4 3 5 4 5 2 4 3 4 1 2 4 5 4 2 1 5 4 1 1 4 3 2 4 1 2 1 4 4 5 5 4 4 5 3 2 5 1 4 2 2 1 1 2 5 2 5 1 5 3 1 4 3 2 4 3 2 2 4 5 5 1 2 3 1 4 1 2 2 2 5 5 2 3 2 4 3 1 1 2 1 2 1 2", "output": "5" }, { "input": "100\n2 1 1 3 5 4 4 2 3 4 3 4 5 4 5 4 2 4 5 3 4 5 4 1 1 4 4 1 1 2 5 4 2 4 5 3 2 5 4 3 4 5 1 3 4 2 5 4 5 4 5 2 4 1 2 5 3 1 4 4 5 3 4 3 1 2 5 4 2 5 4 1 5 3 5 4 1 2 5 3 1 1 1 1 5 3 4 3 5 1 1 5 5 1 1 2 2 1 5 1", "output": "5" }, { "input": "100\n4 4 3 3 2 5 4 4 2 1 4 4 4 5 4 1 2 1 5 2 4 3 4 1 4 1 2 5 1 4 5 4 2 1 2 5 3 4 5 5 2 1 2 2 2 2 2 3 2 5 1 2 2 3 2 5 5 1 3 4 5 2 1 3 4 2 2 4 4 3 3 3 2 3 2 1 5 5 5 2 1 4 2 3 5 1 4 4 2 3 2 5 5 4 3 5 1 3 5 5", "output": "5" }, { "input": "100\n4 4 2 5 4 2 2 3 4 4 3 2 3 3 1 3 4 3 3 4 1 3 1 4 5 3 4 3 1 1 1 3 3 2 3 4 3 4 2 2 1 5 1 4 5 1 1 1 3 3 1 1 3 2 5 4 2 5 2 4 5 4 4 1 1 2 1 1 4 5 1 1 5 3 3 2 5 5 5 1 4 1 4 1 1 3 2 3 4 4 2 5 5 2 5 1 1 3 5 3", "output": "5" }, { "input": "100\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "4" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "5" } ]
1,622,357,248
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
0
def solve(): A = int(input()) B = list(map(int, input().split())) res = sum(B) for i in range(1, 6): x = (res + i)%(A + 1) print(i, (x)) if(x != 1): return i return -1 print(solve())
Title: Dima and Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place. To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment. For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place. Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show. The numbers in the lines are separated by a single space. Output Specification: In a single line print the answer to the problem. Demo Input: ['1\n1\n', '1\n2\n', '2\n3 5\n'] Demo Output: ['3\n', '2\n', '3\n'] Note: In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend. In the second sample Dima can show 2 or 4 fingers.
```python def solve(): A = int(input()) B = list(map(int, input().split())) res = sum(B) for i in range(1, 6): x = (res + i)%(A + 1) print(i, (x)) if(x != 1): return i return -1 print(solve()) ```
0
630
A
Again Twenty Five!
PROGRAMMING
800
[ "number theory" ]
null
null
The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City?
The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5.
Output the last two digits of 5*n* without spaces between them.
[ "2\n" ]
[ "25" ]
none
0
[ { "input": "2", "output": "25" }, { "input": "7", "output": "25" }, { "input": "1000000000000000000", "output": "25" }, { "input": "2000000000000000000", "output": "25" }, { "input": "987654321012345678", "output": "25" } ]
1,694,439,099
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n=int(input()) print((n**5)%100)
Title: Again Twenty Five! Time Limit: None seconds Memory Limit: None megabytes Problem Description: The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of *n* and get last two digits of the number. Yes, of course, *n* can be rather big, and one cannot find the power using a calculator, but we need people who are able to think, not just follow the instructions." Could you pass the interview in the machine vision company in IT City? Input Specification: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=2·1018) — the power in which you need to raise number 5. Output Specification: Output the last two digits of 5*n* without spaces between them. Demo Input: ['2\n'] Demo Output: ['25'] Note: none
```python n=int(input()) print((n**5)%100) ```
0
66
B
Petya and Countryside
PROGRAMMING
1,100
[ "brute force", "implementation" ]
B. Petya and Countryside
2
256
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000.
Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section.
[ "1\n2\n", "5\n1 2 1 2 1\n", "8\n1 2 1 1 1 3 3 4\n" ]
[ "1\n", "3\n", "6\n" ]
none
1,000
[ { "input": "1\n2", "output": "1" }, { "input": "5\n1 2 1 2 1", "output": "3" }, { "input": "8\n1 2 1 1 1 3 3 4", "output": "6" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "10" }, { "input": "2\n100 100", "output": "2" }, { "input": "3\n100 100 100", "output": "3" }, { "input": "11\n1 2 3 4 5 6 5 4 3 2 1", "output": "11" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 100 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 1 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 1 82 83 84 85 86 87 88 89 90 91 92 93 94 100 5 4 3 2 1", "output": "81" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1 86 87 88 89 90 91 92 93 100 6 5 4 3 2 1", "output": "85" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 100 7 6 5 4 3 2 1", "output": "61" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 100 8 7 6 1 4 3 2 1", "output": "96" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 100 10 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 1 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 100 11 10 9 8 7 6 5 4 3 2 1", "output": "55" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 1 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 100 12 11 10 9 8 7 6 5 4 3 2 1", "output": "59" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 100 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "86" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 100 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "83" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 100 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 1 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "74" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 100 9 8 7 6 5 4 3 2 1", "output": "100" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 100 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 1 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1", "output": "52" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 100 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 1 2 1", "output": "98" }, { "input": "10\n1 4 4 4 4 4 1 2 4 3", "output": "7" } ]
1,688,202,923
2,147,483,647
Python 3
OK
TESTS
80
372
0
def tinhgiot(vitri): L = 0 i = vitri-1 while i >= 0 and a[i] <= a[i+1]: L += 1 i -= 1 R = 0 i = vitri+1 while i < len(a) and a[i] <= a[i-1]: R += 1 i += 1 return L+R+1 n = int(input()) a = [] a = list(map(int, input().split())) valuemax = 0 for j in range(0,n): if tinhgiot(j) > valuemax: valuemax = tinhgiot(j) print(valuemax)
Title: Petya and Countryside Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=×<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. Output Specification: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Demo Input: ['1\n2\n', '5\n1 2 1 2 1\n', '8\n1 2 1 1 1 3 3 4\n'] Demo Output: ['1\n', '3\n', '6\n'] Note: none
```python def tinhgiot(vitri): L = 0 i = vitri-1 while i >= 0 and a[i] <= a[i+1]: L += 1 i -= 1 R = 0 i = vitri+1 while i < len(a) and a[i] <= a[i-1]: R += 1 i += 1 return L+R+1 n = int(input()) a = [] a = list(map(int, input().split())) valuemax = 0 for j in range(0,n): if tinhgiot(j) > valuemax: valuemax = tinhgiot(j) print(valuemax) ```
3.907
400
A
Inna and Choose Options
PROGRAMMING
1,000
[ "implementation" ]
null
null
There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers *a* and *b* (*a*·*b*<==<=12), after that he makes a table of size *a*<=×<=*b* from the cards he put on the table as follows: the first *b* cards form the first row of the table, the second *b* cards form the second row of the table and so on, the last *b* cards form the last (number *a*) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses. Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers *a* and *b* to choose. Help her win the game: print to her all the possible ways of numbers *a*,<=*b* that she can choose and win.
The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The *i*-th character of the string shows the character that is written on the *i*-th card from the start.
For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line by whitespaces.
[ "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n" ]
[ "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n" ]
none
500
[ { "input": "4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0" }, { "input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX", "output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1" }, { "input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX", "output": "6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1" } ]
1,569,263,509
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
le=int(input()) for _ in range(le): str1=input() count=0 arr=[1,2,3,4,6,12] arr1=[] for num in arr: flag=False i=12//num for j in range(i): if(str1[j]=="X"): flag=True if(j+i>=12): flag=True break p=(num-1)*i+j for z in range(j,p,+i): if(str1[z]!="X"): flag=False break if(z==p-1): flag=True break if(flag): count+=1 arr1.append(str(str(num)+"x"+str(12//num))) print(count,end=" ") for j in arr1: print(j,end=" ") print("\t")
Title: Inna and Choose Options Time Limit: None seconds Memory Limit: None megabytes Problem Description: There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers *a* and *b* (*a*·*b*<==<=12), after that he makes a table of size *a*<=×<=*b* from the cards he put on the table as follows: the first *b* cards form the first row of the table, the second *b* cards form the second row of the table and so on, the last *b* cards form the last (number *a*) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses. Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers *a* and *b* to choose. Help her win the game: print to her all the possible ways of numbers *a*,<=*b* that she can choose and win. Input Specification: The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The *i*-th character of the string shows the character that is written on the *i*-th card from the start. Output Specification: For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line by whitespaces. Demo Input: ['4\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n'] Demo Output: ['3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0\n'] Note: none
```python le=int(input()) for _ in range(le): str1=input() count=0 arr=[1,2,3,4,6,12] arr1=[] for num in arr: flag=False i=12//num for j in range(i): if(str1[j]=="X"): flag=True if(j+i>=12): flag=True break p=(num-1)*i+j for z in range(j,p,+i): if(str1[z]!="X"): flag=False break if(z==p-1): flag=True break if(flag): count+=1 arr1.append(str(str(num)+"x"+str(12//num))) print(count,end=" ") for j in arr1: print(j,end=" ") print("\t") ```
0
222
E
Decoding Genome
PROGRAMMING
1,900
[ "dp", "matrices" ]
null
null
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*. The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value.
The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2). Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
Print a single integer — the sought number modulo 1000000007 (109<=+<=7).
[ "3 3 2\nab\nba\n", "3 3 0\n", "2 1 1\naa\n" ]
[ "17\n", "27\n", "0\n" ]
In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
2,500
[ { "input": "3 3 2\nab\nba", "output": "17" }, { "input": "3 3 0", "output": "27" }, { "input": "2 1 1\naa", "output": "0" }, { "input": "3 5 4\ncd\nce\ned\nee", "output": "89" }, { "input": "100 5 4\ncd\nce\ned\nee", "output": "537303881" }, { "input": "1 2 4\naa\nbb\nab\nba", "output": "2" }, { "input": "2 2 4\naa\nbb\nab\nba", "output": "0" }, { "input": "3 3 6\naa\nab\nac\nbb\nbc\ncc", "output": "1" }, { "input": "4 4 13\naa\nbc\nad\nac\nbb\nba\nda\ndb\ndd\ncc\nca\ncb\ncd", "output": "1" }, { "input": "2 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "2" }, { "input": "3 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "1" }, { "input": "4 3 7\naa\nac\nba\nbb\ncc\nca\ncb", "output": "0" }, { "input": "1 52 2\naA\nAa", "output": "52" }, { "input": "100000 52 0", "output": "378241178" }, { "input": "10000 52 10\nEN\nYJ\nKH\nGa\nQA\njY\nYf\nSt\nap\nDT", "output": "671474539" }, { "input": "1000000000000 2 0", "output": "959366170" }, { "input": "100 3 6\naa\nab\nac\nbb\nbc\ncc", "output": "0" }, { "input": "1000 10 20\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nab\nbc\ncd\nde\nef\nfg\ngh\nhi\nij\nja", "output": "207125595" }, { "input": "5000 3 0", "output": "22443616" }, { "input": "5000 4 7\naa\nab\nac\nad\nba\nca\nda", "output": "22443616" }, { "input": "5000 4 6\nab\nac\nad\nba\nca\nda", "output": "22443617" }, { "input": "10000 5 4\nce\nee\ncd\ned", "output": "386438816" }, { "input": "50000 52 10\nAa\naA\nBy\ntS\nzA\nZu\nyy\nUU\nen\neq", "output": "447275409" }, { "input": "1000000000000 3 5\naa\nab\nac\nba\nca", "output": "959366170" }, { "input": "1000000000000 3 3\naa\nab\nac", "output": "439049248" }, { "input": "1000000000000 3 4\nab\nac\nba\nca", "output": "959366171" }, { "input": "1000000000000 4 9\naa\nab\nac\nad\nbb\nbc\nbd\ncc\ncd", "output": "8" }, { "input": "1000000000000000 52 0", "output": "588668785" }, { "input": "1000000000000000 52 26\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz", "output": "271910099" }, { "input": "298470512649 26 20\nav\nsf\nqq\nyt\ncz\nkl\nqw\nwe\ner\nrt\nty\nfg\nin\nxy\nbt\nmm\njm\ndp\nno\nuy", "output": "399097981" }, { "input": "10000000000 20 15\nhs\npm\ncd\ner\nht\nmk\nce\nad\nfe\nmj\npf\nlm\nmo\nkd\nde", "output": "768931983" }, { "input": "1000000000000000 26 2\nfj\nho", "output": "688841650" }, { "input": "1000000000000000 10 0", "output": "478484352" }, { "input": "1000000000000000 10 1\ncd", "output": "82984398" }, { "input": "1000000000000000 12 3\nce\ndg\nfb", "output": "792123851" }, { "input": "853332331434235 35 77\nBy\nhs\nzB\njs\nIr\nEa\nHG\nxb\nxG\nFp\nAC\nDt\nwo\nFB\nzh\nim\ntx\nyi\ngC\nkp\njz\ndc\nwE\naa\nsG\nng\ncr\npB\nCg\ncv\nxs\nDn\ndg\nyj\nCd\naC\nIi\ngH\nml\nww\nAD\nir\nti\nEr\nCj\nHt\nAe\nsn\naH\nHv\nan\nDf\nGn\nfC\nay\ngB\nlh\nup\nda\nzs\nbh\nHB\nHd\nmg\nzy\nGi\nzm\nHq\nac\nCB\niE\ncc\nfi\ngm\nHf\neD\nqA", "output": "351800015" } ]
1,693,388,510
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
13
2,000
64,307,200
import sys # sys.setrecursionlimit(1000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from decimal import Decimal # from random import randint # from copy import deepcopy from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort from math import inf,sqrt,gcd,pow,ceil,floor,log,log2,log10,pi,sin,cos,tan,asin,acos,atan # from functools import cmp_to_key # from itertools import permutations,combinations def get(x): if x<=26: return chr(ord('a')+x) return chr(ord('A')+x-27) def binpow(a,b,p): res=1 while b: if b&1: res=res*a%p a=a*a%p b>>=1 return res n,m,k=map(int,input().split()) dp=[[0]*52 for i in range(n+1)] S=set() for i in range(m): c1=get(i) for j in range(m): c2=get(j) S.add(c1+c2) for i in range(k): S.remove(input()) for i in range(m): dp[1][i]=1 for i in range(2,n+1): for j in range(m): c2=get(j) for k in range(m): c1=get(k) if c1+c2 in S: dp[i][j]+=dp[i-1][k] suma=0;mod=1000000007 for i in range(m): suma=(suma+dp[n][i])%mod # print((binpow(52,n,mod)-suma)%mod) print(suma)
Title: Decoding Genome Time Limit: None seconds Memory Limit: None megabytes Problem Description: Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most *m* different nucleotides, numbered from 1 to *m*. Special characteristics of the Martian DNA prevent some nucleotide pairs from following consecutively in this chain. For example, if the nucleotide 1 and nucleotide 2 can not follow consecutively in the Martian DNA, then the chain of nucleotides [1, 2] is not a valid chain of Martian DNA, but the chain of nucleotides [2, 1] can be a valid chain (if there is no corresponding restriction). The number of nucleotide pairs that can't follow in the DNA chain consecutively, is *k*. The needs of gene research required information about the quantity of correct *n*-long chains of the Martian DNA. Your task is to write a program that will calculate this value. Input Specification: The first line contains three space-separated integers *n*,<=*m*,<=*k* (1<=≤<=*n*<=≤<=1015, 1<=≤<=*m*<=≤<=52, 0<=≤<=*k*<=≤<=*m*2). Next *k* lines contain two characters each, without a space between them, representing a forbidden nucleotide pair. The first character represents the first nucleotide in the forbidden pair, the second character represents the second nucleotide. The nucleotides with assigned numbers from 1 to 26 are represented by English alphabet letters from "a" to "z" (1 is an "a", 2 is a "b", ..., 26 is a "z"). Nucleotides with assigned numbers from 27 to 52 are represented by English alphabet letters from "A" to "Z" (27 is an "A", 28 is a "B", ..., 52 is a "Z"). It is guaranteed that each forbidden pair occurs at most once in the input. It is guaranteed that nucleotide's numbers in all forbidden pairs cannot be more than *m*. Note that order is important in nucleotide pairs. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Output Specification: Print a single integer — the sought number modulo 1000000007 (109<=+<=7). Demo Input: ['3 3 2\nab\nba\n', '3 3 0\n', '2 1 1\naa\n'] Demo Output: ['17\n', '27\n', '0\n'] Note: In the second test case all possible three-nucleotide DNAs are permitted. Each nucleotide can take one of three values, thus in total there are 27 distinct three nucleotide DNAs. In the third test sample we cannot make any DNA of two nucleotides — the only possible nucleotide "a" cannot occur two times consecutively.
```python import sys # sys.setrecursionlimit(1000000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from decimal import Decimal # from random import randint # from copy import deepcopy from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import bisect_left,bisect,insort from math import inf,sqrt,gcd,pow,ceil,floor,log,log2,log10,pi,sin,cos,tan,asin,acos,atan # from functools import cmp_to_key # from itertools import permutations,combinations def get(x): if x<=26: return chr(ord('a')+x) return chr(ord('A')+x-27) def binpow(a,b,p): res=1 while b: if b&1: res=res*a%p a=a*a%p b>>=1 return res n,m,k=map(int,input().split()) dp=[[0]*52 for i in range(n+1)] S=set() for i in range(m): c1=get(i) for j in range(m): c2=get(j) S.add(c1+c2) for i in range(k): S.remove(input()) for i in range(m): dp[1][i]=1 for i in range(2,n+1): for j in range(m): c2=get(j) for k in range(m): c1=get(k) if c1+c2 in S: dp[i][j]+=dp[i-1][k] suma=0;mod=1000000007 for i in range(m): suma=(suma+dp[n][i])%mod # print((binpow(52,n,mod)-suma)%mod) print(suma) ```
0
982
A
Row
PROGRAMMING
1,200
[ "brute force", "constructive algorithms" ]
null
null
You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal". Note that the first and last seats are not adjacent (if $n \ne 2$).
The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
[ "3\n101\n", "4\n1011\n", "5\n10001\n" ]
[ "Yes\n", "No\n", "No\n" ]
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
500
[ { "input": "3\n101", "output": "Yes" }, { "input": "4\n1011", "output": "No" }, { "input": "5\n10001", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "100\n0101001010101001010010010101001010100101001001001010010101010010101001001010101001001001010100101010", "output": "Yes" }, { "input": "4\n0100", "output": "No" }, { "input": "42\n011000100101001001101011011010100010011010", "output": "No" }, { "input": "3\n001", "output": "No" }, { "input": "64\n1001001010010010100101010010010100100101001001001001010100101001", "output": "Yes" }, { "input": "3\n111", "output": "No" }, { "input": "4\n0000", "output": "No" }, { "input": "4\n0001", "output": "No" }, { "input": "4\n0010", "output": "No" }, { "input": "4\n0011", "output": "No" }, { "input": "4\n0101", "output": "Yes" }, { "input": "4\n0110", "output": "No" }, { "input": "4\n0111", "output": "No" }, { "input": "4\n1000", "output": "No" }, { "input": "4\n1001", "output": "Yes" }, { "input": "4\n1010", "output": "Yes" }, { "input": "4\n1100", "output": "No" }, { "input": "4\n1101", "output": "No" }, { "input": "4\n1110", "output": "No" }, { "input": "4\n1111", "output": "No" }, { "input": "2\n00", "output": "No" }, { "input": "2\n01", "output": "Yes" }, { "input": "2\n10", "output": "Yes" }, { "input": "2\n11", "output": "No" }, { "input": "3\n000", "output": "No" }, { "input": "3\n010", "output": "Yes" }, { "input": "3\n011", "output": "No" }, { "input": "3\n100", "output": "No" }, { "input": "3\n110", "output": "No" }, { "input": "100\n0111001010101110001100000010011000100101110010001100111110101110001110101010111000010010011000000110", "output": "No" }, { "input": "357\n100101010010010010010100101001001010101010100100100100101001010101001010010100101001010100101001010010100100101001010101010101001001010100101010010100101001010100100100101010010010010100101010010010101001010010010101001001010010010101010100100101010010100100101001010100101001010100101001010010010010100101001010100100100100100100100101010101010010010100101", "output": "Yes" }, { "input": "459\n000111000101010000100001001010111110011011010001100101111010111011101110111101111101100101100011011001100110001001111001101000111001011100110100011111011111000010000110010011100110011011111110011100001101001111000100111011001000001011111100110100001001001100101011100001110110100101011011110100100111101011000101110000100110100100010000000100001001111111000011101010010011001111010111001100000100111001010111011010000011000011100101101011101000011011000110011", "output": "No" }, { "input": "3\n001", "output": "No" }, { "input": "4\n0010", "output": "No" }, { "input": "3\n111", "output": "No" }, { "input": "4\n0110", "output": "No" }, { "input": "2\n11", "output": "No" }, { "input": "2\n10", "output": "Yes" }, { "input": "2\n01", "output": "Yes" }, { "input": "4\n1101", "output": "No" }, { "input": "2\n00", "output": "No" }, { "input": "4\n1111", "output": "No" }, { "input": "15\n000010101010000", "output": "No" }, { "input": "8\n10010100", "output": "No" }, { "input": "5\n00100", "output": "No" }, { "input": "6\n100100", "output": "No" }, { "input": "7\n1000001", "output": "No" }, { "input": "98\n10101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010", "output": "Yes" } ]
1,666,974,343
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
30
0
n = int(input()) seats=input() flag=0 for i in range(n-1): if(seats[i]==seats[i+1]): if(seats[i]=="1" or seats[i]==seats[i+2]): print("NO") flag=1 break if(flag==0): print("YES")
Title: Row Time Limit: None seconds Memory Limit: None megabytes Problem Description: You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal". Note that the first and last seats are not adjacent (if $n \ne 2$). Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. Output Specification: Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase). Demo Input: ['3\n101\n', '4\n1011\n', '5\n10001\n'] Demo Output: ['Yes\n', 'No\n', 'No\n'] Note: In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
```python n = int(input()) seats=input() flag=0 for i in range(n-1): if(seats[i]==seats[i+1]): if(seats[i]=="1" or seats[i]==seats[i+2]): print("NO") flag=1 break if(flag==0): print("YES") ```
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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "50" }, { "input": "100\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992", "output": "42" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 1", "output": "2" }, { "input": "6\n5 4 3 2 1 2", "output": "2" }, { "input": "9\n1 2 3 4 5 6 7 8 9", "output": "9" }, { "input": "7\n99 100 1 2 3 4 5", "output": "5" }, { "input": "5\n3 3 1 2 3", "output": "3" }, { "input": "1\n100", "output": "1" }, { "input": "1\n5", "output": "1" } ]
1,697,741,004
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
from os import path import sys if(path.exists('input.txt')): sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") # for _ in range(int(input())): # n = int(input()) # l = [[j for j in input()] for i in range(n)] # print(l) # n,k = map(int,input().split()) n = int(input()) l = list(map(int,input().split())) i = 1 ca = 1 ans = 0 while(i<=n-1): if l[i]<l[i-1]: ca = 0 else: ca+=1 ans = max(ca,ans) i+=1 print(ans)
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 from os import path import sys if(path.exists('input.txt')): sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") # for _ in range(int(input())): # n = int(input()) # l = [[j for j in input()] for i in range(n)] # print(l) # n,k = map(int,input().split()) n = int(input()) l = list(map(int,input().split())) i = 1 ca = 1 ans = 0 while(i<=n-1): if l[i]<l[i-1]: ca = 0 else: ca+=1 ans = max(ca,ans) i+=1 print(ans) ```
0
876
A
Trip For Meal
PROGRAMMING
900
[ "math" ]
null
null
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters. For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store). Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance.
First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits. Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses. Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses. Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses.
Output one number — minimum distance in meters Winnie must go through to have a meal *n* times.
[ "3\n2\n3\n1\n", "1\n2\n3\n5\n" ]
[ "3\n", "0\n" ]
In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3. In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
500
[ { "input": "3\n2\n3\n1", "output": "3" }, { "input": "1\n2\n3\n5", "output": "0" }, { "input": "10\n1\n8\n3", "output": "9" }, { "input": "7\n10\n5\n6", "output": "30" }, { "input": "9\n9\n7\n5", "output": "42" }, { "input": "9\n37\n85\n76", "output": "296" }, { "input": "76\n46\n77\n11", "output": "860" }, { "input": "80\n42\n1\n37", "output": "79" }, { "input": "8\n80\n55\n1", "output": "61" }, { "input": "10\n13\n72\n17", "output": "117" }, { "input": "9\n24\n1\n63", "output": "8" }, { "input": "65\n5\n8\n7", "output": "320" }, { "input": "56\n8\n9\n3", "output": "170" }, { "input": "59\n8\n1\n2", "output": "58" }, { "input": "75\n50\n50\n5", "output": "415" }, { "input": "75\n54\n76\n66", "output": "3996" }, { "input": "73\n71\n69\n66", "output": "4755" }, { "input": "83\n58\n88\n16", "output": "1354" }, { "input": "74\n31\n11\n79", "output": "803" }, { "input": "62\n27\n16\n72", "output": "976" }, { "input": "72\n95\n27\n9", "output": "657" }, { "input": "1\n2\n2\n1", "output": "0" }, { "input": "1\n1\n1\n1", "output": "0" }, { "input": "1\n1\n1\n99", "output": "0" }, { "input": "100\n100\n100\n100", "output": "9900" }, { "input": "2\n1\n1\n3", "output": "1" }, { "input": "1\n3\n2\n1", "output": "0" }, { "input": "1\n5\n6\n1", "output": "0" }, { "input": "1\n2\n6\n1", "output": "0" }, { "input": "1\n30\n20\n1", "output": "0" }, { "input": "1\n15\n13\n11", "output": "0" }, { "input": "1\n100\n50\n1", "output": "0" }, { "input": "1\n2\n3\n1", "output": "0" }, { "input": "5\n5\n5\n5", "output": "20" }, { "input": "1\n100\n50\n5", "output": "0" }, { "input": "1\n5\n7\n3", "output": "0" }, { "input": "1\n3\n4\n2", "output": "0" }, { "input": "3\n3\n3\n3", "output": "6" }, { "input": "1\n99\n98\n1", "output": "0" }, { "input": "5\n3\n3\n1", "output": "6" }, { "input": "2\n1\n1\n1", "output": "1" }, { "input": "2\n1\n7\n8", "output": "1" }, { "input": "2\n2\n2\n1", "output": "2" }, { "input": "2\n2\n3\n1", "output": "2" }, { "input": "1\n5\n6\n2", "output": "0" }, { "input": "100\n1\n1\n100", "output": "99" }, { "input": "2\n3\n2\n1", "output": "2" }, { "input": "1\n99\n98\n97", "output": "0" } ]
1,618,511,883
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
21
62
0
n=int(input()) l=[] k=3 while(k): a=int(input()) l.append(a) k-=1 mn=min(l) if mn==l[-1]: d=min(l[0],l[1]) + (l[2] * (n-2)) print(d) else: d=min(l[0],l[1])*(n-1) print(d)
Title: Trip For Meal Time Limit: None seconds Memory Limit: None megabytes Problem Description: Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's and Eeyore's house is *b* meters, between Owl's and Eeyore's house is *c* meters. For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal *n* times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store). Winnie-the-Pooh does not like physical activity. He wants to have a meal *n* times, traveling minimum possible distance. Help him to find this distance. Input Specification: First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits. Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses. Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses. Fourth line contains an integer *c* (1<=≤<=*c*<=≤<=100) — distance between Owl's and Eeyore's houses. Output Specification: Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. Demo Input: ['3\n2\n3\n1\n', '1\n2\n3\n5\n'] Demo Output: ['3\n', '0\n'] Note: In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3. In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.
```python n=int(input()) l=[] k=3 while(k): a=int(input()) l.append(a) k-=1 mn=min(l) if mn==l[-1]: d=min(l[0],l[1]) + (l[2] * (n-2)) print(d) else: d=min(l[0],l[1])*(n-1) print(d) ```
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": "=" }, { "input": "0\n0000", "output": "=" }, { "input": "1213121\n1213121", "output": "=" }, { "input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479", "output": ">" }, { "input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8", "output": ">" }, { "input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772", "output": "<" }, { "input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "0000000001\n2", "output": "<" }, { "input": "1000000000000000000000000000000000\n1000000000000000000000000000000001", "output": "<" }, { "input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456", "output": "<" }, { "input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222", "output": "<" }, { "input": "123456789999999\n123456789999999", "output": "=" }, { "input": "111111111111111111111111111111\n222222222222222222222222222222", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "587345873489573457357834\n47957438573458347574375348", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333", "output": "<" }, { "input": "11111111111111111111111111111111111\n44444444444444444444444444444444444", "output": "<" }, { "input": "11111111111111111111111111111111111\n22222222222222222222222222222222222", "output": "<" }, { "input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "<" }, { "input": "1\n2", "output": "<" }, { "input": "9\n0", "output": ">" }, { "input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222", "output": "<" }, { "input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111", "output": "<" }, { "input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444", "output": "<" }, { "input": "01\n2", "output": "<" }, { "input": "00\n01", "output": "<" }, { "input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999", "output": "=" }, { "input": "43278947323248843213443272432\n793439250984509434324323453435435", "output": "<" }, { "input": "0\n1", "output": "<" }, { "input": "010\n011", "output": "<" }, { "input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "0001001\n0001010", "output": "<" }, { "input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111", "output": "=" }, { "input": "00000\n00", "output": "=" }, { "input": "999999999999999999999999999\n999999999999999999999999999", "output": "=" }, { "input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "001\n000000000010", "output": "<" }, { "input": "01\n10", "output": "<" }, { "input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "01\n02", "output": "<" }, { "input": "001111\n0001111", "output": "=" }, { "input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555", "output": "=" }, { "input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283", "output": "=" }, { "input": "001\n2", "output": "<" }, { "input": "000000000\n000000000", "output": "=" }, { "input": "000000\n10", "output": "<" }, { "input": "000000000000000\n001", "output": "<" }, { "input": "0000001\n2", "output": "<" }, { "input": "0000\n123", "output": "<" }, { "input": "951\n960", "output": "<" }, { "input": "002\n0001", "output": ">" }, { "input": "0000001\n01", "output": "=" }, { "input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999", "output": "=" }, { "input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012", "output": "=" }, { "input": "02\n01", "output": ">" }, { "input": "00000111111\n00000110111", "output": ">" }, { "input": "0123\n123", "output": "=" }, { "input": "123771237912798378912\n91239712798379812897389123123123123", "output": "<" }, { "input": "00001\n002", "output": "<" }, { "input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "=" }, { "input": "000000001\n00002", "output": "<" }, { "input": "00002\n00003", "output": "<" }, { "input": "000123456\n123457", "output": "<" }, { "input": "01\n00", "output": ">" }, { "input": "00\n0", "output": "=" }, { "input": "10\n11", "output": "<" }, { "input": "0011\n12", "output": "<" }, { "input": "00\n1", "output": "<" }, { "input": "0\n0", "output": "=" }, { "input": "00\n10", "output": "<" }, { "input": "011\n10", "output": ">" }, { "input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091", "output": "<" }, { "input": "0000001\n00", "output": ">" }, { "input": "01\n1", "output": "=" }, { "input": "010\n001", "output": ">" }, { "input": "100\n111", "output": "<" }, { "input": "1\n0", "output": ">" }, { "input": "000000\n000000000000000000000", "output": "=" }, { "input": "010101\n010101", "output": "=" }, { "input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111", "output": ">" }, { "input": "0000000\n0", "output": "=" }, { "input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123", "output": "<" }, { "input": "0010\n030", "output": "<" } ]
1,697,249,285
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include <bits/stdc++.h> using i64 = long long; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string a, b; std::cin >> a >> b; std::reverse(b.begin(), b.end()); std::reverse(a.begin(), a.end()); while (a.back() == '0') a.pop_back(); while (b.back() == '0') b.pop_back(); std::reverse(b.begin(), b.end()); std::reverse(a.begin(), a.end()); if (a == b) { std::cout << '=' << '\n'; return 0; } std::cout << (a > b ? ">" : "<") << '\n'; return 0; }
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 #include <bits/stdc++.h> using i64 = long long; signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::string a, b; std::cin >> a >> b; std::reverse(b.begin(), b.end()); std::reverse(a.begin(), a.end()); while (a.back() == '0') a.pop_back(); while (b.back() == '0') b.pop_back(); std::reverse(b.begin(), b.end()); std::reverse(a.begin(), a.end()); if (a == b) { std::cout << '=' << '\n'; return 0; } std::cout << (a > b ? ">" : "<") << '\n'; return 0; } ```
-1
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", "output": "1/6" }, { "input": "2 1", "output": "5/6" }, { "input": "2 2", "output": "5/6" }, { "input": "2 3", "output": "2/3" }, { "input": "2 4", "output": "1/2" }, { "input": "2 5", "output": "1/3" }, { "input": "2 6", "output": "1/6" }, { "input": "3 1", "output": "2/3" }, { "input": "3 2", "output": "2/3" }, { "input": "3 3", "output": "2/3" }, { "input": "3 4", "output": "1/2" }, { "input": "3 5", "output": "1/3" }, { "input": "3 6", "output": "1/6" }, { "input": "4 1", "output": "1/2" }, { "input": "4 3", "output": "1/2" }, { "input": "4 4", "output": "1/2" }, { "input": "4 5", "output": "1/3" }, { "input": "4 6", "output": "1/6" }, { "input": "5 1", "output": "1/3" }, { "input": "5 2", "output": "1/3" }, { "input": "5 3", "output": "1/3" }, { "input": "5 4", "output": "1/3" }, { "input": "5 5", "output": "1/3" }, { "input": "5 6", "output": "1/6" }, { "input": "6 1", "output": "1/6" }, { "input": "6 2", "output": "1/6" }, { "input": "6 3", "output": "1/6" }, { "input": "6 4", "output": "1/6" }, { "input": "6 5", "output": "1/6" }, { "input": "6 6", "output": "1/6" } ]
1,675,344,566
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
92
0
a,b=map(int,input().split()) v=max(a,b) vv=6-(v-1) if 6//vv==6/vv: print(f"{1}/{6 // vv}") else: print(f"{vv}/{6}")
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 a,b=map(int,input().split()) v=max(a,b) vv=6-(v-1) if 6//vv==6/vv: print(f"{1}/{6 // vv}") else: print(f"{vv}/{6}") ```
0