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
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,656,890,166
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
tab = input("write tab size: ") space = tab.index(" ") n1 = int(tab[0:space]) n2 = int(tab[space+1::]) print(int((n1*n2)/2)) # arr = [int(j) for j in input("").split()] # print(arr[0]*arr[1]//2) #print(eval(input().replace(' ','*'))//2) # s = 'python is fun' # c = 'n' # lst = [] # for pos,char in enumerate(s): # if(char == c): # lst.append(pos) # print(lst) # s = 'python is fun' # c = 'n' # print([pos for pos, char in enumerate(s) if char == c])
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python tab = input("write tab size: ") space = tab.index(" ") n1 = int(tab[0:space]) n2 = int(tab[space+1::]) print(int((n1*n2)/2)) # arr = [int(j) for j in input("").split()] # print(arr[0]*arr[1]//2) #print(eval(input().replace(' ','*'))//2) # s = 'python is fun' # c = 'n' # lst = [] # for pos,char in enumerate(s): # if(char == c): # lst.append(pos) # print(lst) # s = 'python is fun' # c = 'n' # print([pos for pos, char in enumerate(s) if char == c]) ```
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,440,621
2,147,483,647
Python 3
OK
TESTS
5
31
0
n= int(input()) if n==0: m='0' p=1 print(m,end='') print(p) elif n==1: m=0 p=5 print(m,end='') print(p) else: m=25 print(m)
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()) if n==0: m='0' p=1 print(m,end='') print(p) elif n==1: m=0 p=5 print(m,end='') print(p) else: m=25 print(m) ```
3
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,677,577,237
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
from math import ceil n, t, k, d =map(int,input().split()) if n <=k:print("NO") else: t1=0;t2=0 t1=ceil(n/k)*t bb=ceil(d/t) sub=n-(bb*k) tt=ceil(sub//2)*t t2=tt+bb*t if t1<=t2: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 from math import ceil n, t, k, d =map(int,input().split()) if n <=k:print("NO") else: t1=0;t2=0 t1=ceil(n/k)*t bb=ceil(d/t) sub=n-(bb*k) tt=ceil(sub//2)*t t2=tt+bb*t if t1<=t2:print("No") else:print("YES") ```
0
628
B
New Skateboard
PROGRAMMING
1,300
[ "dp" ]
null
null
Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.
The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9.
Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
[ "124\n", "04\n", "5810438174\n" ]
[ "4\n", "3\n", "9\n" ]
none
0
[ { "input": "124", "output": "4" }, { "input": "04", "output": "3" }, { "input": "5810438174", "output": "9" }, { "input": "1", "output": "0" }, { "input": "039", "output": "1" }, { "input": "97247", "output": "6" }, { "input": "5810438174", "output": "9" }, { "input": "12883340691714056185860211260984431382156326935244", "output": "424" }, { "input": "2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "1528" }, { "input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119521202062222947560634301788787748428236988789594458520867663257476744168528121470923031438015546006185059454402637036376247785881323277542968298682307854655591317046086531554595892680980142608", "output": "30826" }, { "input": "123456", "output": "7" }, { "input": "4", "output": "1" }, { "input": "123", "output": "1" } ]
1,679,977,212
2,147,483,647
Python 3
OK
TESTS
22
265
614,400
a=input() l=r=0 for i in range(len(a)): r=l+(a[i]in'048')+i*(i and int(a[i-1:i+1])%4==0) l=r print(r)
Title: New Skateboard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forgotten the number which he had calculated. The only thing he knows is that the number is divisible by 4. You are given a string *s* consisting of digits (the number on the display of the calculator after Yusuf randomly pressed the keys). Your task is to find the number of substrings which are divisible by 4. A substring can start with a zero. A substring of a string is a nonempty sequence of consecutive characters. For example if string *s* is 124 then we have four substrings that are divisible by 4: 12, 4, 24 and 124. For the string 04 the answer is three: 0, 4, 04. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Input Specification: The only line contains string *s* (1<=≤<=|*s*|<=≤<=3·105). The string *s* contains only digits from 0 to 9. Output Specification: Print integer *a* — the number of substrings of the string *s* that are divisible by 4. Note that the answer can be huge, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. Demo Input: ['124\n', '04\n', '5810438174\n'] Demo Output: ['4\n', '3\n', '9\n'] Note: none
```python a=input() l=r=0 for i in range(len(a)): r=l+(a[i]in'048')+i*(i and int(a[i-1:i+1])%4==0) l=r print(r) ```
3
651
A
Joysticks
PROGRAMMING
1,100
[ "dp", "greedy", "implementation", "math" ]
null
null
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent.
The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively.
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
[ "3 5\n", "4 4\n" ]
[ "6\n", "5\n" ]
In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
500
[ { "input": "3 5", "output": "6" }, { "input": "4 4", "output": "5" }, { "input": "100 100", "output": "197" }, { "input": "1 100", "output": "98" }, { "input": "100 1", "output": "98" }, { "input": "1 4", "output": "2" }, { "input": "1 1", "output": "0" }, { "input": "8 8", "output": "13" }, { "input": "7 2", "output": "7" }, { "input": "24 15", "output": "36" }, { "input": "19 30", "output": "47" }, { "input": "15 31", "output": "44" }, { "input": "14 15", "output": "27" }, { "input": "58 33", "output": "89" }, { "input": "15 25", "output": "38" }, { "input": "59 45", "output": "102" }, { "input": "3 73", "output": "74" }, { "input": "48 1", "output": "47" }, { "input": "100 25", "output": "122" }, { "input": "40 49", "output": "86" }, { "input": "85 73", "output": "155" }, { "input": "29 1", "output": "28" }, { "input": "74 25", "output": "97" }, { "input": "24 57", "output": "78" }, { "input": "23 12", "output": "33" }, { "input": "2 99", "output": "99" }, { "input": "98 2", "output": "97" }, { "input": "2 97", "output": "97" }, { "input": "30 54", "output": "81" }, { "input": "32 53", "output": "82" }, { "input": "32 54", "output": "84" }, { "input": "1 2", "output": "1" }, { "input": "2 1", "output": "1" }, { "input": "2 2", "output": "1" }, { "input": "1 3", "output": "2" }, { "input": "3 1", "output": "2" }, { "input": "1 4", "output": "2" }, { "input": "2 3", "output": "3" }, { "input": "3 2", "output": "3" } ]
1,623,950,979
2,147,483,647
Python 3
OK
TESTS
39
62
0
a,b=map(int,input().split()) m=0 if a==1 and b==1: print("0") else: while a>0 and b>0: if a==b: a+=1 b-=2 m+=1 elif a==1: a+=1 b-=2 m+=1 elif b==1: b+=1 a-=2 m+=1 elif a>b: b+=1 a-=2 m+=1 else: a+=1 b-=2 m+=1 print(m)
Title: Joysticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. Input Specification: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. Output Specification: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Demo Input: ['3 5\n', '4 4\n'] Demo Output: ['6\n', '5\n'] Note: In the first sample game lasts for 6 minute by using the following algorithm: - at the beginning of the first minute connect first joystick to the charger, by the end of this minute first joystick is at 4%, second is at 3%; - continue the game without changing charger, by the end of the second minute the first joystick is at 5%, second is at 1%; - at the beginning of the third minute connect second joystick to the charger, after this minute the first joystick is at 3%, the second one is at 2%; - continue the game without changing charger, by the end of the fourth minute first joystick is at 1%, second one is at 3%; - at the beginning of the fifth minute connect first joystick to the charger, after this minute the first joystick is at 2%, the second one is at 1%; - at the beginning of the sixth minute connect second joystick to the charger, after this minute the first joystick is at 0%, the second one is at 2%. After that the first joystick is completely discharged and the game is stopped.
```python a,b=map(int,input().split()) m=0 if a==1 and b==1: print("0") else: while a>0 and b>0: if a==b: a+=1 b-=2 m+=1 elif a==1: a+=1 b-=2 m+=1 elif b==1: b+=1 a-=2 m+=1 elif a>b: b+=1 a-=2 m+=1 else: a+=1 b-=2 m+=1 print(m) ```
3
361
A
Levko and Table
PROGRAMMING
800
[ "constructive algorithms", "implementation" ]
null
null
Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.
The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000).
Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.
[ "2 4\n", "4 7\n" ]
[ "1 3\n3 1\n", "2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n" ]
In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
500
[ { "input": "2 4", "output": "4 0 \n0 4 " }, { "input": "4 7", "output": "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 " }, { "input": "1 8", "output": "8 " }, { "input": "9 3", "output": "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 3 0 \n0 0 0 0 0 0 0 0 3 " }, { "input": "31 581", "output": "581 0 0 0 0 0 0 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 581 0 0 0 0 0 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 581 0 0 0 0 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 581 0 0 0 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 581 0 0 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 581 0 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 581 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 581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..." }, { "input": "100 1000", "output": "1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 999", "output": "999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 999 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "99 998", "output": "998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 998 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 997", "output": "997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 997 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "81 111", "output": "111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 111 0 0..." }, { "input": "1 407", "output": "407 " }, { "input": "54 341", "output": "341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 341 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 341 0 0 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": "92 460", "output": "460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 460 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "34 47", "output": "47 0 0 0 0 0 0 0 0 0 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 47 0 0 0 0 0 0 0 0 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 47 0 0 0 0 0 0 0 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 47 0 0 0 0 0 0 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 47 0 0 0 0 0 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 47 0 0 0 0 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 47 0 0 0 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 ..." }, { "input": "11 547", "output": "547 0 0 0 0 0 0 0 0 0 0 \n0 547 0 0 0 0 0 0 0 0 0 \n0 0 547 0 0 0 0 0 0 0 0 \n0 0 0 547 0 0 0 0 0 0 0 \n0 0 0 0 547 0 0 0 0 0 0 \n0 0 0 0 0 547 0 0 0 0 0 \n0 0 0 0 0 0 547 0 0 0 0 \n0 0 0 0 0 0 0 547 0 0 0 \n0 0 0 0 0 0 0 0 547 0 0 \n0 0 0 0 0 0 0 0 0 547 0 \n0 0 0 0 0 0 0 0 0 0 547 " }, { "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 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 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..." }, { "input": "99 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 \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 \n0 0 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..." }, { "input": "99 2", "output": "2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "2 7", "output": "7 0 \n0 7 " }, { "input": "100 100", "output": "100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 100 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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": "4 3", "output": "3 0 0 0 \n0 3 0 0 \n0 0 3 0 \n0 0 0 3 " }, { "input": "3 2", "output": "2 0 0 \n0 2 0 \n0 0 2 " } ]
1,631,274,427
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
6,758,400
n,s=input().split() ans=[] for i in range(int(n)): x= [0]*int(n) x[i]=int(s) ans.append(x) print(ans)
Title: Levko and Table Time Limit: None seconds Memory Limit: None megabytes Problem Description: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. Input Specification: The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Output Specification: Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. Demo Input: ['2 4\n', '4 7\n'] Demo Output: ['1 3\n3 1\n', '2 1 0 4\n4 0 2 1\n1 3 3 0\n0 3 2 2\n'] Note: In the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample. In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.
```python n,s=input().split() ans=[] for i in range(int(n)): x= [0]*int(n) x[i]=int(s) ans.append(x) print(ans) ```
0
157
B
Trace
PROGRAMMING
1,000
[ "geometry", "sortings" ]
null
null
One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different.
Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4.
[ "1\n1\n", "3\n1 4 2\n" ]
[ "3.1415926536\n", "40.8407044967\n" ]
In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
1,000
[ { "input": "1\n1", "output": "3.1415926536" }, { "input": "3\n1 4 2", "output": "40.8407044967" }, { "input": "4\n4 1 3 2", "output": "31.4159265359" }, { "input": "4\n100 10 2 1", "output": "31111.1920484997" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "172.7875959474" }, { "input": "1\n1000", "output": "3141592.6535897931" }, { "input": "8\n8 1 7 2 6 3 5 4", "output": "113.0973355292" }, { "input": "100\n1000 999 998 997 996 995 994 993 992 991 990 989 988 987 986 985 984 983 982 981 980 979 978 977 976 975 974 973 972 971 970 969 968 967 966 965 964 963 962 961 960 959 958 957 956 955 954 953 952 951 950 949 948 947 946 945 944 943 942 941 940 939 938 937 936 935 934 933 932 931 930 929 928 927 926 925 924 923 922 921 920 919 918 917 916 915 914 913 912 911 910 909 908 907 906 905 904 903 902 901", "output": "298608.3817237098" }, { "input": "6\n109 683 214 392 678 10", "output": "397266.9574170437" }, { "input": "2\n151 400", "output": "431023.3704798660" }, { "input": "6\n258 877 696 425 663 934", "output": "823521.3902487604" }, { "input": "9\n635 707 108 234 52 180 910 203 782", "output": "1100144.9065826489" }, { "input": "8\n885 879 891 428 522 176 135 983", "output": "895488.9947571954" }, { "input": "3\n269 918 721", "output": "1241695.6467754442" }, { "input": "7\n920 570 681 428 866 935 795", "output": "1469640.1849419588" }, { "input": "2\n517 331", "output": "495517.1260654109" }, { "input": "2\n457 898", "output": "1877274.3981158488" }, { "input": "8\n872 704 973 612 183 274 739 253", "output": "1780774.0965755312" }, { "input": "74\n652 446 173 457 760 847 670 25 196 775 998 279 656 809 883 148 969 884 792 502 641 800 663 938 362 339 545 608 107 184 834 666 149 458 864 72 199 658 618 987 126 723 806 643 689 958 626 904 944 415 427 498 628 331 636 261 281 276 478 220 513 595 510 384 354 561 469 462 799 449 747 109 903 456", "output": "1510006.5089479341" }, { "input": "76\n986 504 673 158 87 332 124 218 714 235 212 122 878 370 938 81 686 323 386 348 410 468 875 107 50 960 82 834 234 663 651 422 794 633 294 771 945 607 146 913 950 858 297 88 882 725 247 872 645 749 799 987 115 394 380 382 971 429 593 426 652 353 351 233 868 598 889 116 71 376 916 464 414 976 138 903", "output": "1528494.7817143100" }, { "input": "70\n12 347 748 962 514 686 192 159 990 4 10 788 602 542 946 215 523 727 799 717 955 796 529 465 897 103 181 515 495 153 710 179 747 145 16 585 943 998 923 708 156 399 770 547 775 285 9 68 713 722 570 143 913 416 663 624 925 218 64 237 797 138 942 213 188 818 780 840 480 758", "output": "1741821.4892636713" }, { "input": "26\n656 508 45 189 561 366 96 486 547 386 703 570 780 689 264 26 11 74 466 76 421 48 982 886 215 650", "output": "1818821.9252031571" }, { "input": "52\n270 658 808 249 293 707 700 78 791 167 92 772 807 502 830 991 945 102 968 376 556 578 326 980 688 368 280 853 646 256 666 638 424 737 321 996 925 405 199 680 953 541 716 481 727 143 577 919 892 355 346 298", "output": "1272941.9273080483" }, { "input": "77\n482 532 200 748 692 697 171 863 586 547 301 149 326 812 147 698 303 691 527 805 681 387 619 947 598 453 167 799 840 508 893 688 643 974 998 341 804 230 538 669 271 404 477 759 943 596 949 235 880 160 151 660 832 82 969 539 708 889 258 81 224 655 790 144 462 582 646 256 445 52 456 920 67 819 631 484 534", "output": "2045673.1891262225" }, { "input": "27\n167 464 924 575 775 97 944 390 297 315 668 296 533 829 851 406 702 366 848 512 71 197 321 900 544 529 116", "output": "1573959.9105970615" }, { "input": "38\n488 830 887 566 720 267 583 102 65 200 884 220 263 858 510 481 316 804 754 568 412 166 374 869 356 977 145 421 500 58 664 252 745 70 381 927 670 772", "output": "1479184.3434235646" }, { "input": "64\n591 387 732 260 840 397 563 136 571 876 831 953 799 493 579 13 559 872 53 678 256 232 969 993 847 14 837 365 547 997 604 199 834 529 306 443 739 49 19 276 343 835 904 588 900 870 439 576 975 955 518 117 131 347 800 83 432 882 869 709 32 950 314 450", "output": "1258248.6984672088" }, { "input": "37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637", "output": "1495219.0323274869" }, { "input": "97\n768 569 306 968 437 779 227 561 412 60 44 807 234 645 169 858 580 396 343 145 842 723 416 80 456 247 81 150 297 116 760 964 312 558 101 850 549 650 299 868 121 435 579 705 118 424 302 812 970 397 659 565 916 183 933 459 6 593 518 717 326 305 744 470 75 981 824 221 294 324 194 293 251 446 481 215 338 861 528 829 921 945 540 89 450 178 24 460 990 392 148 219 934 615 932 340 937", "output": "1577239.7333274092" }, { "input": "94\n145 703 874 425 277 652 239 496 458 658 339 842 564 699 893 352 625 980 432 121 798 872 499 859 850 721 414 825 543 843 304 111 342 45 219 311 50 748 465 902 781 822 504 985 919 656 280 310 917 438 464 527 491 713 906 329 635 777 223 810 501 535 156 252 806 112 971 719 103 443 165 98 579 554 244 996 221 560 301 51 977 422 314 858 528 772 448 626 185 194 536 66 577 677", "output": "1624269.3753516484" }, { "input": "97\n976 166 649 81 611 927 480 231 998 711 874 91 969 521 531 414 993 790 317 981 9 261 437 332 173 573 904 777 882 990 658 878 965 64 870 896 271 732 431 53 761 943 418 602 708 949 930 130 512 240 363 458 673 319 131 784 224 48 919 126 208 212 911 59 677 535 450 273 479 423 79 807 336 18 72 290 724 28 123 605 287 228 350 897 250 392 885 655 746 417 643 114 813 378 355 635 905", "output": "1615601.7212203942" }, { "input": "91\n493 996 842 9 748 178 1 807 841 519 796 998 84 670 778 143 707 208 165 893 154 943 336 150 761 881 434 112 833 55 412 682 552 945 758 189 209 600 354 325 440 844 410 20 136 665 88 791 688 17 539 821 133 236 94 606 483 446 429 60 960 476 915 134 137 852 754 908 276 482 117 252 297 903 981 203 829 811 471 135 188 667 710 393 370 302 874 872 551 457 692", "output": "1806742.5014501044" }, { "input": "95\n936 736 17 967 229 607 589 291 242 244 29 698 800 566 630 667 90 416 11 94 812 838 668 520 678 111 490 823 199 973 681 676 683 721 262 896 682 713 402 691 874 44 95 704 56 322 822 887 639 433 406 35 988 61 176 496 501 947 440 384 372 959 577 370 754 802 1 945 427 116 746 408 308 391 397 730 493 183 203 871 831 862 461 565 310 344 504 378 785 137 279 123 475 138 415", "output": "1611115.5269110680" }, { "input": "90\n643 197 42 218 582 27 66 704 195 445 641 675 285 639 503 686 242 327 57 955 848 287 819 992 756 749 363 48 648 736 580 117 752 921 923 372 114 313 202 337 64 497 399 25 883 331 24 871 917 8 517 486 323 529 325 92 891 406 864 402 263 773 931 253 625 31 17 271 140 131 232 586 893 525 846 54 294 562 600 801 214 55 768 683 389 738 314 284 328 804", "output": "1569819.2914796301" }, { "input": "98\n29 211 984 75 333 96 840 21 352 168 332 433 130 944 215 210 620 442 363 877 91 491 513 955 53 82 351 19 998 706 702 738 770 453 344 117 893 590 723 662 757 16 87 546 312 669 568 931 224 374 927 225 751 962 651 587 361 250 256 240 282 600 95 64 384 589 813 783 39 918 412 648 506 283 886 926 443 173 946 241 310 33 622 565 261 360 547 339 943 367 354 25 479 743 385 485 896 741", "output": "2042921.1539616778" }, { "input": "93\n957 395 826 67 185 4 455 880 683 654 463 84 258 878 553 592 124 585 9 133 20 609 43 452 725 125 801 537 700 685 771 155 566 376 19 690 383 352 174 208 177 416 304 1000 533 481 87 509 358 233 681 22 507 659 36 859 952 259 138 271 594 779 576 782 119 69 608 758 283 616 640 523 710 751 34 106 774 92 874 568 864 660 998 992 474 679 180 409 15 297 990 689 501", "output": "1310703.8710041976" }, { "input": "97\n70 611 20 30 904 636 583 262 255 501 604 660 212 128 199 138 545 576 506 528 12 410 77 888 783 972 431 188 338 485 148 793 907 678 281 922 976 680 252 724 253 920 177 361 721 798 960 572 99 622 712 466 608 49 612 345 266 751 63 594 40 695 532 789 520 930 825 929 48 59 405 135 109 735 508 186 495 772 375 587 201 324 447 610 230 947 855 318 856 956 313 810 931 175 668 183 688", "output": "1686117.9099228707" }, { "input": "96\n292 235 391 180 840 172 218 997 166 287 329 20 886 325 400 471 182 356 448 337 417 319 58 106 366 764 393 614 90 831 924 314 667 532 64 874 3 434 350 352 733 795 78 640 967 63 47 879 635 272 145 569 468 792 153 761 770 878 281 467 209 208 298 37 700 18 334 93 5 750 412 779 523 517 360 649 447 328 311 653 57 578 767 460 647 663 50 670 151 13 511 580 625 907 227 89", "output": "1419726.5608617242" }, { "input": "100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 639 638 260 419 8 142 403 298 204 169 887 388 241 983 885 267 643 943 417 237 452 562 6 839 149 742 832 896 100 831 712 754 679 743 135 222 445 680 210 955 220 63 960 487 514 824 481 584 441 997 795 290 10 45 510 678 844 503 407 945 850 84 858 934 500 320 936 663 736 592 161 670 606 465 864 969 293 863 868 393 899 744", "output": "1556458.0979239127" }, { "input": "100\n321 200 758 415 190 710 920 992 873 898 814 259 359 66 971 210 838 545 663 652 684 277 36 756 963 459 335 484 462 982 532 423 131 703 307 229 391 938 253 847 542 975 635 928 220 980 222 567 557 181 366 824 900 180 107 979 112 564 525 413 300 422 876 615 737 343 902 8 654 628 469 913 967 785 893 314 909 215 912 262 20 709 363 915 997 954 986 454 596 124 74 159 660 550 787 418 895 786 293 50", "output": "1775109.8050211088" }, { "input": "100\n859 113 290 762 701 63 188 431 810 485 671 673 99 658 194 227 511 435 941 212 551 124 89 222 42 321 657 815 898 171 216 482 707 567 724 491 414 942 820 351 48 653 685 312 586 24 20 627 602 498 533 173 463 262 621 466 119 299 580 964 510 987 40 698 521 998 847 651 746 215 808 563 785 837 631 772 404 923 682 244 232 214 390 350 968 771 517 900 70 543 934 554 681 368 642 575 891 728 478 317", "output": "1447969.4788174964" }, { "input": "100\n941 283 349 457 52 837 299 284 796 305 893 624 101 972 738 204 121 70 17 704 836 791 95 111 162 952 472 724 733 580 878 177 705 804 11 211 463 417 288 409 410 485 896 755 921 267 164 656 505 765 539 439 535 19 991 689 220 474 114 944 884 144 926 849 486 566 117 35 749 499 797 303 362 905 690 890 976 66 590 183 234 683 39 297 769 787 376 541 571 759 495 200 261 352 73 493 831 442 273 339", "output": "1597889.4218394549" }, { "input": "100\n110 868 147 888 291 282 916 542 917 337 235 595 498 621 814 249 261 713 445 666 142 275 319 49 900 543 333 606 487 670 620 769 852 258 230 867 603 491 714 839 879 37 21 74 590 190 397 506 499 967 152 862 200 107 145 23 614 167 857 475 79 598 270 906 626 116 89 59 651 846 723 201 50 699 522 408 634 132 226 414 824 764 513 586 526 238 556 162 667 173 684 415 527 743 10 442 552 274 350 822", "output": "1567230.6191330721" }, { "input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000", "output": "298608.3817237098" } ]
1,432,046,961
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
92
0
import math def solve(): n = int(input()) a = [int(x) for x in input().split()] a.sort(reverse=True) a += [0] ans = 0 for i in range(0, n, 2): ans += math.pi * (a[i] * a[i] - a[i-1] * a[i-1]) print(ans) if __name__ == "__main__": solve()
Title: Trace Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *r**i* (1<=≤<=*r**i*<=≤<=1000) — the circles' radii. It is guaranteed that all circles are different. Output Specification: Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. Demo Input: ['1\n1\n', '3\n1 4 2\n'] Demo Output: ['3.1415926536\n', '40.8407044967\n'] Note: In the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 1<sup class="upper-index">2</sup> = π. In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 4<sup class="upper-index">2</sup> - π × 2<sup class="upper-index">2</sup>) + π × 1<sup class="upper-index">2</sup> = π × 12 + π = 13π
```python import math def solve(): n = int(input()) a = [int(x) for x in input().split()] a.sort(reverse=True) a += [0] ans = 0 for i in range(0, n, 2): ans += math.pi * (a[i] * a[i] - a[i-1] * a[i-1]) print(ans) if __name__ == "__main__": solve() ```
0
194
B
Square
PROGRAMMING
1,200
[ "math" ]
null
null
There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw?
The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample.
For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. 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\n4 8 100\n" ]
[ "17\n33\n401\n" ]
none
1,000
[ { "input": "3\n4 8 100", "output": "17\n33\n401" }, { "input": "8\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 13", "output": "4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n4000000001\n27" }, { "input": "3\n13 17 21", "output": "27\n35\n43" } ]
1,591,623,731
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
155
3,788,800
input() li = list(map(int, input().split())) for x in li: if x % 2: print(2 * x + 1) else: print(4 * x + 1)
Title: Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a square painted on a piece of paper, the square's side equals *n* meters. John Doe draws crosses on the square's perimeter. John paints the first cross in the lower left corner of the square. Then John moves along the square's perimeter in the clockwise direction (first upwards, then to the right, then downwards, then to the left and so on). Every time he walks (*n*<=+<=1) meters, he draws a cross (see picture for clarifications). John Doe stops only when the lower left corner of the square has two crosses. How many crosses will John draw? Input Specification: The first line contains integer *t* (1<=≤<=*t*<=≤<=104) — the number of test cases. The second line contains *t* space-separated integers *n**i* (1<=≤<=*n**i*<=≤<=109) — the sides of the square for each test sample. Output Specification: For each test sample print on a single line the answer to it, that is, the number of crosses John will draw as he will move along the square of the corresponding size. Print the answers to the samples in the order in which the samples are given in the input. 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\n4 8 100\n'] Demo Output: ['17\n33\n401\n'] Note: none
```python input() li = list(map(int, input().split())) for x in li: if x % 2: print(2 * x + 1) else: print(4 * x + 1) ```
0
222
A
Shooshuns and Sequence
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same.
The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found.
Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1.
[ "3 2\n3 1 1\n", "3 1\n3 1 1\n" ]
[ "1\n", "-1\n" ]
In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
500
[ { "input": "3 2\n3 1 1", "output": "1" }, { "input": "3 1\n3 1 1", "output": "-1" }, { "input": "1 1\n1", "output": "0" }, { "input": "2 1\n1 1", "output": "0" }, { "input": "2 1\n2 1", "output": "-1" }, { "input": "4 4\n1 2 3 4", "output": "3" }, { "input": "4 3\n1 2 3 4", "output": "-1" }, { "input": "5 3\n2 1 1 1 1", "output": "1" }, { "input": "5 3\n1 1 1 1 1", "output": "0" }, { "input": "5 5\n1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "10 1\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 1\n2 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 2\n2 1 1 1 1 1 1 1 1 1", "output": "1" }, { "input": "10 2\n1 2 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "10 3\n3 2 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 1\n1 2 3 4 5 6 7 8 9 10", "output": "-1" }, { "input": "10 10\n1 2 3 4 5 6 7 8 9 10", "output": "9" }, { "input": "20 10\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 11\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "10" }, { "input": "20 9\n1 2 3 4 5 6 7 8 9 10 1 1 1 1 1 1 1 1 1 1", "output": "-1" }, { "input": "20 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "0" }, { "input": "20 20\n20 1 19 2 18 3 17 4 16 5 15 6 14 7 13 8 12 9 11 10", "output": "19" } ]
1,661,753,515
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
18,022,400
n,k=map(int,input().split(" ")) l=[int(f) for f in input().split(" ")] if k==n: print(k-1) elif l[::-1][0]==l[::-1][1]: count=2 for i in range(1,n-1): if l[::-1][i]==l[::-1][i+1]: count+=1 else: break if count==n: print(0) elif k>n-count: print(n-count) else: print(-1) else: if k==1: print(-1)
Title: Shooshuns and Sequence Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. Input Specification: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. Output Specification: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Demo Input: ['3 2\n3 1 1\n', '3 1\n3 1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first test case after the first operation the blackboard will have sequence [1, 1, 1]. So, one operation is enough to make all numbers the same. Thus, the answer equals one. In the second test case the sequence will never consist of the same numbers. It will always contain at least two distinct numbers 3 and 1. Thus, the answer equals -1.
```python n,k=map(int,input().split(" ")) l=[int(f) for f in input().split(" ")] if k==n: print(k-1) elif l[::-1][0]==l[::-1][1]: count=2 for i in range(1,n-1): if l[::-1][i]==l[::-1][i+1]: count+=1 else: break if count==n: print(0) elif k>n-count: print(n-count) else: print(-1) else: if k==1: print(-1) ```
0
505
A
Mr. Kitayuta's Gift
PROGRAMMING
1,100
[ "brute force", "implementation", "strings" ]
null
null
Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.
The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter.
If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.
[ "revive\n", "ee\n", "kitayuta\n" ]
[ "reviver\n", "eye", "NA\n" ]
For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
500
[ { "input": "revive", "output": "reviver" }, { "input": "ee", "output": "eee" }, { "input": "kitayuta", "output": "NA" }, { "input": "evima", "output": "NA" }, { "input": "a", "output": "aa" }, { "input": "yutampo", "output": "NA" }, { "input": "fft", "output": "tfft" }, { "input": "shuseki", "output": "NA" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "ewcdcwerp", "output": "NA" }, { "input": "noon", "output": "nooon" }, { "input": "add", "output": "adda" }, { "input": "iq", "output": "qiq" }, { "input": "hogloid", "output": "NA" }, { "input": "yosupo", "output": "NA" }, { "input": "stat", "output": "stats" }, { "input": "level", "output": "levvel" }, { "input": "iwiwi", "output": "iwiiwi" }, { "input": "racecar", "output": "raceecar" }, { "input": "dog", "output": "NA" }, { "input": "squirrel", "output": "NA" }, { "input": "slime", "output": "NA" }, { "input": "palindrome", "output": "NA" }, { "input": "nqwcvcwqn", "output": "nqwcvvcwqn" }, { "input": "lsdijfjisl", "output": "lsdijfjidsl" }, { "input": "jewiiwefj", "output": "jfewiiwefj" }, { "input": "vnwmvvmonv", "output": "NA" }, { "input": "zennyuu", "output": "NA" }, { "input": "mrtoudai", "output": "NA" }, { "input": "z", "output": "zz" }, { "input": "babccba", "output": "babccbab" }, { "input": "battaba", "output": "abattaba" }, { "input": "bbb", "output": "bbbb" }, { "input": "zaa", "output": "zaaz" }, { "input": "abbabab", "output": "NA" }, { "input": "racecar", "output": "raceecar" }, { "input": "zzz", "output": "zzzz" }, { "input": "eviver", "output": "reviver" }, { "input": "aaaaa", "output": "aaaaaa" }, { "input": "eee", "output": "eeee" } ]
1,422,577,299
2,147,483,647
Python 3
OK
TESTS
40
62
0
def ispal(s): i = 0 j = len(s) - 1 while i < j: if s[i] != s[j]: return False i += 1 j -= 1 return True alpha = 'abcdefghijklmnopqrstuvwxyz' found = 0 s = input() for i in range(0,len(s)+1): for j in range(len(alpha)): temp = s[:i] + alpha[j] + s[i:] if ispal(temp): found = 1 print(temp) break if found: break if not found: print("NA")
Title: Mr. Kitayuta's Gift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them. Input Specification: The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. Output Specification: If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. Demo Input: ['revive\n', 'ee\n', 'kitayuta\n'] Demo Output: ['reviver\n', 'eye', 'NA\n'] Note: For the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver". For the second sample, there is more than one solution. For example, "eve" will also be accepted. For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.
```python def ispal(s): i = 0 j = len(s) - 1 while i < j: if s[i] != s[j]: return False i += 1 j -= 1 return True alpha = 'abcdefghijklmnopqrstuvwxyz' found = 0 s = input() for i in range(0,len(s)+1): for j in range(len(alpha)): temp = s[:i] + alpha[j] + s[i:] if ispal(temp): found = 1 print(temp) break if found: break if not found: print("NA") ```
3
607
A
Chain Reaction
PROGRAMMING
1,600
[ "binary search", "dp" ]
null
null
There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed.
The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*.
Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added.
[ "4\n1 9\n3 1\n6 1\n7 4\n", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n" ]
[ "1\n", "3\n" ]
For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
500
[ { "input": "4\n1 9\n3 1\n6 1\n7 4", "output": "1" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1", "output": "3" }, { "input": "1\n0 1", "output": "0" }, { "input": "1\n0 1000000", "output": "0" }, { "input": "1\n1000000 1000000", "output": "0" }, { "input": "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7", "output": "4" }, { "input": "5\n1 1\n3 1\n5 1\n7 10\n8 10", "output": "2" }, { "input": "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1", "output": "4" } ]
1,681,265,733
2,147,483,647
Python 3
OK
TESTS
41
561
8,499,200
from sys import stdin from bisect import bisect_left def main(): n = int(input()) beacons = [tuple(map(int, input().split())) for _ in range(n)] beacons.sort() # dp[i] stores the number of beacons that can be saved when considering the beacons from the rightmost one to the i-th one dp = [0] * n for i in range(n): last_undestroyed = bisect_left(beacons, (beacons[i][0] - beacons[i][1],)) - 1 dp[i] = 1 if last_undestroyed == -1 else dp[last_undestroyed] + 1 # The minimum number of beacons destroyed ans = n - max(dp) print(ans) main()
Title: Chain Reaction Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* beacons located at distinct positions on a number line. The *i*-th beacon has position *a**i* and power level *b**i*. When the *i*-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance *b**i* inclusive. The beacon itself is not destroyed however. Saitama will activate the beacons one at a time from right to left. If a beacon is destroyed, it cannot be activated. Saitama wants Genos to add a beacon strictly to the right of all the existing beacons, with any position and any power level, such that the least possible number of beacons are destroyed. Note that Genos's placement of the beacon means it will be the first beacon activated. Help Genos by finding the minimum number of beacons that could be destroyed. Input Specification: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the initial number of beacons. The *i*-th of next *n* lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=1<=000<=000, 1<=≤<=*b**i*<=≤<=1<=000<=000) — the position and power level of the *i*-th beacon respectively. No two beacons will have the same position, so *a**i*<=≠<=*a**j* if *i*<=≠<=*j*. Output Specification: Print a single integer — the minimum number of beacons that could be destroyed if exactly one beacon is added. Demo Input: ['4\n1 9\n3 1\n6 1\n7 4\n', '7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n'] Demo Output: ['1\n', '3\n'] Note: For the first sample case, the minimum number of beacons destroyed is 1. One way to achieve this is to place a beacon at position 9 with power level 2. For the second sample case, the minimum number of beacons destroyed is 3. One way to achieve this is to place a beacon at position 1337 with power level 42.
```python from sys import stdin from bisect import bisect_left def main(): n = int(input()) beacons = [tuple(map(int, input().split())) for _ in range(n)] beacons.sort() # dp[i] stores the number of beacons that can be saved when considering the beacons from the rightmost one to the i-th one dp = [0] * n for i in range(n): last_undestroyed = bisect_left(beacons, (beacons[i][0] - beacons[i][1],)) - 1 dp[i] = 1 if last_undestroyed == -1 else dp[last_undestroyed] + 1 # The minimum number of beacons destroyed ans = n - max(dp) print(ans) main() ```
3
768
B
Code For 1
PROGRAMMING
1,600
[ "constructive algorithms", "dfs and similar", "divide and conquer" ]
null
null
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility. Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=&gt;<=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1. Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test?
The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=&lt;<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*. It is guaranteed that *r* is not greater than the length of the final list.
Output the total number of 1s in the range *l* to *r* in the final sequence.
[ "7 2 5\n", "10 3 10\n" ]
[ "4\n", "5\n" ]
Consider first example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4. For the second example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5.
1,000
[ { "input": "7 2 5", "output": "4" }, { "input": "10 3 10", "output": "5" }, { "input": "56 18 40", "output": "20" }, { "input": "203 40 124", "output": "67" }, { "input": "903316762502 354723010040 354723105411", "output": "78355" }, { "input": "33534354842198 32529564319236 32529564342569", "output": "22239" }, { "input": "62518534961045 50734311240112 50734311287877", "output": "42439" }, { "input": "95173251245550 106288351347530 106288351372022", "output": "16565" }, { "input": "542 321 956", "output": "336" }, { "input": "3621 237 2637", "output": "2124" }, { "input": "9056 336 896", "output": "311" }, { "input": "36007 368 24490", "output": "13253" }, { "input": "244269 149154 244246", "output": "88609" }, { "input": "880234 669493 757150", "output": "73585" }, { "input": "3740160 1031384 1104236", "output": "64965" }, { "input": "11586121 15337246 15397874", "output": "41868" }, { "input": "38658997 35923164 35985664", "output": "36004" }, { "input": "192308932 207804787 207866400", "output": "44142" }, { "input": "950099012 175922161 176000556", "output": "69369" }, { "input": "2787326787 3799676481 3799680514", "output": "2618" }, { "input": "14417262581 8527979363 8528075536", "output": "80707" }, { "input": "39889373539 7747197212 7747278363", "output": "47105" }, { "input": "251772781087 70597428577 70597479816", "output": "46933" }, { "input": "0 1 1", "output": "0" }, { "input": "1 1 1", "output": "1" }, { "input": "3 2 3", "output": "2" }, { "input": "14 7 12", "output": "5" }, { "input": "1125899906842623 1 100001", "output": "100001" }, { "input": "1125899906842623 1125899906742623 1125899906842623", "output": "100001" }, { "input": "1000 1 1023", "output": "1000" }, { "input": "281474976710656 17179869184 17179869186", "output": "1" }, { "input": "2 2 2", "output": "0" }, { "input": "3 2 2", "output": "1" } ]
1,697,724,771
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
15
0
def final(n, l, r): def manage(n): seq=[n] while True: newseq = [] for item in seq: if item!=0 and item !=1: newseq.extend([round(item / 2), item % 2, round(item / 2)]) seq=newseq flag = False for item in seq: if item > 1: flag = True if not flag: break return seq def count(seq,l,r): count=0 for item in seq[l:r+1]: if item==1: count+=bin(item).count('1') return count seq=manage(n) return count(seq,l,r)
Title: Code For 1 Time Limit: None seconds Memory Limit: None megabytes Problem Description: Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam sets off his journey to the Citadel. However becoming a trainee at the Citadel is not a cakewalk and hence the maesters at the Citadel gave Sam a problem to test his eligibility. Initially Sam has a list with a single element *n*. Then he has to perform certain operations on this list. In each operation Sam must remove any element *x*, such that *x*<=&gt;<=1, from the list and insert at the same position , , sequentially. He must continue with these operations until all the elements in the list are either 0 or 1. Now the masters want the total number of 1s in the range *l* to *r* (1-indexed). Sam wants to become a maester but unfortunately he cannot solve this problem. Can you help Sam to pass the eligibility test? Input Specification: The first line contains three integers *n*, *l*, *r* (0<=≤<=*n*<=&lt;<=250, 0<=≤<=*r*<=-<=*l*<=≤<=105, *r*<=≥<=1, *l*<=≥<=1) – initial element and the range *l* to *r*. It is guaranteed that *r* is not greater than the length of the final list. Output Specification: Output the total number of 1s in the range *l* to *r* in the final sequence. Demo Input: ['7 2 5\n', '10 3 10\n'] Demo Output: ['4\n', '5\n'] Note: Consider first example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 2-nd to 5-th in list is [1, 1, 1, 1]. The number of ones is 4. For the second example: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/52e9bc51ef858cacc27fc274c7ba9419d5c1ded9.png" style="max-width: 100.0%;max-height: 100.0%;"/> Elements on positions from 3-rd to 10-th in list is [1, 1, 1, 0, 1, 0, 1, 0]. The number of ones is 5.
```python def final(n, l, r): def manage(n): seq=[n] while True: newseq = [] for item in seq: if item!=0 and item !=1: newseq.extend([round(item / 2), item % 2, round(item / 2)]) seq=newseq flag = False for item in seq: if item > 1: flag = True if not flag: break return seq def count(seq,l,r): count=0 for item in seq[l:r+1]: if item==1: count+=bin(item).count('1') return count seq=manage(n) return count(seq,l,r) ```
0
409
H
A + B Strikes Back
PROGRAMMING
1,500
[ "*special", "brute force", "constructive algorithms", "dsu", "implementation" ]
null
null
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try?
The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space.
Output the sum of the given integers.
[ "5 14\n", "381 492\n" ]
[ "19\n", "873\n" ]
none
0
[ { "input": "5 14", "output": "19" }, { "input": "381 492", "output": "873" }, { "input": "536 298", "output": "834" }, { "input": "143 522", "output": "665" }, { "input": "433 126", "output": "559" }, { "input": "723 350", "output": "1073" }, { "input": "632 264", "output": "896" }, { "input": "923 488", "output": "1411" }, { "input": "522 92", "output": "614" }, { "input": "953 553", "output": "1506" }, { "input": "242 86", "output": "328" }, { "input": "151 691", "output": "842" }, { "input": "441 915", "output": "1356" }, { "input": "740 519", "output": "1259" }, { "input": "339 433", "output": "772" }, { "input": "629 657", "output": "1286" }, { "input": "538 261", "output": "799" }, { "input": "828 485", "output": "1313" }, { "input": "117 399", "output": "516" }, { "input": "399 280", "output": "679" } ]
1,644,839,253
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
0
0
a,b=map(int,input().split()) c=2 print(a+b)
Title: A + B Strikes Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input Specification: The input contains two integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=103), separated by a single space. Output Specification: Output the sum of the given integers. Demo Input: ['5 14\n', '381 492\n'] Demo Output: ['19\n', '873\n'] Note: none
```python a,b=map(int,input().split()) c=2 print(a+b) ```
0
94
A
Restoring Password
PROGRAMMING
900
[ "implementation", "strings" ]
A. Restoring Password
2
256
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification.
The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.
Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.
[ "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n", "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n" ]
[ "12345678\n", "30234919\n" ]
none
500
[ { "input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110", "output": "12345678" }, { "input": "10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000", "output": "30234919" }, { "input": "00010101101110110101100110101100010101100010101111000101011010011010110010000011\n0101010110\n0001001101\n1001101011\n0000100011\n0010101111\n1110110101\n0001010110\n0110111000\n0000111110\n0010000011", "output": "65264629" }, { "input": "10100100010010010011011001101000100100110110011010011001101011000100110110011010\n1111110011\n1001000111\n1001000100\n1100010011\n0110011010\n0010000001\n1110101110\n0010000110\n0010010011\n1010010001", "output": "98484434" }, { "input": "00101100011111010001001000000110110000000110010011001111111010110010001011000000\n0010000001\n0110010011\n0010000010\n1011001000\n0011111110\n0110001000\n1111010001\n1011000000\n0000100110\n0010110001", "output": "96071437" }, { "input": "10001110111110000001000010001010001110110000100010100010111101101101010000100010\n0000010110\n1101010111\n1000101111\n0001011110\n0011110101\n0101100100\n0110110101\n0000100010\n1000111011\n1110000001", "output": "89787267" }, { "input": "10010100011001010001010101001101010100110100111011001010111100011001000010100000\n0011100000\n1001100100\n0001100100\n0010100000\n0101010011\n0010101110\n0010101111\n0100111011\n1001010001\n1111111110", "output": "88447623" }, { "input": "01101100111000000101011011001110000001011111111000111111100001011010001001011001\n1000000101\n0101101000\n0101110101\n1101011110\n0000101100\n1111111000\n0001001101\n0110111011\n0110110011\n1001011001", "output": "80805519" }, { "input": "11100011000100010110010011101010101010011110001100011010111110011000011010110111\n1110001100\n0110101111\n0100111010\n0101000000\n1001100001\n1010101001\n0000100010\n1010110111\n1100011100\n0100010110", "output": "09250147" }, { "input": "10000110110000010100000010001000111101110110101011110111000100001101000000100010\n0000010100\n0000110001\n0110101011\n1101110001\n1000011011\n0000110100\n0011110111\n1000110010\n0000100010\n0000011011", "output": "40862358" }, { "input": "01000000010000000110100101000110110000100100000001101100001000011111111001010001\n1011000010\n1111101010\n0111110011\n0000000110\n0000001001\n0001111111\n0110010010\n0100000001\n1011001000\n1001010001", "output": "73907059" }, { "input": "01111000111110011001110101110011110000111110010001101100110110100111101011001101\n1110010001\n1001100000\n1100001000\n1010011110\n1011001101\n0111100011\n1101011100\n1110011001\n1111000011\n0010000101", "output": "57680434" }, { "input": "01001100101000100010001011110001000101001001100010010000001001001100101001011111\n1001011111\n1110010111\n0111101011\n1000100010\n0011100101\n0100000010\n0010111100\n0100010100\n1001100010\n0100110010", "output": "93678590" }, { "input": "01110111110000111011101010110110101011010100110111000011101101110101011101001000\n0110000101\n1010101101\n1101010111\n1101011100\n0100110111\n0111011111\n1100011001\n0111010101\n0000111011\n1101001000", "output": "58114879" }, { "input": "11101001111100110101110011010100110011011110100111010110110011000111000011001101\n1100011100\n1100110101\n1011101000\n0011011110\n0011001101\n0100010001\n1110100111\n1010101100\n1110110100\n0101101100", "output": "61146904" }, { "input": "10101010001011010001001001011000100101100001011011101010101110101010001010101000\n0010110101\n1010011010\n1010101000\n1011010001\n1010101011\n0010010110\n0110100010\n1010100101\n0001011011\n0110100001", "output": "23558422" }, { "input": "11110101001100010000110100001110101011011111010100110001000001001010001001101111\n0101101100\n1001101111\n1010101101\n0100101000\n1111110000\n0101010010\n1100010000\n1111010100\n1101000011\n1011111111", "output": "76827631" }, { "input": "10001100110000110111100011001101111110110011110101000011011100001101110000110111\n0011110101\n0101100011\n1000110011\n1011011001\n0111111011\n0101111011\n0000110111\n0100001110\n1000000111\n0110110111", "output": "26240666" }, { "input": "10000100010000111101100100111101111011101000001001100001000110000010010000111101\n1001001111\n0000111101\n1000010001\n0110011101\n0110101000\n1011111001\n0111101110\n1000001001\n1101011111\n0001010100", "output": "21067271" }, { "input": "01101111000110111100011011110001101111001010001100101000110001010101100100000010\n1010001100\n0011010011\n0101010110\n1111001100\n1100011000\n0100101100\n1001100101\n0110111100\n0011001101\n0100000010", "output": "77770029" }, { "input": "10100111011010001011111000000111100000010101000011000010111101010000111010011101\n1010011101\n1010111111\n0110100110\n1111000100\n1110000001\n0000101111\n0011111000\n1000110001\n0101000011\n1010001011", "output": "09448580" }, { "input": "10000111111000011111001010101010010011111001001111000010010100100011000010001100\n1101101110\n1001001111\n0000100101\n1100111010\n0010101010\n1110000110\n1100111101\n0010001100\n1110000001\n1000011111", "output": "99411277" }, { "input": "10110110111011001111101100111100111111011011011011001111110110010011100010000111\n0111010011\n0111101100\n1001101010\n0101000101\n0010000111\n0011111101\n1011001111\n1101111000\n1011011011\n1001001110", "output": "86658594" }, { "input": "01001001100101100011110110111100000110001111001000100000110111110010000000011000\n0100100110\n1000001011\n1000111110\n0000011000\n0101100011\n1101101111\n1111001000\n1011011001\n1000001101\n0010101000", "output": "04536863" }, { "input": "10010100011101000011100100001100101111000010111100000010010000001001001101011101\n1001000011\n1101000011\n1001010001\n1101011101\n1000010110\n0011111101\n0010111100\n0000100100\n1010001000\n0101000110", "output": "21066773" }, { "input": "01111111110101111111011111111111010010000001100000101000100100111001011010001001\n0111111111\n0101111111\n0100101101\n0001100000\n0011000101\n0011100101\n1101001000\n0010111110\n1010001001\n1111000111", "output": "01063858" }, { "input": "00100011111001001010001111000011101000001110100000000100101011101000001001001010\n0010001111\n1001001010\n1010011001\n0011100111\n1000111000\n0011110000\n0000100010\n0001001010\n1111110111\n1110100000", "output": "01599791" }, { "input": "11011101000100110100110011010101100011111010011010010011010010010010100110101111\n0100110100\n1001001010\n0001111101\n1101011010\n1101110100\n1100110101\n0110101111\n0110001111\n0001101000\n1010011010", "output": "40579016" }, { "input": "10000010111101110110011000111110000011100110001111100100000111000011011000001011\n0111010100\n1010110110\n1000001110\n1110000100\n0110001111\n1101110110\n1100001101\n1000001011\n0000000101\n1001000001", "output": "75424967" }, { "input": "11101100101110111110111011111010001111111111000001001001000010001111111110110010\n0101100001\n1111010011\n1110111110\n0100110100\n1110011111\n1000111111\n0010010000\n1110110010\n0011000010\n1111000001", "output": "72259657" }, { "input": "01011110100101111010011000001001100000101001110011010111101011010000110110010101\n0100111100\n0101110011\n0101111010\n0110000010\n0101001111\n1101000011\n0110010101\n0111011010\n0001101110\n1001110011", "output": "22339256" }, { "input": "01100000100101111000100001100010000110000010100100100001100000110011101001110000\n0101111000\n1001110000\n0001000101\n0110110111\n0010100100\n1000011000\n1101110110\n0110000010\n0001011010\n0011001110", "output": "70554591" }, { "input": "11110011011000001001111100110101001000010100100000110011001110011111100100100001\n1010011000\n1111001101\n0100100001\n1111010011\n0100100000\n1001111110\n1010100111\n1000100111\n1000001001\n1100110011", "output": "18124952" }, { "input": "10001001011000100101010110011101011001110010000001010110000101000100101111101010\n0101100001\n1100001100\n1111101010\n1000100101\n0010000001\n0100010010\n0010110110\n0101100111\n0000001110\n1101001110", "output": "33774052" }, { "input": "00110010000111001001001100100010010111101011011110001011111100000101000100000001\n0100000001\n1011011110\n0010111111\n0111100111\n0100111001\n0000010100\n1001011110\n0111001001\n0100010011\n0011001000", "output": "97961250" }, { "input": "01101100001000110101101100101111101110010011010111100011010100010001101000110101\n1001101001\n1000110101\n0110110000\n0111100100\n0011010111\n1110111001\n0001000110\n0000000100\n0001101001\n1011001011", "output": "21954161" }, { "input": "10101110000011010110101011100000101101000110100000101101101101110101000011110010\n0110100000\n1011011011\n0011110010\n0001110110\n0010110100\n1100010010\n0001101011\n1010111000\n0011010110\n0111010100", "output": "78740192" }, { "input": "11000101011100100111010000010001000001001100101100000011000000001100000101011010\n1100010101\n1111101011\n0101011010\n0100000100\n1000110111\n1100100111\n1100101100\n0111001000\n0000110000\n0110011111", "output": "05336882" }, { "input": "11110100010000101110010110001000001011100101100010110011011011111110001100110110\n0101100010\n0100010001\n0000101110\n1100110110\n0101000101\n0011001011\n1111010001\n1000110010\n1111111000\n1010011111", "output": "62020383" }, { "input": "00011001111110000011101011010001010111100110100101000110011111011001100000001100\n0111001101\n0101011110\n0001100111\n1101011111\n1110000011\n0000001100\n0111010001\n1101100110\n1010110100\n0110100101", "output": "24819275" }, { "input": "10111110010011111001001111100101010111010011111001001110101000111110011001111101\n0011111001\n0101011101\n0100001010\n0001110010\n1001111101\n0011101010\n1111001001\n1100100001\n1001101000\n1011111001", "output": "90010504" }, { "input": "01111101111100101010001001011110111001110111110111011111011110110111111011011111\n1111110111\n0010000101\n0110000100\n0111111011\n1011100111\n1100101010\n1011011111\n1100010001\n0111110111\n0010010111", "output": "85948866" }, { "input": "01111100000111110000110010111001111100001001101010110010111010001000101001101010\n0100010101\n1011110101\n1010100100\n1010000001\n1001101010\n0101100110\n1000100010\n0111110000\n1100101110\n0110010110", "output": "77874864" }, { "input": "11100011010000000010011110010111001011111001000111000000001000000000100111100101\n0000000010\n1110001101\n0011010101\n0111100101\n1001000111\n1101001111\n0111010110\n1100101111\n0110000000\n1101101011", "output": "10374003" }, { "input": "01111011100111101110011001000110001111101000111110100100100001011111001011100010\n0110010100\n1100010001\n0111101110\n1001001000\n1010011011\n1000111110\n0010110101\n1011100010\n0101111100\n0110010001", "output": "22955387" }, { "input": "11011010001100000011000100110011010101000110011110110000001100111100001000011111\n0000100010\n1000011111\n1101101000\n0110011110\n0011110000\n1100000011\n0010001100\n0101101000\n0001001100\n1101010100", "output": "25893541" }, { "input": "01011001011111010010101111011001000011001100011101101111011011010011101011110110\n0100001100\n0101100101\n1111111011\n1111010010\n1111101100\n1100011101\n1011000011\n1101001110\n1011110110\n0110001010", "output": "13805878" }, { "input": "11110011011000111111001100111110001111111100000010111100110100110011111111001101\n1111001101\n1001101010\n1100110010\n0011001111\n0001011110\n1000110011\n1000111111\n0110001010\n1001011101\n1100000010", "output": "06369030" }, { "input": "01110011110010000011011001011000001000010110010110011001100001100110001100101000\n0000100001\n0110011000\n1010000010\n1110011101\n0111001111\n1100101000\n0010000011\n0110010000\n1100100101\n0110010110", "output": "46909115" }, { "input": "00001011001111110111111111011111111101110101110100010111010010100101100001010110\n1111110111\n0001010110\n0111011011\n0111000001\n1010010110\n0101110100\n0001000101\n0000111000\n0110100001\n0000101100", "output": "90005541" } ]
1,697,709,407
2,147,483,647
PyPy 3-64
OK
TESTS
50
124
0
n=input() m=[] seq_size = 10 seq_num = 8 a='' for i in range(seq_num): m.append(n[i*seq_size:(i+1)*seq_size]) mas=[] for i in range(10): l=input() mas.append(l) for i in m: a+=str(mas.index(i)) print(a)
Title: Restoring Password Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password". Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address. Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits. Help Igor K. restore his ISQ account by the encrypted password and encryption specification. Input Specification: The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. Output Specification: Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. Demo Input: ['01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n', '10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1001000110\n1010110111\n0010110111\n1101001101\n1011000001\n1110010101\n1011011000\n0110001000\n'] Demo Output: ['12345678\n', '30234919\n'] Note: none
```python n=input() m=[] seq_size = 10 seq_num = 8 a='' for i in range(seq_num): m.append(n[i*seq_size:(i+1)*seq_size]) mas=[] for i in range(10): l=input() mas.append(l) for i in m: a+=str(mas.index(i)) print(a) ```
3.969
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,698,690,299
2,147,483,647
Python 3
OK
TESTS
37
358
819,200
IN = lambda x:list(map(x, input().split())) n, m = IN(x = int) l1 = [] l2 = [] for x in range(m): a,b = IN(x = str) l1 += [a]; l2 += [b] for y in input().split(): if y in l1: if len(l2[l1.index(y)]) < len(y): print(l2[l1.index(y)], end = " ") else: print(y, end = " ") else: if len(l1[l2.index(y)]) <= len(y): print(l1[l2.index(y)], end = " ") else: print(y, end = " ")
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python IN = lambda x:list(map(x, input().split())) n, m = IN(x = int) l1 = [] l2 = [] for x in range(m): a,b = IN(x = str) l1 += [a]; l2 += [b] for y in input().split(): if y in l1: if len(l2[l1.index(y)]) < len(y): print(l2[l1.index(y)], end = " ") else: print(y, end = " ") else: if len(l1[l2.index(y)]) <= len(y): print(l1[l2.index(y)], end = " ") else: print(y, end = " ") ```
3
465
A
inc ARG
PROGRAMMING
900
[ "implementation" ]
null
null
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit.
Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell.
[ "4\n1100\n", "4\n1111\n" ]
[ "3\n", "4\n" ]
In the first sample the cell ends up with value 0010, in the second sample — with 0000.
500
[ { "input": "4\n1100", "output": "3" }, { "input": "4\n1111", "output": "4" }, { "input": "1\n0", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n00", "output": "1" }, { "input": "2\n01", "output": "1" }, { "input": "2\n10", "output": "2" }, { "input": "2\n11", "output": "2" }, { "input": "10\n0000000000", "output": "1" }, { "input": "20\n11111111110110001100", "output": "11" }, { "input": "50\n01011110100010000001010000100001001101001101101011", "output": "1" }, { "input": "60\n111111111101111111111111111111111111111111111111111111111111", "output": "11" }, { "input": "60\n111111111111111111111111111111111111111111111111111111111111", "output": "60" }, { "input": "66\n111111010010011001110011000111000100011110011001111110011111111101", "output": "7" }, { "input": "90\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "91\n1011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "2" }, { "input": "92\n11111111101011111011111111111111111111111011101111111111011111111111111101111111101011111101", "output": "10" }, { "input": "100\n0001011110100011001100100010111001000001111101101001001001001011110100101101010000000110100101110010", "output": "1" }, { "input": "100\n0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1011001110001000011111110011000100001110010110111101110110011011011000010100110001111100000010110010", "output": "2" }, { "input": "100\n1101111011001111111111110011110111101110111111111111111111111111111111011111111111110111111111111111", "output": "3" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110", "output": "100" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111101", "output": "99" }, { "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000", "output": "96" }, { "input": "100\n1111111111111111111111111111111110011000110110001010101100100100001000010010010010000100110000010101", "output": "34" } ]
1,688,650,266
2,147,483,647
PyPy 3-64
OK
TESTS
29
61
0
import sys input = sys.stdin.readline n = int(input()) data = input().rstrip()[::-1] tmp = bin(int(data, 2) + 1)[2:] tmp = (n - len(tmp)) * '0' + tmp cnt = 0 for i in range(n): if data[-(i + 1)] != tmp[-(i + 1)]: cnt += 1 print(cnt)
Title: inc ARG Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of bits in the cell. The second line contains a string consisting of *n* characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. Output Specification: Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. Demo Input: ['4\n1100\n', '4\n1111\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample the cell ends up with value 0010, in the second sample — with 0000.
```python import sys input = sys.stdin.readline n = int(input()) data = input().rstrip()[::-1] tmp = bin(int(data, 2) + 1)[2:] tmp = (n - len(tmp)) * '0' + tmp cnt = 0 for i in range(n): if data[-(i + 1)] != tmp[-(i + 1)]: cnt += 1 print(cnt) ```
3
987
A
Infinity Gauntlet
PROGRAMMING
800
[ "implementation" ]
null
null
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.
In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.
In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.
[ "4\nred\npurple\nyellow\norange\n", "0\n" ]
[ "2\nSpace\nTime\n", "6\nTime\nMind\nSoul\nPower\nReality\nSpace\n" ]
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
500
[ { "input": "4\nred\npurple\nyellow\norange", "output": "2\nSpace\nTime" }, { "input": "0", "output": "6\nMind\nSpace\nPower\nTime\nReality\nSoul" }, { "input": "6\npurple\nblue\nyellow\nred\ngreen\norange", "output": "0" }, { "input": "1\npurple", "output": "5\nTime\nReality\nSoul\nSpace\nMind" }, { "input": "3\nblue\norange\npurple", "output": "3\nTime\nReality\nMind" }, { "input": "2\nyellow\nred", "output": "4\nPower\nSoul\nSpace\nTime" }, { "input": "1\ngreen", "output": "5\nReality\nSpace\nPower\nSoul\nMind" }, { "input": "2\npurple\ngreen", "output": "4\nReality\nMind\nSpace\nSoul" }, { "input": "1\nblue", "output": "5\nPower\nReality\nSoul\nTime\nMind" }, { "input": "2\npurple\nblue", "output": "4\nMind\nSoul\nTime\nReality" }, { "input": "2\ngreen\nblue", "output": "4\nReality\nMind\nPower\nSoul" }, { "input": "3\npurple\ngreen\nblue", "output": "3\nMind\nReality\nSoul" }, { "input": "1\norange", "output": "5\nReality\nTime\nPower\nSpace\nMind" }, { "input": "2\npurple\norange", "output": "4\nReality\nMind\nTime\nSpace" }, { "input": "2\norange\ngreen", "output": "4\nSpace\nMind\nReality\nPower" }, { "input": "3\norange\npurple\ngreen", "output": "3\nReality\nSpace\nMind" }, { "input": "2\norange\nblue", "output": "4\nTime\nMind\nReality\nPower" }, { "input": "3\nblue\ngreen\norange", "output": "3\nPower\nMind\nReality" }, { "input": "4\nblue\norange\ngreen\npurple", "output": "2\nMind\nReality" }, { "input": "1\nred", "output": "5\nTime\nSoul\nMind\nPower\nSpace" }, { "input": "2\nred\npurple", "output": "4\nMind\nSpace\nTime\nSoul" }, { "input": "2\nred\ngreen", "output": "4\nMind\nSpace\nPower\nSoul" }, { "input": "3\nred\npurple\ngreen", "output": "3\nSoul\nSpace\nMind" }, { "input": "2\nblue\nred", "output": "4\nMind\nTime\nPower\nSoul" }, { "input": "3\nred\nblue\npurple", "output": "3\nTime\nMind\nSoul" }, { "input": "3\nred\nblue\ngreen", "output": "3\nSoul\nPower\nMind" }, { "input": "4\npurple\nblue\ngreen\nred", "output": "2\nMind\nSoul" }, { "input": "2\norange\nred", "output": "4\nPower\nMind\nTime\nSpace" }, { "input": "3\nred\norange\npurple", "output": "3\nMind\nSpace\nTime" }, { "input": "3\nred\norange\ngreen", "output": "3\nMind\nSpace\nPower" }, { "input": "4\nred\norange\ngreen\npurple", "output": "2\nSpace\nMind" }, { "input": "3\nblue\norange\nred", "output": "3\nPower\nMind\nTime" }, { "input": "4\norange\nblue\npurple\nred", "output": "2\nTime\nMind" }, { "input": "4\ngreen\norange\nred\nblue", "output": "2\nMind\nPower" }, { "input": "5\npurple\norange\nblue\nred\ngreen", "output": "1\nMind" }, { "input": "1\nyellow", "output": "5\nPower\nSoul\nReality\nSpace\nTime" }, { "input": "2\npurple\nyellow", "output": "4\nTime\nReality\nSpace\nSoul" }, { "input": "2\ngreen\nyellow", "output": "4\nSpace\nReality\nPower\nSoul" }, { "input": "3\npurple\nyellow\ngreen", "output": "3\nSoul\nReality\nSpace" }, { "input": "2\nblue\nyellow", "output": "4\nTime\nReality\nPower\nSoul" }, { "input": "3\nyellow\nblue\npurple", "output": "3\nSoul\nReality\nTime" }, { "input": "3\ngreen\nyellow\nblue", "output": "3\nSoul\nReality\nPower" }, { "input": "4\nyellow\nblue\ngreen\npurple", "output": "2\nReality\nSoul" }, { "input": "2\nyellow\norange", "output": "4\nTime\nSpace\nReality\nPower" }, { "input": "3\nyellow\npurple\norange", "output": "3\nSpace\nReality\nTime" }, { "input": "3\norange\nyellow\ngreen", "output": "3\nSpace\nReality\nPower" }, { "input": "4\ngreen\nyellow\norange\npurple", "output": "2\nSpace\nReality" }, { "input": "3\nyellow\nblue\norange", "output": "3\nTime\nReality\nPower" }, { "input": "4\norange\npurple\nblue\nyellow", "output": "2\nReality\nTime" }, { "input": "4\nblue\norange\nyellow\ngreen", "output": "2\nReality\nPower" }, { "input": "5\ngreen\nyellow\norange\nblue\npurple", "output": "1\nReality" }, { "input": "3\nyellow\npurple\nred", "output": "3\nTime\nSoul\nSpace" }, { "input": "3\nred\ngreen\nyellow", "output": "3\nPower\nSoul\nSpace" }, { "input": "4\nred\npurple\ngreen\nyellow", "output": "2\nSpace\nSoul" }, { "input": "3\nred\nyellow\nblue", "output": "3\nPower\nSoul\nTime" }, { "input": "4\nblue\nyellow\nred\npurple", "output": "2\nTime\nSoul" }, { "input": "4\nblue\nyellow\nred\ngreen", "output": "2\nSoul\nPower" }, { "input": "5\nred\nyellow\ngreen\nblue\npurple", "output": "1\nSoul" }, { "input": "3\nred\nyellow\norange", "output": "3\nPower\nSpace\nTime" }, { "input": "4\norange\ngreen\nyellow\nred", "output": "2\nPower\nSpace" }, { "input": "5\norange\nred\ngreen\nyellow\npurple", "output": "1\nSpace" }, { "input": "4\nyellow\nred\norange\nblue", "output": "2\nTime\nPower" }, { "input": "5\npurple\nblue\norange\nyellow\nred", "output": "1\nTime" }, { "input": "5\norange\nblue\nyellow\nred\ngreen", "output": "1\nPower" } ]
1,581,040,004
2,147,483,647
Python 3
OK
TESTS
64
124
0
a=['purple', 'green', 'blue', 'orange', 'red', 'yellow'] b=['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'] n=int(input()) c=[input() for _ in [0]*n] d=[b[x] for x,y in enumerate(a) if y not in c] print(len(d),*d,sep='\n')
Title: Infinity Gauntlet Time Limit: None seconds Memory Limit: None megabytes Problem Description: You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems: - the Power Gem of purple color, - the Time Gem of green color, - the Space Gem of blue color, - the Soul Gem of orange color, - the Reality Gem of red color, - the Mind Gem of yellow color. Using colors of Gems you saw in the Gauntlet determine the names of absent Gems. Input Specification: In the first line of input there is one integer $n$ ($0 \le n \le 6$) — the number of Gems in Infinity Gauntlet. In next $n$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters. Output Specification: In the first line output one integer $m$ ($0 \le m \le 6$) — the number of absent Gems. Then in $m$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase. Demo Input: ['4\nred\npurple\nyellow\norange\n', '0\n'] Demo Output: ['2\nSpace\nTime\n', '6\nTime\nMind\nSoul\nPower\nReality\nSpace\n'] Note: In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space. In the second sample Thanos doesn't have any Gems, so he needs all six.
```python a=['purple', 'green', 'blue', 'orange', 'red', 'yellow'] b=['Power', 'Time', 'Space', 'Soul', 'Reality', 'Mind'] n=int(input()) c=[input() for _ in [0]*n] d=[b[x] for x,y in enumerate(a) if y not in c] print(len(d),*d,sep='\n') ```
3
507
C
Guess Your Way Out!
PROGRAMMING
1,700
[ "implementation", "math", "trees" ]
null
null
Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the leaf nodes from the left to the right from 1 to 2*h*. The exit is located at some node *n* where 1<=≤<=*n*<=≤<=2*h*, the player doesn't know where the exit is so he has to guess his way out! Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules: - Character 'L' means "go to the left child of the current node"; - Character 'R' means "go to the right child of the current node"; - If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node; - If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command; - If he reached a leaf node that is not the exit, he returns to the parent of the current node; - If he reaches an exit, the game is finished. Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit?
Input consists of two integers *h*,<=*n* (1<=≤<=*h*<=≤<=50, 1<=≤<=*n*<=≤<=2*h*).
Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm.
[ "1 2\n", "2 3\n", "3 6\n", "10 1024\n" ]
[ "2", "5", "10", "2046" ]
A perfect binary tree of height *h* is a binary tree consisting of *h* + 1 levels. Level 0 consists of a single node called root, level *h* consists of 2<sup class="upper-index">*h*</sup> nodes called leaves. Each node that is not a leaf has exactly two children, left and right one. Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit. <img class="tex-graphics" src="https://espresso.codeforces.com/e9d0715dc8cd9b4f6ac7a0fb137563f857660adc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,500
[ { "input": "1 2", "output": "2" }, { "input": "2 3", "output": "5" }, { "input": "3 6", "output": "10" }, { "input": "10 1024", "output": "2046" }, { "input": "10 577", "output": "1345" }, { "input": "11 550", "output": "408" }, { "input": "19 12783", "output": "503251" }, { "input": "28 72803174", "output": "50649698" }, { "input": "39 457181784666", "output": "830699159852" }, { "input": "12 955", "output": "2871" }, { "input": "13 154", "output": "7770" }, { "input": "14 2334", "output": "9440" }, { "input": "15 15512", "output": "14926" }, { "input": "16 21395", "output": "2899" }, { "input": "17 80239", "output": "177237" }, { "input": "18 153276", "output": "328766" }, { "input": "20 589266", "output": "1505684" }, { "input": "21 1687606", "output": "3522472" }, { "input": "24 14428281", "output": "26969983" }, { "input": "29 113463931", "output": "347736449" }, { "input": "1 1", "output": "1" }, { "input": "3 8", "output": "14" }, { "input": "31 1819651953", "output": "3412135549" }, { "input": "33 2599588275", "output": "1357401405" }, { "input": "38 262402936512", "output": "519008349260" }, { "input": "4 13", "output": "27" }, { "input": "40 615535158153", "output": "1572205271927" }, { "input": "42 1042128038474", "output": "3195908899134" }, { "input": "45 17519319833295", "output": "17381304930499" }, { "input": "46 34999315964173", "output": "34646522010881" }, { "input": "49 295606900104348", "output": "820858833984106" }, { "input": "50 905353992267944", "output": "1871650493613618" }, { "input": "3 5", "output": "11" }, { "input": "4 14", "output": "26" }, { "input": "6 40", "output": "88" }, { "input": "7 31", "output": "95" }, { "input": "8 19", "output": "205" }, { "input": "10 359", "output": "91" }, { "input": "11 349", "output": "1057" }, { "input": "13 4796", "output": "10298" }, { "input": "20 742273", "output": "1182599" }, { "input": "22 3343393", "output": "7009189" }, { "input": "24 3543583", "output": "10865127" }, { "input": "25 678676", "output": "31527640" }, { "input": "27 109473899", "output": "209022797" }, { "input": "29 19827102", "output": "478963048" }, { "input": "8 204", "output": "422" }, { "input": "30 414940886", "output": "372407442" }, { "input": "32 3786259360", "output": "8003335020" }, { "input": "35 31233562499", "output": "60951693197" }, { "input": "38 99361414961", "output": "28342263489" }, { "input": "9 43", "output": "391" }, { "input": "40 874338951117", "output": "1800799608767" }, { "input": "33 2696188969", "output": "505562011" }, { "input": "35 12080044014", "output": "2415167450" }, { "input": "12 2715", "output": "4185" }, { "input": "29 524109003", "output": "1052258991" }, { "input": "50 1", "output": "1125899906842623" }, { "input": "50 1125899906842624", "output": "2251799813685246" }, { "input": "50 562949953421312", "output": "562949953421312" }, { "input": "50 844424930131968", "output": "1407374883553280" }, { "input": "50 375299968947542", "output": "50" } ]
1,606,941,942
2,147,483,647
PyPy 3
OK
TESTS
62
140
0
import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() def printOutput(ans): sys.stdout.write(str(ans) + "\n") def solve(h, n): heightNodes = [1 for _ in range(51)] for height in range(1, 51): heightNodes[height] = 2 ** height + heightNodes[height - 1] curPos = 2 ** (h - 1) depth = h add = 2 ** (h - 1) direction = -1 total = 0 # visited root while True: if depth == 0: break if (curPos >= n and direction == -1) or ( curPos < n and direction == 1 ): # this means n is to the left total += 1 depth -= 1 add //= 2 curPos += direction * (add) else: total += heightNodes[depth - 1] direction *= -1 return total def readinput(): h, n = getInts() printOutput(solve(h, n)) readinput()
Title: Guess Your Way Out! Time Limit: None seconds Memory Limit: None megabytes Problem Description: Amr bought a new video game "Guess Your Way Out!". The goal of the game is to find an exit from the maze that looks like a perfect binary tree of height *h*. The player is initially standing at the root of the tree and the exit from the tree is located at some leaf node. Let's index all the leaf nodes from the left to the right from 1 to 2*h*. The exit is located at some node *n* where 1<=≤<=*n*<=≤<=2*h*, the player doesn't know where the exit is so he has to guess his way out! Amr follows simple algorithm to choose the path. Let's consider infinite command string "LRLRLRLRL..." (consisting of alternating characters 'L' and 'R'). Amr sequentially executes the characters of the string using following rules: - Character 'L' means "go to the left child of the current node"; - Character 'R' means "go to the right child of the current node"; - If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node; - If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command; - If he reached a leaf node that is not the exit, he returns to the parent of the current node; - If he reaches an exit, the game is finished. Now Amr wonders, if he follows this algorithm, how many nodes he is going to visit before reaching the exit? Input Specification: Input consists of two integers *h*,<=*n* (1<=≤<=*h*<=≤<=50, 1<=≤<=*n*<=≤<=2*h*). Output Specification: Output a single integer representing the number of nodes (excluding the exit node) Amr is going to visit before reaching the exit by following this algorithm. Demo Input: ['1 2\n', '2 3\n', '3 6\n', '10 1024\n'] Demo Output: ['2', '5', '10', '2046'] Note: A perfect binary tree of height *h* is a binary tree consisting of *h* + 1 levels. Level 0 consists of a single node called root, level *h* consists of 2<sup class="upper-index">*h*</sup> nodes called leaves. Each node that is not a leaf has exactly two children, left and right one. Following picture illustrates the sample test number 3. Nodes are labeled according to the order of visit. <img class="tex-graphics" src="https://espresso.codeforces.com/e9d0715dc8cd9b4f6ac7a0fb137563f857660adc.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() def printOutput(ans): sys.stdout.write(str(ans) + "\n") def solve(h, n): heightNodes = [1 for _ in range(51)] for height in range(1, 51): heightNodes[height] = 2 ** height + heightNodes[height - 1] curPos = 2 ** (h - 1) depth = h add = 2 ** (h - 1) direction = -1 total = 0 # visited root while True: if depth == 0: break if (curPos >= n and direction == -1) or ( curPos < n and direction == 1 ): # this means n is to the left total += 1 depth -= 1 add //= 2 curPos += direction * (add) else: total += heightNodes[depth - 1] direction *= -1 return total def readinput(): h, n = getInts() printOutput(solve(h, n)) readinput() ```
3
584
A
Olesya and Rodion
PROGRAMMING
1,000
[ "math" ]
null
null
Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1.
The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by.
Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.
[ "3 2\n" ]
[ "712" ]
none
500
[ { "input": "3 2", "output": "222" }, { "input": "2 2", "output": "22" }, { "input": "4 3", "output": "3333" }, { "input": "5 3", "output": "33333" }, { "input": "10 7", "output": "7777777777" }, { "input": "2 9", "output": "99" }, { "input": "18 8", "output": "888888888888888888" }, { "input": "1 5", "output": "5" }, { "input": "1 10", "output": "-1" }, { "input": "100 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "10 2", "output": "2222222222" }, { "input": "18 10", "output": "111111111111111110" }, { "input": "1 9", "output": "9" }, { "input": "7 6", "output": "6666666" }, { "input": "4 4", "output": "4444" }, { "input": "14 7", "output": "77777777777777" }, { "input": "3 8", "output": "888" }, { "input": "1 3", "output": "3" }, { "input": "2 8", "output": "88" }, { "input": "3 8", "output": "888" }, { "input": "4 3", "output": "3333" }, { "input": "5 9", "output": "99999" }, { "input": "4 8", "output": "8888" }, { "input": "3 4", "output": "444" }, { "input": "9 4", "output": "444444444" }, { "input": "8 10", "output": "11111110" }, { "input": "1 6", "output": "6" }, { "input": "20 3", "output": "33333333333333333333" }, { "input": "15 10", "output": "111111111111110" }, { "input": "31 4", "output": "4444444444444444444444444444444" }, { "input": "18 9", "output": "999999999999999999" }, { "input": "72 4", "output": "444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "76 8", "output": "8888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "12 5", "output": "555555555555" }, { "input": "54 5", "output": "555555555555555555555555555555555555555555555555555555" }, { "input": "96 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "15 9", "output": "999999999999999" }, { "input": "100 2", "output": "2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222" }, { "input": "99 3", "output": "333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333" }, { "input": "98 4", "output": "44444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444" }, { "input": "97 5", "output": "5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "100 6", "output": "6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "98 8", "output": "88888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888" }, { "input": "97 9", "output": "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "3 10", "output": "110" }, { "input": "2 4", "output": "44" }, { "input": "2 10", "output": "10" }, { "input": "10 10", "output": "1111111110" }, { "input": "4 10", "output": "1110" }, { "input": "25 10", "output": "1111111111111111111111110" }, { "input": "50 10", "output": "11111111111111111111111111111111111111111111111110" }, { "input": "5 10", "output": "11110" }, { "input": "99 10", "output": "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "100 10", "output": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110" }, { "input": "1 2", "output": "2" }, { "input": "20 10", "output": "11111111111111111110" }, { "input": "99 7", "output": "777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" }, { "input": "89 5", "output": "55555555555555555555555555555555555555555555555555555555555555555555555555555555555555555" }, { "input": "6 10", "output": "111110" }, { "input": "3 8", "output": "888" }, { "input": "1 9", "output": "9" }, { "input": "1 4", "output": "4" }, { "input": "100 7", "output": "7777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777" } ]
1,696,287,260
2,147,483,647
PyPy 3-64
OK
TESTS
65
62
0
n,k = map(int,input().split()) if n==1 and k==10: print(-1) elif k==10: print('1'+'0'*(n-1)) else: print(str(k)*n)
Title: Olesya and Rodion Time Limit: None seconds Memory Limit: None megabytes Problem Description: Olesya loves numbers consisting of *n* digits, and Rodion only likes numbers that are divisible by *t*. Find some number that satisfies both of them. Your task is: given the *n* and *t* print an integer strictly larger than zero consisting of *n* digits that is divisible by *t*. If such number doesn't exist, print <=-<=1. Input Specification: The single line contains two numbers, *n* and *t* (1<=≤<=*n*<=≤<=100, 2<=≤<=*t*<=≤<=10) — the length of the number and the number it should be divisible by. Output Specification: Print one such positive number without leading zeroes, — the answer to the problem, or <=-<=1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them. Demo Input: ['3 2\n'] Demo Output: ['712'] Note: none
```python n,k = map(int,input().split()) if n==1 and k==10: print(-1) elif k==10: print('1'+'0'*(n-1)) else: print(str(k)*n) ```
3
793
A
Oleg and shares
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
[ "3 3\n12 9 15\n", "2 2\n10 9\n", "4 1\n1 1000000000 1000000000 1000000000\n" ]
[ "3", "-1", "2999999997" ]
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
500
[ { "input": "3 3\n12 9 15", "output": "3" }, { "input": "2 2\n10 9", "output": "-1" }, { "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997" }, { "input": "1 11\n123", "output": "0" }, { "input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14", "output": "151" }, { "input": "20 5\n59 54 19 88 55 100 54 3 6 13 99 38 36 71 59 6 64 85 45 54", "output": "-1" }, { "input": "100 10\n340 70 440 330 130 120 340 210 440 110 410 120 180 40 50 230 70 110 310 360 480 70 230 120 230 310 470 60 210 60 210 480 290 250 450 440 150 40 500 230 280 250 30 50 310 50 230 360 420 260 330 80 50 160 70 470 140 180 380 190 250 30 220 410 80 310 280 50 20 430 440 180 310 190 190 330 90 190 320 390 170 460 230 30 80 500 470 370 80 500 400 120 220 150 70 120 70 320 260 260", "output": "2157" }, { "input": "100 18\n489 42 300 366 473 105 220 448 70 488 201 396 168 281 67 235 324 291 313 387 407 223 39 144 224 233 72 318 229 377 62 171 448 119 354 282 147 447 260 384 172 199 67 326 311 431 337 142 281 202 404 468 38 120 90 437 33 420 249 372 367 253 255 411 309 333 103 176 162 120 203 41 352 478 216 498 224 31 261 493 277 99 375 370 394 229 71 488 246 194 233 13 66 111 366 456 277 360 116 354", "output": "-1" }, { "input": "4 2\n1 2 3 4", "output": "-1" }, { "input": "3 4\n3 5 5", "output": "-1" }, { "input": "3 2\n88888884 88888886 88888888", "output": "3" }, { "input": "2 1\n1000000000 1000000000", "output": "0" }, { "input": "4 2\n1000000000 100000000 100000000 100000000", "output": "450000000" }, { "input": "2 2\n1000000000 1000000000", "output": "0" }, { "input": "3 3\n3 2 1", "output": "-1" }, { "input": "3 4\n3 5 3", "output": "-1" }, { "input": "3 2\n1 2 2", "output": "-1" }, { "input": "4 2\n2 3 3 2", "output": "-1" }, { "input": "3 2\n1 2 4", "output": "-1" }, { "input": "3 2\n3 4 4", "output": "-1" }, { "input": "3 3\n4 7 10", "output": "3" }, { "input": "4 3\n2 2 5 1", "output": "-1" }, { "input": "3 3\n1 3 5", "output": "-1" }, { "input": "2 5\n5 9", "output": "-1" }, { "input": "2 3\n5 7", "output": "-1" }, { "input": "3 137\n1000000000 1000000000 1000000000", "output": "0" }, { "input": "5 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 5\n1 2 5", "output": "-1" }, { "input": "3 3\n1000000000 1000000000 999999997", "output": "2" }, { "input": "2 4\n5 6", "output": "-1" }, { "input": "4 1\n1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "2 3\n5 8", "output": "1" }, { "input": "2 6\n8 16", "output": "-1" }, { "input": "5 3\n15 14 9 12 18", "output": "-1" }, { "input": "3 3\n1 2 3", "output": "-1" }, { "input": "3 3\n3 4 5", "output": "-1" }, { "input": "2 5\n8 17", "output": "-1" }, { "input": "2 1\n1 2", "output": "1" }, { "input": "1 1\n1000000000", "output": "0" }, { "input": "3 3\n5 3 4", "output": "-1" }, { "input": "3 6\n10 14 12", "output": "-1" }, { "input": "2 2\n3 5", "output": "1" }, { "input": "3 5\n1 3 4", "output": "-1" }, { "input": "4 3\n1 6 6 6", "output": "-1" }, { "input": "2 3\n1 8", "output": "-1" }, { "input": "3 5\n6 11 17", "output": "-1" }, { "input": "2 2\n1 4", "output": "-1" }, { "input": "2 4\n6 8", "output": "-1" }, { "input": "2 1\n2 3", "output": "1" }, { "input": "4 4\n1 5 8 14", "output": "-1" }, { "input": "3 3\n1 5 3", "output": "-1" }, { "input": "4 3\n1 2 2 5", "output": "-1" }, { "input": "3 2\n1 4 6", "output": "-1" }, { "input": "2 3\n6 9", "output": "1" }, { "input": "3 3\n2 3 4", "output": "-1" }, { "input": "3 2\n9 10 10", "output": "-1" }, { "input": "2 2\n9 12", "output": "-1" }, { "input": "2 2\n100000003 100000005", "output": "1" }, { "input": "2 3\n2 4", "output": "-1" }, { "input": "3 2\n2 3 5", "output": "-1" }, { "input": "3 3\n1 3 4", "output": "-1" }, { "input": "10 2\n2 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "4499999991" }, { "input": "3 5\n2 4 5", "output": "-1" }, { "input": "2 3\n7 10", "output": "1" }, { "input": "3 10\n10 13 17", "output": "-1" }, { "input": "2 3\n1 6", "output": "-1" }, { "input": "1 7\n1000000000", "output": "0" }, { "input": "2 4\n3 7", "output": "1" }, { "input": "2 3\n2 5", "output": "1" }, { "input": "20 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "0" }, { "input": "3 3\n7 8 8", "output": "-1" }, { "input": "4 10\n1 11 100 11", "output": "-1" } ]
1,593,018,892
2,147,483,647
PyPy 3
OK
TESTS
88
234
34,099,200
n , k = map(int,input().split()) l = list(map(int,input().split())) st = set(l) cnt = 0 if len(st) == 1 : print(0) exit() else: x = min(l) for i in l : c = i - x if c % k == 0 : cnt += c // k else: print(-1) exit() print(cnt)
Title: Oleg and shares Time Limit: None seconds Memory Limit: None megabytes Problem Description: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. Output Specification: Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. Demo Input: ['3 3\n12 9 15\n', '2 2\n10 9\n', '4 1\n1 1000000000 1000000000 1000000000\n'] Demo Output: ['3', '-1', '2999999997'] Note: Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3. In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal. In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.
```python n , k = map(int,input().split()) l = list(map(int,input().split())) st = set(l) cnt = 0 if len(st) == 1 : print(0) exit() else: x = min(l) for i in l : c = i - x if c % k == 0 : cnt += c // k else: print(-1) exit() print(cnt) ```
3
155
A
I_love_\%username\%
PROGRAMMING
800
[ "brute force" ]
null
null
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.
The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.
Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.
[ "5\n100 50 200 150 200\n", "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n" ]
[ "2\n", "4\n" ]
In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
500
[ { "input": "5\n100 50 200 150 200", "output": "2" }, { "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4" }, { "input": "1\n6", "output": "0" }, { "input": "2\n2 1", "output": "1" }, { "input": "5\n100 36 53 7 81", "output": "2" }, { "input": "5\n7 36 53 81 100", "output": "4" }, { "input": "5\n100 81 53 36 7", "output": "4" }, { "input": "10\n8 6 3 4 9 10 7 7 1 3", "output": "5" }, { "input": "10\n1627 1675 1488 1390 1812 1137 1746 1324 1952 1862", "output": "6" }, { "input": "10\n1 3 3 4 6 7 7 8 9 10", "output": "7" }, { "input": "10\n1952 1862 1812 1746 1675 1627 1488 1390 1324 1137", "output": "9" }, { "input": "25\n1448 4549 2310 2725 2091 3509 1565 2475 2232 3989 4231 779 2967 2702 608 3739 721 1552 2767 530 3114 665 1940 48 4198", "output": "5" }, { "input": "33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047 1041 1028 1120 1126 1063 1117 1110 1044 1093 1101", "output": "5" }, { "input": "34\n821 5536 2491 6074 7216 9885 764 1603 778 8736 8987 771 617 1587 8943 7922 439 7367 4115 8886 7878 6899 8811 5752 3184 3401 9760 9400 8995 4681 1323 6637 6554 6498", "output": "7" }, { "input": "68\n6764 6877 6950 6768 6839 6755 6726 6778 6699 6805 6777 6985 6821 6801 6791 6805 6940 6761 6677 6999 6911 6699 6959 6933 6903 6843 6972 6717 6997 6756 6789 6668 6735 6852 6735 6880 6723 6834 6810 6694 6780 6679 6698 6857 6826 6896 6979 6968 6957 6988 6960 6700 6919 6892 6984 6685 6813 6678 6715 6857 6976 6902 6780 6686 6777 6686 6842 6679", "output": "9" }, { "input": "60\n9000 9014 9034 9081 9131 9162 9174 9199 9202 9220 9221 9223 9229 9235 9251 9260 9268 9269 9270 9298 9307 9309 9313 9323 9386 9399 9407 9495 9497 9529 9531 9544 9614 9615 9627 9627 9643 9654 9656 9657 9685 9699 9701 9736 9745 9758 9799 9827 9843 9845 9854 9854 9885 9891 9896 9913 9942 9963 9986 9992", "output": "57" }, { "input": "100\n7 61 12 52 41 16 34 99 30 44 48 89 31 54 21 1 48 52 61 15 35 87 21 76 64 92 44 81 16 93 84 92 32 15 68 76 53 39 26 4 11 26 7 4 99 99 61 65 55 85 65 67 47 39 2 74 63 49 98 87 5 94 22 30 25 42 31 84 49 23 89 60 16 26 92 27 9 57 75 61 94 35 83 47 99 100 63 24 91 88 79 10 15 45 22 64 3 11 89 83", "output": "4" }, { "input": "100\n9999 9999 9999 9998 9998 9998 9997 9996 9996 9995 9993 9993 9991 9990 9989 9986 9984 9984 9983 9981 9981 9980 9980 9980 9979 9977 9977 9977 9977 9977 9976 9976 9975 9975 9973 9972 9972 9972 9972 9971 9969 9969 9969 9968 9967 9965 9962 9962 9962 9962 9960 9958 9958 9955 9954 9954 9954 9954 9950 9949 9949 9947 9943 9943 9940 9940 9939 9937 9937 9937 9936 9935 9932 9932 9931 9929 9927 9927 9926 9923 9919 9919 9918 9918 9918 9917 9917 9916 9916 9915 9914 9911 9910 9907 9907 9906 9905 9905 9904 9901", "output": "57" }, { "input": "100\n158 159 157 156 155 154 160 153 161 152 162 163 151 164 150 165 149 148 147 166 146 167 145 144 143 142 168 141 169 170 140 139 138 137 171 136 135 134 172 173 174 133 175 132 177 178 131 179 180 130 129 181 128 127 182 126 183 125 124 184 123 122 121 120 119 118 117 185 186 187 188 189 116 190 115 191 192 193 114 113 112 111 110 109 108 194 195 107 106 105 196 197 104 198 199 103 102 200 101 100", "output": "99" }, { "input": "2\n0 10000", "output": "1" }, { "input": "2\n5 5", "output": "0" }, { "input": "2\n1 1", "output": "0" }, { "input": "2\n10 10", "output": "0" }, { "input": "1\n0", "output": "0" } ]
1,692,593,754
2,147,483,647
Python 3
OK
TESTS
37
92
0
n = int(input()) points = list(map(int, input().split())) amazing_performance = 0 highest_point = points[0] lowest_point = points[0] for i in range(1, n): if points[i] > highest_point: highest_point = points[i] amazing_performance += 1 elif points[i] < lowest_point: lowest_point = points[i] amazing_performance += 1 print(amazing_performance)
Title: I_love_\%username\% Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. Input Specification: The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. Output Specification: Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. Demo Input: ['5\n100 50 200 150 200\n', '10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n'] Demo Output: ['2\n', '4\n'] Note: In the first sample the performances number 2 and 3 are amazing. In the second sample the performances number 2, 4, 9 and 10 are amazing.
```python n = int(input()) points = list(map(int, input().split())) amazing_performance = 0 highest_point = points[0] lowest_point = points[0] for i in range(1, n): if points[i] > highest_point: highest_point = points[i] amazing_performance += 1 elif points[i] < lowest_point: lowest_point = points[i] amazing_performance += 1 print(amazing_performance) ```
3
930
A
Peculiar apple-tree
PROGRAMMING
1,500
[ "dfs and similar", "graphs", "trees" ]
null
null
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest.
First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down.
Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest.
[ "3\n1 1\n", "5\n1 2 2 2\n", "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n" ]
[ "1\n", "3\n", "4\n" ]
In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
500
[ { "input": "3\n1 1", "output": "1" }, { "input": "5\n1 2 2 2", "output": "3" }, { "input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "output": "4" }, { "input": "2\n1", "output": "2" }, { "input": "3\n1 2", "output": "3" }, { "input": "20\n1 1 1 1 1 4 1 2 4 1 2 1 7 1 2 2 9 7 1", "output": "2" }, { "input": "20\n1 2 1 2 2 1 2 4 1 6 2 2 4 3 2 6 2 5 9", "output": "2" }, { "input": "20\n1 1 1 4 2 4 3 1 2 8 3 2 11 13 15 1 12 13 12", "output": "4" }, { "input": "20\n1 2 2 4 3 5 5 6 6 9 11 9 9 12 13 10 15 13 15", "output": "4" }, { "input": "20\n1 2 3 4 5 6 7 8 9 6 11 12 12 7 13 15 16 11 13", "output": "8" }, { "input": "10\n1 1 1 2 1 3 4 2 1", "output": "2" }, { "input": "30\n1 1 1 2 1 2 1 1 2 1 1 1 2 2 4 3 6 2 3 5 3 4 11 5 3 3 4 7 6", "output": "4" }, { "input": "40\n1 1 1 1 1 1 1 1 1 3 4 3 3 1 3 6 7 4 5 2 4 3 9 1 4 2 5 3 5 9 5 9 10 12 3 7 2 11 1", "output": "2" }, { "input": "50\n1 1 1 1 1 2 3 3 2 1 1 2 3 1 3 1 5 6 4 1 1 2 1 2 1 10 17 2 2 4 12 9 6 6 5 13 1 3 2 8 25 3 22 1 10 13 6 3 2", "output": "4" }, { "input": "10\n1 1 1 1 2 1 3 4 3", "output": "2" }, { "input": "30\n1 2 1 1 1 2 1 4 2 3 9 2 3 2 1 1 4 3 12 4 8 8 3 7 9 1 9 19 1", "output": "2" }, { "input": "40\n1 1 1 2 3 1 2 1 3 7 1 3 4 3 2 3 4 1 2 2 4 1 7 4 1 3 2 1 4 5 3 10 14 11 10 13 8 7 4", "output": "2" }, { "input": "50\n1 2 1 1 1 3 1 3 1 5 3 2 7 3 6 6 3 1 4 2 3 10 8 9 1 4 5 2 8 6 12 9 7 5 7 19 3 15 10 4 12 4 19 5 16 5 3 13 5", "output": "2" }, { "input": "10\n1 1 1 2 3 2 1 2 3", "output": "2" }, { "input": "30\n1 1 1 1 2 1 4 4 2 3 2 1 1 1 1 3 1 1 3 2 3 5 1 2 9 16 2 4 3", "output": "2" }, { "input": "40\n1 1 1 2 1 2 1 2 4 8 1 7 1 6 2 8 2 12 4 11 5 5 15 3 12 11 22 11 13 13 24 6 10 15 3 6 7 1 2", "output": "2" }, { "input": "50\n1 1 1 1 3 4 1 2 3 5 1 2 1 5 1 10 4 11 1 8 8 4 4 12 5 3 4 1 1 2 5 13 13 2 2 10 12 3 19 14 1 1 15 3 23 21 12 3 14", "output": "4" }, { "input": "10\n1 1 1 1 2 4 1 1 3", "output": "2" }, { "input": "30\n1 1 1 1 3 3 2 3 7 4 1 2 4 6 2 8 1 2 13 7 5 15 3 3 8 4 4 18 3", "output": "2" }, { "input": "40\n1 1 1 2 2 1 1 4 6 4 7 7 7 4 4 8 10 7 5 1 5 13 7 8 2 11 18 2 1 20 7 3 12 16 2 22 4 22 14", "output": "4" }, { "input": "50\n1 1 1 2 2 1 3 5 3 1 9 4 4 2 12 15 3 13 8 8 4 13 20 17 19 2 4 3 9 5 17 9 17 1 5 7 6 5 20 11 31 33 32 20 6 25 1 2 6", "output": "4" }, { "input": "10\n1 1 1 3 3 5 6 8 3", "output": "4" }, { "input": "30\n1 2 2 1 5 5 5 1 7 4 10 2 4 11 2 3 10 10 7 13 12 4 10 3 22 25 8 1 1", "output": "6" }, { "input": "40\n1 2 2 2 2 4 2 2 6 9 3 9 9 9 3 5 7 7 2 17 4 4 8 8 25 18 12 27 8 19 26 15 33 26 33 9 24 4 27", "output": "4" }, { "input": "50\n1 1 3 3 4 5 5 2 4 3 9 9 1 5 5 7 5 5 16 1 18 3 6 5 6 13 26 12 23 20 17 21 9 17 19 34 12 24 11 9 32 10 40 42 7 40 11 25 3", "output": "6" }, { "input": "10\n1 2 1 2 5 5 6 6 6", "output": "2" }, { "input": "30\n1 1 3 3 5 6 7 5 7 6 5 4 8 6 10 12 14 9 15 20 6 21 14 24 17 23 23 18 8", "output": "2" }, { "input": "40\n1 2 2 3 1 2 5 6 4 8 11 12 9 5 12 7 4 16 16 15 6 22 17 24 10 8 22 4 27 9 19 23 16 18 28 22 5 35 19", "output": "4" }, { "input": "50\n1 2 3 4 5 5 5 7 1 2 11 5 7 11 11 11 15 3 17 10 6 18 14 14 24 11 10 7 17 18 8 7 19 18 31 27 21 30 34 32 27 39 38 22 32 23 31 48 25", "output": "2" }, { "input": "10\n1 2 2 4 5 5 6 4 7", "output": "2" }, { "input": "30\n1 2 3 3 5 6 3 8 9 10 10 10 11 7 8 8 15 16 13 13 19 12 15 18 18 24 27 25 10", "output": "6" }, { "input": "40\n1 2 3 4 5 6 6 8 7 10 11 3 12 11 15 12 17 15 10 20 16 20 12 20 15 21 20 26 29 23 29 30 23 24 35 33 25 32 36", "output": "8" }, { "input": "50\n1 2 2 2 5 6 7 7 9 10 7 4 5 4 15 15 16 17 10 19 18 16 15 24 20 8 27 16 19 24 23 32 17 23 29 18 35 35 38 35 39 41 42 38 19 46 38 28 29", "output": "6" }, { "input": "10\n1 2 3 4 5 5 5 7 9", "output": "8" }, { "input": "30\n1 2 3 4 5 6 5 3 6 7 8 11 12 13 15 15 13 13 19 10 14 10 15 23 21 9 27 22 28", "output": "4" }, { "input": "40\n1 2 2 3 3 6 5 5 9 7 8 11 13 7 10 10 16 14 18 20 11 19 23 18 20 21 25 16 29 25 27 31 26 34 33 23 36 33 32", "output": "6" }, { "input": "50\n1 2 2 4 5 5 7 6 9 10 11 12 13 7 14 15 14 17 10 14 9 21 23 23 19 26 19 25 11 24 22 27 26 34 35 30 37 31 38 32 40 32 42 44 37 21 40 40 48", "output": "10" }, { "input": "10\n1 2 3 4 3 6 6 6 7", "output": "4" }, { "input": "30\n1 2 2 4 5 6 5 7 9 6 4 12 7 14 12 12 15 17 13 12 8 20 21 15 17 24 21 19 16", "output": "4" }, { "input": "40\n1 2 3 4 4 6 6 4 9 9 10 12 10 12 12 16 8 13 18 14 17 20 21 23 25 22 25 26 29 26 27 27 33 31 33 34 36 29 34", "output": "10" }, { "input": "50\n1 2 3 3 4 3 6 7 8 10 11 10 12 11 11 14 13 8 17 20 21 19 15 18 21 18 17 23 25 28 25 27 29 32 32 34 37 29 30 39 41 35 24 41 37 36 41 35 43", "output": "10" }, { "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", "output": "1" }, { "input": "99\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 92 93 94 95 96 97 98", "output": "99" }, { "input": "100\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", "output": "2" }, { "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 92 93 94 95 96 97 98 99", "output": "100" } ]
1,644,592,407
2,147,483,647
Python 3
OK
TESTS
90
156
14,950,400
n=int(input()) a=[*map(int,input().split())] q={} for i in range(1,n+1): q[i]=0 for i in range(n-1): q[i+2]=q[a[i]]+1 z={} for i in q.values(): z[i]=z.get(i,0)+1 print(sum(z[i]%2 for i in z))
Title: Peculiar apple-tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. Input Specification: First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down. Output Specification: Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. Demo Input: ['3\n1 1\n', '5\n1 2 2 2\n', '18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n'] Demo Output: ['1\n', '3\n', '4\n'] Note: In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them. In the second example Arcady will be able to collect 3 apples. First one is one initially situated in first inflorescence. In a second apple from 2nd inflorescence will roll down to 1st (Arcady will collect it) and apples from 3rd, 4th, 5th inflorescences will roll down to 2nd. Two of them will annihilate and one not annihilated will roll down from 2-nd inflorescence to 1st one in the next second and Arcady will collect it.
```python n=int(input()) a=[*map(int,input().split())] q={} for i in range(1,n+1): q[i]=0 for i in range(n-1): q[i+2]=q[a[i]]+1 z={} for i in q.values(): z[i]=z.get(i,0)+1 print(sum(z[i]%2 for i in z)) ```
3
471
A
MUH and Sticks
PROGRAMMING
1,100
[ "implementation" ]
null
null
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
[ "4 2 5 4 4 4\n", "4 4 5 4 4 5\n", "1 2 3 4 5 6\n" ]
[ "Bear", "Elephant", "Alien" ]
If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
500
[ { "input": "4 2 5 4 4 4", "output": "Bear" }, { "input": "4 4 5 4 4 5", "output": "Elephant" }, { "input": "1 2 3 4 5 6", "output": "Alien" }, { "input": "5 5 5 5 5 5", "output": "Elephant" }, { "input": "1 1 1 2 3 5", "output": "Alien" }, { "input": "1 1 1 1 1 1", "output": "Elephant" }, { "input": "9 9 9 9 9 9", "output": "Elephant" }, { "input": "1 8 9 1 1 1", "output": "Bear" }, { "input": "9 9 9 1 9 9", "output": "Bear" }, { "input": "1 2 3 8 9 7", "output": "Alien" }, { "input": "5 5 5 6 6 6", "output": "Alien" }, { "input": "1 1 2 2 3 4", "output": "Alien" }, { "input": "4 4 4 4 4 2", "output": "Bear" }, { "input": "2 2 3 3 4 4", "output": "Alien" }, { "input": "4 4 4 4 4 5", "output": "Bear" }, { "input": "1 1 2 2 2 2", "output": "Elephant" }, { "input": "1 2 5 5 5 5", "output": "Bear" }, { "input": "4 4 2 2 2 2", "output": "Elephant" }, { "input": "1 1 1 1 1 2", "output": "Bear" }, { "input": "2 2 4 4 4 4", "output": "Elephant" }, { "input": "4 4 4 4 4 3", "output": "Bear" }, { "input": "4 4 5 6 7 8", "output": "Alien" }, { "input": "4 4 4 4 2 2", "output": "Elephant" }, { "input": "1 1 1 1 2 2", "output": "Elephant" }, { "input": "1 1 3 3 3 5", "output": "Alien" }, { "input": "1 2 2 3 3 3", "output": "Alien" }, { "input": "1 2 2 2 2 2", "output": "Bear" }, { "input": "1 3 3 3 4 5", "output": "Alien" }, { "input": "5 1 1 1 1 1", "output": "Bear" } ]
1,607,382,446
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
93
307,200
X=input().split() T={} for x in X: T[x] = T.get(x,0) + 1 if len(T) == 1: print("Elephant") exit(0) # find legs: legs=-1 for x in T: if T[x] >= 4: legs=x break if legs == -1: print("Alien") exit(0) if T[legs] == 4 and len(T) == 3: print("Bear") exit(0) if T[legs] == 5 and len(T) == 3: print("Bear") exit print("Elephant")
Title: MUH and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. Input Specification: The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. Output Specification: If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). Demo Input: ['4 2 5 4 4 4\n', '4 4 5 4 4 5\n', '1 2 3 4 5 6\n'] Demo Output: ['Bear', 'Elephant', 'Alien'] Note: If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue.
```python X=input().split() T={} for x in X: T[x] = T.get(x,0) + 1 if len(T) == 1: print("Elephant") exit(0) # find legs: legs=-1 for x in T: if T[x] >= 4: legs=x break if legs == -1: print("Alien") exit(0) if T[legs] == 4 and len(T) == 3: print("Bear") exit(0) if T[legs] == 5 and len(T) == 3: print("Bear") exit print("Elephant") ```
0
441
B
Valera and Fruits
PROGRAMMING
1,400
[ "greedy", "implementation" ]
null
null
Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well?
The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree.
Print a single integer — the maximum number of fruit that Valera can collect.
[ "2 3\n1 5\n2 3\n", "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n" ]
[ "8\n", "60\n" ]
In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
1,000
[ { "input": "2 3\n1 5\n2 3", "output": "8" }, { "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20", "output": "60" }, { "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202", "output": "10596" }, { "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426", "output": "4740" }, { "input": "2 1500\n2 575\n1 2522", "output": "3097" }, { "input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772", "output": "18465" }, { "input": "24 1524\n16 934\n23 1940\n21 1447\n20 417\n24 1340\n22 1932\n13 775\n19 2918\n12 2355\n9 593\n11 2676\n3 1857\n16 868\n13 426\n18 1679\n22 991\n9 2728\n10 2497\n16 1221\n9 772\n23 2522\n24 982\n12 1431\n18 757", "output": "25893" }, { "input": "1 10\n3000 30", "output": "20" }, { "input": "2 1\n30 3\n31 2", "output": "3" }, { "input": "4 2061\n1 426\n3 2522\n1 772\n1 1447", "output": "5167" }, { "input": "2 1\n1 1\n1 1", "output": "2" }, { "input": "1 10\n3000 20", "output": "20" }, { "input": "1 1000\n3000 2000", "output": "2000" }, { "input": "2 100\n3000 100\n3000 100", "output": "200" }, { "input": "2 3\n1 6\n3 6", "output": "12" }, { "input": "1 40\n3000 42", "output": "42" }, { "input": "1 100\n3000 200", "output": "200" }, { "input": "1 50\n3000 100", "output": "100" }, { "input": "1 1\n3000 2", "output": "2" }, { "input": "2 3000\n3000 3000\n3000 3000", "output": "6000" }, { "input": "2 2\n2999 3\n3000 2", "output": "5" }, { "input": "1 2\n3000 3", "output": "3" }, { "input": "2 5\n2999 10\n3000 5", "output": "15" }, { "input": "1 3\n5 3", "output": "3" }, { "input": "2 1000\n2999 2000\n3000 1000", "output": "3000" }, { "input": "1 5\n3000 10", "output": "10" }, { "input": "1 10\n3000 15", "output": "15" }, { "input": "5 1\n10 100\n2698 100\n200 100\n3000 100\n1500 100", "output": "10" }, { "input": "1 1\n3000 3000", "output": "2" }, { "input": "2 10\n2999 100\n3000 100", "output": "30" }, { "input": "1 10\n3000 100", "output": "20" } ]
1,402,243,742
2,342
Python 3
TIME_LIMIT_EXCEEDED
PRETESTS
3
1,000
512,000
from sys import stdin def solve(n, v, ab): result = 0 trees = list(sorted(ab, key=lambda t: t[0])) days = [] for abi in trees: day = abi[0] days.append(day) days.append(day + 1) days = list(set(sorted(days))) debug(days) for d in days: debug('result before day ' + str(i) + ': ' + str(result)) debug('day ' + str(i)) day_limit = v yesterday_trees = filter(lambda t: t[0] + 1 == d, trees) today_trees = filter(lambda t: t[0] == d, trees) for yt in yesterday_trees: fruits_on_tree = yt[1] if day_limit > 0: if fruits_on_tree > 0: cut_fruits = min(day_limit, fruits_on_tree) yt[1] -= cut_fruits day_limit -= cut_fruits result += cut_fruits for tt in today_trees: fruits_on_tree = tt[1] if day_limit > 0: if fruits_on_tree > 0: cut_fruits = min(day_limit, fruits_on_tree) tt[1] -= cut_fruits day_limit -= cut_fruits result += cut_fruits return result def debug(arg): pass # print(arg) if __name__ == '__main__': s = stdin.readline().split(' ') n = int(s[0]) v = int(s[1]) ab = [] for i in range(0, n): str_ab = stdin.readline().split(' ') abi = [int(abij) for abij in str_ab] ab.append(abi) solution = solve(n, v, ab) print(solution)
Title: Valera and Fruits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera loves his garden, where *n* fruit trees grow. This year he will enjoy a great harvest! On the *i*-th tree *b**i* fruit grow, they will ripen on a day number *a**i*. Unfortunately, the fruit on the tree get withered, so they can only be collected on day *a**i* and day *a**i*<=+<=1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than *v* fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? Input Specification: The first line contains two space-separated integers *n* and *v* (1<=≤<=*n*,<=*v*<=≤<=3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next *n* lines contain the description of trees in the garden. The *i*-th line contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=3000) — the day the fruits ripen on the *i*-th tree and the number of fruits on the *i*-th tree. Output Specification: Print a single integer — the maximum number of fruit that Valera can collect. Demo Input: ['2 3\n1 5\n2 3\n', '5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n'] Demo Output: ['8\n', '60\n'] Note: In the first sample, in order to obtain the optimal answer, you should act as follows. - On the first day collect 3 fruits from the 1-st tree. - On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. - On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither.
```python from sys import stdin def solve(n, v, ab): result = 0 trees = list(sorted(ab, key=lambda t: t[0])) days = [] for abi in trees: day = abi[0] days.append(day) days.append(day + 1) days = list(set(sorted(days))) debug(days) for d in days: debug('result before day ' + str(i) + ': ' + str(result)) debug('day ' + str(i)) day_limit = v yesterday_trees = filter(lambda t: t[0] + 1 == d, trees) today_trees = filter(lambda t: t[0] == d, trees) for yt in yesterday_trees: fruits_on_tree = yt[1] if day_limit > 0: if fruits_on_tree > 0: cut_fruits = min(day_limit, fruits_on_tree) yt[1] -= cut_fruits day_limit -= cut_fruits result += cut_fruits for tt in today_trees: fruits_on_tree = tt[1] if day_limit > 0: if fruits_on_tree > 0: cut_fruits = min(day_limit, fruits_on_tree) tt[1] -= cut_fruits day_limit -= cut_fruits result += cut_fruits return result def debug(arg): pass # print(arg) if __name__ == '__main__': s = stdin.readline().split(' ') n = int(s[0]) v = int(s[1]) ab = [] for i in range(0, n): str_ab = stdin.readline().split(' ') abi = [int(abij) for abij in str_ab] ab.append(abi) solution = solve(n, v, ab) print(solution) ```
0
558
E
A Simple Task
PROGRAMMING
2,300
[ "data structures", "sortings", "strings" ]
null
null
This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*<==<=1 or in non-increasing order if *k*<==<=0. Output the final string after applying the queries.
The first line will contain two integers *n*,<=*q* (1<=≤<=*n*<=≤<=105, 0<=≤<=*q*<=≤<=50<=000), the length of the string and the number of queries respectively. Next line contains a string *S* itself. It contains only lowercase English letters. Next *q* lines will contain three integers each *i*,<=*j*,<=*k* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*, ).
Output one line, the string *S* after applying the queries.
[ "10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1\n", "10 1\nagjucbvdfk\n1 10 1\n" ]
[ "cbcaaaabdd", "abcdfgjkuv" ]
First sample test explanation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3ac4e8cc7e335675a4a2b7b4758bfb3865377cea.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a90b5b03cf59288d8861f0142ecbdf6b12f69e5c.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1f482a91a275b6bce07eaed85312eac0cfcc6ccf.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/33b1a4a924f4bd562551ba4e40309f180dbe22e0.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bddc77fd5b02858eb2ff29819cd16a93dbd241e6.png" style="max-width: 100.0%;max-height: 100.0%;"/>
2,500
[ { "input": "10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1", "output": "cbcaaaabdd" }, { "input": "10 1\nagjucbvdfk\n1 10 1", "output": "abcdfgjkuv" }, { "input": "10 6\nrmaahmdmuo\n1 3 1\n4 6 0\n5 6 1\n7 8 0\n8 10 0\n8 9 1", "output": "amrmahmoud" }, { "input": "10 5\nhbtngdflmj\n1 10 1\n2 9 0\n3 8 1\n4 7 0\n5 6 1", "output": "bnflhjgmdt" }, { "input": "13 0\nokaywearedone", "output": "okaywearedone" } ]
1,589,908,976
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
5,000
1,126,400
MAX_CHAR = 26; def desc(str): charCount = [0] * MAX_CHAR; stri = "" for i in range(len(str)): charCount[ord(str[i]) - ord('a')] += 1; for i in range(MAX_CHAR - 1, -1, -1): stri = stri + (chr(97 + i)*charCount[i]); return stri def inc(str): charCount = [0] * MAX_CHAR; stri = "" for i in range(len(str)): charCount[ord(str[i]) - ord('a')] += 1; for i in range(MAX_CHAR): stri = stri + (chr(97 + i) * charCount[i]); return stri def main(): n1, q1 = input().split() n = int(n1) q = int(q1) s = input() while q: i1, j1, k1 = input().split() i = int(i1) j = int(j1) k = int(k1) s1 = s[:i - 1] s2 = s[i - 1:j] s3 = s[j:] if k == 0: s2 = desc(s2) if k == 1: s2 = inc(s2) s = s1 + s2 + s3 q -= 1 print(s) main()
Title: A Simple Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: This task is very simple. Given a string *S* of length *n* and *q* queries each query is on the format *i* *j* *k* which means sort the substring consisting of the characters from *i* to *j* in non-decreasing order if *k*<==<=1 or in non-increasing order if *k*<==<=0. Output the final string after applying the queries. Input Specification: The first line will contain two integers *n*,<=*q* (1<=≤<=*n*<=≤<=105, 0<=≤<=*q*<=≤<=50<=000), the length of the string and the number of queries respectively. Next line contains a string *S* itself. It contains only lowercase English letters. Next *q* lines will contain three integers each *i*,<=*j*,<=*k* (1<=≤<=*i*<=≤<=*j*<=≤<=*n*, ). Output Specification: Output one line, the string *S* after applying the queries. Demo Input: ['10 5\nabacdabcda\n7 10 0\n5 8 1\n1 4 0\n3 6 0\n7 10 1\n', '10 1\nagjucbvdfk\n1 10 1\n'] Demo Output: ['cbcaaaabdd', 'abcdfgjkuv'] Note: First sample test explanation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3ac4e8cc7e335675a4a2b7b4758bfb3865377cea.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a90b5b03cf59288d8861f0142ecbdf6b12f69e5c.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1f482a91a275b6bce07eaed85312eac0cfcc6ccf.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/33b1a4a924f4bd562551ba4e40309f180dbe22e0.png" style="max-width: 100.0%;max-height: 100.0%;"/> <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bddc77fd5b02858eb2ff29819cd16a93dbd241e6.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python MAX_CHAR = 26; def desc(str): charCount = [0] * MAX_CHAR; stri = "" for i in range(len(str)): charCount[ord(str[i]) - ord('a')] += 1; for i in range(MAX_CHAR - 1, -1, -1): stri = stri + (chr(97 + i)*charCount[i]); return stri def inc(str): charCount = [0] * MAX_CHAR; stri = "" for i in range(len(str)): charCount[ord(str[i]) - ord('a')] += 1; for i in range(MAX_CHAR): stri = stri + (chr(97 + i) * charCount[i]); return stri def main(): n1, q1 = input().split() n = int(n1) q = int(q1) s = input() while q: i1, j1, k1 = input().split() i = int(i1) j = int(j1) k = int(k1) s1 = s[:i - 1] s2 = s[i - 1:j] s3 = s[j:] if k == 0: s2 = desc(s2) if k == 1: s2 = inc(s2) s = s1 + s2 + s3 q -= 1 print(s) main() ```
0
58
A
Chat room
PROGRAMMING
1,000
[ "greedy", "strings" ]
A. Chat room
1
256
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, if Vasya types the word "ahhellllloou", it will be considered that he said hello, and if he types "hlelo", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word *s*.
The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.
If Vasya managed to say hello, print "YES", otherwise print "NO".
[ "ahhellllloou\n", "hlelo\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "ahhellllloou", "output": "YES" }, { "input": "hlelo", "output": "NO" }, { "input": "helhcludoo", "output": "YES" }, { "input": "hehwelloho", "output": "YES" }, { "input": "pnnepelqomhhheollvlo", "output": "YES" }, { "input": "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,610,403,135
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
77
0
if __name__ == '__main__': n = input() state = 0 for i in range(len(n)): if state == 0 and n[i] == 'h': state = 1 continue if state == 1 and n[i] == 'e' and n[i - 1] == 'h': state = 2 continue elif state == 1 and n[i] != 'e' and n[i - 1] == 'h' and n[i] != 'h': break if state == 2 and n[i] == 'l' and n[i - 1] == 'e': state = 3 continue elif state == 2 and n[i] != 'l' and n[i - 1] == 'e' and n[i] != 'e': break if state == 3 and n[i] == 'l' and n[i - 1] == 'l': state = 4 continue elif state == 3 and n[i] != 'l' and n[i - 1] == 'l': break if state == 4 and n[i] == 'o' and n[i - 1] == 'l': state = 5 break elif state == 4 and n[i] != 'o' and n[i - 1] == 'l' and n[i] != 'l': break if state == 5: print('YES') else: print('NO')
Title: Chat room Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several 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 if __name__ == '__main__': n = input() state = 0 for i in range(len(n)): if state == 0 and n[i] == 'h': state = 1 continue if state == 1 and n[i] == 'e' and n[i - 1] == 'h': state = 2 continue elif state == 1 and n[i] != 'e' and n[i - 1] == 'h' and n[i] != 'h': break if state == 2 and n[i] == 'l' and n[i - 1] == 'e': state = 3 continue elif state == 2 and n[i] != 'l' and n[i - 1] == 'e' and n[i] != 'e': break if state == 3 and n[i] == 'l' and n[i - 1] == 'l': state = 4 continue elif state == 3 and n[i] != 'l' and n[i - 1] == 'l': break if state == 4 and n[i] == 'o' and n[i - 1] == 'l': state = 5 break elif state == 4 and n[i] != 'o' and n[i - 1] == 'l' and n[i] != 'l': break if state == 5: print('YES') else: print('NO') ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "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,664,612,937
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
def flagstones(m,n,a): flags=0 if (m%a)==0: flags+=(m//a) elif (m%a)!=0: flags+=((m//a)+1) if (n%a)==0: flags*=(n//a) elif (n%a)==0: flags*=((n//a)+1) return flags theatre = input().split() m = int(theatre[0]) n = int(theatre[1]) a = int(theatre[2]) print(flagstones(m,n,a))
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 def flagstones(m,n,a): flags=0 if (m%a)==0: flags+=(m//a) elif (m%a)!=0: flags+=((m//a)+1) if (n%a)==0: flags*=(n//a) elif (n%a)==0: flags*=((n//a)+1) return flags theatre = input().split() m = int(theatre[0]) n = int(theatre[1]) a = int(theatre[2]) print(flagstones(m,n,a)) ```
0
0
none
none
none
0
[ "none" ]
null
null
The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that one could any point of any country can be reached from any point of any other State. Since roads are always expensive, the governments of the states of the newly formed alliance asked you to help them assess the costs. To do this, you have been issued a map that can be represented as a rectangle table consisting of *n* rows and *m* columns. Any cell of the map either belongs to one of three states, or is an area where it is allowed to build a road, or is an area where the construction of the road is not allowed. A cell is called passable, if it belongs to one of the states, or the road was built in this cell. From any passable cells you can move up, down, right and left, if the cell that corresponds to the movement exists and is passable. Your task is to construct a road inside a minimum number of cells, so that it would be possible to get from any cell of any state to any cell of any other state using only passable cells. It is guaranteed that initially it is possible to reach any cell of any state from any cell of this state, moving only along its cells. It is also guaranteed that for any state there is at least one cell that belongs to it.
The first line of the input contains the dimensions of the map *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns respectively. Each of the next *n* lines contain *m* characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to the cell where it is allowed to build a road and the character '#' means no construction is allowed in this cell.
Print a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1.
[ "4 5\n11..2\n#..22\n#.323\n.#333", "1 5\n1#2#3\n" ]
[ "2", "-1\n" ]
none
0
[]
1,445,883,605
5,105
Python 3
WRONG_ANSWER
TESTS
4
2,355
21,913,600
from collections import deque infin = float('inf') second = float('inf') third = float('inf') n, m = map(int, input().split()) visit = [[0 for i in range(m)] for j in range(n)] maps = [] queue = deque() for i in range(n): maps.append(input()) for j in range(len(maps[i])): if maps[i][j] in '1': queue.append((i, j)) visit[i][j] = 1 def bfs(err): global second, third while queue: x, y = queue.popleft() if maps[x][y] == '2' and second > visit[x][y]: second = visit[x][y] if maps[x][y] == '3' and third > visit[x][y]: third = visit[x][y] if x + 1 < n and not visit[x + 1][y] and maps[x + 1][y] in '123.': if maps[x + 1][y] == '.': visit[x + 1][y] = visit[x][y] + 1 queue.append((x + 1, y)) else: queue.appendleft((x + 1, y)) visit[x + 1][y] = visit[x][y] if x and not visit[x - 1][y] and maps[x - 1][y] in '123.': if maps[x - 1][y] == '.': queue.append((x - 1, y)) visit[x - 1][y] = visit[x][y] + 1 else: queue.appendleft((x - 1, y)) visit[x - 1][y] = visit[x][y] if y + 1 < m and not visit[x][y + 1] and maps[x][y + 1] in '123.': if maps[x][y + 1] == '.': queue.append((x, y + 1)) visit[x][y + 1] = visit[x][y] + 1 else: queue.appendleft((x, y + 1)) visit[x][y + 1] = visit[x][y] if y and not visit[x][y - 1] and maps[x][y - 1] in '123.': if maps[x][y - 1] == '.': queue.append((x, y - 1)) visit[x][y - 1] = visit[x][y] + 1 else: queue.appendleft((x, y - 1)) visit[x][y - 1] = visit[x][y] bfs(0) if second == infin or third == infin: print('-1') else: print(max(second, third) - 1)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was decided that a road between the states should be built to guarantee so that one could any point of any country can be reached from any point of any other State. Since roads are always expensive, the governments of the states of the newly formed alliance asked you to help them assess the costs. To do this, you have been issued a map that can be represented as a rectangle table consisting of *n* rows and *m* columns. Any cell of the map either belongs to one of three states, or is an area where it is allowed to build a road, or is an area where the construction of the road is not allowed. A cell is called passable, if it belongs to one of the states, or the road was built in this cell. From any passable cells you can move up, down, right and left, if the cell that corresponds to the movement exists and is passable. Your task is to construct a road inside a minimum number of cells, so that it would be possible to get from any cell of any state to any cell of any other state using only passable cells. It is guaranteed that initially it is possible to reach any cell of any state from any cell of this state, moving only along its cells. It is also guaranteed that for any state there is at least one cell that belongs to it. Input Specification: The first line of the input contains the dimensions of the map *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns respectively. Each of the next *n* lines contain *m* characters, describing the rows of the map. Digits from 1 to 3 represent the accessory to the corresponding state. The character '.' corresponds to the cell where it is allowed to build a road and the character '#' means no construction is allowed in this cell. Output Specification: Print a single integer — the minimum number of cells you need to build a road inside in order to connect all the cells of all states. If such a goal is unachievable, print -1. Demo Input: ['4 5\n11..2\n#..22\n#.323\n.#333', '1 5\n1#2#3\n'] Demo Output: ['2', '-1\n'] Note: none
```python from collections import deque infin = float('inf') second = float('inf') third = float('inf') n, m = map(int, input().split()) visit = [[0 for i in range(m)] for j in range(n)] maps = [] queue = deque() for i in range(n): maps.append(input()) for j in range(len(maps[i])): if maps[i][j] in '1': queue.append((i, j)) visit[i][j] = 1 def bfs(err): global second, third while queue: x, y = queue.popleft() if maps[x][y] == '2' and second > visit[x][y]: second = visit[x][y] if maps[x][y] == '3' and third > visit[x][y]: third = visit[x][y] if x + 1 < n and not visit[x + 1][y] and maps[x + 1][y] in '123.': if maps[x + 1][y] == '.': visit[x + 1][y] = visit[x][y] + 1 queue.append((x + 1, y)) else: queue.appendleft((x + 1, y)) visit[x + 1][y] = visit[x][y] if x and not visit[x - 1][y] and maps[x - 1][y] in '123.': if maps[x - 1][y] == '.': queue.append((x - 1, y)) visit[x - 1][y] = visit[x][y] + 1 else: queue.appendleft((x - 1, y)) visit[x - 1][y] = visit[x][y] if y + 1 < m and not visit[x][y + 1] and maps[x][y + 1] in '123.': if maps[x][y + 1] == '.': queue.append((x, y + 1)) visit[x][y + 1] = visit[x][y] + 1 else: queue.appendleft((x, y + 1)) visit[x][y + 1] = visit[x][y] if y and not visit[x][y - 1] and maps[x][y - 1] in '123.': if maps[x][y - 1] == '.': queue.append((x, y - 1)) visit[x][y - 1] = visit[x][y] + 1 else: queue.appendleft((x, y - 1)) visit[x][y - 1] = visit[x][y] bfs(0) if second == infin or third == infin: print('-1') else: print(max(second, third) - 1) ```
0
189
A
Cut Ribbon
PROGRAMMING
1,300
[ "brute force", "dp" ]
null
null
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.
The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide.
Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.
[ "5 5 3 2\n", "7 5 5 2\n" ]
[ "2\n", "2\n" ]
In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
500
[ { "input": "5 5 3 2", "output": "2" }, { "input": "7 5 5 2", "output": "2" }, { "input": "4 4 4 4", "output": "1" }, { "input": "1 1 1 1", "output": "1" }, { "input": "4000 1 2 3", "output": "4000" }, { "input": "4000 3 4 5", "output": "1333" }, { "input": "10 3 4 5", "output": "3" }, { "input": "100 23 15 50", "output": "2" }, { "input": "3119 3515 1021 7", "output": "11" }, { "input": "918 102 1327 1733", "output": "9" }, { "input": "3164 42 430 1309", "output": "15" }, { "input": "3043 317 1141 2438", "output": "7" }, { "input": "26 1 772 2683", "output": "26" }, { "input": "370 2 1 15", "output": "370" }, { "input": "734 12 6 2", "output": "367" }, { "input": "418 18 14 17", "output": "29" }, { "input": "18 16 28 9", "output": "2" }, { "input": "14 6 2 17", "output": "7" }, { "input": "29 27 18 2", "output": "2" }, { "input": "29 12 7 10", "output": "3" }, { "input": "27 23 4 3", "output": "9" }, { "input": "5 14 5 2", "output": "1" }, { "input": "5 17 26 5", "output": "1" }, { "input": "9 1 10 3", "output": "9" }, { "input": "2 19 15 1", "output": "2" }, { "input": "4 6 4 9", "output": "1" }, { "input": "10 6 2 9", "output": "5" }, { "input": "2 2 9 6", "output": "1" }, { "input": "6 2 4 1", "output": "6" }, { "input": "27 24 5 27", "output": "1" }, { "input": "2683 83 26 2709", "output": "101" }, { "input": "728 412 789 158", "output": "3" }, { "input": "3964 4 2916 176", "output": "991" }, { "input": "3399 2035 2 3334", "output": "683" }, { "input": "3455 244 3301 3", "output": "991" }, { "input": "595 2263 3625 1", "output": "595" }, { "input": "4000 1 1 1", "output": "4000" }, { "input": "3999 2 2 3999", "output": "1" }, { "input": "25 6 8 11", "output": "3" }, { "input": "4000 500 1000 2000", "output": "8" }, { "input": "53 10 11 23", "output": "5" }, { "input": "100 100 1 1", "output": "100" }, { "input": "17 3 4 10", "output": "5" }, { "input": "413 101 102 105", "output": "4" }, { "input": "490 4 49 50", "output": "111" }, { "input": "3999 2 3 3", "output": "1999" }, { "input": "8 3 8 4", "output": "2" }, { "input": "5 1 3 3", "output": "5" }, { "input": "100 3 17 22", "output": "27" }, { "input": "4000 2 3 4", "output": "2000" }, { "input": "4000 3 3 5", "output": "1332" }, { "input": "13 4 6 7", "output": "2" }, { "input": "4000 5 2 2", "output": "2000" }, { "input": "3999 2 2 3", "output": "1999" }, { "input": "4000 33 7 3333", "output": "564" }, { "input": "60 33 20 9", "output": "4" }, { "input": "100 9 11 99", "output": "10" }, { "input": "2009 6 8 9", "output": "334" } ]
1,679,482,708
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
46
0
n, a, b, c = map(int, input().split()) lArr = [a, b, c] lArr.sort() possArr = [] for i in lArr: if i > n: continue l = n possCount = 1 if i == l: possArr.append(1) while l > i: l -= i possCount += 1 if l == a or l == b or l == c or l % a == 0 or l % b == 0 or l % c == 0: possArr.append(possCount) possArr.sort() print(possArr[-1])
Title: Cut Ribbon Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting. Input Specification: The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. Output Specification: Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. Demo Input: ['5 5 3 2\n', '7 5 5 2\n'] Demo Output: ['2\n', '2\n'] Note: In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3. In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2.
```python n, a, b, c = map(int, input().split()) lArr = [a, b, c] lArr.sort() possArr = [] for i in lArr: if i > n: continue l = n possCount = 1 if i == l: possArr.append(1) while l > i: l -= i possCount += 1 if l == a or l == b or l == c or l % a == 0 or l % b == 0 or l % c == 0: possArr.append(possCount) possArr.sort() print(possArr[-1]) ```
0
515
C
Drazil and Factorial
PROGRAMMING
1,400
[ "greedy", "math", "sortings" ]
null
null
Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes.
Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.
[ "4\n1234\n", "3\n555\n" ]
[ "33222\n", "555\n" ]
In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "4\n1234", "output": "33222" }, { "input": "3\n555", "output": "555" }, { "input": "15\n012345781234578", "output": "7777553333222222222222" }, { "input": "1\n8", "output": "7222" }, { "input": "10\n1413472614", "output": "75333332222222" }, { "input": "8\n68931246", "output": "77553333332222222" }, { "input": "7\n4424368", "output": "75333332222222222" }, { "input": "6\n576825", "output": "7755532222" }, { "input": "5\n97715", "output": "7775332" }, { "input": "3\n915", "output": "75332" }, { "input": "2\n26", "output": "532" }, { "input": "1\n4", "output": "322" }, { "input": "15\n028745260720699", "output": "7777755533333332222222222" }, { "input": "13\n5761790121605", "output": "7775555333322" }, { "input": "10\n3312667105", "output": "755533332" }, { "input": "1\n7", "output": "7" }, { "input": "15\n989898989898989", "output": "777777777777777333333333333333322222222222222222222222222222" }, { "input": "15\n000000000000007", "output": "7" }, { "input": "15\n999999999999990", "output": "77777777777777333333333333333333333333333322222222222222" }, { "input": "1\n2", "output": "2" }, { "input": "1\n3", "output": "3" }, { "input": "1\n4", "output": "322" }, { "input": "1\n5", "output": "5" }, { "input": "1\n6", "output": "53" }, { "input": "1\n7", "output": "7" }, { "input": "1\n9", "output": "7332" }, { "input": "2\n09", "output": "7332" }, { "input": "13\n1337251172966", "output": "777555333333222" }, { "input": "15\n987654329876543", "output": "777777555533333333332222222222222" }, { "input": "9\n234567899", "output": "777755333333322222222" }, { "input": "2\n99", "output": "77333322" }, { "input": "2\n66", "output": "5533" }, { "input": "3\n999", "output": "777333333222" }, { "input": "5\n99999", "output": "77777333333333322222" }, { "input": "9\n123456789", "output": "77755333332222222" }, { "input": "9\n987654321", "output": "77755333332222222" }, { "input": "3\n666", "output": "555333" }, { "input": "2\n26", "output": "532" }, { "input": "6\n555777", "output": "777555" }, { "input": "10\n1234567899", "output": "777755333333322222222" }, { "input": "4\n6666", "output": "55553333" }, { "input": "4\n9754", "output": "775333222" }, { "input": "2\n95", "output": "75332" }, { "input": "14\n11122233344455", "output": "55333333222222222" }, { "input": "12\n836544897832", "output": "77777553333333222222222222222" } ]
1,625,917,931
2,147,483,647
PyPy 3
OK
TESTS
45
109
0
l=[""," ","2","3","322","5","53","7","7222","7332"] s="" n=int(input()) k=input() for i in range(n): s=s+l[int(k[i])] s=list(s) s.sort(reverse=True) print(*s,sep="")
Title: Drazil and Factorial Time Limit: None seconds Memory Limit: None megabytes Problem Description: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. Output Specification: Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. Demo Input: ['4\n1234\n', '3\n555\n'] Demo Output: ['33222\n', '555\n'] Note: In the first case, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/f5a4207f23215fddce977ab5ea9e9d2e7578fb52.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python l=[""," ","2","3","322","5","53","7","7222","7332"] s="" n=int(input()) k=input() for i in range(n): s=s+l[int(k[i])] s=list(s) s.sort(reverse=True) print(*s,sep="") ```
3
761
D
Dasha and Very Difficult Problem
PROGRAMMING
1,700
[ "binary search", "brute force", "constructive algorithms", "greedy", "sortings" ]
null
null
Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*. About sequences *a* and *b* we know that their elements are in the range from *l* to *r*. More formally, elements satisfy the following conditions: *l*<=≤<=*a**i*<=≤<=*r* and *l*<=≤<=*b**i*<=≤<=*r*. About sequence *c* we know that all its elements are distinct. Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence *a* and the compressed sequence of the sequence *c* were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence *c* of length *n* is a sequence *p* of length *n*, so that *p**i* equals to the number of integers which are less than or equal to *c**i* in the sequence *c*. For example, for the sequence *c*<==<=[250,<=200,<=300,<=100,<=50] the compressed sequence will be *p*<==<=[4,<=3,<=5,<=2,<=1]. Pay attention that in *c* all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to *n* inclusively. Help Dasha to find any sequence *b* for which the calculated compressed sequence of sequence *c* is correct.
The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*l*<=≤<=*r*<=≤<=109) — the length of the sequence and boundaries of the segment where the elements of sequences *a* and *b* are. The next line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (*l*<=≤<=*a**i*<=≤<=*r*) — the elements of the sequence *a*. The next line contains *n* distinct integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the compressed sequence of the sequence *c*.
If there is no the suitable sequence *b*, then in the only line print "-1". Otherwise, in the only line print *n* integers — the elements of any suitable sequence *b*.
[ "5 1 5\n1 1 1 1 1\n3 1 5 4 2\n", "4 2 9\n3 4 8 9\n3 2 1 4\n", "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6\n" ]
[ "3 1 5 4 2 ", "2 2 2 9 ", "-1\n" ]
Sequence *b* which was found in the second sample is suitable, because calculated sequence *c* = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that *c*<sub class="lower-index">*i*</sub> = *b*<sub class="lower-index">*i*</sub> - *a*<sub class="lower-index">*i*</sub>) has compressed sequence equals to *p* = [3, 2, 1, 4].
2,000
[ { "input": "5 1 5\n1 1 1 1 1\n3 1 5 4 2", "output": "3 1 5 4 2 " }, { "input": "4 2 9\n3 4 8 9\n3 2 1 4", "output": "2 2 2 9 " }, { "input": "6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6", "output": "-1" }, { "input": "5 1 7\n1 4 4 6 5\n5 2 1 4 3", "output": "2 2 1 6 4 " }, { "input": "5 10 100\n12 14 15 11 13\n4 2 1 5 3", "output": "10 10 10 10 10 " }, { "input": "2 1 1000000000\n1000000000 1\n2 1", "output": "-1" }, { "input": "2 1 1000000000\n1000000000 1\n1 2", "output": "1 1 " }, { "input": "5 1 5\n1 1 1 1 1\n1 2 3 4 5", "output": "1 2 3 4 5 " }, { "input": "5 1 5\n1 1 1 1 1\n2 3 1 5 4", "output": "2 3 1 5 4 " }, { "input": "1 1000000000 1000000000\n1000000000\n1", "output": "1000000000 " }, { "input": "6 3 7\n6 7 5 5 5 5\n2 1 4 3 5 6", "output": "3 3 4 3 5 6 " }, { "input": "3 5 100\n10 50 100\n3 2 1", "output": "5 5 5 " }, { "input": "10 1 10\n9 2 9 5 5 2 6 8 2 8\n2 10 1 6 7 8 5 3 9 4", "output": "2 3 1 2 3 1 2 2 2 3 " }, { "input": "30 100 200\n102 108 122 116 107 145 195 145 119 110 187 196 140 174 104 190 193 181 118 127 157 111 139 175 173 191 181 105 142 166\n30 26 20 23 27 15 2 14 21 25 6 1 17 10 29 5 3 7 22 19 13 24 18 9 11 4 8 28 16 12", "output": "100 100 100 100 100 101 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 101 100 100 100 " }, { "input": "50 10 15\n13 14 12 14 12 15 13 10 11 11 15 10 14 11 14 12 11 10 10 13 11 13 12 15 14 15 13 15 13 10 12 10 15 15 10 14 11 11 10 14 11 12 13 12 10 11 13 15 14 11\n20 10 25 13 29 6 24 47 37 39 2 44 12 33 9 26 35 49 46 19 38 23 30 5 16 4 21 7 18 45 28 43 1 8 48 15 36 40 50 11 32 27 22 31 42 41 17 3 14 34", "output": "-1" }, { "input": "10 8 10\n8 10 10 9 8 10 10 10 10 10\n9 5 6 8 10 2 7 3 1 4", "output": "-1" }, { "input": "50 1 50\n6 20 27 26 46 35 41 41 4 12 48 13 20 5 35 7 37 3 18 17 22 42 28 1 30 46 38 38 42 29 33 42 8 45 22 40 11 33 12 15 16 49 30 19 29 40 5 12 32 22\n47 27 35 40 31 26 42 19 11 49 37 3 41 34 36 30 16 44 12 4 46 20 14 39 32 25 18 1 21 6 2 17 48 7 5 24 29 33 50 43 8 15 28 23 22 13 45 38 10 9", "output": "-1" }, { "input": "11 5 11\n9 8 7 5 7 5 9 5 10 5 7\n3 4 6 9 5 11 2 10 1 8 7", "output": "6 6 7 8 6 10 5 9 5 7 8 " } ]
1,604,150,401
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
93
204,800
n, l, f = map(int, input().split()) a = [int(x) for x in input().split()] c = [int(x) for x in input().split()] b = [] for i in range(n): b.append(a[i]+c[i]) m = max(b) if m > f: diff = m-f for i in range(n): b[i] -= diff else: diff = f-m for i in range(n): b[i] += diff if min(b) < l or max(b) > l: print(-1) exit(0) for i in range(n): if i == n-1: print(b[i]) else: print(b[i], end=' ')
Title: Dasha and Very Difficult Problem Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dasha logged into the system and began to solve problems. One of them is as follows: Given two sequences *a* and *b* of length *n* each you need to write a sequence *c* of length *n*, the *i*-th element of which is calculated as follows: *c**i*<==<=*b**i*<=-<=*a**i*. About sequences *a* and *b* we know that their elements are in the range from *l* to *r*. More formally, elements satisfy the following conditions: *l*<=≤<=*a**i*<=≤<=*r* and *l*<=≤<=*b**i*<=≤<=*r*. About sequence *c* we know that all its elements are distinct. Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence *a* and the compressed sequence of the sequence *c* were known from that test. Let's give the definition to a compressed sequence. A compressed sequence of sequence *c* of length *n* is a sequence *p* of length *n*, so that *p**i* equals to the number of integers which are less than or equal to *c**i* in the sequence *c*. For example, for the sequence *c*<==<=[250,<=200,<=300,<=100,<=50] the compressed sequence will be *p*<==<=[4,<=3,<=5,<=2,<=1]. Pay attention that in *c* all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to *n* inclusively. Help Dasha to find any sequence *b* for which the calculated compressed sequence of sequence *c* is correct. Input Specification: The first line contains three integers *n*, *l*, *r* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*l*<=≤<=*r*<=≤<=109) — the length of the sequence and boundaries of the segment where the elements of sequences *a* and *b* are. The next line contains *n* integers *a*1,<=<=*a*2,<=<=...,<=<=*a**n* (*l*<=≤<=*a**i*<=≤<=*r*) — the elements of the sequence *a*. The next line contains *n* distinct integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n* (1<=≤<=*p**i*<=≤<=*n*) — the compressed sequence of the sequence *c*. Output Specification: If there is no the suitable sequence *b*, then in the only line print "-1". Otherwise, in the only line print *n* integers — the elements of any suitable sequence *b*. Demo Input: ['5 1 5\n1 1 1 1 1\n3 1 5 4 2\n', '4 2 9\n3 4 8 9\n3 2 1 4\n', '6 1 5\n1 1 1 1 1 1\n2 3 5 4 1 6\n'] Demo Output: ['3 1 5 4 2 ', '2 2 2 9 ', '-1\n'] Note: Sequence *b* which was found in the second sample is suitable, because calculated sequence *c* = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that *c*<sub class="lower-index">*i*</sub> = *b*<sub class="lower-index">*i*</sub> - *a*<sub class="lower-index">*i*</sub>) has compressed sequence equals to *p* = [3, 2, 1, 4].
```python n, l, f = map(int, input().split()) a = [int(x) for x in input().split()] c = [int(x) for x in input().split()] b = [] for i in range(n): b.append(a[i]+c[i]) m = max(b) if m > f: diff = m-f for i in range(n): b[i] -= diff else: diff = f-m for i in range(n): b[i] += diff if min(b) < l or max(b) > l: print(-1) exit(0) for i in range(n): if i == n-1: print(b[i]) else: print(b[i], end=' ') ```
0
877
A
Alex and broken contest
PROGRAMMING
1,100
[ "implementation", "strings" ]
null
null
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
[ "Alex_and_broken_contest\n", "NikitaAndString\n", "Danil_and_Olya\n" ]
[ "NO", "YES", "NO" ]
none
500
[ { "input": "Alex_and_broken_contest", "output": "NO" }, { "input": "NikitaAndString", "output": "YES" }, { "input": "Danil_and_Olya", "output": "NO" }, { "input": "Slava____and_the_game", "output": "YES" }, { "input": "Olya_and_energy_drinks", "output": "YES" }, { "input": "Danil_and_part_time_job", "output": "YES" }, { "input": "Ann_and_books", "output": "YES" }, { "input": "Olya", "output": "YES" }, { "input": "Nikita", "output": "YES" }, { "input": "Slava", "output": "YES" }, { "input": "Vanya", "output": "NO" }, { "input": "I_dont_know_what_to_write_here", "output": "NO" }, { "input": "danil_and_work", "output": "NO" }, { "input": "Ann", "output": "YES" }, { "input": "Batman_Nananananananan_Batman", "output": "NO" }, { "input": "Olya_Nikita_Ann_Slava_Danil", "output": "NO" }, { "input": "its_me_Mario", "output": "NO" }, { "input": "A", "output": "NO" }, { "input": "Wake_up_Neo", "output": "NO" }, { "input": "Hardest_problem_ever", "output": "NO" }, { "input": "Nikita_Nikita", "output": "NO" }, { "input": "____________________________________________________________________________________________________", "output": "NO" }, { "input": "Nikitb", "output": "NO" }, { "input": "Unn", "output": "NO" }, { "input": "oLya_adn_smth", "output": "NO" }, { "input": "FloorISLava", "output": "NO" }, { "input": "ann", "output": "NO" }, { "input": "aa", "output": "NO" }, { "input": "AAnnnnn", "output": "YES" }, { "input": "AnnAnn", "output": "NO" }, { "input": "Annn", "output": "YES" }, { "input": "Dilzhan", "output": "NO" }, { "input": "Danilaaa", "output": "YES" }, { "input": "AndAnn", "output": "YES" }, { "input": "OlyaAnnAnn", "output": "NO" }, { "input": "DanilDanilOlya", "output": "NO" }, { "input": "DDanil", "output": "YES" }, { "input": "AnnAnnDanil", "output": "NO" }, { "input": "And_Danil", "output": "YES" }, { "input": "abcddddDanil", "output": "YES" }, { "input": "DanilOlyaOlya", "output": "NO" }, { "input": "Nikitaaa", "output": "YES" }, { "input": "aaabbba", "output": "NO" }, { "input": "Ann_Ann_Danil", "output": "NO" }, { "input": "Danil_Danil_Nikita", "output": "NO" }, { "input": "AlexaaaaaaBBBBBOlyaDDDDD", "output": "YES" }, { "input": "IloveDaniland", "output": "YES" }, { "input": "AnAnn", "output": "YES" }, { "input": "Danil_Danil_Olya", "output": "NO" }, { "input": "DanilDanilSlava", "output": "NO" }, { "input": "DanilDanil", "output": "NO" }, { "input": "OlyOlya", "output": "YES" }, { "input": "NikitaNikitb", "output": "YES" }, { "input": "ababaca", "output": "NO" }, { "input": "AnnNikitaNikitaNikitaNikita__good_luck", "output": "NO" } ]
1,564,142,476
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
124
0
s=input() c=0 if "Danil" in s: c+=1 if "Olya" in s: c+=1 if "Slava" in s: c+=1 if "Ann" in s: c+=1 if "Nikita" in s : c+=1 if c==1: print('YES') else: print('NO')
Title: Alex and broken contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. Input Specification: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. Output Specification: Print "YES", if problem is from this contest, and "NO" otherwise. Demo Input: ['Alex_and_broken_contest\n', 'NikitaAndString\n', 'Danil_and_Olya\n'] Demo Output: ['NO', 'YES', 'NO'] Note: none
```python s=input() c=0 if "Danil" in s: c+=1 if "Olya" in s: c+=1 if "Slava" in s: c+=1 if "Ann" in s: c+=1 if "Nikita" in s : c+=1 if c==1: print('YES') else: print('NO') ```
0
667
A
Pouring Rain
PROGRAMMING
1,100
[ "geometry", "math" ]
null
null
A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter.
The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup.
If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104.
[ "1 2 3 100\n", "1 1 1 1\n" ]
[ "NO\n", "YES\n3.659792366325\n" ]
In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
500
[ { "input": "1 2 3 100", "output": "NO" }, { "input": "1 1 1 1", "output": "YES\n3.659792366325" }, { "input": "48 7946 7992 72", "output": "NO" }, { "input": "72 6791 8546 46", "output": "NO" }, { "input": "100 5635 9099 23", "output": "NO" }, { "input": "20 287 3845 5", "output": "YES\n39.646277165210" }, { "input": "48 6428 9807 83", "output": "NO" }, { "input": "72 5272 4552 64", "output": "NO" }, { "input": "100 4117 5106 34", "output": "NO" }, { "input": "20 2961 9852 15", "output": "YES\n180.991437129723" }, { "input": "48 1805 3109 93", "output": "NO" }, { "input": "72 8534 7042 65", "output": "NO" }, { "input": "1 47 80 68", "output": "YES\n1.388102806810" }, { "input": "4 495 8813 1", "output": "YES\n0.706823517575" }, { "input": "5 2797 5925 9", "output": "YES\n9.553973511669" }, { "input": "1 8324 4362 23", "output": "YES\n1.505007106354" }, { "input": "6 1976 8455 3", "output": "YES\n6.674898722265" }, { "input": "7 2644 8080 5", "output": "YES\n12.900417790197" }, { "input": "3 4183 5491 98", "output": "YES\n6.162185601824" }, { "input": "2 8591 320 101", "output": "YES\n9999.259991757254" }, { "input": "10000 10000 10000 10000", "output": "NO" }, { "input": "2 5000 12 3", "output": "YES\n6099.653943875812" }, { "input": "10 1000 100 1", "output": "YES\n3659.792366325487" } ]
1,461,953,619
5,919
Python 3
OK
TESTS
23
62
4,608,000
import math (d,h,v,e) = tuple([int(p) for p in input().strip('\n').split(' ')]) increaseByRain = math.pi * (d/2) * (d/2) * e totalRate = v - increaseByRain if totalRate <= 0: print('NO') else: print('YES') currentVol = math.pi * (d/2) * (d/2) * h print(str(currentVol/totalRate))
Title: Pouring Rain Time Limit: None seconds Memory Limit: None megabytes Problem Description: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter. Input Specification: The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. Output Specification: If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. Demo Input: ['1 2 3 100\n', '1 1 1 1\n'] Demo Output: ['NO\n', 'YES\n3.659792366325\n'] Note: In the first example the water fills the cup faster than you can drink from it. In the second example area of the cup's bottom equals to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/419dc74dcd7bc392019c9fe748fe1fdb08ab521a.png" style="max-width: 100.0%;max-height: 100.0%;"/>, thus we can conclude that you decrease the level of water by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/e8edb237e1f805fe83c2f47e48d3a9d03f2ee304.png" style="max-width: 100.0%;max-height: 100.0%;"/> centimeters per second. At the same time water level increases by 1 centimeter per second due to rain. Thus, cup will be empty in <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9dae615d7e2c5c7c03cb478848fb06aba1a8942e.png" style="max-width: 100.0%;max-height: 100.0%;"/> seconds.
```python import math (d,h,v,e) = tuple([int(p) for p in input().strip('\n').split(' ')]) increaseByRain = math.pi * (d/2) * (d/2) * e totalRate = v - increaseByRain if totalRate <= 0: print('NO') else: print('YES') currentVol = math.pi * (d/2) * (d/2) * h print(str(currentVol/totalRate)) ```
3
946
A
Partition
PROGRAMMING
800
[ "greedy" ]
null
null
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*.
Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*.
[ "3\n1 -2 0\n", "6\n16 23 16 15 42 8\n" ]
[ "3\n", "120\n" ]
In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
0
[ { "input": "3\n1 -2 0", "output": "3" }, { "input": "6\n16 23 16 15 42 8", "output": "120" }, { "input": "1\n-1", "output": "1" }, { "input": "100\n-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 -100", "output": "10000" }, { "input": "2\n-1 5", "output": "6" }, { "input": "3\n-2 0 1", "output": "3" }, { "input": "12\n-1 -2 -3 4 4 -6 -6 56 3 3 -3 3", "output": "94" }, { "input": "4\n1 -1 1 -1", "output": "4" }, { "input": "4\n100 -100 100 -100", "output": "400" }, { "input": "3\n-2 -5 10", "output": "17" }, { "input": "5\n1 -2 3 -4 5", "output": "15" }, { "input": "3\n-100 100 -100", "output": "300" }, { "input": "6\n1 -1 1 -1 1 -1", "output": "6" }, { "input": "6\n2 -2 2 -2 2 -2", "output": "12" }, { "input": "9\n12 93 -2 0 0 0 3 -3 -9", "output": "122" }, { "input": "6\n-1 2 4 -5 -3 55", "output": "70" }, { "input": "6\n-12 8 68 -53 1 -15", "output": "157" }, { "input": "2\n-2 1", "output": "3" }, { "input": "3\n100 -100 100", "output": "300" }, { "input": "5\n100 100 -1 -100 2", "output": "303" }, { "input": "6\n-5 -4 -3 -2 -1 0", "output": "15" }, { "input": "6\n4 4 4 -3 -3 2", "output": "20" }, { "input": "2\n-1 2", "output": "3" }, { "input": "1\n100", "output": "100" }, { "input": "5\n-1 -2 3 1 2", "output": "9" }, { "input": "5\n100 -100 100 -100 100", "output": "500" }, { "input": "5\n1 -1 1 -1 1", "output": "5" }, { "input": "4\n0 0 0 -1", "output": "1" }, { "input": "5\n100 -100 -1 2 100", "output": "303" }, { "input": "2\n75 0", "output": "75" }, { "input": "4\n55 56 -59 -58", "output": "228" }, { "input": "2\n9 71", "output": "80" }, { "input": "2\n9 70", "output": "79" }, { "input": "2\n9 69", "output": "78" }, { "input": "2\n100 -100", "output": "200" }, { "input": "4\n-9 4 -9 5", "output": "27" }, { "input": "42\n91 -27 -79 -56 80 -93 -23 10 80 94 61 -89 -64 81 34 99 31 -32 -69 92 79 -9 73 66 -8 64 99 99 58 -19 -40 21 1 -33 93 -23 -62 27 55 41 57 36", "output": "2348" }, { "input": "7\n-1 2 2 2 -1 2 -1", "output": "11" }, { "input": "6\n-12 8 17 -69 7 -88", "output": "201" }, { "input": "3\n1 -2 5", "output": "8" }, { "input": "6\n-2 3 -4 5 6 -1", "output": "21" }, { "input": "2\n-5 1", "output": "6" }, { "input": "4\n2 2 -2 4", "output": "10" }, { "input": "68\n21 47 -75 -25 64 83 83 -21 89 24 43 44 -35 34 -42 92 -96 -52 -66 64 14 -87 25 -61 -78 83 -96 -18 95 83 -93 -28 75 49 87 65 -93 -69 -2 95 -24 -36 -61 -71 88 -53 -93 -51 -81 -65 -53 -46 -56 6 65 58 19 100 57 61 -53 44 -58 48 -8 80 -88 72", "output": "3991" }, { "input": "5\n5 5 -10 -1 1", "output": "22" }, { "input": "3\n-1 2 3", "output": "6" }, { "input": "76\n57 -38 -48 -81 93 -32 96 55 -44 2 38 -46 42 64 71 -73 95 31 -39 -62 -1 75 -17 57 28 52 12 -11 82 -84 59 -86 73 -97 34 97 -57 -85 -6 39 -5 -54 95 24 -44 35 -18 9 91 7 -22 -61 -80 54 -40 74 -90 15 -97 66 -52 -49 -24 65 21 -93 -29 -24 -4 -1 76 -93 7 -55 -53 1", "output": "3787" }, { "input": "5\n-1 -2 1 2 3", "output": "9" }, { "input": "4\n2 2 -2 -2", "output": "8" }, { "input": "6\n100 -100 100 -100 100 -100", "output": "600" }, { "input": "100\n-59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 61 -9 95 42 -73 -64 91 -96 2 53 -8 82 -79 16 18 -5 -53 26 71 38 -31 12 -33 -1 -65 -6 3 -89 22 33 -27 -36 41 11 -47 -32 47 -56 -38 57 -63 -41 23 41 29 78 16 -65 90 -58 -12 6 -60 42 -36 -52 -54 -95 -10 29 70 50 -94 1 93 48 -71 -77 -16 54 56 -60 66 76 31 8 44 -61 -74 23 37 38 18 -18 29 41", "output": "4362" }, { "input": "2\n-1 1", "output": "2" }, { "input": "3\n1 -2 100", "output": "103" }, { "input": "5\n1 -2 3 1 2", "output": "9" }, { "input": "10\n100 -10 -100 10 10 10 10 10 10 10", "output": "280" }, { "input": "4\n2 0 -2 4", "output": "8" }, { "input": "4\n3 -3 1 -1", "output": "8" }, { "input": "3\n1 -1 1", "output": "3" }, { "input": "4\n2 5 -2 4", "output": "13" }, { "input": "2\n-2 2", "output": "4" }, { "input": "3\n1 -2 1", "output": "4" }, { "input": "5\n-1 -2 1 1 -1", "output": "6" }, { "input": "4\n-2 0 2 4", "output": "8" }, { "input": "8\n-42 7 87 -16 -5 65 -88 1", "output": "311" }, { "input": "3\n1 -3 4", "output": "8" }, { "input": "1\n1", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n-1 2 -1", "output": "4" }, { "input": "18\n-21 12 65 66 -24 62 82 35 -45 -47 28 37 5 -32 22 -14 -69 -95", "output": "761" }, { "input": "4\n-1 1 -1 1", "output": "4" }, { "input": "5\n-1 2 1 1 1", "output": "6" }, { "input": "3\n1 1 1", "output": "3" } ]
1,573,835,228
2,147,483,647
Python 3
OK
TESTS
72
109
0
n=int(input()) a=list(map(int,input().split())) sum=0 for i in a: sum+=abs(i) print(sum)
Title: Partition Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≤<=*a**i*<=≤<=100) — the elements of sequence *a*. Output Specification: Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. Demo Input: ['3\n1 -2 0\n', '6\n16 23 16 15 42 8\n'] Demo Output: ['3\n', '120\n'] Note: In the first example we may choose *b* = {1, 0}, *c* = { - 2}. Then *B* = 1, *C* =  - 2, *B* - *C* = 3. In the second example we choose *b* = {16, 23, 16, 15, 42, 8}, *c* = {} (an empty sequence). Then *B* = 120, *C* = 0, *B* - *C* = 120.
```python n=int(input()) a=list(map(int,input().split())) sum=0 for i in a: sum+=abs(i) print(sum) ```
3
484
A
Bits
PROGRAMMING
1,700
[ "bitmasks", "constructive algorithms" ]
null
null
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the smallest of them.
The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000). Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018).
For each query print the answer in a separate line.
[ "3\n1 2\n2 4\n1 10\n" ]
[ "1\n3\n7\n" ]
The binary representations of numbers from 1 to 10 are listed below: 1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub> 2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub> 3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub> 4<sub class="lower-index">10</sub> = 100<sub class="lower-index">2</sub> 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub> 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub> 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub> 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub> 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>
500
[ { "input": "3\n1 2\n2 4\n1 10", "output": "1\n3\n7" }, { "input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10\n7 7\n7 8\n7 9\n7 10\n8 8\n8 9\n8 10\n9 9\n9 10\n10 10", "output": "1\n1\n3\n3\n3\n3\n7\n7\n7\n7\n2\n3\n3\n3\n3\n7\n7\n7\n7\n3\n3\n3\n3\n7\n7\n7\n7\n4\n5\n5\n7\n7\n7\n7\n5\n5\n7\n7\n7\n7\n6\n7\n7\n7\n7\n7\n7\n7\n7\n8\n9\n9\n9\n9\n10" }, { "input": "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000", "output": "7\n63\n511\n8191\n65535\n524287\n8388607\n67108863\n536870911\n8589934591\n68719476735\n549755813887\n8796093022207\n70368744177663\n562949953421311\n9007199254740991\n72057594037927935\n576460752303423487" }, { "input": "3\n0 0\n1 3\n2 4", "output": "0\n3\n3" }, { "input": "17\n0 0\n0 8\n1 8\n36 39\n3 4\n3 7\n2 17\n8 12\n9 12\n10 12\n10 15\n6 14\n8 15\n9 15\n15 15\n100000000000000000 1000000000000000000\n99999999999999999 1000000000000000000", "output": "0\n7\n7\n39\n3\n7\n15\n11\n11\n11\n15\n7\n15\n15\n15\n576460752303423487\n576460752303423487" } ]
1,518,608,482
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
5,632,000
tCases = int(input()) inp = [] for x in range(tCases): l ,r = map(int,input().split()) val = l for y in range (l,r): if(bin(y).count("1")> bin(val).count("1")): val = y print(val)
Title: Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*. You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the smallest of them. Input Specification: The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000). Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). Output Specification: For each query print the answer in a separate line. Demo Input: ['3\n1 2\n2 4\n1 10\n'] Demo Output: ['1\n3\n7\n'] Note: The binary representations of numbers from 1 to 10 are listed below: 1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub> 2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub> 3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub> 4<sub class="lower-index">10</sub> = 100<sub class="lower-index">2</sub> 5<sub class="lower-index">10</sub> = 101<sub class="lower-index">2</sub> 6<sub class="lower-index">10</sub> = 110<sub class="lower-index">2</sub> 7<sub class="lower-index">10</sub> = 111<sub class="lower-index">2</sub> 8<sub class="lower-index">10</sub> = 1000<sub class="lower-index">2</sub> 9<sub class="lower-index">10</sub> = 1001<sub class="lower-index">2</sub> 10<sub class="lower-index">10</sub> = 1010<sub class="lower-index">2</sub>
```python tCases = int(input()) inp = [] for x in range(tCases): l ,r = map(int,input().split()) val = l for y in range (l,r): if(bin(y).count("1")> bin(val).count("1")): val = y print(val) ```
0
954
A
Diagonal Walking
PROGRAMMING
800
[ "implementation" ]
null
null
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements.
The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R.
Print the minimum possible length of the sequence of moves after all replacements are done.
[ "5\nRUURU\n", "17\nUUURRRRRUUURURUUU\n" ]
[ "3\n", "13\n" ]
In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
0
[ { "input": "5\nRUURU", "output": "3" }, { "input": "17\nUUURRRRRUUURURUUU", "output": "13" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU", "output": "100" }, { "input": "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR", "output": "67" }, { "input": "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUURUUUUUUUUUUUUUUUUUUUUU", "output": "99" }, { "input": "3\nRUR", "output": "2" }, { "input": "1\nR", "output": "1" }, { "input": "5\nRURUU", "output": "3" }, { "input": "1\nU", "output": "1" }, { "input": "2\nUR", "output": "1" }, { "input": "23\nUUUUUUUUUUUUUUUUUUUUUUU", "output": "23" } ]
1,638,205,130
2,147,483,647
Python 3
OK
TESTS
11
46
0
# -*- coding: utf-8 -*- """diagonal walking .ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1pAmw3SAXBpNn-FeuwNJCdgpcYI-BxCEJ """ n=int(input()) a=input() count=n i=0 while i<n-1: if a[i]!=a[i+1]: count-=1 i+=2 else: i+=1 print(count)
Title: Diagonal Walking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. Input Specification: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. Output Specification: Print the minimum possible length of the sequence of moves after all replacements are done. Demo Input: ['5\nRUURU\n', '17\nUUURRRRRUUURURUUU\n'] Demo Output: ['3\n', '13\n'] Note: In the first test the shortened sequence of moves may be DUD (its length is 3). In the second test the shortened sequence of moves can be UUDRRRDUDDUUU (its length is 13).
```python # -*- coding: utf-8 -*- """diagonal walking .ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1pAmw3SAXBpNn-FeuwNJCdgpcYI-BxCEJ """ n=int(input()) a=input() count=n i=0 while i<n-1: if a[i]!=a[i+1]: count-=1 i+=2 else: i+=1 print(count) ```
3
999
C
Alphabetic Removals
PROGRAMMING
1,200
[ "implementation" ]
null
null
You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string.
The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters.
Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).
[ "15 3\ncccaabababaccbc\n", "15 9\ncccaabababaccbc\n", "1 1\nu\n" ]
[ "cccbbabaccbc\n", "cccccc\n", "" ]
none
0
[ { "input": "15 3\ncccaabababaccbc", "output": "cccbbabaccbc" }, { "input": "15 9\ncccaabababaccbc", "output": "cccccc" }, { "input": "5 2\nzyzyx", "output": "zzy" }, { "input": "4 3\nhack", "output": "k" }, { "input": "4 3\nzzzz", "output": "z" }, { "input": "6 5\naaccdd", "output": "d" }, { "input": "2 1\nzz", "output": "z" }, { "input": "14 5\nhxehmvkybeklnj", "output": "xmvkyklnj" } ]
1,681,469,192
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
8,908,800
a,b = map(int,input().split()) string = input() for x in range(b): string = string.replace(min(string),"",1) print(string)
Title: Alphabetic Removals Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: - if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item; - ... - remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $k$ times, thus removing exactly $k$ characters. Help Polycarp find the resulting string. Input Specification: The first line of input contains two integers $n$ and $k$ ($1 \le k \le n \le 4 \cdot 10^5$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $s$ consisting of $n$ lowercase Latin letters. Output Specification: Print the string that will be obtained from $s$ after Polycarp removes exactly $k$ letters using the above algorithm $k$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break). Demo Input: ['15 3\ncccaabababaccbc\n', '15 9\ncccaabababaccbc\n', '1 1\nu\n'] Demo Output: ['cccbbabaccbc\n', 'cccccc\n', ''] Note: none
```python a,b = map(int,input().split()) string = input() for x in range(b): string = string.replace(min(string),"",1) print(string) ```
0
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,603,861,637
2,147,483,647
Python 3
OK
TESTS
24
218
0
l,q=[0]*3,0 for i in range(3):l[i]=list(map(int,input().split()));q+=sum(l[i]) for i in range(3):l[i][i]=q//2-sum(l[i]);print(*l[i])
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 l,q=[0]*3,0 for i in range(3):l[i]=list(map(int,input().split()));q+=sum(l[i]) for i in range(3):l[i][i]=q//2-sum(l[i]);print(*l[i]) ```
3
753
B
Interactive Bulls and Cows (Easy)
PROGRAMMING
1,600
[ "brute force", "constructive algorithms", "implementation" ]
null
null
This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is *s* and the second player are trying to guess it with a string *x*. The number of "bulls" is a number of such positions *i* (1<=≤<=*i*<=≤<=4) where *s*[*i*]<==<=*x*[*i*]. The number of "cows" is a number of such digits *c* that *s* contains *c* in the position *i* (i.e. *s*[*i*]<==<=*c*), *x* contains *c*, but *x*[*i*]<=≠<=*c*. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string *s* that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number *x* or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string.
To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string *s* and the string *x**i* printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the *i*-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value *x**i* in a single line and executes operation flush.
The program must use the standard output to print queries. Your program must output requests — 4-digit strings *x*1,<=*x*2,<=..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries.
[ "0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n" ]
[ "8000\n0179\n3159\n3210\n0112\n0123" ]
The secret string *s* in the example is "0123".
1,000
[ { "input": "0123", "output": "20" }, { "input": "1234", "output": "20" }, { "input": "9876", "output": "20" }, { "input": "7158", "output": "20" }, { "input": "7590", "output": "20" }, { "input": "7325", "output": "20" }, { "input": "7524", "output": "20" }, { "input": "7269", "output": "20" }, { "input": "7802", "output": "20" }, { "input": "7436", "output": "20" }, { "input": "7190", "output": "20" }, { "input": "7390", "output": "20" }, { "input": "2548", "output": "20" }, { "input": "2193", "output": "20" }, { "input": "2491", "output": "20" }, { "input": "2469", "output": "20" }, { "input": "2659", "output": "20" }, { "input": "2405", "output": "20" }, { "input": "2058", "output": "20" }, { "input": "2580", "output": "20" }, { "input": "2316", "output": "20" }, { "input": "2516", "output": "20" }, { "input": "8796", "output": "20" }, { "input": "8534", "output": "20" }, { "input": "9067", "output": "20" }, { "input": "8712", "output": "20" }, { "input": "9023", "output": "20" }, { "input": "8645", "output": "20" }, { "input": "8623", "output": "20" }, { "input": "8923", "output": "20" }, { "input": "8567", "output": "20" }, { "input": "8756", "output": "20" }, { "input": "0351", "output": "20" }, { "input": "9863", "output": "20" }, { "input": "0518", "output": "20" }, { "input": "0263", "output": "20" }, { "input": "0462", "output": "20" }, { "input": "0429", "output": "20" }, { "input": "0629", "output": "20" }, { "input": "0374", "output": "20" }, { "input": "3209", "output": "20" } ]
1,483,003,948
1,648
Python 3
OK
TESTS
41
62
4,608,000
from sys import stdout from itertools import permutations var = [] for i in range(10): print(str(i) * 4) stdout.flush() a, b = map(int, input().split()) if a: var.append(str(i)) for t in permutations(var): print(''.join(t)) stdout.flush() a, b = map(int, input().split()) if a == 4: break
Title: Interactive Bulls and Cows (Easy) Time Limit: None seconds Memory Limit: None megabytes Problem Description: This problem is a little bit unusual. Here you are to implement an interaction with a testing system. That means that you can make queries and get responses in the online mode. Please be sure to use the stream flushing operation after each query's output in order not to leave part of your output in some buffer. For example, in C++ you've got to use the fflush(stdout) function, in Java — call System.out.flush(), and in Pascal — flush(output). Bulls and Cows (also known as Cows and Bulls or Pigs and Bulls or Bulls and Cleots) is an old code-breaking paper and pencil game for two players, predating the similar commercially marketed board game Mastermind. On a sheet of paper, the first player thinks a secret string. This string consists only of digits and has the length 4. The digits in the string must be all different, no two or more equal digits are allowed. Then the second player tries to guess his opponent's string. For every guess the first player gives the number of matches. If the matching digits are on their right positions, they are "bulls", if on different positions, they are "cows". Thus a response is a pair of numbers — the number of "bulls" and the number of "cows". A try can contain equal digits. More formally, let's the secret string is *s* and the second player are trying to guess it with a string *x*. The number of "bulls" is a number of such positions *i* (1<=≤<=*i*<=≤<=4) where *s*[*i*]<==<=*x*[*i*]. The number of "cows" is a number of such digits *c* that *s* contains *c* in the position *i* (i.e. *s*[*i*]<==<=*c*), *x* contains *c*, but *x*[*i*]<=≠<=*c*. For example, the secret string is "0427", the opponent's try is "0724", then the answer is 2 bulls and 2 cows (the bulls are "0" and "2", the cows are "4" and "7"). If the secret string is "0123", the opponent's try is "0330", then the answer is 1 bull and 1 cow. In this problem you are to guess the string *s* that the system has chosen. You only know that the chosen string consists of 4 distinct digits. You can make queries to the testing system, each query is the output of a single 4-digit string. The answer to the query is the number of bulls and number of cows. If the system's response equals "4 0", that means the interaction with your problem is over and the program must terminate. That is possible for two reasons — the program either guessed the number *x* or made an invalid action (for example, printed letters instead of digits). Your program is allowed to do at most 50 queries. You can hack solutions of other participants providing a 4-digit string containing distinct digits — the secret string. Input Specification: To read answers to the queries, the program must use the standard input. The program will receive pairs of non-negative integers in the input, one pair per line. The first number in a pair is a number of bulls and the second one is a number of cows of the string *s* and the string *x**i* printed by your program. If the system response equals "4 0", then your solution should terminate. The testing system will let your program read the *i*-th pair of integers from the input only after your program displays the corresponding system query in the output: prints value *x**i* in a single line and executes operation flush. Output Specification: The program must use the standard output to print queries. Your program must output requests — 4-digit strings *x*1,<=*x*2,<=..., one per line. After the output of each line the program must execute flush operation. The program should read the answer to the query from the standard input. Your program is allowed to do at most 50 queries. Demo Input: ['0 1\n2 0\n1 1\n0 4\n2 1\n4 0\n'] Demo Output: ['8000\n0179\n3159\n3210\n0112\n0123'] Note: The secret string *s* in the example is "0123".
```python from sys import stdout from itertools import permutations var = [] for i in range(10): print(str(i) * 4) stdout.flush() a, b = map(int, input().split()) if a: var.append(str(i)) for t in permutations(var): print(''.join(t)) stdout.flush() a, b = map(int, input().split()) if a == 4: break ```
3
63
B
Settlers' Training
PROGRAMMING
1,200
[ "implementation" ]
B. Settlers' Training
2
256
In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease. Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank. To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present. At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one. You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*).
Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.
[ "4 4\n1 2 2 3\n", "4 3\n1 1 1 1\n" ]
[ "4", "5" ]
In the first example the ranks will be raised in the following manner: 1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
1,000
[ { "input": "4 4\n1 2 2 3", "output": "4" }, { "input": "4 3\n1 1 1 1", "output": "5" }, { "input": "3 3\n1 2 3", "output": "2" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 5\n1", "output": "4" }, { "input": "1 5\n4", "output": "1" }, { "input": "2 6\n2 5", "output": "4" }, { "input": "6 10\n1 1 3 4 9 9", "output": "10" }, { "input": "7 7\n1 1 1 1 1 1 7", "output": "11" }, { "input": "10 10\n1 1 1 3 3 4 7 8 8 8", "output": "11" }, { "input": "10 13\n1 1 1 1 1 1 1 1 1 1", "output": "21" }, { "input": "10 13\n2 6 6 7 9 9 9 10 12 12", "output": "11" }, { "input": "17 9\n2 3 4 5 5 5 5 5 6 6 7 7 8 8 8 8 8", "output": "17" }, { "input": "18 24\n3 3 3 4 5 7 8 8 9 9 9 9 10 10 11 11 11 11", "output": "30" }, { "input": "23 2\n1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2", "output": "12" }, { "input": "37 42\n1 1 1 1 1 2 2 2 2 2 3 4 4 4 4 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 7 8 8 8 8 8", "output": "70" }, { "input": "44 50\n38 38 38 38 38 38 38 39 39 39 39 39 39 39 40 40 40 40 40 41 41 41 41 41 41 41 42 42 42 43 43 43 44 44 44 44 45 45 45 46 46 46 46 46", "output": "47" }, { "input": "57 100\n2 2 4 7 8 10 12 12 14 15 16 18 19 21 21 22 25 26 26 33 38 40 44 44 44 45 47 47 50 51 51 54 54 54 54 55 56 58 61 65 67 68 68 70 74 75 78 79 83 86 89 90 92 95 96 96 97", "output": "99" }, { "input": "78 10\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9", "output": "78" }, { "input": "96 78\n20 20 20 20 20 21 21 21 22 23 23 24 24 25 25 27 28 29 30 30 30 32 32 32 33 33 33 33 34 34 35 36 37 37 39 39 41 41 41 41 42 42 43 43 43 44 44 45 46 46 48 48 49 50 51 51 51 52 53 55 55 56 56 56 56 57 58 59 60 61 61 61 62 62 62 63 63 64 64 64 65 65 65 66 66 67 68 69 71 72 72 73 73 75 75 75", "output": "98" }, { "input": "100 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", "output": "0" }, { "input": "100 100\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", "output": "198" }, { "input": "100 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 100\n1 1 4 4 5 5 7 9 10 10 11 11 12 12 12 13 14 15 16 16 16 17 18 18 19 20 22 25 26 27 29 32 33 34 34 35 35 35 36 36 37 37 38 39 39 40 41 42 44 44 46 47 47 47 47 50 53 53 53 55 56 56 57 57 58 58 59 59 62 64 64 64 64 68 68 68 69 70 70 71 74 77 77 77 79 80 80 81 84 86 88 88 91 93 94 96 96 99 99 99", "output": "108" }, { "input": "100 100\n1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 7 7 7 7 8 8 8 8 8 9 9 9 9 9 9 9 10 10 10 10 10 11 11 11 11 11 12 12 12 12 12 12 13 13 13 13 13 13 13 14 14 14 14 14 14 14 14 14 14 14 14 14 15 15 15 15 15", "output": "184" }, { "input": "100 100\n20 20 20 21 21 21 21 21 22 23 23 23 23 23 23 24 24 25 25 26 26 26 26 26 27 27 27 27 28 28 28 28 29 29 29 29 29 30 30 30 30 31 32 32 34 34 34 34 34 34 34 34 35 35 35 36 36 37 37 37 37 37 37 38 38 38 39 40 41 41 42 42 42 42 42 43 43 43 44 44 44 44 44 45 45 45 45 45 46 46 46 46 46 47 47 47 48 48 48 50", "output": "150" }, { "input": "100 2\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 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2", "output": "59" }, { "input": "30 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 49", "output": "77" }, { "input": "40 20\n5 5 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 20 20 20 20 20 20 20 20 20 20", "output": "31" }, { "input": "81 90\n1 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90", "output": "89" }, { "input": "100 20\n1 1 1 1 1 1 1 1 1 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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 13 13 13 13 13 13 13 13 13", "output": "106" }, { "input": "100 100\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 100", "output": "197" }, { "input": "100 100\n49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 51", "output": "148" }, { "input": "1 100\n1", "output": "99" }, { "input": "4 3\n1 1 2 2", "output": "4" }, { "input": "10 100\n98 99 99 99 99 99 99 100 100 100", "output": "7" }, { "input": "5 100\n1 2 2 100 100", "output": "100" } ]
1,622,060,653
2,147,483,647
PyPy 3
OK
TESTS
37
218
1,331,200
n,k=list(map(int,input().split())) a=list(map(int,input().split())) c=0 while a!=[k]*n: a.sort() for i in range(1,n): if a[i]!=a[i-1]: a[i-1]+=1 if a[n-1]<k: a[n-1]+=1 c+=1 print(c)
Title: Settlers' Training Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly *n* soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease. Every soldier has a rank — some natural number from 1 to *k*. 1 stands for a private and *k* stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank. To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the *n* soldiers are present. At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank *k* are present, exactly one soldier increases his rank by one. You know the ranks of all *n* soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank *k*. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains *n* numbers in the non-decreasing order. The *i*-th of them, *a**i*, represents the rank of the *i*-th soldier in the defense building (1<=≤<=*i*<=≤<=*n*, 1<=≤<=*a**i*<=≤<=*k*). Output Specification: Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank. Demo Input: ['4 4\n1 2 2 3\n', '4 3\n1 1 1 1\n'] Demo Output: ['4', '5'] Note: In the first example the ranks will be raised in the following manner: 1 2 2 3  →  2 2 3 4  →  2 3 4 4  →  3 4 4 4  →  4 4 4 4 Thus totals to 4 training sessions that require 4 golden coins.
```python n,k=list(map(int,input().split())) a=list(map(int,input().split())) c=0 while a!=[k]*n: a.sort() for i in range(1,n): if a[i]!=a[i-1]: a[i-1]+=1 if a[n-1]<k: a[n-1]+=1 c+=1 print(c) ```
3.94302
0
none
none
none
0
[ "none" ]
null
null
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*?
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory.
Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor.
[ "10 3\n6 2\n2 1\n7 3\n", "8 4\n3 1\n6 2\n5 2\n2 1\n" ]
[ "4\n", "-1\n" ]
In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
0
[ { "input": "10 3\n6 2\n2 1\n7 3", "output": "4" }, { "input": "8 4\n3 1\n6 2\n5 2\n2 1", "output": "-1" }, { "input": "8 3\n7 2\n6 2\n1 1", "output": "2" }, { "input": "4 2\n8 3\n3 1", "output": "2" }, { "input": "11 4\n16 4\n11 3\n10 3\n15 4", "output": "3" }, { "input": "16 6\n3 1\n16 4\n10 3\n9 3\n19 5\n8 2", "output": "4" }, { "input": "1 0", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 1\n1 1", "output": "1" }, { "input": "1 2\n1 1\n2 2", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 0", "output": "-1" }, { "input": "2 1\n3 3", "output": "2" }, { "input": "3 2\n1 1\n3 3", "output": "3" }, { "input": "3 3\n1 1\n3 3\n2 2", "output": "3" }, { "input": "3 0", "output": "-1" }, { "input": "1 1\n2 1", "output": "1" }, { "input": "2 2\n2 1\n1 1", "output": "1" }, { "input": "2 3\n3 2\n1 1\n2 1", "output": "1" }, { "input": "3 0", "output": "-1" }, { "input": "3 1\n1 1", "output": "-1" }, { "input": "2 2\n1 1\n3 1", "output": "1" }, { "input": "1 3\n1 1\n2 1\n3 1", "output": "1" }, { "input": "81 0", "output": "-1" }, { "input": "22 1\n73 73", "output": "22" }, { "input": "63 2\n10 10\n64 64", "output": "63" }, { "input": "88 3\n37 37\n15 15\n12 12", "output": "88" }, { "input": "29 4\n66 66\n47 47\n62 62\n2 2", "output": "29" }, { "input": "9 40\n72 72\n47 47\n63 63\n66 66\n21 21\n94 94\n28 28\n45 45\n93 93\n25 25\n100 100\n43 43\n49 49\n9 9\n74 74\n26 26\n42 42\n50 50\n2 2\n92 92\n76 76\n3 3\n78 78\n44 44\n69 69\n36 36\n65 65\n81 81\n13 13\n46 46\n24 24\n96 96\n73 73\n82 82\n68 68\n64 64\n41 41\n31 31\n29 29\n10 10", "output": "9" }, { "input": "50 70\n3 3\n80 80\n23 23\n11 11\n87 87\n7 7\n63 63\n61 61\n67 67\n53 53\n9 9\n43 43\n55 55\n27 27\n5 5\n1 1\n99 99\n65 65\n37 37\n60 60\n32 32\n38 38\n81 81\n2 2\n34 34\n17 17\n82 82\n26 26\n71 71\n4 4\n16 16\n19 19\n39 39\n51 51\n6 6\n49 49\n64 64\n83 83\n10 10\n56 56\n30 30\n76 76\n90 90\n42 42\n47 47\n91 91\n21 21\n52 52\n40 40\n77 77\n35 35\n88 88\n75 75\n95 95\n28 28\n15 15\n69 69\n22 22\n48 48\n66 66\n31 31\n98 98\n73 73\n25 25\n97 97\n18 18\n13 13\n54 54\n72 72\n29 29", "output": "50" }, { "input": "6 0", "output": "-1" }, { "input": "32 1\n9 5", "output": "16" }, { "input": "73 2\n17 9\n21 11", "output": "37" }, { "input": "6 3\n48 24\n51 26\n62 31", "output": "3" }, { "input": "43 4\n82 41\n52 26\n88 44\n41 21", "output": "22" }, { "input": "28 40\n85 43\n19 10\n71 36\n39 20\n57 29\n6 3\n15 8\n11 6\n99 50\n77 39\n79 40\n31 16\n35 18\n24 12\n54 27\n93 47\n90 45\n72 36\n63 32\n22 11\n83 42\n5 3\n12 6\n56 28\n94 47\n25 13\n41 21\n29 15\n36 18\n23 12\n1 1\n84 42\n55 28\n58 29\n9 5\n68 34\n86 43\n3 2\n48 24\n98 49", "output": "14" }, { "input": "81 70\n55 28\n85 43\n58 29\n20 10\n4 2\n47 24\n42 21\n28 14\n26 13\n38 19\n9 5\n83 42\n7 4\n72 36\n18 9\n61 31\n41 21\n64 32\n90 45\n46 23\n67 34\n2 1\n6 3\n27 14\n87 44\n39 20\n11 6\n21 11\n35 18\n48 24\n44 22\n3 2\n71 36\n62 31\n34 17\n16 8\n99 50\n57 29\n13 7\n79 40\n100 50\n53 27\n89 45\n36 18\n43 22\n92 46\n98 49\n75 38\n40 20\n97 49\n37 19\n68 34\n30 15\n96 48\n17 9\n12 6\n45 23\n65 33\n76 38\n84 42\n23 12\n91 46\n52 26\n8 4\n32 16\n77 39\n88 44\n86 43\n70 35\n51 26", "output": "41" }, { "input": "34 0", "output": "-1" }, { "input": "63 1\n94 24", "output": "16" }, { "input": "4 2\n38 10\n48 12", "output": "1" }, { "input": "37 3\n66 17\n89 23\n60 15", "output": "10" }, { "input": "71 4\n15 4\n13 4\n4 1\n70 18", "output": "18" }, { "input": "77 40\n49 13\n66 17\n73 19\n15 4\n36 9\n1 1\n41 11\n91 23\n51 13\n46 12\n39 10\n42 11\n56 14\n61 16\n70 18\n92 23\n65 17\n54 14\n97 25\n8 2\n87 22\n33 9\n28 7\n38 10\n50 13\n26 7\n7 2\n31 8\n84 21\n47 12\n27 7\n53 14\n19 5\n93 24\n29 8\n3 1\n77 20\n62 16\n9 3\n44 11", "output": "20" }, { "input": "18 70\n51 13\n55 14\n12 3\n43 11\n42 11\n95 24\n96 24\n29 8\n65 17\n71 18\n18 5\n62 16\n31 8\n100 25\n4 1\n77 20\n56 14\n24 6\n93 24\n97 25\n79 20\n40 10\n49 13\n86 22\n21 6\n46 12\n6 2\n14 4\n23 6\n20 5\n52 13\n88 22\n39 10\n70 18\n94 24\n13 4\n37 10\n41 11\n91 23\n85 22\n83 21\n89 23\n33 9\n64 16\n67 17\n57 15\n47 12\n36 9\n72 18\n81 21\n76 19\n35 9\n80 20\n34 9\n5 2\n22 6\n84 21\n63 16\n74 19\n90 23\n68 17\n98 25\n87 22\n2 1\n92 23\n50 13\n38 10\n28 7\n8 2\n60 15", "output": "5" }, { "input": "89 0", "output": "-1" }, { "input": "30 1\n3 1", "output": "-1" }, { "input": "63 2\n48 6\n17 3", "output": "8" }, { "input": "96 3\n45 6\n25 4\n35 5", "output": "12" }, { "input": "37 4\n2 1\n29 4\n27 4\n47 6", "output": "5" }, { "input": "64 40\n40 5\n92 12\n23 3\n75 10\n71 9\n2 1\n54 7\n18 3\n9 2\n74 10\n87 11\n11 2\n90 12\n30 4\n48 6\n12 2\n91 12\n60 8\n35 5\n13 2\n53 7\n46 6\n38 5\n59 8\n97 13\n32 4\n6 1\n36 5\n43 6\n83 11\n81 11\n99 13\n69 9\n10 2\n21 3\n78 10\n31 4\n27 4\n57 8\n1 1", "output": "8" }, { "input": "17 70\n63 8\n26 4\n68 9\n30 4\n61 8\n84 11\n39 5\n53 7\n4 1\n81 11\n50 7\n91 12\n59 8\n90 12\n20 3\n21 3\n83 11\n94 12\n37 5\n8 1\n49 7\n34 5\n19 3\n44 6\n74 10\n2 1\n73 10\n88 11\n43 6\n36 5\n57 8\n64 8\n76 10\n40 5\n71 9\n95 12\n15 2\n41 6\n89 12\n42 6\n96 12\n1 1\n52 7\n38 5\n45 6\n78 10\n82 11\n16 2\n48 6\n51 7\n56 7\n28 4\n87 11\n93 12\n46 6\n29 4\n97 13\n54 7\n35 5\n3 1\n79 10\n99 13\n13 2\n55 7\n100 13\n11 2\n75 10\n24 3\n33 5\n22 3", "output": "3" }, { "input": "9 0", "output": "-1" }, { "input": "50 1\n31 2", "output": "-1" }, { "input": "79 2\n11 1\n22 2", "output": "-1" }, { "input": "16 3\n100 7\n94 6\n3 1", "output": "1" }, { "input": "58 4\n73 5\n52 4\n69 5\n3 1", "output": "4" }, { "input": "25 40\n70 5\n28 2\n60 4\n54 4\n33 3\n21 2\n51 4\n20 2\n44 3\n79 5\n65 5\n1 1\n52 4\n23 2\n38 3\n92 6\n63 4\n3 1\n91 6\n5 1\n64 4\n34 3\n25 2\n97 7\n89 6\n61 4\n71 5\n88 6\n29 2\n56 4\n45 3\n6 1\n53 4\n57 4\n90 6\n76 5\n8 1\n46 3\n73 5\n87 6", "output": "2" }, { "input": "78 70\n89 6\n52 4\n87 6\n99 7\n3 1\n25 2\n46 3\n78 5\n35 3\n68 5\n85 6\n23 2\n60 4\n88 6\n17 2\n8 1\n15 1\n67 5\n95 6\n59 4\n94 6\n31 2\n4 1\n16 1\n10 1\n97 7\n42 3\n2 1\n24 2\n34 3\n37 3\n70 5\n18 2\n41 3\n48 3\n58 4\n20 2\n38 3\n72 5\n50 4\n49 4\n40 3\n61 4\n6 1\n45 3\n28 2\n13 1\n27 2\n96 6\n56 4\n91 6\n77 5\n12 1\n11 1\n53 4\n76 5\n74 5\n82 6\n55 4\n80 5\n14 1\n44 3\n7 1\n83 6\n79 5\n92 6\n66 5\n36 3\n73 5\n100 7", "output": "5" }, { "input": "95 0", "output": "-1" }, { "input": "33 1\n30 1", "output": "-1" }, { "input": "62 2\n14 1\n15 1", "output": "-1" }, { "input": "3 3\n6 1\n25 1\n38 2", "output": "1" }, { "input": "44 4\n72 3\n80 3\n15 1\n36 2", "output": "2" }, { "input": "34 40\n25 1\n28 1\n78 3\n5 1\n13 1\n75 3\n15 1\n67 3\n57 2\n23 1\n26 1\n61 2\n22 1\n48 2\n85 3\n24 1\n82 3\n83 3\n53 2\n38 2\n19 1\n33 2\n69 3\n17 1\n79 3\n54 2\n77 3\n97 4\n20 1\n35 2\n14 1\n18 1\n71 3\n21 1\n36 2\n56 2\n44 2\n63 2\n72 3\n32 1", "output": "2" }, { "input": "83 70\n79 3\n49 2\n2 1\n44 2\n38 2\n77 3\n86 3\n31 1\n83 3\n82 3\n35 2\n7 1\n78 3\n23 1\n39 2\n58 2\n1 1\n87 3\n72 3\n20 1\n48 2\n14 1\n13 1\n6 1\n70 3\n55 2\n52 2\n25 1\n11 1\n61 2\n76 3\n95 3\n32 1\n66 3\n29 1\n9 1\n5 1\n3 1\n88 3\n59 2\n96 3\n10 1\n63 2\n40 2\n42 2\n34 2\n43 2\n19 1\n89 3\n94 3\n24 1\n98 4\n12 1\n30 1\n69 3\n17 1\n50 2\n8 1\n93 3\n16 1\n97 4\n54 2\n71 3\n18 1\n33 2\n80 3\n15 1\n99 4\n75 3\n4 1", "output": "3" }, { "input": "2 0", "output": "-1" }, { "input": "36 1\n96 1", "output": "1" }, { "input": "73 2\n34 1\n4 1", "output": "-1" }, { "input": "6 3\n37 1\n22 1\n70 1", "output": "1" }, { "input": "47 4\n66 1\n57 1\n85 1\n47 1", "output": "1" }, { "input": "9 40\n73 1\n21 1\n37 1\n87 1\n33 1\n69 1\n49 1\n19 1\n35 1\n93 1\n71 1\n43 1\n79 1\n85 1\n29 1\n72 1\n76 1\n47 1\n17 1\n67 1\n95 1\n41 1\n54 1\n88 1\n42 1\n80 1\n98 1\n96 1\n10 1\n24 1\n78 1\n18 1\n3 1\n91 1\n2 1\n15 1\n5 1\n60 1\n36 1\n46 1", "output": "1" }, { "input": "63 70\n82 1\n53 1\n57 1\n46 1\n97 1\n19 1\n36 1\n90 1\n23 1\n88 1\n68 1\n45 1\n2 1\n70 1\n86 1\n8 1\n83 1\n40 1\n99 1\n42 1\n32 1\n52 1\n81 1\n50 1\n77 1\n37 1\n54 1\n75 1\n4 1\n49 1\n73 1\n22 1\n21 1\n98 1\n18 1\n51 1\n14 1\n76 1\n92 1\n80 1\n78 1\n33 1\n79 1\n89 1\n67 1\n9 1\n44 1\n60 1\n64 1\n55 1\n29 1\n100 1\n16 1\n87 1\n10 1\n12 1\n25 1\n85 1\n30 1\n63 1\n39 1\n38 1\n31 1\n5 1\n26 1\n91 1\n43 1\n72 1\n48 1\n94 1", "output": "1" }, { "input": "2 0", "output": "-1" } ]
1,505,658,442
4,942
Python 3
WRONG_ANSWER
PRETESTS
2
46
4,608,000
n, m = map(int,input().split()) a = [True] * 100 for i in range(m): x, y = map(int,input().split()) if y == 1: for j in range(x): a[j - 1] = False else: for j in range(x // y + 1 if x % y != 0 else x // y): for j in range(1, 101): if not(j * (y - 1) < x <= j * y): a[j - 1] = False vars = [] for i in range(1, n + 1): if a[i - 1]: for j in range(1, 101): if i * (j - 1) < n <= i * j: vars.append(j) break if len(vars) == 1: print(vars[0]) else: print(-1)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat *n*? Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory. *m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*f**i* (1<=≤<=*k**i*<=≤<=100, 1<=≤<=*f**i*<=≤<=100), which means that the flat *k**i* is on the *f**i*-th floor. All values *k**i* are distinct. It is guaranteed that the given information is not self-contradictory. Output Specification: Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. Demo Input: ['10 3\n6 2\n2 1\n7 3\n', '8 4\n3 1\n6 2\n5 2\n2 1\n'] Demo Output: ['4\n', '-1\n'] Note: In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
```python n, m = map(int,input().split()) a = [True] * 100 for i in range(m): x, y = map(int,input().split()) if y == 1: for j in range(x): a[j - 1] = False else: for j in range(x // y + 1 if x % y != 0 else x // y): for j in range(1, 101): if not(j * (y - 1) < x <= j * y): a[j - 1] = False vars = [] for i in range(1, n + 1): if a[i - 1]: for j in range(1, 101): if i * (j - 1) < n <= i * j: vars.append(j) break if len(vars) == 1: print(vars[0]) else: print(-1) ```
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,407,049,132
2,147,483,647
Python 3
OK
TESTS
50
124
0
n = int(input()) m = [int(i) for i in input().split(' ')] a,b = map(int,input().split(' ')) SUM = 0 for i in range(a-1,b-1): SUM += m[i] print(SUM)
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 n = int(input()) m = [int(i) for i in input().split(' ')] a,b = map(int,input().split(' ')) SUM = 0 for i in range(a-1,b-1): SUM += m[i] print(SUM) ```
3.969
747
A
Display Size
PROGRAMMING
800
[ "brute force", "math" ]
null
null
A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible.
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have.
Print two integers — the number of rows and columns on the display.
[ "8\n", "64\n", "5\n", "999999\n" ]
[ "2 4\n", "8 8\n", "1 5\n", "999 1001\n" ]
In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
500
[ { "input": "8", "output": "2 4" }, { "input": "64", "output": "8 8" }, { "input": "5", "output": "1 5" }, { "input": "999999", "output": "999 1001" }, { "input": "716539", "output": "97 7387" }, { "input": "1", "output": "1 1" }, { "input": "2", "output": "1 2" }, { "input": "3", "output": "1 3" }, { "input": "4", "output": "2 2" }, { "input": "6", "output": "2 3" }, { "input": "7", "output": "1 7" }, { "input": "9", "output": "3 3" }, { "input": "10", "output": "2 5" }, { "input": "11", "output": "1 11" }, { "input": "12", "output": "3 4" }, { "input": "15", "output": "3 5" }, { "input": "100", "output": "10 10" }, { "input": "101", "output": "1 101" }, { "input": "169", "output": "13 13" }, { "input": "179", "output": "1 179" }, { "input": "190", "output": "10 19" }, { "input": "1000", "output": "25 40" }, { "input": "10000", "output": "100 100" }, { "input": "10001", "output": "73 137" }, { "input": "100000", "output": "250 400" }, { "input": "100001", "output": "11 9091" }, { "input": "1000000", "output": "1000 1000" }, { "input": "999983", "output": "1 999983" }, { "input": "524288", "output": "512 1024" }, { "input": "954493", "output": "971 983" }, { "input": "966289", "output": "983 983" }, { "input": "944663", "output": "961 983" }, { "input": "912673", "output": "97 9409" }, { "input": "732641", "output": "679 1079" }, { "input": "232897", "output": "343 679" }, { "input": "16807", "output": "49 343" }, { "input": "999958", "output": "2 499979" }, { "input": "990151", "output": "1 990151" }, { "input": "997002", "output": "998 999" }, { "input": "20", "output": "4 5" }, { "input": "20261", "output": "1 20261" }, { "input": "999123", "output": "3 333041" }, { "input": "901841", "output": "1 901841" } ]
1,499,831,877
2,147,483,647
Python 3
OK
TESTS
43
77
5,529,600
import math while True: try: num = int(input()) ans = int(math.sqrt(num)) while True: if num % ans == 0: print(ans, num // ans) break else: ans -= 1 except EOFError: break
Title: Display Size Time Limit: None seconds Memory Limit: None megabytes Problem Description: A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≤<=*b*; - the difference *b*<=-<=*a* is as small as possible. Input Specification: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=106) — the number of pixels display should have. Output Specification: Print two integers — the number of rows and columns on the display. Demo Input: ['8\n', '64\n', '5\n', '999999\n'] Demo Output: ['2 4\n', '8 8\n', '1 5\n', '999 1001\n'] Note: In the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels. In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels. In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.
```python import math while True: try: num = int(input()) ans = int(math.sqrt(num)) while True: if num % ans == 0: print(ans, num // ans) break else: ans -= 1 except EOFError: break ```
3
986
A
Fair
PROGRAMMING
1,600
[ "graphs", "greedy", "number theory", "shortest paths" ]
null
null
Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads. There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s$ different types of goods. It costs $d(u,v)$ coins to bring goods from town $u$ to town $v$ where $d(u,v)$ is the length of the shortest path from $u$ to $v$. Length of a path is the number of roads in this path. The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $n$ towns.
There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le min(n, 100)$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le k$), where $a_i$ is the type of goods produced in the $i$-th town. It is guaranteed that all integers between $1$ and $k$ occur at least once among integers $a_{i}$. In the next $m$ lines roads are described. Each road is described by two integers $u$ $v$ ($1 \le u, v \le n$, $u \ne v$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.
Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces.
[ "5 5 4 3\n1 2 4 3 2\n1 2\n2 3\n3 4\n4 1\n4 5\n", "7 6 3 2\n1 2 3 3 2 2 1\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n" ]
[ "2 2 2 2 3 \n", "1 1 1 2 2 1 1 \n" ]
Let's look at the first sample. To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$. Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$. Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equals $2$. Town $4$: Goods from towns $4$ ($0$), $1$ ($1$), $5$ ($1$). Sum equals $2$. Town $5$: Goods from towns $5$ ($0$), $4$ ($1$), $3$ ($2$). Sum equals $3$.
500
[]
1,608,912,072
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
5
2,000
64,512,000
# Not my code # https://codeforces.com/contest/986/submission/102262061 # Template: https://codeforces.com/profile/kabeer27 from __future__ import division, print_function from collections import defaultdict,deque import math import io,os,sys #input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #out=__pypy__.builders.StringBuilder() from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def main(): n,m,k,s=map(int,input().split()) l=list(map(int,input().split())) graph=defaultdict(list) for j in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) ans=[[0 for i in range(k)]for j in range(n)] for c in range(1,k+1): temp=[100]*n d=deque() for i in range(n): if l[i]==c: temp[i]=0 d.append(i) while(len(d)>0): v=d.popleft() for i in graph[v]: if temp[v]+1<temp[i]: temp[i]=temp[v]+1 d.append(i) for i in range(n): ans[i][c-1]=temp[i] res=0 for i in range(n): ans[i].sort() res=sum(ans[i][:s]) print(res,end=' ') ######## Python 2 and 3 footer by Pajenegod and c1729 # Note because cf runs old PyPy3 version which doesn't have the sped up # unicode strings, PyPy3 strings will many times be slower than pypy2. # There is a way to get around this by using binary strings in PyPy3 # but its syntax is different which makes it kind of a mess to use. # So on cf, use PyPy2 for best string performance. py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: 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, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') main()
Title: Fair Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some company is going to hold a fair in Byteland. There are $n$ towns in Byteland and $m$ two-way roads between towns. Of course, you can reach any town from any other town using roads. There are $k$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $s$ different types of goods. It costs $d(u,v)$ coins to bring goods from town $u$ to town $v$ where $d(u,v)$ is the length of the shortest path from $u$ to $v$. Length of a path is the number of roads in this path. The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $n$ towns. Input Specification: There are $4$ integers $n$, $m$, $k$, $s$ in the first line of input ($1 \le n \le 10^{5}$, $0 \le m \le 10^{5}$, $1 \le s \le k \le min(n, 100)$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_{i} \le k$), where $a_i$ is the type of goods produced in the $i$-th town. It is guaranteed that all integers between $1$ and $k$ occur at least once among integers $a_{i}$. In the next $m$ lines roads are described. Each road is described by two integers $u$ $v$ ($1 \le u, v \le n$, $u \ne v$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads. Output Specification: Print $n$ numbers, the $i$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $i$. Separate numbers with spaces. Demo Input: ['5 5 4 3\n1 2 4 3 2\n1 2\n2 3\n3 4\n4 1\n4 5\n', '7 6 3 2\n1 2 3 3 2 2 1\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n'] Demo Output: ['2 2 2 2 3 \n', '1 1 1 2 2 1 1 \n'] Note: Let's look at the first sample. To hold a fair in town $1$ you can bring goods from towns $1$ ($0$ coins), $2$ ($1$ coin) and $4$ ($1$ coin). Total numbers of coins is $2$. Town $2$: Goods from towns $2$ ($0$), $1$ ($1$), $3$ ($1$). Sum equals $2$. Town $3$: Goods from towns $3$ ($0$), $2$ ($1$), $4$ ($1$). Sum equals $2$. Town $4$: Goods from towns $4$ ($0$), $1$ ($1$), $5$ ($1$). Sum equals $2$. Town $5$: Goods from towns $5$ ($0$), $4$ ($1$), $3$ ($2$). Sum equals $3$.
```python # Not my code # https://codeforces.com/contest/986/submission/102262061 # Template: https://codeforces.com/profile/kabeer27 from __future__ import division, print_function from collections import defaultdict,deque import math import io,os,sys #input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #out=__pypy__.builders.StringBuilder() from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def main(): n,m,k,s=map(int,input().split()) l=list(map(int,input().split())) graph=defaultdict(list) for j in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) ans=[[0 for i in range(k)]for j in range(n)] for c in range(1,k+1): temp=[100]*n d=deque() for i in range(n): if l[i]==c: temp[i]=0 d.append(i) while(len(d)>0): v=d.popleft() for i in graph[v]: if temp[v]+1<temp[i]: temp[i]=temp[v]+1 d.append(i) for i in range(n): ans[i][c-1]=temp[i] res=0 for i in range(n): ans[i].sort() res=sum(ans[i][:s]) print(res,end=' ') ######## Python 2 and 3 footer by Pajenegod and c1729 # Note because cf runs old PyPy3 version which doesn't have the sped up # unicode strings, PyPy3 strings will many times be slower than pypy2. # There is a way to get around this by using binary strings in PyPy3 # but its syntax is different which makes it kind of a mess to use. # So on cf, use PyPy2 for best string performance. py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: 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, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') main() ```
0
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,661,444,583
2,147,483,647
Python 3
OK
TESTS
76
46
0
n=int(input()) if n%2!=0: print(0) else: print(((n//2)-1)//2)
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python n=int(input()) if n%2!=0: print(0) else: print(((n//2)-1)//2) ```
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,696,915,715
2,147,483,647
PyPy 3-64
OK
TESTS
21
156
2,252,800
r = 0 for i in range(int(input())): if sum([int(i) for i in input().split(" ")]) >= 2: r+=1 print(r)
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 r = 0 for i in range(int(input())): if sum([int(i) for i in input().split(" ")]) >= 2: r+=1 print(r) ```
3
370
A
Rook, Bishop and King
PROGRAMMING
1,100
[ "graphs", "math", "shortest paths" ]
null
null
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem.
The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8.
Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number.
[ "4 3 1 6\n", "5 5 5 6\n" ]
[ "2 1 3\n", "1 0 1\n" ]
none
500
[ { "input": "4 3 1 6", "output": "2 1 3" }, { "input": "5 5 5 6", "output": "1 0 1" }, { "input": "1 1 8 8", "output": "2 1 7" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 1 1 8", "output": "1 0 7" }, { "input": "8 1 1 1", "output": "1 0 7" }, { "input": "8 1 1 8", "output": "2 1 7" }, { "input": "7 7 6 6", "output": "2 1 1" }, { "input": "8 1 8 8", "output": "1 0 7" }, { "input": "1 8 1 1", "output": "1 0 7" }, { "input": "1 8 8 1", "output": "2 1 7" }, { "input": "1 8 8 8", "output": "1 0 7" }, { "input": "8 8 1 1", "output": "2 1 7" }, { "input": "8 8 1 8", "output": "1 0 7" }, { "input": "8 8 8 1", "output": "1 0 7" }, { "input": "1 3 1 6", "output": "1 0 3" }, { "input": "1 3 1 4", "output": "1 0 1" }, { "input": "1 3 1 5", "output": "1 2 2" }, { "input": "3 3 2 4", "output": "2 1 1" }, { "input": "3 3 1 5", "output": "2 1 2" }, { "input": "1 6 2 1", "output": "2 2 5" }, { "input": "1 5 6 4", "output": "2 2 5" }, { "input": "1 3 3 7", "output": "2 2 4" }, { "input": "1 1 8 1", "output": "1 0 7" }, { "input": "1 7 5 4", "output": "2 0 4" }, { "input": "1 5 2 7", "output": "2 0 2" }, { "input": "1 4 6 2", "output": "2 0 5" }, { "input": "1 2 3 5", "output": "2 0 3" }, { "input": "1 8 8 7", "output": "2 2 7" }, { "input": "6 5 6 2", "output": "1 0 3" }, { "input": "6 3 3 5", "output": "2 0 3" }, { "input": "6 1 7 8", "output": "2 2 7" }, { "input": "1 2 3 2", "output": "1 2 2" }, { "input": "3 8 7 2", "output": "2 2 6" }, { "input": "4 2 6 4", "output": "2 1 2" }, { "input": "1 1 1 3", "output": "1 2 2" }, { "input": "6 8 8 6", "output": "2 1 2" }, { "input": "6 7 4 1", "output": "2 2 6" }, { "input": "6 5 1 4", "output": "2 2 5" }, { "input": "3 2 7 6", "output": "2 1 4" }, { "input": "3 8 4 1", "output": "2 2 7" }, { "input": "3 6 1 4", "output": "2 1 2" } ]
1,571,164,347
2,147,483,647
Python 3
OK
TESTS
42
124
0
def solve_king(r1, c1, r2, c2): return max(abs(r1-r2), abs(c1-c2)) def solve_rook(r1, c1, r2, c2): return (r1 != r2) + (c1 != c2) def solve_elephant(r1, c1, r2, c2): if (r1 + c1)%2 == (r2 + c2)%2: return 1 + (abs(r1-r2) != abs(c1-c2)) return 0 def solve(r1, c1, r2, c2): king = solve_king(r1, c1, r2, c2) rook = solve_rook(r1, c1, r2, c2) elephant = solve_elephant(r1, c1, r2, c2) return f'{rook} {elephant} {king}' r1, r2, c1, c2 = map(int, input().split()) print(solve(r1, r2, c1, c2))
Title: Rook, Bishop and King Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=×<=8 table. A field is represented by a pair of integers (*r*,<=*c*) — the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction — horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. Input Specification: The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≤<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≤<=8) — the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. Output Specification: Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Demo Input: ['4 3 1 6\n', '5 5 5 6\n'] Demo Output: ['2 1 3\n', '1 0 1\n'] Note: none
```python def solve_king(r1, c1, r2, c2): return max(abs(r1-r2), abs(c1-c2)) def solve_rook(r1, c1, r2, c2): return (r1 != r2) + (c1 != c2) def solve_elephant(r1, c1, r2, c2): if (r1 + c1)%2 == (r2 + c2)%2: return 1 + (abs(r1-r2) != abs(c1-c2)) return 0 def solve(r1, c1, r2, c2): king = solve_king(r1, c1, r2, c2) rook = solve_rook(r1, c1, r2, c2) elephant = solve_elephant(r1, c1, r2, c2) return f'{rook} {elephant} {king}' r1, r2, c1, c2 = map(int, input().split()) print(solve(r1, r2, c1, c2)) ```
3
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\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", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,685,770,751
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
2
92
0
def main(): take = input().split() n = int(take[0]) m = int(take[1]) lst = input().split() for i in range(len(lst)): lst[i] = int(lst[i]) lst.sort() current = 0 minimum = lst[current + n - 1] - lst[current] while current + n != len(lst): if minimum < lst[current + n - 1] - lst[current]: minimum = lst[current + n - 1] - lst[current] current += 1 print(minimum) main()
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python def main(): take = input().split() n = int(take[0]) m = int(take[1]) lst = input().split() for i in range(len(lst)): lst[i] = int(lst[i]) lst.sort() current = 0 minimum = lst[current + n - 1] - lst[current] while current + n != len(lst): if minimum < lst[current + n - 1] - lst[current]: minimum = lst[current + n - 1] - lst[current] current += 1 print(minimum) main() ```
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,629,347,493
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
154
20,172,800
n,a=int(input()),list(map(int,input().split())) temp=sum(a)-sum(a)//(n+1)*(n+1) if temp==0:print(temp+2) else:print(1)
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 n,a=int(input()),list(map(int,input().split())) temp=sum(a)-sum(a)//(n+1)*(n+1) if temp==0:print(temp+2) else:print(1) ```
0
460
A
Vasya and Socks
PROGRAMMING
900
[ "brute force", "implementation", "math" ]
null
null
Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks?
The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space.
Print a single integer — the answer to the problem.
[ "2 2\n", "9 3\n" ]
[ "3\n", "13\n" ]
In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
500
[ { "input": "2 2", "output": "3" }, { "input": "9 3", "output": "13" }, { "input": "1 2", "output": "1" }, { "input": "2 3", "output": "2" }, { "input": "1 99", "output": "1" }, { "input": "4 4", "output": "5" }, { "input": "10 2", "output": "19" }, { "input": "10 9", "output": "11" }, { "input": "100 100", "output": "101" }, { "input": "2 27", "output": "2" }, { "input": "99 100", "output": "99" }, { "input": "99 2", "output": "197" }, { "input": "100 3", "output": "149" }, { "input": "98 3", "output": "146" }, { "input": "4 4", "output": "5" }, { "input": "100 2", "output": "199" }, { "input": "62 4", "output": "82" }, { "input": "99 10", "output": "109" }, { "input": "100 5", "output": "124" }, { "input": "80 80", "output": "81" }, { "input": "95 16", "output": "101" }, { "input": "75 16", "output": "79" }, { "input": "99 74", "output": "100" }, { "input": "20 21", "output": "20" }, { "input": "52 96", "output": "52" }, { "input": "24 5", "output": "29" } ]
1,663,752,998
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a,b=map(int,input().split()) n=a*b if n%2!=0: n+=1 res=n//2-1 print(res)
Title: Vasya and Socks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? Input Specification: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. Output Specification: Print a single integer — the answer to the problem. Demo Input: ['2 2\n', '9 3\n'] Demo Output: ['3\n', '13\n'] Note: In the first sample Vasya spends the first two days wearing the socks that he had initially. Then on day three he puts on the socks that were bought on day two. In the second sample Vasya spends the first nine days wearing the socks that he had initially. Then he spends three days wearing the socks that were bought on the third, sixth and ninth days. Than he spends another day wearing the socks that were bought on the twelfth day.
```python a,b=map(int,input().split()) n=a*b if n%2!=0: n+=1 res=n//2-1 print(res) ```
0
32
B
Borze
PROGRAMMING
800
[ "expression parsing", "implementation" ]
B. Borze
2
256
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.
The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).
Output the decoded ternary number. It can have leading zeroes.
[ ".-.--\n", "--.\n", "-..-.--\n" ]
[ "012", "20", "1012" ]
none
1,000
[ { "input": ".-.--", "output": "012" }, { "input": "--.", "output": "20" }, { "input": "-..-.--", "output": "1012" }, { "input": "---..", "output": "210" }, { "input": "..--.---..", "output": "0020210" }, { "input": "-.....----.", "output": "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,680,851,575
2,147,483,647
Python 3
OK
TESTS
30
92
0
n = input() m = "" k = "" for i in n: if i == "."and len(m) == 0: k += "0" else: m += i if len(m) == 2: if m == "-.": k += "1" m = "" else: k += "2" m = "" print(k)
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 n = input() m = "" k = "" for i in n: if i == "."and len(m) == 0: k += "0" else: m += i if len(m) == 2: if m == "-.": k += "1" m = "" else: k += "2" m = "" print(k) ```
3.977
660
C
Hard Process
PROGRAMMING
1,600
[ "binary search", "dp", "two pointers" ]
null
null
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*).
The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*.
On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them.
[ "7 1\n1 0 0 1 1 0 1\n", "10 2\n1 0 0 1 0 1 0 1 0 1\n" ]
[ "4\n1 0 0 1 1 1 1\n", "5\n1 0 0 1 1 1 1 1 0 1\n" ]
none
0
[ { "input": "7 1\n1 0 0 1 1 0 1", "output": "4\n1 0 0 1 1 1 1" }, { "input": "10 2\n1 0 0 1 0 1 0 1 0 1", "output": "5\n1 0 0 1 1 1 1 1 0 1" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "1 0\n0", "output": "0\n0" }, { "input": "7 0\n0 1 0 0 0 1 0", "output": "1\n0 1 0 0 0 1 0" }, { "input": "7 2\n1 0 1 1 0 0 0", "output": "5\n1 1 1 1 1 0 0" }, { "input": "7 3\n1 0 0 0 0 1 0", "output": "4\n1 1 1 1 0 1 0" }, { "input": "3 0\n1 1 1", "output": "3\n1 1 1" }, { "input": "1 0\n1", "output": "1\n1" }, { "input": "2 0\n0 1", "output": "1\n0 1" }, { "input": "1 1\n0", "output": "1\n1" }, { "input": "3 1\n0 0 1", "output": "2\n0 1 1" }, { "input": "2 0\n0 0", "output": "0\n0 0" }, { "input": "3 1\n0 0 0", "output": "1\n1 0 0" }, { "input": "7 7\n1 0 1 0 0 0 0", "output": "7\n1 1 1 1 1 1 1" }, { "input": "1 1\n1", "output": "1\n1" }, { "input": "3 0\n0 0 0", "output": "0\n0 0 0" }, { "input": "7 3\n1 1 1 1 1 1 1", "output": "7\n1 1 1 1 1 1 1" }, { "input": "10 3\n0 0 1 0 0 1 0 0 1 1", "output": "6\n0 0 1 0 1 1 1 1 1 1" }, { "input": "2 1\n0 0", "output": "1\n1 0" }, { "input": "2 2\n1 0", "output": "2\n1 1" } ]
1,691,808,985
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
def maximize_consecutive_ones(ar, n, k): left, right = 0, 0 max_length = 0 zeros_count = 0 while right < n: if ar[right] == 0: zeros_count += 1 while zeros_count > k: if ar[left] == 0: zeros_count -= 1 left += 1 max_length = max(max_length, right - left + 1) right += 1 return max_length def main(): n, k = map(int, input().split()) ar = list(map(int, input().split())) result = maximize_consecutive_ones(ar, n, k) print(result) # Modify the array to maximize f(a) left, right = 0, 0 zeros_count = 0 while right < n: if ar[right] == 0: zeros_count += 1 while zeros_count > k: if ar[left] == 0: zeros_count -= 1 left += 1 if right - left + 1 == result: for i in range(left, right + 1): ar[i] = 1 break right += 1 print(*ar) if _name_ == "_main_": main()
Title: Hard Process Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. Output Specification: On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones. On the second line print *n* integers *a**j* — the elements of the array *a* after the changes. If there are multiple answers, you can print any one of them. Demo Input: ['7 1\n1 0 0 1 1 0 1\n', '10 2\n1 0 0 1 0 1 0 1 0 1\n'] Demo Output: ['4\n1 0 0 1 1 1 1\n', '5\n1 0 0 1 1 1 1 1 0 1\n'] Note: none
```python def maximize_consecutive_ones(ar, n, k): left, right = 0, 0 max_length = 0 zeros_count = 0 while right < n: if ar[right] == 0: zeros_count += 1 while zeros_count > k: if ar[left] == 0: zeros_count -= 1 left += 1 max_length = max(max_length, right - left + 1) right += 1 return max_length def main(): n, k = map(int, input().split()) ar = list(map(int, input().split())) result = maximize_consecutive_ones(ar, n, k) print(result) # Modify the array to maximize f(a) left, right = 0, 0 zeros_count = 0 while right < n: if ar[right] == 0: zeros_count += 1 while zeros_count > k: if ar[left] == 0: zeros_count -= 1 left += 1 if right - left + 1 == result: for i in range(left, right + 1): ar[i] = 1 break right += 1 print(*ar) if _name_ == "_main_": main() ```
-1
53
C
Little Frog
PROGRAMMING
1,200
[ "constructive algorithms" ]
C. Little Frog
2
256
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him.
The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds.
Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any.
[ "2\n", "3\n" ]
[ "1 2 ", "1 3 2 " ]
none
1,500
[ { "input": "2", "output": "1 2 " }, { "input": "3", "output": "1 3 2 " }, { "input": "4", "output": "1 4 2 3 " }, { "input": "5", "output": "1 5 2 4 3 " }, { "input": "6", "output": "1 6 2 5 3 4 " }, { "input": "1", "output": "1 " }, { "input": "9149", "output": "1 9149 2 9148 3 9147 4 9146 5 9145 6 9144 7 9143 8 9142 9 9141 10 9140 11 9139 12 9138 13 9137 14 9136 15 9135 16 9134 17 9133 18 9132 19 9131 20 9130 21 9129 22 9128 23 9127 24 9126 25 9125 26 9124 27 9123 28 9122 29 9121 30 9120 31 9119 32 9118 33 9117 34 9116 35 9115 36 9114 37 9113 38 9112 39 9111 40 9110 41 9109 42 9108 43 9107 44 9106 45 9105 46 9104 47 9103 48 9102 49 9101 50 9100 51 9099 52 9098 53 9097 54 9096 55 9095 56 9094 57 9093 58 9092 59 9091 60 9090 61 9089 62 9088 63 9087 64 9086 65 9085 ..." }, { "input": "2877", "output": "1 2877 2 2876 3 2875 4 2874 5 2873 6 2872 7 2871 8 2870 9 2869 10 2868 11 2867 12 2866 13 2865 14 2864 15 2863 16 2862 17 2861 18 2860 19 2859 20 2858 21 2857 22 2856 23 2855 24 2854 25 2853 26 2852 27 2851 28 2850 29 2849 30 2848 31 2847 32 2846 33 2845 34 2844 35 2843 36 2842 37 2841 38 2840 39 2839 40 2838 41 2837 42 2836 43 2835 44 2834 45 2833 46 2832 47 2831 48 2830 49 2829 50 2828 51 2827 52 2826 53 2825 54 2824 55 2823 56 2822 57 2821 58 2820 59 2819 60 2818 61 2817 62 2816 63 2815 64 2814 65 2813 ..." }, { "input": "2956", "output": "1 2956 2 2955 3 2954 4 2953 5 2952 6 2951 7 2950 8 2949 9 2948 10 2947 11 2946 12 2945 13 2944 14 2943 15 2942 16 2941 17 2940 18 2939 19 2938 20 2937 21 2936 22 2935 23 2934 24 2933 25 2932 26 2931 27 2930 28 2929 29 2928 30 2927 31 2926 32 2925 33 2924 34 2923 35 2922 36 2921 37 2920 38 2919 39 2918 40 2917 41 2916 42 2915 43 2914 44 2913 45 2912 46 2911 47 2910 48 2909 49 2908 50 2907 51 2906 52 2905 53 2904 54 2903 55 2902 56 2901 57 2900 58 2899 59 2898 60 2897 61 2896 62 2895 63 2894 64 2893 65 2892 ..." }, { "input": "3035", "output": "1 3035 2 3034 3 3033 4 3032 5 3031 6 3030 7 3029 8 3028 9 3027 10 3026 11 3025 12 3024 13 3023 14 3022 15 3021 16 3020 17 3019 18 3018 19 3017 20 3016 21 3015 22 3014 23 3013 24 3012 25 3011 26 3010 27 3009 28 3008 29 3007 30 3006 31 3005 32 3004 33 3003 34 3002 35 3001 36 3000 37 2999 38 2998 39 2997 40 2996 41 2995 42 2994 43 2993 44 2992 45 2991 46 2990 47 2989 48 2988 49 2987 50 2986 51 2985 52 2984 53 2983 54 2982 55 2981 56 2980 57 2979 58 2978 59 2977 60 2976 61 2975 62 2974 63 2973 64 2972 65 2971 ..." }, { "input": "3114", "output": "1 3114 2 3113 3 3112 4 3111 5 3110 6 3109 7 3108 8 3107 9 3106 10 3105 11 3104 12 3103 13 3102 14 3101 15 3100 16 3099 17 3098 18 3097 19 3096 20 3095 21 3094 22 3093 23 3092 24 3091 25 3090 26 3089 27 3088 28 3087 29 3086 30 3085 31 3084 32 3083 33 3082 34 3081 35 3080 36 3079 37 3078 38 3077 39 3076 40 3075 41 3074 42 3073 43 3072 44 3071 45 3070 46 3069 47 3068 48 3067 49 3066 50 3065 51 3064 52 3063 53 3062 54 3061 55 3060 56 3059 57 3058 58 3057 59 3056 60 3055 61 3054 62 3053 63 3052 64 3051 65 3050 ..." }, { "input": "3193", "output": "1 3193 2 3192 3 3191 4 3190 5 3189 6 3188 7 3187 8 3186 9 3185 10 3184 11 3183 12 3182 13 3181 14 3180 15 3179 16 3178 17 3177 18 3176 19 3175 20 3174 21 3173 22 3172 23 3171 24 3170 25 3169 26 3168 27 3167 28 3166 29 3165 30 3164 31 3163 32 3162 33 3161 34 3160 35 3159 36 3158 37 3157 38 3156 39 3155 40 3154 41 3153 42 3152 43 3151 44 3150 45 3149 46 3148 47 3147 48 3146 49 3145 50 3144 51 3143 52 3142 53 3141 54 3140 55 3139 56 3138 57 3137 58 3136 59 3135 60 3134 61 3133 62 3132 63 3131 64 3130 65 3129 ..." }, { "input": "3273", "output": "1 3273 2 3272 3 3271 4 3270 5 3269 6 3268 7 3267 8 3266 9 3265 10 3264 11 3263 12 3262 13 3261 14 3260 15 3259 16 3258 17 3257 18 3256 19 3255 20 3254 21 3253 22 3252 23 3251 24 3250 25 3249 26 3248 27 3247 28 3246 29 3245 30 3244 31 3243 32 3242 33 3241 34 3240 35 3239 36 3238 37 3237 38 3236 39 3235 40 3234 41 3233 42 3232 43 3231 44 3230 45 3229 46 3228 47 3227 48 3226 49 3225 50 3224 51 3223 52 3222 53 3221 54 3220 55 3219 56 3218 57 3217 58 3216 59 3215 60 3214 61 3213 62 3212 63 3211 64 3210 65 3209 ..." }, { "input": "7000", "output": "1 7000 2 6999 3 6998 4 6997 5 6996 6 6995 7 6994 8 6993 9 6992 10 6991 11 6990 12 6989 13 6988 14 6987 15 6986 16 6985 17 6984 18 6983 19 6982 20 6981 21 6980 22 6979 23 6978 24 6977 25 6976 26 6975 27 6974 28 6973 29 6972 30 6971 31 6970 32 6969 33 6968 34 6967 35 6966 36 6965 37 6964 38 6963 39 6962 40 6961 41 6960 42 6959 43 6958 44 6957 45 6956 46 6955 47 6954 48 6953 49 6952 50 6951 51 6950 52 6949 53 6948 54 6947 55 6946 56 6945 57 6944 58 6943 59 6942 60 6941 61 6940 62 6939 63 6938 64 6937 65 6936 ..." }, { "input": "7079", "output": "1 7079 2 7078 3 7077 4 7076 5 7075 6 7074 7 7073 8 7072 9 7071 10 7070 11 7069 12 7068 13 7067 14 7066 15 7065 16 7064 17 7063 18 7062 19 7061 20 7060 21 7059 22 7058 23 7057 24 7056 25 7055 26 7054 27 7053 28 7052 29 7051 30 7050 31 7049 32 7048 33 7047 34 7046 35 7045 36 7044 37 7043 38 7042 39 7041 40 7040 41 7039 42 7038 43 7037 44 7036 45 7035 46 7034 47 7033 48 7032 49 7031 50 7030 51 7029 52 7028 53 7027 54 7026 55 7025 56 7024 57 7023 58 7022 59 7021 60 7020 61 7019 62 7018 63 7017 64 7016 65 7015 ..." }, { "input": "4653", "output": "1 4653 2 4652 3 4651 4 4650 5 4649 6 4648 7 4647 8 4646 9 4645 10 4644 11 4643 12 4642 13 4641 14 4640 15 4639 16 4638 17 4637 18 4636 19 4635 20 4634 21 4633 22 4632 23 4631 24 4630 25 4629 26 4628 27 4627 28 4626 29 4625 30 4624 31 4623 32 4622 33 4621 34 4620 35 4619 36 4618 37 4617 38 4616 39 4615 40 4614 41 4613 42 4612 43 4611 44 4610 45 4609 46 4608 47 4607 48 4606 49 4605 50 4604 51 4603 52 4602 53 4601 54 4600 55 4599 56 4598 57 4597 58 4596 59 4595 60 4594 61 4593 62 4592 63 4591 64 4590 65 4589 ..." }, { "input": "9995", "output": "1 9995 2 9994 3 9993 4 9992 5 9991 6 9990 7 9989 8 9988 9 9987 10 9986 11 9985 12 9984 13 9983 14 9982 15 9981 16 9980 17 9979 18 9978 19 9977 20 9976 21 9975 22 9974 23 9973 24 9972 25 9971 26 9970 27 9969 28 9968 29 9967 30 9966 31 9965 32 9964 33 9963 34 9962 35 9961 36 9960 37 9959 38 9958 39 9957 40 9956 41 9955 42 9954 43 9953 44 9952 45 9951 46 9950 47 9949 48 9948 49 9947 50 9946 51 9945 52 9944 53 9943 54 9942 55 9941 56 9940 57 9939 58 9938 59 9937 60 9936 61 9935 62 9934 63 9933 64 9932 65 9931 ..." }, { "input": "9996", "output": "1 9996 2 9995 3 9994 4 9993 5 9992 6 9991 7 9990 8 9989 9 9988 10 9987 11 9986 12 9985 13 9984 14 9983 15 9982 16 9981 17 9980 18 9979 19 9978 20 9977 21 9976 22 9975 23 9974 24 9973 25 9972 26 9971 27 9970 28 9969 29 9968 30 9967 31 9966 32 9965 33 9964 34 9963 35 9962 36 9961 37 9960 38 9959 39 9958 40 9957 41 9956 42 9955 43 9954 44 9953 45 9952 46 9951 47 9950 48 9949 49 9948 50 9947 51 9946 52 9945 53 9944 54 9943 55 9942 56 9941 57 9940 58 9939 59 9938 60 9937 61 9936 62 9935 63 9934 64 9933 65 9932 ..." }, { "input": "9997", "output": "1 9997 2 9996 3 9995 4 9994 5 9993 6 9992 7 9991 8 9990 9 9989 10 9988 11 9987 12 9986 13 9985 14 9984 15 9983 16 9982 17 9981 18 9980 19 9979 20 9978 21 9977 22 9976 23 9975 24 9974 25 9973 26 9972 27 9971 28 9970 29 9969 30 9968 31 9967 32 9966 33 9965 34 9964 35 9963 36 9962 37 9961 38 9960 39 9959 40 9958 41 9957 42 9956 43 9955 44 9954 45 9953 46 9952 47 9951 48 9950 49 9949 50 9948 51 9947 52 9946 53 9945 54 9944 55 9943 56 9942 57 9941 58 9940 59 9939 60 9938 61 9937 62 9936 63 9935 64 9934 65 9933 ..." }, { "input": "9998", "output": "1 9998 2 9997 3 9996 4 9995 5 9994 6 9993 7 9992 8 9991 9 9990 10 9989 11 9988 12 9987 13 9986 14 9985 15 9984 16 9983 17 9982 18 9981 19 9980 20 9979 21 9978 22 9977 23 9976 24 9975 25 9974 26 9973 27 9972 28 9971 29 9970 30 9969 31 9968 32 9967 33 9966 34 9965 35 9964 36 9963 37 9962 38 9961 39 9960 40 9959 41 9958 42 9957 43 9956 44 9955 45 9954 46 9953 47 9952 48 9951 49 9950 50 9949 51 9948 52 9947 53 9946 54 9945 55 9944 56 9943 57 9942 58 9941 59 9940 60 9939 61 9938 62 9937 63 9936 64 9935 65 9934 ..." }, { "input": "9999", "output": "1 9999 2 9998 3 9997 4 9996 5 9995 6 9994 7 9993 8 9992 9 9991 10 9990 11 9989 12 9988 13 9987 14 9986 15 9985 16 9984 17 9983 18 9982 19 9981 20 9980 21 9979 22 9978 23 9977 24 9976 25 9975 26 9974 27 9973 28 9972 29 9971 30 9970 31 9969 32 9968 33 9967 34 9966 35 9965 36 9964 37 9963 38 9962 39 9961 40 9960 41 9959 42 9958 43 9957 44 9956 45 9955 46 9954 47 9953 48 9952 49 9951 50 9950 51 9949 52 9948 53 9947 54 9946 55 9945 56 9944 57 9943 58 9942 59 9941 60 9940 61 9939 62 9938 63 9937 64 9936 65 9935 ..." }, { "input": "10000", "output": "1 10000 2 9999 3 9998 4 9997 5 9996 6 9995 7 9994 8 9993 9 9992 10 9991 11 9990 12 9989 13 9988 14 9987 15 9986 16 9985 17 9984 18 9983 19 9982 20 9981 21 9980 22 9979 23 9978 24 9977 25 9976 26 9975 27 9974 28 9973 29 9972 30 9971 31 9970 32 9969 33 9968 34 9967 35 9966 36 9965 37 9964 38 9963 39 9962 40 9961 41 9960 42 9959 43 9958 44 9957 45 9956 46 9955 47 9954 48 9953 49 9952 50 9951 51 9950 52 9949 53 9948 54 9947 55 9946 56 9945 57 9944 58 9943 59 9942 60 9941 61 9940 62 9939 63 9938 64 9937 65 9936..." } ]
1,609,922,344
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
307,200
mounds = int(input()) m = list(range(1,mounds+1)) m1 = [1] m.remove(1) for i in range(1,len(m)+1): if i%2==1: m1.append(max(m)) m.remove(max(m)) else: m1.append(min(m)) m.remove(min(m)) print(' '.join(map(str,m1)))
Title: Little Frog Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For that he makes a route plan, to decide the order in which to jump on the mounds. Vasya can pick any mound as the first one. He thinks it boring to jump two times at the same distance. That's why he wants any two jumps on his route to have different lengths. Help Vasya the Frog and make the plan for him. Input Specification: The single line contains a number *n* (1<=≤<=*n*<=≤<=104) which is the number of mounds. Output Specification: Print *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) which are the frog's route plan. - All the *p**i*'s should be mutually different. - All the |*p**i*–*p**i*<=+<=1|'s should be mutually different (1<=≤<=*i*<=≤<=*n*<=-<=1). If there are several solutions, output any. Demo Input: ['2\n', '3\n'] Demo Output: ['1 2 ', '1 3 2 '] Note: none
```python mounds = int(input()) m = list(range(1,mounds+1)) m1 = [1] m.remove(1) for i in range(1,len(m)+1): if i%2==1: m1.append(max(m)) m.remove(max(m)) else: m1.append(min(m)) m.remove(min(m)) print(' '.join(map(str,m1))) ```
0
165
A
Supercentral Point
PROGRAMMING
1,000
[ "implementation" ]
null
null
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.
The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.
Print the only number — the number of supercentral points of the given set.
[ "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n", "5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n" ]
[ "2\n", "1\n" ]
In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
500
[ { "input": "8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3", "output": "2" }, { "input": "5\n0 0\n0 1\n1 0\n0 -1\n-1 0", "output": "1" }, { "input": "9\n-565 -752\n-184 723\n-184 -752\n-184 1\n950 723\n-565 723\n950 -752\n950 1\n-565 1", "output": "1" }, { "input": "25\n-651 897\n916 897\n-651 -808\n-748 301\n-734 414\n-651 -973\n-734 897\n916 -550\n-758 414\n916 180\n-758 -808\n-758 -973\n125 -550\n125 -973\n125 301\n916 414\n-748 -808\n-651 301\n-734 301\n-307 897\n-651 -550\n-651 414\n125 -808\n-748 -550\n916 -808", "output": "7" }, { "input": "1\n487 550", "output": "0" }, { "input": "10\n990 -396\n990 736\n990 646\n990 -102\n990 -570\n990 155\n990 528\n990 489\n990 268\n990 676", "output": "0" }, { "input": "30\n507 836\n525 836\n-779 196\n507 -814\n525 -814\n525 42\n525 196\n525 -136\n-779 311\n507 -360\n525 300\n507 578\n507 311\n-779 836\n507 300\n525 -360\n525 311\n-779 -360\n-779 578\n-779 300\n507 42\n525 578\n-779 379\n507 196\n525 379\n507 379\n-779 -814\n-779 42\n-779 -136\n507 -136", "output": "8" }, { "input": "25\n890 -756\n890 -188\n-37 -756\n-37 853\n523 998\n-261 853\n-351 853\n-351 -188\n523 -756\n-261 -188\n-37 998\n523 -212\n-351 998\n-37 -188\n-351 -756\n-37 -212\n890 998\n890 -212\n523 853\n-351 -212\n-261 -212\n-261 998\n-261 -756\n890 853\n523 -188", "output": "9" }, { "input": "21\n-813 -11\n486 254\n685 254\n-708 254\n-55 -11\n-671 -191\n486 -11\n-671 -11\n685 -11\n685 -191\n486 -191\n-55 254\n-708 -11\n-813 254\n-708 -191\n41 -11\n-671 254\n-813 -191\n41 254\n-55 -191\n41 -191", "output": "5" }, { "input": "4\n1 0\n2 0\n1 1\n1 -1", "output": "0" } ]
1,620,315,522
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
92
6,963,200
n = int(input()) l_c = list() for _ in range(n): l_c.append(list(map(int, input().split()))) t = 0 for i in range(n): s_i = set() for j in range(n): if i == j: pass elif l_c[i][0] == l_c[j][0]: if l_c[i][1] > l_c[j][1]: s_i.add("D") elif l_c[i][1] < l_c[j][1]: s_i.add("U") elif l_c[i][1] == l_c[j][1]: if l_c[i][0] > l_c[j][0]: s_i.add("L") elif l_c[i][0] < l_c[j][0]: s_i.add("R") if len(s_i) == 4: t += 1
Title: Supercentral Point Time Limit: None seconds Memory Limit: None megabytes Problem Description: One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (*x*1,<=*y*1),<=(*x*2,<=*y*2),<=...,<=(*x**n*,<=*y**n*). Let's define neighbors for some fixed point from the given set (*x*,<=*y*): - point (*x*',<=*y*') is (*x*,<=*y*)'s right neighbor, if *x*'<=&gt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s left neighbor, if *x*'<=&lt;<=*x* and *y*'<==<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s lower neighbor, if *x*'<==<=*x* and *y*'<=&lt;<=*y* - point (*x*',<=*y*') is (*x*,<=*y*)'s upper neighbor, if *x*'<==<=*x* and *y*'<=&gt;<=*y* We'll consider point (*x*,<=*y*) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points. Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set. Input Specification: The first input line contains the only integer *n* (1<=≤<=*n*<=≤<=200) — the number of points in the given set. Next *n* lines contain the coordinates of the points written as "*x* *y*" (without the quotes) (|*x*|,<=|*y*|<=≤<=1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different. Output Specification: Print the only number — the number of supercentral points of the given set. Demo Input: ['8\n1 1\n4 2\n3 1\n1 2\n0 2\n0 1\n1 0\n1 3\n', '5\n0 0\n0 1\n1 0\n0 -1\n-1 0\n'] Demo Output: ['2\n', '1\n'] Note: In the first sample the supercentral points are only points (1, 1) and (1, 2). In the second sample there is one supercental point — point (0, 0).
```python n = int(input()) l_c = list() for _ in range(n): l_c.append(list(map(int, input().split()))) t = 0 for i in range(n): s_i = set() for j in range(n): if i == j: pass elif l_c[i][0] == l_c[j][0]: if l_c[i][1] > l_c[j][1]: s_i.add("D") elif l_c[i][1] < l_c[j][1]: s_i.add("U") elif l_c[i][1] == l_c[j][1]: if l_c[i][0] > l_c[j][0]: s_i.add("L") elif l_c[i][0] < l_c[j][0]: s_i.add("R") if len(s_i) == 4: t += 1 ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "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,673,468,514
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
n=input() f = n.split(" ") n=int(f[0]) m=int(f[1]) a=int(f[2]) if n>m: print(int((n*a)/m)) else: print(int((m*a)/a))
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=input() f = n.split(" ") n=int(f[0]) m=int(f[1]) a=int(f[2]) if n>m: print(int((n*a)/m)) else: print(int((m*a)/a)) ```
0
604
B
More Cowbell
PROGRAMMING
1,400
[ "binary search", "greedy" ]
null
null
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=&gt;<=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively. The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
[ "2 1\n2 5\n", "4 3\n2 3 5 9\n", "3 2\n3 5 7\n" ]
[ "7\n", "9\n", "8\n" ]
In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}. In the third sample, the optimal solution is {3, 5} and {7}.
1,000
[ { "input": "2 1\n2 5", "output": "7" }, { "input": "4 3\n2 3 5 9", "output": "9" }, { "input": "3 2\n3 5 7", "output": "8" }, { "input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 10\n3 15 31 61 63 63 68 94 98 100", "output": "100" }, { "input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983", "output": "9983" }, { "input": "10 9\n7 29 35 38 41 47 54 56 73 74", "output": "74" }, { "input": "1 2342\n12345", "output": "12345" }, { "input": "10 5\n15 15 20 28 38 44 46 52 69 94", "output": "109" }, { "input": "10 9\n6 10 10 32 36 38 69 80 82 93", "output": "93" }, { "input": "10 10\n4 19 22 24 25 43 49 56 78 88", "output": "88" }, { "input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946", "output": "9946" }, { "input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986", "output": "9986" }, { "input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927", "output": "9927" }, { "input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970", "output": "9970" }, { "input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993", "output": "11103" }, { "input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983", "output": "10676" }, { "input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866", "output": "10011" }, { "input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804", "output": "10009" }, { "input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934", "output": "9934" }, { "input": "1 50000\n2", "output": "2" }, { "input": "1 40000\n23456", "output": "23456" }, { "input": "1 2\n10", "output": "10" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 2\n2 3", "output": "3" }, { "input": "4 2\n1 2 8 9", "output": "10" } ]
1,660,937,061
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
1,575
6,553,600
n, k = list(map(int, input().split())) sizes = list(map(int, input().split())) left, right = max(sizes), sum(sizes) while left < right: mid = (left + right) // 2 counter, valid = 0, True i = 0 while i < len(sizes) - 1: if sizes[i] + sizes[i + 1] <= mid: i += 2 else: i += 1 counter += 1 if i == len(sizes) - 1: counter += 1 if counter <= k: right = mid else: left = mid + 1 print(right)
Title: More Cowbell Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=&gt;<=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. Input Specification: The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively. The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. Output Specification: Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. Demo Input: ['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n'] Demo Output: ['7\n', '9\n', '8\n'] Note: In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}. In the third sample, the optimal solution is {3, 5} and {7}.
```python n, k = list(map(int, input().split())) sizes = list(map(int, input().split())) left, right = max(sizes), sum(sizes) while left < right: mid = (left + right) // 2 counter, valid = 0, True i = 0 while i < len(sizes) - 1: if sizes[i] + sizes[i + 1] <= mid: i += 2 else: i += 1 counter += 1 if i == len(sizes) - 1: counter += 1 if counter <= k: right = mid else: left = mid + 1 print(right) ```
0
20
C
Dijkstra?
PROGRAMMING
1,900
[ "graphs", "shortest paths" ]
C. Dijkstra?
1
64
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices.
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
[ "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n" ]
[ "1 4 3 5 ", "1 4 3 5 " ]
none
1,500
[ { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5 " }, { "input": "2 1\n1 2 1", "output": "1 2 " }, { "input": "3 1\n1 2 1", "output": "-1" }, { "input": "3 3\n1 2 1\n1 3 2\n2 3 1", "output": "1 3 " }, { "input": "10 10\n1 5 12\n2 4 140\n2 10 149\n3 6 154\n3 7 9\n3 8 226\n3 10 132\n4 10 55\n5 8 33\n7 8 173", "output": "1 5 8 7 3 10 " }, { "input": "10 10\n1 5 178\n1 8 221\n2 7 92\n2 8 159\n3 5 55\n3 6 179\n3 10 237\n4 8 205\n5 6 191\n8 10 157", "output": "1 8 10 " }, { "input": "10 10\n1 4 200\n1 9 197\n3 4 79\n3 5 213\n3 6 149\n5 8 3\n5 9 189\n6 7 130\n6 9 51\n8 10 135", "output": "1 9 5 8 10 " }, { "input": "10 10\n1 4 201\n2 3 238\n3 4 40\n3 6 231\n3 8 45\n4 5 227\n4 6 58\n4 9 55\n5 7 14\n6 10 242", "output": "1 4 6 10 " } ]
1,597,822,809
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
77
204,800
#version 2 with priority queue class node: def __init__(self,data): self.next = None self.data = data class Priority_queue: def __init__(self): self.head = None def dequeue(self): temp = self.head data = temp.data if temp.next: self.head = temp.next del temp return data[0],data[1] else: self.head = None del temp return data[0],data[1] def enqueue(self,data): new_node = node(data) if self.head: temp = self.head prev = None while temp: if temp.data[0]>data[0]: break prev = temp temp = temp.next else: prev.next = new_node return if temp == self.head: self.head = new_node new_node.next = temp return else: prev.next = new_node new_node.next = temp return else: self.head = new_node self.tail = new_node def dijkstra(k,graph,visited): n = len(visited) parent = [-1]*n #creating an array just to track the path infinite = float('inf') #creating a variable which gives reference to infinite dist = [infinite]*(n) #creating an distance list & assigning to infinite ind_hash = {} for i in range(n): ind_hash.update({visited[i]:i}) que = Priority_queue() que.enqueue((0,ind_hash[1])) while que.head and visited[ind_hash[k]]: min_dist,ind = que.dequeue() if visited[ind] != False: i = visited[ind] visited[ind] = False #checking that the node with the minimum distance is not visited for edge in graph[i]: vind = ind_hash[edge[0]] if visited[vind]: di = min_dist + edge[1] if di<dist[vind]: que.enqueue((di,vind)) parent[vind] = ind dist[vind] = di return parent def show_path(path,j): if j == -1: return show_path(path,path[j]) print(vertex[j],end=" ") if __name__ == "__main__": graph = defaultdict(list) z,m = map(int,input().split()) for _ in range(m): u,v,w = map(int,input().split()) if u!=v: if graph[u]: for vw in graph[u]: if vw[0] == v: if vw[1] > w: vw[1] = w break break else: graph[u].append([v,w]) else: graph[u].append([v,w]) if graph[v]: for vw in graph[v]: if vw[0] == u: if vw[1] > w: vw[1] = w break break else: graph[v].append([u,w]) else: graph[v].append([u,w]) vertex = list(graph.keys()) if (z) not in vertex: print(-1) else: pa = dijkstra(z,graph,vertex) vertex = list(graph.keys()) l = vertex.index(z) if pa[l]==-1: print(-1) else: show_path(pa,l)
Title: Dijkstra? Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. Input Specification: The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge endpoints and *w**i* is the length of the edge. It is possible that the graph has loops and multiple edges between pair of vertices. Output Specification: Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. Demo Input: ['5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n', '5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n'] Demo Output: ['1 4 3 5 ', '1 4 3 5 '] Note: none
```python #version 2 with priority queue class node: def __init__(self,data): self.next = None self.data = data class Priority_queue: def __init__(self): self.head = None def dequeue(self): temp = self.head data = temp.data if temp.next: self.head = temp.next del temp return data[0],data[1] else: self.head = None del temp return data[0],data[1] def enqueue(self,data): new_node = node(data) if self.head: temp = self.head prev = None while temp: if temp.data[0]>data[0]: break prev = temp temp = temp.next else: prev.next = new_node return if temp == self.head: self.head = new_node new_node.next = temp return else: prev.next = new_node new_node.next = temp return else: self.head = new_node self.tail = new_node def dijkstra(k,graph,visited): n = len(visited) parent = [-1]*n #creating an array just to track the path infinite = float('inf') #creating a variable which gives reference to infinite dist = [infinite]*(n) #creating an distance list & assigning to infinite ind_hash = {} for i in range(n): ind_hash.update({visited[i]:i}) que = Priority_queue() que.enqueue((0,ind_hash[1])) while que.head and visited[ind_hash[k]]: min_dist,ind = que.dequeue() if visited[ind] != False: i = visited[ind] visited[ind] = False #checking that the node with the minimum distance is not visited for edge in graph[i]: vind = ind_hash[edge[0]] if visited[vind]: di = min_dist + edge[1] if di<dist[vind]: que.enqueue((di,vind)) parent[vind] = ind dist[vind] = di return parent def show_path(path,j): if j == -1: return show_path(path,path[j]) print(vertex[j],end=" ") if __name__ == "__main__": graph = defaultdict(list) z,m = map(int,input().split()) for _ in range(m): u,v,w = map(int,input().split()) if u!=v: if graph[u]: for vw in graph[u]: if vw[0] == v: if vw[1] > w: vw[1] = w break break else: graph[u].append([v,w]) else: graph[u].append([v,w]) if graph[v]: for vw in graph[v]: if vw[0] == u: if vw[1] > w: vw[1] = w break break else: graph[v].append([u,w]) else: graph[v].append([u,w]) vertex = list(graph.keys()) if (z) not in vertex: print(-1) else: pa = dijkstra(z,graph,vertex) vertex = list(graph.keys()) l = vertex.index(z) if pa[l]==-1: print(-1) else: show_path(pa,l) ```
-1
182
B
Vasya's Calendar
PROGRAMMING
1,000
[ "implementation" ]
null
null
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1. Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month. A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1.
The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one.
Print a single number — the number of times Vasya manually increased the day number by one throughout the last year.
[ "4\n2\n2 2\n", "5\n3\n3 4 3\n", "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n" ]
[ "2\n", "3\n", "7\n" ]
In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing.
500
[ { "input": "4\n2\n2 2", "output": "2" }, { "input": "5\n3\n3 4 3", "output": "3" }, { "input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31", "output": "7" }, { "input": "1\n1\n1", "output": "0" }, { "input": "1\n2\n1 1", "output": "0" }, { "input": "2\n2\n1 1", "output": "1" }, { "input": "10\n2\n10 2", "output": "0" }, { "input": "10\n3\n6 3 6", "output": "11" }, { "input": "10\n4\n8 7 1 5", "output": "14" }, { "input": "10\n5\n2 7 8 4 4", "output": "19" }, { "input": "10\n6\n8 3 4 9 6 1", "output": "20" }, { "input": "10\n7\n10 5 3 1 1 9 1", "output": "31" }, { "input": "10\n8\n6 5 10 6 8 1 3 2", "output": "31" }, { "input": "10\n9\n6 2 7 5 5 4 8 6 2", "output": "37" }, { "input": "10\n10\n1 10 1 10 1 1 7 8 6 7", "output": "45" }, { "input": "100\n100\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50 27 15 7 89 98 10 11 15 99 49 4 51 77 52", "output": "5099" }, { "input": "101\n100\n19 17 15 16 28 69 41 47 75 42 19 98 16 90 92 47 21 4 98 17 27 31 90 10 14 92 62 73 56 55 6 60 62 22 78 1 3 86 18 59 92 41 21 34 67 9 92 78 77 45 50 92 57 61 11 98 89 72 57 93 100 12 61 48 5 48 38 9 65 64 77 29 18 55 94 42 10 77 43 46 7 89 8 13 5 53 80 59 23 100 30 28 29 24 85 56 10 22 24 16", "output": "5301" }, { "input": "102\n100\n31 22 59 16 11 56 81 4 19 31 8 72 4 92 18 7 13 12 62 40 34 67 40 23 96 4 90 28 3 18 54 49 10 71 73 79 69 7 41 75 59 13 2 78 72 6 95 33 52 97 7 86 57 94 12 93 19 94 59 28 5 96 46 102 2 101 57 85 53 69 72 39 14 75 8 16 10 57 26 4 85 18 89 84 48 93 54 21 78 6 67 35 11 78 91 91 97 15 8 32", "output": "5447" }, { "input": "103\n100\n68 38 41 54 37 11 35 26 43 97 70 3 13 11 64 83 3 95 99 16 4 13 22 27 64 20 95 38 40 87 6 17 95 67 31 24 85 33 98 24 89 101 66 38 42 5 95 18 95 13 103 85 72 73 68 93 22 59 48 59 72 46 5 41 54 32 48 69 3 76 2 26 102 44 39 58 55 85 40 16 81 78 92 63 25 97 83 2 54 16 20 63 19 8 84 34 1 22 43 93", "output": "5358" }, { "input": "104\n100\n65 74 94 71 98 38 88 67 71 84 45 79 55 86 55 51 27 89 14 66 29 63 8 103 98 94 87 81 58 68 24 96 60 36 48 95 28 72 95 42 87 7 14 23 99 77 34 14 90 31 8 99 29 30 9 88 42 1 77 61 55 85 17 98 62 78 27 1 58 69 82 62 62 81 56 104 66 8 17 23 7 61 59 70 79 64 78 16 32 11 59 4 24 73 55 2 95 39 62 13", "output": "4773" } ]
1,629,204,602
2,147,483,647
PyPy 3
OK
TESTS
40
248
21,504,000
d=int(input()) k=int(input()) ans=0 for x in map(int,input().split()[:-1]): ans+=d-x print(ans)
Title: Vasya's Calendar Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date. The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does not keep information about the current month, so when a new day comes, it simply increases the current day number by one. The clock cannot display number *d*<=+<=1, so after day number *d* it shows day 1 (the current day counter resets). The mechanism of the clock allows you to increase the day number by one manually. When you execute this operation, day *d* is also followed by day 1. Vasya begins each day checking the day number on the clock. If the day number on the clock does not match the actual day number in the current month, then Vasya manually increases it by one. Vasya is persistent and repeats this operation until the day number on the clock matches the actual number of the current day in the current month. A year passed and Vasya wonders how many times he manually increased the day number by one, from the first day of the first month to the last day of the *n*-th month inclusive, considering that on the first day of the first month the clock display showed day 1. Input Specification: The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106). The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000). The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — the number of days in each month in the order in which they follow, starting from the first one. Output Specification: Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. Demo Input: ['4\n2\n2 2\n', '5\n3\n3 4 3\n', '31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n'] Demo Output: ['2\n', '3\n', '7\n'] Note: In the first sample the situation is like this: - Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by 1 manually. After that the clock shows 1. - Day 2. Month 2. The clock shows 2. Vasya changes nothing.
```python d=int(input()) k=int(input()) ans=0 for x in map(int,input().split()[:-1]): ans+=d-x print(ans) ```
3
61
A
Ultra-Fast Mathematician
PROGRAMMING
800
[ "implementation" ]
A. Ultra-Fast Mathematician
2
256
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate.
There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.
Write one line — the corresponding answer. Do not omit the leading 0s.
[ "1010100\n0100101\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n" ]
[ "1110001\n", "111\n", "0100\n", "00010\n" ]
none
500
[ { "input": "1010100\n0100101", "output": "1110001" }, { "input": "000\n111", "output": "111" }, { "input": "1110\n1010", "output": "0100" }, { "input": "01110\n01100", "output": "00010" }, { "input": "011101\n000001", "output": "011100" }, { "input": "10\n01", "output": "11" }, { "input": "00111111\n11011101", "output": "11100010" }, { "input": "011001100\n101001010", "output": "110000110" }, { "input": "1100100001\n0110101100", "output": "1010001101" }, { "input": "00011101010\n10010100101", "output": "10001001111" }, { "input": "100000101101\n111010100011", "output": "011010001110" }, { "input": "1000001111010\n1101100110001", "output": "0101101001011" }, { "input": "01011111010111\n10001110111010", "output": "11010001101101" }, { "input": "110010000111100\n001100101011010", "output": "111110101100110" }, { "input": "0010010111110000\n0000000011010110", "output": "0010010100100110" }, { "input": "00111110111110000\n01111100001100000", "output": "01000010110010000" }, { "input": "101010101111010001\n001001111101111101", "output": "100011010010101100" }, { "input": "0110010101111100000\n0011000101000000110", "output": "0101010000111100110" }, { "input": "11110100011101010111\n00001000011011000000", "output": "11111100000110010111" }, { "input": "101010101111101101001\n111010010010000011111", "output": "010000111101101110110" }, { "input": "0000111111100011000010\n1110110110110000001010", "output": "1110001001010011001000" }, { "input": "10010010101000110111000\n00101110100110111000111", "output": "10111100001110001111111" }, { "input": "010010010010111100000111\n100100111111100011001110", "output": "110110101101011111001001" }, { "input": "0101110100100111011010010\n0101100011010111001010001", "output": "0000010111110000010000011" }, { "input": "10010010100011110111111011\n10000110101100000001000100", "output": "00010100001111110110111111" }, { "input": "000001111000000100001000000\n011100111101111001110110001", "output": "011101000101111101111110001" }, { "input": "0011110010001001011001011100\n0000101101000011101011001010", "output": "0011011111001010110010010110" }, { "input": "11111000000000010011001101111\n11101110011001010100010000000", "output": "00010110011001000111011101111" }, { "input": "011001110000110100001100101100\n001010000011110000001000101001", "output": "010011110011000100000100000101" }, { "input": "1011111010001100011010110101111\n1011001110010000000101100010101", "output": "0000110100011100011111010111010" }, { "input": "10111000100001000001010110000001\n10111000001100101011011001011000", "output": "00000000101101101010001111011001" }, { "input": "000001010000100001000000011011100\n111111111001010100100001100000111", "output": "111110101001110101100001111011011" }, { "input": "1101000000000010011011101100000110\n1110000001100010011010000011011110", "output": "0011000001100000000001101111011000" }, { "input": "01011011000010100001100100011110001\n01011010111000001010010100001110000", "output": "00000001111010101011110000010000001" }, { "input": "000011111000011001000110111100000100\n011011000110000111101011100111000111", "output": "011000111110011110101101011011000011" }, { "input": "1001000010101110001000000011111110010\n0010001011010111000011101001010110000", "output": "1011001001111001001011101010101000010" }, { "input": "00011101011001100101111111000000010101\n10010011011011001011111000000011101011", "output": "10001110000010101110000111000011111110" }, { "input": "111011100110001001101111110010111001010\n111111101101111001110010000101101000100", "output": "000100001011110000011101110111010001110" }, { "input": "1111001001101000001000000010010101001010\n0010111100111110001011000010111110111001", "output": "1101110101010110000011000000101011110011" }, { "input": "00100101111000000101011111110010100011010\n11101110001010010101001000111110101010100", "output": "11001011110010010000010111001100001001110" }, { "input": "101011001110110100101001000111010101101111\n100111100110101011010100111100111111010110", "output": "001100101000011111111101111011101010111001" }, { "input": "1111100001100101000111101001001010011100001\n1000110011000011110010001011001110001000001", "output": "0111010010100110110101100010000100010100000" }, { "input": "01100111011111010101000001101110000001110101\n10011001011111110000000101011001001101101100", "output": "11111110000000100101000100110111001100011001" }, { "input": "110010100111000100100101100000011100000011001\n011001111011100110000110111001110110100111011", "output": "101011011100100010100011011001101010100100010" }, { "input": "0001100111111011010110100100111000000111000110\n1100101011000000000001010010010111001100110001", "output": "1101001100111011010111110110101111001011110111" }, { "input": "00000101110110110001110010100001110100000100000\n10010000110011110001101000111111101010011010001", "output": "10010101000101000000011010011110011110011110001" }, { "input": "110000100101011100100011001111110011111110010001\n101011111001011100110110111101110011010110101100", "output": "011011011100000000010101110010000000101000111101" }, { "input": "0101111101011111010101011101000011101100000000111\n0000101010110110001110101011011110111001010100100", "output": "0101010111101001011011110110011101010101010100011" }, { "input": "11000100010101110011101000011111001010110111111100\n00001111000111001011111110000010101110111001000011", "output": "11001011010010111000010110011101100100001110111111" }, { "input": "101000001101111101101111111000001110110010101101010\n010011100111100001100000010001100101000000111011011", "output": "111011101010011100001111101001101011110010010110001" }, { "input": "0011111110010001010100010110111000110011001101010100\n0111000000100010101010000100101000000100101000111001", "output": "0100111110110011111110010010010000110111100101101101" }, { "input": "11101010000110000011011010000001111101000111011111100\n10110011110001010100010110010010101001010111100100100", "output": "01011001110111010111001100010011010100010000111011000" }, { "input": "011000100001000001101000010110100110011110100111111011\n111011001000001001110011001111011110111110110011011111", "output": "100011101001001000011011011001111000100000010100100100" }, { "input": "0111010110010100000110111011010110100000000111110110000\n1011100100010001101100000100111111101001110010000100110", "output": "1100110010000101101010111111101001001001110101110010110" }, { "input": "10101000100111000111010001011011011011110100110101100011\n11101111000000001100100011111000100100000110011001101110", "output": "01000111100111001011110010100011111111110010101100001101" }, { "input": "000000111001010001000000110001001011100010011101010011011\n110001101000010010000101000100001111101001100100001010010", "output": "110001010001000011000101110101000100001011111001011001001" }, { "input": "0101011100111010000111110010101101111111000000111100011100\n1011111110000010101110111001000011100000100111111111000111", "output": "1110100010111000101001001011101110011111100111000011011011" }, { "input": "11001000001100100111100111100100101011000101001111001001101\n10111110100010000011010100110100100011101001100000001110110", "output": "01110110101110100100110011010000001000101100101111000111011" }, { "input": "010111011011101000000110000110100110001110100001110110111011\n101011110011101011101101011111010100100001100111100100111011", "output": "111100101000000011101011011001110010101111000110010010000000" }, { "input": "1001011110110110000100011001010110000100011010010111010101110\n1101111100001000010111110011010101111010010100000001000010111", "output": "0100100010111110010011101010000011111110001110010110010111001" }, { "input": "10000010101111100111110101111000010100110111101101111111111010\n10110110101100101010011001011010100110111011101100011001100111", "output": "00110100000011001101101100100010110010001100000001100110011101" }, { "input": "011111010011111000001010101001101001000010100010111110010100001\n011111001011000011111001000001111001010110001010111101000010011", "output": "000000011000111011110011101000010000010100101000000011010110010" }, { "input": "1111000000110001011101000100100100001111011100001111001100011111\n1101100110000101100001100000001001011011111011010101000101001010", "output": "0010100110110100111100100100101101010100100111011010001001010101" }, { "input": "01100000101010010011001110100110110010000110010011011001100100011\n10110110010110111100100111000111000110010000000101101110000010111", "output": "11010110111100101111101001100001110100010110010110110111100110100" }, { "input": "001111111010000100001100001010011001111110011110010111110001100111\n110000101001011000100010101100100110000111100000001101001110010111", "output": "111111010011011100101110100110111111111001111110011010111111110000" }, { "input": "1011101011101101011110101101011101011000010011100101010101000100110\n0001000001001111010111100100111101100000000001110001000110000000110", "output": "1010101010100010001001001001100000111000010010010100010011000100000" }, { "input": "01000001011001010011011100010000100100110101111011011011110000001110\n01011110000110011011000000000011000111100001010000000011111001110000", "output": "00011111011111001000011100010011100011010100101011011000001001111110" }, { "input": "110101010100110101000001111110110100010010000100111110010100110011100\n111010010111111011100110101011001011001110110111110100000110110100111", "output": "001111000011001110100111010101111111011100110011001010010010000111011" }, { "input": "1001101011000001011111100110010010000011010001001111011100010100110001\n1111100111110101001111010001010000011001001001010110001111000000100101", "output": "0110001100110100010000110111000010011010011000011001010011010100010100" }, { "input": "00000111110010110001110110001010010101000111011001111111100110011110010\n00010111110100000100110101000010010001100001100011100000001100010100010", "output": "00010000000110110101000011001000000100100110111010011111101010001010000" }, { "input": "100101011100101101000011010001011001101110101110001100010001010111001110\n100001111100101011011111110000001111000111001011111110000010101110111001", "output": "000100100000000110011100100001010110101001100101110010010011111001110111" }, { "input": "1101100001000111001101001011101000111000011110000001001101101001111011010\n0101011101010100011011010110101000010010110010011110101100000110110001000", "output": "1000111100010011010110011101000000101010101100011111100001101111001010010" }, { "input": "01101101010011110101100001110101111011100010000010001101111000011110111111\n00101111001101001100111010000101110000100101101111100111101110010100011011", "output": "01000010011110111001011011110000001011000111101101101010010110001010100100" }, { "input": "101100101100011001101111110110110010100110110010100001110010110011001101011\n000001011010101011110011111101001110000111000010001101000010010000010001101", "output": "101101110110110010011100001011111100100001110000101100110000100011011100110" }, { "input": "0010001011001010001100000010010011110110011000100000000100110000101111001110\n1100110100111000110100001110111001011101001100001010100001010011100110110001", "output": "1110111111110010111000001100101010101011010100101010100101100011001001111111" }, { "input": "00101101010000000101011001101011001100010001100000101011101110000001111001000\n10010110010111000000101101000011101011001010000011011101101011010000000011111", "output": "10111011000111000101110100101000100111011011100011110110000101010001111010111" }, { "input": "111100000100100000101001100001001111001010001000001000000111010000010101101011\n001000100010100101111011111011010110101100001111011000010011011011100010010110", "output": "110100100110000101010010011010011001100110000111010000010100001011110111111101" }, { "input": "0110001101100100001111110101101000100101010010101010011001101001001101110000000\n0111011000000010010111011110010000000001000110001000011001101000000001110100111", "output": "0001010101100110011000101011111000100100010100100010000000000001001100000100111" }, { "input": "10001111111001000101001011110101111010100001011010101100111001010001010010001000\n10000111010010011110111000111010101100000011110001101111001000111010100000000001", "output": "00001000101011011011110011001111010110100010101011000011110001101011110010001001" }, { "input": "100110001110110000100101001110000011110110000110000000100011110100110110011001101\n110001110101110000000100101001101011111100100100001001000110000001111100011110110", "output": "010111111011000000100001100111101000001010100010001001100101110101001010000111011" }, { "input": "0000010100100000010110111100011111111010011101000000100000011001001101101100111010\n0100111110011101010110101011110110010111001111000110101100101110111100101000111111", "output": "0100101010111101000000010111101001101101010010000110001100110111110001000100000101" }, { "input": "11000111001010100001110000001001011010010010110000001110100101000001010101100110111\n11001100100100100001101010110100000111100011101110011010110100001001000011011011010", "output": "00001011101110000000011010111101011101110001011110010100010001001000010110111101101" }, { "input": "010110100010001000100010101001101010011010111110100001000100101000111011100010100001\n110000011111101101010011111000101010111010100001001100001001100101000000111000000000", "output": "100110111101100101110001010001000000100000011111101101001101001101111011011010100001" }, { "input": "0000011110101110010101110110110101100001011001101010101001000010000010000000101001101\n1100111111011100000110000111101110011111100111110001011001000010011111100001001100011", "output": "1100100001110010010011110001011011111110111110011011110000000000011101100001100101110" }, { "input": "10100000101101110001100010010010100101100011010010101000110011100000101010110010000000\n10001110011011010010111011011101101111000111110000111000011010010101001100000001010011", "output": "00101110110110100011011001001111001010100100100010010000101001110101100110110011010011" }, { "input": "001110000011111101101010011111000101010111010100001001100001001100101000000111000000000\n111010000000000000101001110011001000111011001100101010011001000011101001001011110000011", "output": "110100000011111101000011101100001101101100011000100011111000001111000001001100110000011" }, { "input": "1110111100111011010101011011001110001010010010110011110010011111000010011111010101100001\n1001010101011001001010100010101100000110111101011000100010101111111010111100001110010010", "output": "0111101001100010011111111001100010001100101111101011010000110000111000100011011011110011" }, { "input": "11100010001100010011001100001100010011010001101110011110100101110010101101011101000111111\n01110000000110111010110100001010000101011110100101010011000110101110101101110111011110001", "output": "10010010001010101001111000000110010110001111001011001101100011011100000000101010011001110" }, { "input": "001101011001100101101100110000111000101011001001100100000100101000100000110100010111111101\n101001111110000010111101111110001001111001111101111010000110111000100100110010010001011111", "output": "100100100111100111010001001110110001010010110100011110000010010000000100000110000110100010" }, { "input": "1010110110010101000110010010110101011101010100011001101011000110000000100011100100011000000\n0011011111100010001111101101000111001011101110100000110111100100101111010110101111011100011", "output": "1001101001110111001001111111110010010110111010111001011100100010101111110101001011000100011" }, { "input": "10010010000111010111011111110010100101100000001100011100111011100010000010010001011100001100\n00111010100010110010000100010111010001111110100100100011101000101111111111001101101100100100", "output": "10101000100101100101011011100101110100011110101000111111010011001101111101011100110000101000" }, { "input": "010101110001010101100000010111010000000111110011001101100011001000000011001111110000000010100\n010010111011100101010101111110110000000111000100001101101001001000001100101110001010000100001", "output": "000111001010110000110101101001100000000000110111000000001010000000001111100001111010000110101" }, { "input": "1100111110011001000111101001001011000110011010111111100010111111001100111111011101100111101011\n1100000011001000110100110111000001011001010111101000010010100011000001100100111101101000010110", "output": "0000111101010001110011011110001010011111001101010111110000011100001101011011100000001111111101" }, { "input": "00011000100100110111100101100100000000010011110111110010101110110011100001010111010011110100101\n00011011111011111011100101100111100101001110010111000010000111000100100100000001110101111011011", "output": "00000011011111001100000000000011100101011101100000110000101001110111000101010110100110001111110" }, { "input": "000101011001001100000111100010110101111011110101111101000110001101011010111110110011100100000001\n011000101010011111011000111000100000000011011000000001111110001000001111101010110000011100001111", "output": "011101110011010011011111011010010101111000101101111100111000000101010101010100000011111000001110" }, { "input": "1000101001011010000100100100010010011101011001110101111011101111111110010101001101010001010101001\n0110110010011100011111011111110111000000010001110100001010111110101011010011111011111110000110000", "output": "1110011011000110011011111011100101011101001000000001110001010001010101000110110110101111010011001" }, { "input": "01111010010101100111110111111011011010100001011101010000111100101101101110111011001100101011100111\n00001100110110100001111011000010001001001100000010111101000001111011100000010111010010000011000010", "output": "01110110100011000110001100111001010011101101011111101101111101010110001110101100011110101000100101" }, { "input": "111101011101111000001011001101111010110111001101110100100011111011011101001101010101011010111000110\n101111100101101101001100110011000001111010011101110111110110101110011011110011111100001001110101101", "output": "010010111000010101000111111110111011001101010000000011010101010101000110111110101001010011001101011" }, { "input": "1010000011010110011101001101110001110010000111011101110010110110111111001001110100101100010101010001\n0111101000111100101100000101111010100100001000011101010100110011100011010011010101000100101011100011", "output": "1101101011101010110001001000001011010110001111000000100110000101011100011010100001101000111110110010" }, { "input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111010", "output": "1111111010111111101011111110101111111010111111101011111110101111111010111111101011111110101111111011" }, { "input": "0\n0", "output": "0" }, { "input": "0\n1", "output": "1" } ]
1,649,830,524
2,147,483,647
Python 3
OK
TESTS
102
46
0
numOne = (input()) numTwo = (input()) result = [] for x in range(len(numOne)): if numOne[x] == numTwo[x]: result.append("0") else: result.append("1") print(''.join(result))
Title: Ultra-Fast Mathematician Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part. In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The *i*-th digit of the answer is 1 if and only if the *i*-th digit of the two given numbers differ. In the other case the *i*-th digit of the answer is 0. Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length. Now you are going to take part in Shapur's contest. See if you are faster and more accurate. Input Specification: There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. Output Specification: Write one line — the corresponding answer. Do not omit the leading 0s. Demo Input: ['1010100\n0100101\n', '000\n111\n', '1110\n1010\n', '01110\n01100\n'] Demo Output: ['1110001\n', '111\n', '0100\n', '00010\n'] Note: none
```python numOne = (input()) numTwo = (input()) result = [] for x in range(len(numOne)): if numOne[x] == numTwo[x]: result.append("0") else: result.append("1") print(''.join(result)) ```
3.9885
389
B
Fox and Cross
PROGRAMMING
1,100
[ "greedy", "implementation" ]
null
null
Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way.
The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'.
Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".
[ "5\n.#...\n####.\n.####\n...#.\n.....\n", "4\n####\n####\n####\n####\n", "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n", "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n", "3\n...\n...\n...\n" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
1,000
[ { "input": "4\n####\n####\n####\n####", "output": "NO" }, { "input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "output": "YES" }, { "input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "output": "NO" }, { "input": "5\n.....\n.#...\n####.\n.####\n...#.", "output": "YES" }, { "input": "5\n#....\n###..\n.###.\n..##.\n..##.", "output": "NO" }, { "input": "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#..#####.\n##########\n.#..#...#.", "output": "YES" }, { "input": "8\n.#...##.\n##.##.#.\n#....##.\n#.###.##\n...##..#\n#..#.##.\n#..#.#..\n#....###", "output": "NO" }, { "input": "15\n.#...##.##.....\n.###.#.#.##..#.\n##.#####......#\n#....###.#..#..\n#.##.#.###.###.\n.###....#.###.#\n##.....##..#...\n.#.########...#\n##..#..##..#.##\n#...#....##....\n.......#.......\n.#..#.#.####...\n.#..#...#..###.\n#..#.#..#......\n###.....##....#", "output": "NO" }, { "input": "7\n.......\n.......\n.......\n.......\n.....#.\n....###\n.....#.", "output": "YES" }, { "input": "9\n.#.#....#\n#.#.....#\n.#..#..#.\n#.#....##\n...#...#.\n#..###.#.\n....#..##\n.#.###...\n....##..#", "output": "NO" }, { "input": "5\n#...#\n.....\n..#..\n.....\n#...#", "output": "NO" }, { "input": "3\n.#.\n#.#\n.#.", "output": "NO" }, { "input": "3\n...\n...\n..#", "output": "NO" } ]
1,620,655,763
2,147,483,647
Python 3
OK
TESTS
42
77
6,963,200
n=int(input()) l=[] s=0 for i in range(n): o=input() s+=o.count("#") l+=[list(o)] q=[[1 for i in range(n)]for i in range(n)] for i in range(1,n-1): for j in range(1,n-1): if l[i][j]=="#"and q[i][j]: if l[i+1][j]=="#" and q[i+1][j]: if l[i-1][j]=="#" and q[i-1][j]: if l[i][j+1]=="#" and q[i][j+1]: if l[i][j-1]=="#" and q[i][j-1]: s-=5 q[i+1][j]=q[i-1][j]=q[i][j-1]=q[i][j+1]=0 print("YNEOS"[s!=0::2])
Title: Fox and Cross Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way. Input Specification: The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. Output Specification: Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". Demo Input: ['5\n.#...\n####.\n.####\n...#.\n.....\n', '4\n####\n####\n####\n####\n', '6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n', '6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.\n', '3\n...\n...\n...\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n', 'NO\n', 'YES\n'] Note: In example 1, you can draw two crosses. The picture below shows what they look like. In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.
```python n=int(input()) l=[] s=0 for i in range(n): o=input() s+=o.count("#") l+=[list(o)] q=[[1 for i in range(n)]for i in range(n)] for i in range(1,n-1): for j in range(1,n-1): if l[i][j]=="#"and q[i][j]: if l[i+1][j]=="#" and q[i+1][j]: if l[i-1][j]=="#" and q[i-1][j]: if l[i][j+1]=="#" and q[i][j+1]: if l[i][j-1]=="#" and q[i][j-1]: s-=5 q[i+1][j]=q[i-1][j]=q[i][j-1]=q[i][j+1]=0 print("YNEOS"[s!=0::2]) ```
3
486
A
Calculating Function
PROGRAMMING
800
[ "implementation", "math" ]
null
null
For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*.
The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015).
Print *f*(*n*) in a single line.
[ "4\n", "5\n" ]
[ "2\n", "-3\n" ]
*f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
500
[ { "input": "4", "output": "2" }, { "input": "5", "output": "-3" }, { "input": "1000000000", "output": "500000000" }, { "input": "1000000001", "output": "-500000001" }, { "input": "1000000000000000", "output": "500000000000000" }, { "input": "100", "output": "50" }, { "input": "101", "output": "-51" }, { "input": "102", "output": "51" }, { "input": "103", "output": "-52" }, { "input": "104", "output": "52" }, { "input": "105", "output": "-53" }, { "input": "106", "output": "53" }, { "input": "107", "output": "-54" }, { "input": "108", "output": "54" }, { "input": "109", "output": "-55" }, { "input": "208170109961052", "output": "104085054980526" }, { "input": "46017661651072", "output": "23008830825536" }, { "input": "4018154546667", "output": "-2009077273334" }, { "input": "288565475053", "output": "-144282737527" }, { "input": "3052460231", "output": "-1526230116" }, { "input": "29906716", "output": "14953358" }, { "input": "87897701693326", "output": "43948850846663" }, { "input": "8240", "output": "4120" }, { "input": "577935", "output": "-288968" }, { "input": "62", "output": "31" }, { "input": "1", "output": "-1" }, { "input": "2", "output": "1" }, { "input": "9999999999999", "output": "-5000000000000" }, { "input": "1000000000000", "output": "500000000000" }, { "input": "99999999999999", "output": "-50000000000000" }, { "input": "999999999999999", "output": "-500000000000000" }, { "input": "42191359342", "output": "21095679671" }, { "input": "100000000000000", "output": "50000000000000" }, { "input": "145645214654154", "output": "72822607327077" }, { "input": "4294967296", "output": "2147483648" }, { "input": "3037000499", "output": "-1518500250" }, { "input": "10000000000001", "output": "-5000000000001" }, { "input": "100000017040846", "output": "50000008520423" }, { "input": "98979894985999", "output": "-49489947493000" } ]
1,692,080,694
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
1,331,200
"""Подсчет функции""" def main(): n = int(input()) count = 0 mul = 1 for i in range(1, n+1): mul *= (-1) count = count + i*mul print(count) if __name__ == "__main__": main()
Title: Calculating Function Time Limit: None seconds Memory Limit: None megabytes Problem Description: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. Input Specification: The single line contains the positive integer *n* (1<=≤<=*n*<=≤<=1015). Output Specification: Print *f*(*n*) in a single line. Demo Input: ['4\n', '5\n'] Demo Output: ['2\n', '-3\n'] Note: *f*(4) =  - 1 + 2 - 3 + 4 = 2 *f*(5) =  - 1 + 2 - 3 + 4 - 5 =  - 3
```python """Подсчет функции""" def main(): n = int(input()) count = 0 mul = 1 for i in range(1, n+1): mul *= (-1) count = count + i*mul print(count) if __name__ == "__main__": main() ```
0
37
A
Towers
PROGRAMMING
1,000
[ "sortings" ]
A. Towers
2
256
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.
The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000.
In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.
[ "3\n1 2 3\n", "4\n6 5 6 7\n" ]
[ "1 3\n", "2 3\n" ]
none
500
[ { "input": "3\n1 2 3", "output": "1 3" }, { "input": "4\n6 5 6 7", "output": "2 3" }, { "input": "4\n3 2 1 1", "output": "2 3" }, { "input": "4\n1 2 3 3", "output": "2 3" }, { "input": "3\n20 22 36", "output": "1 3" }, { "input": "25\n47 30 94 41 45 20 96 51 110 129 24 116 9 47 32 82 105 114 116 75 154 151 70 42 162", "output": "2 23" }, { "input": "45\n802 664 442 318 318 827 417 878 711 291 231 414 807 553 657 392 279 202 386 606 465 655 658 112 887 15 25 502 95 44 679 775 942 609 209 871 31 234 4 231 150 110 22 823 193", "output": "2 43" }, { "input": "63\n93 180 116 7 8 179 268 279 136 94 221 153 264 190 278 19 19 63 153 26 158 225 25 49 89 218 111 149 255 225 197 122 243 80 3 224 107 178 202 17 53 92 69 42 228 24 81 205 95 8 265 82 228 156 127 241 172 159 106 60 67 155 111", "output": "2 57" }, { "input": "83\n246 535 994 33 390 927 321 97 223 922 812 705 79 80 977 457 476 636 511 137 6 360 815 319 717 674 368 551 714 628 278 713 761 553 184 414 623 753 428 214 581 115 439 61 677 216 772 592 187 603 658 310 439 559 870 376 109 321 189 337 277 26 70 734 796 907 979 693 570 227 345 650 737 633 701 914 134 403 972 940 371 6 642", "output": "2 80" }, { "input": "105\n246 57 12 204 165 123 246 68 191 310 3 152 386 333 374 257 158 104 333 50 80 290 8 340 101 76 221 316 388 289 138 359 316 26 93 290 105 178 81 195 41 196 218 180 244 292 187 97 315 323 174 119 248 239 92 312 31 2 101 180 307 170 338 314 163 281 217 31 142 238 280 190 190 156 70 74 329 113 151 8 141 313 366 40 253 116 168 124 135 230 294 266 353 389 371 359 195 200 183 237 93 102 315 118 188", "output": "2 92" }, { "input": "123\n112 277 170 247 252 115 157 293 256 143 196 90 12 164 164 42 8 223 167 109 175 232 239 111 148 51 9 254 93 32 268 162 231 91 47 162 161 191 195 145 247 292 129 199 230 94 144 217 18 205 176 20 143 198 121 243 211 262 230 277 195 255 108 290 220 275 158 2 286 200 60 267 278 207 123 150 123 116 131 13 12 226 33 244 30 275 263 45 158 192 254 149 242 176 62 224 221 288 250 160 155 225 132 143 276 293 218 145 197 175 33 129 79 206 210 192 222 262 190 52 274 243 233", "output": "3 101" }, { "input": "5\n5 5 5 5 5", "output": "5 1" }, { "input": "3\n1000 1000 1000", "output": "3 1" }, { "input": "1\n1000", "output": "1 1" }, { "input": "1\n1", "output": "1 1" }, { "input": "5\n1 1000 1000 1000 1000", "output": "4 2" }, { "input": "5\n1000 1000 1000 8 7", "output": "3 3" } ]
1,655,823,669
2,147,483,647
Python 3
OK
TESTS
61
92
0
x = int(input()) barl = list(map(int, input().split())) li = [] maxbar = "A" for i in barl: if i not in li: if maxbar=="A": maxbar = barl.count(i) elif barl.count(i)>maxbar: maxbar = barl.count(i) li.append(i) print(maxbar, len(li))
Title: Towers Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. Input Specification: The first line contains an integer *N* (1<=≤<=*N*<=≤<=1000) — the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* — the lengths of the bars. All the lengths are natural numbers not exceeding 1000. Output Specification: In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars. Demo Input: ['3\n1 2 3\n', '4\n6 5 6 7\n'] Demo Output: ['1 3\n', '2 3\n'] Note: none
```python x = int(input()) barl = list(map(int, input().split())) li = [] maxbar = "A" for i in barl: if i not in li: if maxbar=="A": maxbar = barl.count(i) elif barl.count(i)>maxbar: maxbar = barl.count(i) li.append(i) print(maxbar, len(li)) ```
3.977
258
A
Little Elephant and Bits
PROGRAMMING
1,100
[ "greedy", "math" ]
null
null
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation.
The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits.
In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem.
[ "101\n", "110010\n" ]
[ "11\n", "11010\n" ]
In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
500
[ { "input": "101", "output": "11" }, { "input": "110010", "output": "11010" }, { "input": "10000", "output": "1000" }, { "input": "1111111110", "output": "111111111" }, { "input": "10100101011110101", "output": "1100101011110101" }, { "input": "111010010111", "output": "11110010111" }, { "input": "11110111011100000000", "output": "1111111011100000000" }, { "input": "11110010010100001110110101110011110110100111101", "output": "1111010010100001110110101110011110110100111101" }, { "input": "1001011111010010100111111", "output": "101011111010010100111111" }, { "input": "1111111111", "output": "111111111" }, { "input": "1111111111111111111100111101001110110111111000001111110101001101001110011000001011001111111000110101", "output": "111111111111111111110111101001110110111111000001111110101001101001110011000001011001111111000110101" }, { "input": "11010110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100", "output": "1110110000100100101111110111001001010011000011011000010010100111010101000111010011101101111110001111000101000001100011101110100" }, { "input": "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011", "output": "1111111111111111111111111110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011" }, { "input": "11100010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011", "output": "1110010010010000110101101101100111111001010001101101001001111010110010111001011010000001100110101000101111000001111101111110010000010101110011110101101010110001100011101111011100010011101100111110010111111100110101000000111101000000000110100100101111101000110101010101101001110001110000101011010101100011100100111100010001011010010001100011111110010011010011000111000100111100010110100011010010101011011011111110100001110000011011" }, { "input": "11", "output": "1" }, { "input": "111", "output": "11" }, { "input": "111111", "output": "11111" }, { "input": "11111", "output": "1111" }, { "input": "1111", "output": "111" } ]
1,621,327,667
2,147,483,647
PyPy 3
TIME_LIMIT_EXCEEDED
TESTS
16
2,000
7,782,400
def maximus(a): k = 0 for i in range(len(a)): res_str = a[:i] + a[i + 1:] t = int(res_str, 2) if t > k: k = t return bin(k).replace("0b", "") a = input() print(maximus(a))
Title: Little Elephant and Bits Time Limit: None seconds Memory Limit: None megabytes Problem Description: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. Input Specification: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. Output Specification: In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. Demo Input: ['101\n', '110010\n'] Demo Output: ['11\n', '11010\n'] Note: In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>. In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub class="lower-index">10</sub>.
```python def maximus(a): k = 0 for i in range(len(a)): res_str = a[:i] + a[i + 1:] t = int(res_str, 2) if t > k: k = t return bin(k).replace("0b", "") a = input() print(maximus(a)) ```
0
441
A
Valera and Antique Items
PROGRAMMING
1,000
[ "implementation" ]
null
null
Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with.
The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller.
In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order.
[ "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n", "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n" ]
[ "3\n1 2 3\n", "0\n\n" ]
In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
500
[ { "input": "3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3" }, { "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0" }, { "input": "2 100001\n1 895737\n1 541571", "output": "0" }, { "input": "1 1000000\n1 1000000", "output": "0" }, { "input": "1 1000000\n1 561774", "output": "1\n1" }, { "input": "3 1000000\n5 1000000 568832 1000000 1000000 1000000\n13 1000000 1000000 1000000 596527 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000\n20 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000", "output": "2\n1 2" }, { "input": "3 999999\n7 1000000 1000000 1000000 999999 1000000 999999 1000000\n6 999999 1000000 999999 1000000 999999 999999\n7 999999 1000000 1000000 999999 1000000 1000000 1000000", "output": "0" }, { "input": "3 999999\n22 1000000 1000000 999999 999999 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 999999 1000000 1000000 999999 1000000 1000000 1000000 352800 999999 1000000\n14 999999 999999 999999 999999 999999 1000000 999999 999999 999999 999999 702638 999999 1000000 999999\n5 999999 1000000 1000000 999999 363236", "output": "3\n1 2 3" }, { "input": "1 50001\n1 50000", "output": "1\n1" } ]
1,643,004,827
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
2
109
1,228,800
n,v = [int(i) for i in input().split()] count = 0 ans = [] arr = [] for _ in range(n): lst = [int(i) for i in input().split()] arr.append(lst) for lst in arr: for j in range(1,len(lst)): if lst[j]<v: count+=1 ans.append(lst[0]) break ans.sort() print(count) for i in ans: print(i,end=" ")
Title: Valera and Antique Items Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with. Input Specification: The first line contains two space-separated integers *n*,<=*v* (1<=≤<=*n*<=≤<=50; 104<=≤<=*v*<=≤<=106) — the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≤<=*k**i*<=≤<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≤<=*s**ij*<=≤<=106) — the current prices of the items of the *i*-th seller. Output Specification: In the first line, print integer *p* — the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≤<=*q**i*<=≤<=*n*) — the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. Demo Input: ['3 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000\n', '3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000\n'] Demo Output: ['3\n1 2 3\n', '0\n\n'] Note: In the first sample Valera can bargain with each of the sellers. He can outbid the following items: a 40000 item from the first seller, a 20000 item from the second seller, and a 10000 item from the third seller. In the second sample Valera can not make a deal with any of the sellers, as the prices of all items in the auction too big for him.
```python n,v = [int(i) for i in input().split()] count = 0 ans = [] arr = [] for _ in range(n): lst = [int(i) for i in input().split()] arr.append(lst) for lst in arr: for j in range(1,len(lst)): if lst[j]<v: count+=1 ans.append(lst[0]) break ans.sort() print(count) for i in ans: print(i,end=" ") ```
0
365
B
The Fibonacci Segment
PROGRAMMING
1,100
[ "implementation" ]
null
null
You have array *a*1,<=*a*2,<=...,<=*a**n*. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) is good if *a**i*<==<=*a**i*<=-<=1<=+<=*a**i*<=-<=2, for all *i* (*l*<=+<=2<=≤<=*i*<=≤<=*r*). Let's define *len*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1, *len*([*l*,<=*r*]) is the length of the segment [*l*,<=*r*]. Segment [*l*1,<=*r*1], is longer than segment [*l*2,<=*r*2], if *len*([*l*1,<=*r*1])<=&gt;<=*len*([*l*2,<=*r*2]). Your task is to find a good segment of the maximum length in array *a*. Note that a segment of length 1 or 2 is always good.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109).
Print the length of the longest good segment in array *a*.
[ "10\n1 2 3 5 8 13 21 34 55 89\n", "5\n1 1 1 1 1\n" ]
[ "10\n", "2\n" ]
none
1,000
[ { "input": "10\n1 2 3 5 8 13 21 34 55 89", "output": "10" }, { "input": "5\n1 1 1 1 1", "output": "2" }, { "input": "1\n1000", "output": "1" }, { "input": "51\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", "output": "50" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "3\n0 0 0", "output": "3" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "5\n0 0 0 0 0", "output": "5" }, { "input": "6\n10 20 30 10 40 50", "output": "4" }, { "input": "5\n8 9 17 26 43", "output": "5" }, { "input": "12\n1 2 3 5 8 13 0 1 1 2 3 5", "output": "6" }, { "input": "13\n1 2 3 5 8 13 7 0 1 1 2 3 5", "output": "6" }, { "input": "2\n1 3", "output": "2" }, { "input": "2\n7 1", "output": "2" } ]
1,639,245,928
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
93
0
# author: violist # created: 11.12.2021 18:37:45 import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if (n == 1 or n == 2): print(n) sys.exit() aktualny_pocet, maximalny_pocet = 2, 2 for i in range(2, n): if (a[i] == a[i - 2] + a[i - 1]): aktualny_pocet += 1 else: maximalny_pocet = max(maximalny_pocet, aktualny_pocet) aktualny_pocet = 0 maximalny_pocet = max(maximalny_pocet, aktualny_pocet) print(maximalny_pocet)
Title: The Fibonacci Segment Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have array *a*1,<=*a*2,<=...,<=*a**n*. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) is good if *a**i*<==<=*a**i*<=-<=1<=+<=*a**i*<=-<=2, for all *i* (*l*<=+<=2<=≤<=*i*<=≤<=*r*). Let's define *len*([*l*,<=*r*])<==<=*r*<=-<=*l*<=+<=1, *len*([*l*,<=*r*]) is the length of the segment [*l*,<=*r*]. Segment [*l*1,<=*r*1], is longer than segment [*l*2,<=*r*2], if *len*([*l*1,<=*r*1])<=&gt;<=*len*([*l*2,<=*r*2]). Your task is to find a good segment of the maximum length in array *a*. Note that a segment of length 1 or 2 is always good. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). Output Specification: Print the length of the longest good segment in array *a*. Demo Input: ['10\n1 2 3 5 8 13 21 34 55 89\n', '5\n1 1 1 1 1\n'] Demo Output: ['10\n', '2\n'] Note: none
```python # author: violist # created: 11.12.2021 18:37:45 import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) if (n == 1 or n == 2): print(n) sys.exit() aktualny_pocet, maximalny_pocet = 2, 2 for i in range(2, n): if (a[i] == a[i - 2] + a[i - 1]): aktualny_pocet += 1 else: maximalny_pocet = max(maximalny_pocet, aktualny_pocet) aktualny_pocet = 0 maximalny_pocet = max(maximalny_pocet, aktualny_pocet) print(maximalny_pocet) ```
0
745
A
Hongcow Learns the Cyclic Shift
PROGRAMMING
900
[ "implementation", "strings" ]
null
null
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z').
Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.
[ "abcd\n", "bbb\n", "yzyz\n" ]
[ "4\n", "1\n", "2\n" ]
For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
500
[ { "input": "abcd", "output": "4" }, { "input": "bbb", "output": "1" }, { "input": "yzyz", "output": "2" }, { "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25" }, { "input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron", "output": "14" }, { "input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "1" }, { "input": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy", "output": "2" }, { "input": "y", "output": "1" }, { "input": "ervbfotfedpozygoumbmxeaqegouaqqzqerlykhmvxvvlcaos", "output": "49" }, { "input": "zyzzzyyzyyyzyyzyzyzyzyzzzyyyzzyzyyzzzzzyyyzzzzyzyy", "output": "50" }, { "input": "zzfyftdezzfyftdezzfyftdezzfyftdezzfyftdezzfyftde", "output": "8" }, { "input": "yehcqdlllqpuxdsaicyjjxiylahgxbygmsopjbxhtimzkashs", "output": "49" }, { "input": "yyyyzzzyzzzyzyzyzyyyyyzzyzyzyyyyyzyzyyyzyzzyyzzzz", "output": "49" }, { "input": "zkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnwzkqcrhzlzsnw", "output": "12" }, { "input": "xxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxyxxy", "output": "3" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaab", "output": "25" }, { "input": "aabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaaba", "output": "4" }, { "input": "pqqpqqpqqpqqpqqpqqpqqpqqpqqpqqpqqppqppqppqppqppq", "output": "48" }, { "input": "zxkljaqzxkljaqzxkljaqzxkljaqzxrljaqzxkljaqzxkljaq", "output": "49" }, { "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx", "output": "50" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaz", "output": "50" }, { "input": "abcddcba", "output": "8" }, { "input": "aabaabaabaacaabaabaabaacaabaabaabaacaabaabaabaac", "output": "12" }, { "input": "aabaabcaabaabcdaabaabcaabaabcd", "output": "15" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaaa", "output": "47" }, { "input": "ababaababaaababaababaaaababaababaaababaababaaa", "output": "23" }, { "input": "aaababaab", "output": "9" }, { "input": "aba", "output": "3" } ]
1,696,222,924
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
word = input() print(len(set(word)))
Title: Hongcow Learns the Cyclic Shift Time Limit: None seconds Memory Limit: None megabytes Problem Description: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). Output Specification: Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. Demo Input: ['abcd\n', 'bbb\n', 'yzyz\n'] Demo Output: ['4\n', '1\n', '2\n'] Note: For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda". For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb". For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy".
```python word = input() print(len(set(word))) ```
0
78
B
Easter Eggs
PROGRAMMING
1,200
[ "constructive algorithms", "implementation" ]
B. Easter Eggs
2
256
The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible.
The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100).
Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them.
[ "8\n", "13\n" ]
[ "ROYGRBIV\n", "ROYGBIVGBIVYG\n" ]
The way the eggs will be painted in the first sample is shown on the picture:
1,000
[ { "input": "8", "output": "ROYGBIVG" }, { "input": "13", "output": "ROYGBIVOYGBIV" }, { "input": "7", "output": "ROYGBIV" }, { "input": "10", "output": "ROYGBIVYGB" }, { "input": "14", "output": "ROYGBIVROYGBIV" }, { "input": "50", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "9", "output": "ROYGBIVGB" }, { "input": "11", "output": "ROYGBIVYGBI" }, { "input": "12", "output": "ROYGBIVOYGBI" }, { "input": "15", "output": "ROYGBIVROYGBIVG" }, { "input": "16", "output": "ROYGBIVROYGBIVGB" }, { "input": "17", "output": "ROYGBIVROYGBIVYGB" }, { "input": "18", "output": "ROYGBIVROYGBIVYGBI" }, { "input": "19", "output": "ROYGBIVROYGBIVOYGBI" }, { "input": "20", "output": "ROYGBIVROYGBIVOYGBIV" }, { "input": "21", "output": "ROYGBIVROYGBIVROYGBIV" }, { "input": "22", "output": "ROYGBIVROYGBIVROYGBIVG" }, { "input": "23", "output": "ROYGBIVROYGBIVROYGBIVGB" }, { "input": "24", "output": "ROYGBIVROYGBIVROYGBIVYGB" }, { "input": "25", "output": "ROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "28", "output": "ROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "29", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "34", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "43", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "61", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "79", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" }, { "input": "81", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "92", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "95", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVYGBI" }, { "input": "96", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBI" }, { "input": "97", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVOYGBIV" }, { "input": "98", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIV" }, { "input": "99", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVG" }, { "input": "100", "output": "ROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVROYGBIVGB" } ]
1,696,880,580
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
def paint_eggs(n): colors = ["R", "O", "Y", "G", "B", "I", "V"] painted_eggs = [] painted_eggs.append(colors[0]) painted_eggs.append(colors[1]) painted_eggs.append(colors[2]) painted_eggs.append(colors[3]) for i in range(4, n): painted_eggs.append(colors[i % 7]) return "".join(painted_eggs) # Example usage: n = int(input()) result = paint_eggs(n) print(result)
Title: Easter Eggs Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: The Easter Rabbit laid *n* eggs in a circle and is about to paint them. Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied: - Each of the seven colors should be used to paint at least one egg. - Any four eggs lying sequentially should be painted different colors. Help the Easter Rabbit paint the eggs in the required manner. We know that it is always possible. Input Specification: The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). Output Specification: Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indigo, "V" stands for violet. If there are several answers, print any of them. Demo Input: ['8\n', '13\n'] Demo Output: ['ROYGRBIV\n', 'ROYGBIVGBIVYG\n'] Note: The way the eggs will be painted in the first sample is shown on the picture:
```python def paint_eggs(n): colors = ["R", "O", "Y", "G", "B", "I", "V"] painted_eggs = [] painted_eggs.append(colors[0]) painted_eggs.append(colors[1]) painted_eggs.append(colors[2]) painted_eggs.append(colors[3]) for i in range(4, n): painted_eggs.append(colors[i % 7]) return "".join(painted_eggs) # Example usage: n = int(input()) result = paint_eggs(n) print(result) ```
0
12
C
Fruits
PROGRAMMING
1,100
[ "greedy", "implementation", "sortings" ]
C. Fruits
1
256
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).
The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy.
Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
[ "5 3\n4 2 1 10 5\napple\norange\nmango\n", "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n" ]
[ "7 19\n", "11 30\n" ]
none
0
[ { "input": "5 3\n4 2 1 10 5\napple\norange\nmango", "output": "7 19" }, { "input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30" }, { "input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl", "output": "173 173" }, { "input": "1 4\n1\nu\nu\nu\nu", "output": "4 4" }, { "input": "3 3\n4 2 3\nwivujdxzjm\nawagljmtc\nwivujdxzjm", "output": "7 11" }, { "input": "3 4\n10 10 10\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk\nodchpcsdhldqnkbhwtwnx\nldqnkbhwtwnxk", "output": "40 40" }, { "input": "3 1\n14 26 22\naag", "output": "14 26" }, { "input": "2 2\n5 5\ndcypj\npiyqiagzjlvbhgfndhfu", "output": "10 10" }, { "input": "4 3\n5 3 10 3\nxzjhplrzkbbzkypfazf\nxzjhplrzkbbzkypfazf\nh", "output": "9 25" }, { "input": "5 5\n10 10 6 7 9\niyerjkvzibxhllkeuagptnoqrzm\nvzibxhllkeuag\niyerjkvzibxhllkeuagptnoqrzm\nnoq\nnoq", "output": "35 49" }, { "input": "10 8\n19 18 20 13 19 13 11 10 19 16\nkayangqlsqmcd\nqls\nqydawlbludrgrjfjrhd\nfjrh\nqls\nqls\nrnmmayh\nkayangqlsqmcd", "output": "94 154" }, { "input": "5 15\n61 56 95 42 85\noq\ndwxivk\ntxdxzsfdj\noq\noq\ndwxivk\ntxdxzsfdj\ndwxivk\ntxdxzsfdj\nk\nk\ndwxivk\noq\nk\ntxdxzsfdj", "output": "891 1132" }, { "input": "12 18\n42 44 69 16 81 64 12 68 70 75 75 67\nfm\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nqamklzfmrjnqgdspwfasjnplg\nl\nl\nl\nfm\nqamklzfmrjnqgdspwfasjnplg\nl\nnplgwotfm\np\nl\namklzfm\ntkpubqamklzfmrjn\npwf\nfm\np", "output": "606 1338" }, { "input": "24 24\n34 69 89 45 87 30 78 14 53 16 27 54 75 95 10 69 80 71 43 3 91 9 8 7\nswtcofrcpeyszydwkrg\nszyd\npeyszyd\nrcpeyszydwkrgfj\npeyszydwkrgf\nzydw\nsmzginydyrtua\nj\nj\ntzwsw\ngfj\nyssoqnlpsm\ninydyrtuatzw\ninydy\nlpsmzginydyrtuatzwswtcofrcpeyszy\nyssoqnlpsm\npeyszyd\nyssoqnlpsm\ninydy\npeyszyd\ninydyrtuatzw\nat\nfj\nswtcofrcpeyszydwkrg", "output": "552 1769" } ]
1,686,459,380
2,147,483,647
Python 3
OK
TESTS
25
46
0
x , y = map(int,input().split()) l = list(map(int,input().split())) fruits = [] for i in range(y): fruits.append(input()) cnt = [] for i in set(fruits): cnt.append(fruits.count(i)) cnt = sorted(cnt)[::-1] l.sort() mini = 0 maxi = 0 for i in range(len(cnt)): mini+=(l[i]*cnt[i]) print(mini,end=" ") for i in range(len(cnt)): maxi+=(l[-1*(i+1)]*cnt[i]) print(maxi)
Title: Fruits Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags). Input Specification: The first line of the input contains two integer number *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. Output Specification: Print two numbers *a* and *b* (*a*<=≤<=*b*) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Demo Input: ['5 3\n4 2 1 10 5\napple\norange\nmango\n', '6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange\n'] Demo Output: ['7 19\n', '11 30\n'] Note: none
```python x , y = map(int,input().split()) l = list(map(int,input().split())) fruits = [] for i in range(y): fruits.append(input()) cnt = [] for i in set(fruits): cnt.append(fruits.count(i)) cnt = sorted(cnt)[::-1] l.sort() mini = 0 maxi = 0 for i in range(len(cnt)): mini+=(l[i]*cnt[i]) print(mini,end=" ") for i in range(len(cnt)): maxi+=(l[-1*(i+1)]*cnt[i]) print(maxi) ```
3.977
401
C
Team
PROGRAMMING
1,400
[ "constructive algorithms", "greedy", "implementation" ]
null
null
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: - there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way.
The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1.
In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1.
[ "1 2\n", "4 8\n", "4 10\n", "1 5\n" ]
[ "101\n", "110110110101\n", "11011011011011\n", "-1\n" ]
none
1,500
[ { "input": "1 2", "output": "101" }, { "input": "4 8", "output": "110110110101" }, { "input": "4 10", "output": "11011011011011" }, { "input": "1 5", "output": "-1" }, { "input": "3 4", "output": "1010101" }, { "input": "3 10", "output": "-1" }, { "input": "74 99", "output": "11011011011011011011011011011011011011011011011011011011011011011011011010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101" }, { "input": "19 30", "output": "1101101101101101101101101101101010101010101010101" }, { "input": "33 77", "output": "-1" }, { "input": "3830 6966", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "1000000 1000000", "output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1027 2030", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "4610 4609", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "3342 3339", "output": "-1" }, { "input": "7757 7755", "output": "-1" }, { "input": "10 8", "output": "-1" }, { "input": "4247 8495", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "7101 14204", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9801 19605", "output": "-1" }, { "input": "4025 6858", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "7129 13245", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "8826 12432", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "6322 9256", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "8097 14682", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "6196 6197", "output": "1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1709 2902", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "455 512", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101..." }, { "input": "1781 1272", "output": "-1" }, { "input": "3383 5670", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "954 1788", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9481 15554", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "9079 100096", "output": "-1" }, { "input": "481533 676709", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "423472 564888", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "227774 373297", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "42346 51898", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "739107 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "455043 798612", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "801460 801459", "output": "0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010..." }, { "input": "303498 503791", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "518822 597833", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "32342 64687", "output": "-1" }, { "input": "873192 873189", "output": "-1" }, { "input": "384870 450227", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "201106 208474", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "775338 980888", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "263338 393171", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "241043 330384", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "307203 614408", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "379310 417986", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "661101 785111", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "284634 319008", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "500000 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "499999 1000000", "output": "1101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101101..." }, { "input": "3 1", "output": "-1" }, { "input": "14124 242112", "output": "-1" }, { "input": "2 1", "output": "010" }, { "input": "2 3", "output": "10101" }, { "input": "1 4", "output": "11011" }, { "input": "2 6", "output": "11011011" }, { "input": "2 5", "output": "1101101" }, { "input": "2 4", "output": "110101" }, { "input": "2 3", "output": "10101" }, { "input": "2 2", "output": "1010" }, { "input": "2 1", "output": "010" }, { "input": "1 1", "output": "10" }, { "input": "1 3", "output": "1101" }, { "input": "3 2", "output": "01010" }, { "input": "5 4", "output": "010101010" }, { "input": "4 3", "output": "0101010" }, { "input": "11 10", "output": "010101010101010101010" }, { "input": "8 7", "output": "010101010101010" }, { "input": "4 2", "output": "-1" }, { "input": "6 5", "output": "01010101010" }, { "input": "3 7", "output": "1101101101" }, { "input": "5 1", "output": "-1" }, { "input": "10 1", "output": "-1" }, { "input": "4 9", "output": "1101101101101" }, { "input": "6 4", "output": "-1" }, { "input": "12 10", "output": "-1" }, { "input": "4 100", "output": "-1" } ]
1,590,917,149
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
140
0
z,o = [int(x) for x in input().split()] if o>=z-1 and o<=z+1: # 101010...... if z>o: print("01"*o,"0",sep="") elif o>z: print("10"*z,"1",sep="") else: print("10"*o,sep="") elif (z-1)*2<=o and o<=z*2+2: mini = min([o//2,z]) s = "110"*mini z-=mini o-=mini*2 if z: s="0"+s if o: s+= "1"*o print(s) else: print(-1)
Title: Team Time Limit: None seconds Memory Limit: None megabytes Problem Description: Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing numbers 1 and 0. The boys are very superstitious. They think that they can do well at the Olympiad if they begin with laying all the cards in a row so that: - there wouldn't be a pair of any side-adjacent cards with zeroes in a row; - there wouldn't be a group of three consecutive cards containing numbers one. Today Vanya brought *n* cards with zeroes and *m* cards with numbers one. The number of cards was so much that the friends do not know how to put all those cards in the described way. Help them find the required arrangement of the cards or else tell the guys that it is impossible to arrange cards in such a way. Input Specification: The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. Output Specification: In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. Demo Input: ['1 2\n', '4 8\n', '4 10\n', '1 5\n'] Demo Output: ['101\n', '110110110101\n', '11011011011011\n', '-1\n'] Note: none
```python z,o = [int(x) for x in input().split()] if o>=z-1 and o<=z+1: # 101010...... if z>o: print("01"*o,"0",sep="") elif o>z: print("10"*z,"1",sep="") else: print("10"*o,sep="") elif (z-1)*2<=o and o<=z*2+2: mini = min([o//2,z]) s = "110"*mini z-=mini o-=mini*2 if z: s="0"+s if o: s+= "1"*o print(s) else: print(-1) ```
0
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,480,183,005
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n, a, b, c = (int(x) for x in input().split()) nd = 4 - n % 4 if nd == 0: print 0 elif nd == 1: print(a) elif nd == 2: print(min(2 * a, b)) else: print(min(3 * a, min(a + b, 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 = (int(x) for x in input().split()) nd = 4 - n % 4 if nd == 0: print 0 elif nd == 1: print(a) elif nd == 2: print(min(2 * a, b)) else: print(min(3 * a, min(a + b, c))) ```
-1
483
A
Counterexample
PROGRAMMING
1,100
[ "brute force", "implementation", "math", "number theory" ]
null
null
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*. More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime.
The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50).
Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.
[ "2 4\n", "10 11\n", "900000000000000009 900000000000000029\n" ]
[ "2 3 4\n", "-1\n", "900000000000000009 900000000000000010 900000000000000021\n" ]
In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
500
[ { "input": "2 4", "output": "2 3 4" }, { "input": "10 11", "output": "-1" }, { "input": "900000000000000009 900000000000000029", "output": "900000000000000009 900000000000000010 900000000000000021" }, { "input": "640097987171091791 640097987171091835", "output": "640097987171091792 640097987171091793 640097987171091794" }, { "input": "19534350415104721 19534350415104725", "output": "19534350415104722 19534350415104723 19534350415104724" }, { "input": "933700505788726243 933700505788726280", "output": "933700505788726244 933700505788726245 933700505788726246" }, { "input": "1 3", "output": "-1" }, { "input": "1 4", "output": "2 3 4" }, { "input": "1 1", "output": "-1" }, { "input": "266540997167959130 266540997167959164", "output": "266540997167959130 266540997167959131 266540997167959132" }, { "input": "267367244641009850 267367244641009899", "output": "267367244641009850 267367244641009851 267367244641009852" }, { "input": "268193483524125978 268193483524125993", "output": "268193483524125978 268193483524125979 268193483524125980" }, { "input": "269019726702209402 269019726702209432", "output": "269019726702209402 269019726702209403 269019726702209404" }, { "input": "269845965585325530 269845965585325576", "output": "269845965585325530 269845965585325531 269845965585325532" }, { "input": "270672213058376250 270672213058376260", "output": "270672213058376250 270672213058376251 270672213058376252" }, { "input": "271498451941492378 271498451941492378", "output": "-1" }, { "input": "272324690824608506 272324690824608523", "output": "272324690824608506 272324690824608507 272324690824608508" }, { "input": "273150934002691930 273150934002691962", "output": "273150934002691930 273150934002691931 273150934002691932" }, { "input": "996517375802030516 996517375802030524", "output": "996517375802030516 996517375802030517 996517375802030518" }, { "input": "997343614685146644 997343614685146694", "output": "997343614685146644 997343614685146645 997343614685146646" }, { "input": "998169857863230068 998169857863230083", "output": "998169857863230068 998169857863230069 998169857863230070" }, { "input": "998996101041313492 998996101041313522", "output": "998996101041313492 998996101041313493 998996101041313494" }, { "input": "999822344219396916 999822344219396961", "output": "999822344219396916 999822344219396917 999822344219396918" }, { "input": "648583102513043 648583102513053", "output": "648583102513044 648583102513045 648583102513046" }, { "input": "266540997167959130 266540997167959131", "output": "-1" }, { "input": "267367244641009850 267367244641009850", "output": "-1" }, { "input": "268193483524125978 268193483524125979", "output": "-1" }, { "input": "269019726702209402 269019726702209402", "output": "-1" }, { "input": "269845965585325530 269845965585325530", "output": "-1" }, { "input": "270672213058376250 270672213058376254", "output": "270672213058376250 270672213058376251 270672213058376252" }, { "input": "271498451941492378 271498451941492379", "output": "-1" }, { "input": "272324690824608506 272324690824608508", "output": "272324690824608506 272324690824608507 272324690824608508" }, { "input": "273150934002691930 273150934002691931", "output": "-1" }, { "input": "996517375802030516 996517375802030518", "output": "996517375802030516 996517375802030517 996517375802030518" }, { "input": "997343614685146644 997343614685146644", "output": "-1" }, { "input": "2147483647 2147483649", "output": "-1" }, { "input": "3 5", "output": "-1" }, { "input": "1 7", "output": "2 3 4" }, { "input": "9 12", "output": "9 11 12" }, { "input": "4 4", "output": "-1" }, { "input": "11 13", "output": "-1" }, { "input": "2 2", "output": "-1" } ]
1,620,053,697
2,147,483,647
PyPy 3
OK
TESTS
42
108
1,433,600
def HCF(l, r): while r: l, r = r, l%r return l found = False l, r = map(int, input().split()) for i in range(l, r+1): for j in range(i, r+1): for k in range(j, r+1): if HCF(i, j) == 1 and HCF(j, k) == 1 and HCF(i, k) != 1: print(i, j, k) found = True break if found: break if found: break if not found: print(-1)
Title: Counterexample Time Limit: None seconds Memory Limit: None megabytes Problem Description: Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) is coprime, then the pair (*a*,<=*c*) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (*a*,<=*b*,<=*c*), for which the statement is false, and the numbers meet the condition *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*. More specifically, you need to find three numbers (*a*,<=*b*,<=*c*), such that *l*<=≤<=*a*<=&lt;<=*b*<=&lt;<=*c*<=≤<=*r*, pairs (*a*,<=*b*) and (*b*,<=*c*) are coprime, and pair (*a*,<=*c*) is not coprime. Input Specification: The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). Output Specification: Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1. Demo Input: ['2 4\n', '10 11\n', '900000000000000009 900000000000000029\n'] Demo Output: ['2 3 4\n', '-1\n', '900000000000000009 900000000000000010 900000000000000021\n'] Note: In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.
```python def HCF(l, r): while r: l, r = r, l%r return l found = False l, r = map(int, input().split()) for i in range(l, r+1): for j in range(i, r+1): for k in range(j, r+1): if HCF(i, j) == 1 and HCF(j, k) == 1 and HCF(i, k) != 1: print(i, j, k) found = True break if found: break if found: break if not found: print(-1) ```
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,679,428,142
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
31
0
from sys import stdin rd = stdin.readline l, r, a = map(int, rd().split()) res = max(l, r) + a if res & 1: print(res - 1) else: print(res)
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 from sys import stdin rd = stdin.readline l, r, a = map(int, rd().split()) res = max(l, r) + a if res & 1: print(res - 1) else: print(res) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\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", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,669,734,589
2,147,483,647
Python 3
OK
TESTS
18
92
0
s,n = list(map(int, input().split())) prices = list(map(int, input().split())) prices.sort() dif = 999 for i in range(n-s+1): if prices[i+(s-1)] - prices[i] < dif: dif = prices[i+(s-1)] - prices[i] print(dif)
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python s,n = list(map(int, input().split())) prices = list(map(int, input().split())) prices.sort() dif = 999 for i in range(n-s+1): if prices[i+(s-1)] - prices[i] < dif: dif = prices[i+(s-1)] - prices[i] print(dif) ```
3
499
B
Lecture
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes.
The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters.
Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input.
[ "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n", "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n" ]
[ "codeforces round letter round\n", "hbnyiyc joll joll un joll\n" ]
none
500
[ { "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round" }, { "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll" }, { "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b" }, { "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs" }, { "input": "1 1\namit am\namit", "output": "am" }, { "input": "1 1\na c\na", "output": "a" } ]
1,683,279,460
2,147,483,647
Python 3
OK
TESTS
37
452
921,600
n,m = map(int,input().split()) a = [] b = [] c = [] e = [] for i in range(m): a.insert(i,list(map(str,input().split()))) d = list(map(str,input().split())) for i in range(m): b.insert(i,a[i][0]) for i in range(m): c.insert(i,a[i][1]) for i in range(n): if(len(b[b.index(d[i])]) <= len(c[b.index(d[i])])): e.insert(i,b[b.index(d[i])]) else: e.insert(i,c[b.index(d[i])]) print(' '.join(e))
Title: Lecture Time Limit: None seconds Memory Limit: None megabytes Problem Description: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. Output Specification: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Demo Input: ['4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest\n', '5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll\n'] Demo Output: ['codeforces round letter round\n', 'hbnyiyc joll joll un joll\n'] Note: none
```python n,m = map(int,input().split()) a = [] b = [] c = [] e = [] for i in range(m): a.insert(i,list(map(str,input().split()))) d = list(map(str,input().split())) for i in range(m): b.insert(i,a[i][0]) for i in range(m): c.insert(i,a[i][1]) for i in range(n): if(len(b[b.index(d[i])]) <= len(c[b.index(d[i])])): e.insert(i,b[b.index(d[i])]) else: e.insert(i,c[b.index(d[i])]) print(' '.join(e)) ```
3
748
A
Santa Claus and a Place in a Class
PROGRAMMING
800
[ "implementation", "math" ]
null
null
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!
The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.
Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.
[ "4 3 9\n", "4 3 24\n", "2 4 4\n" ]
[ "2 2 L\n", "4 3 R\n", "1 2 R\n" ]
The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
500
[ { "input": "4 3 9", "output": "2 2 L" }, { "input": "4 3 24", "output": "4 3 R" }, { "input": "2 4 4", "output": "1 2 R" }, { "input": "3 10 24", "output": "2 2 R" }, { "input": "10 3 59", "output": "10 3 L" }, { "input": "10000 10000 160845880", "output": "8043 2940 R" }, { "input": "1 1 1", "output": "1 1 L" }, { "input": "1 1 2", "output": "1 1 R" }, { "input": "1 10000 1", "output": "1 1 L" }, { "input": "1 10000 20000", "output": "1 10000 R" }, { "input": "10000 1 1", "output": "1 1 L" }, { "input": "10000 1 10000", "output": "5000 1 R" }, { "input": "10000 1 20000", "output": "10000 1 R" }, { "input": "3 2 1", "output": "1 1 L" }, { "input": "3 2 2", "output": "1 1 R" }, { "input": "3 2 3", "output": "1 2 L" }, { "input": "3 2 4", "output": "1 2 R" }, { "input": "3 2 5", "output": "2 1 L" }, { "input": "3 2 6", "output": "2 1 R" }, { "input": "3 2 7", "output": "2 2 L" }, { "input": "3 2 8", "output": "2 2 R" }, { "input": "3 2 9", "output": "3 1 L" }, { "input": "3 2 10", "output": "3 1 R" }, { "input": "3 2 11", "output": "3 2 L" }, { "input": "3 2 12", "output": "3 2 R" }, { "input": "300 2000 1068628", "output": "268 314 R" }, { "input": "300 2000 584756", "output": "147 378 R" }, { "input": "300 2000 268181", "output": "68 91 L" }, { "input": "10000 9999 186450844", "output": "9324 4745 R" }, { "input": "10000 9999 197114268", "output": "9857 6990 R" }, { "input": "10000 9999 112390396", "output": "5621 818 R" }, { "input": "10000 10000 1", "output": "1 1 L" }, { "input": "10000 10000 2", "output": "1 1 R" }, { "input": "10000 10000 100000001", "output": "5001 1 L" }, { "input": "10000 10000 199999999", "output": "10000 10000 L" }, { "input": "10000 10000 200000000", "output": "10000 10000 R" }, { "input": "1 2 1", "output": "1 1 L" }, { "input": "1 2 2", "output": "1 1 R" }, { "input": "1 2 3", "output": "1 2 L" }, { "input": "1 2 4", "output": "1 2 R" }, { "input": "2 1 1", "output": "1 1 L" }, { "input": "2 1 2", "output": "1 1 R" }, { "input": "2 1 3", "output": "2 1 L" }, { "input": "2 1 4", "output": "2 1 R" }, { "input": "4 3 7", "output": "2 1 L" }, { "input": "1 1 1", "output": "1 1 L" } ]
1,482,657,565
865
Python 3
OK
TESTS
46
62
4,608,000
n,m,k=map(int,input().split()) r=(k-1)//(m*2)+1 d=(k-1)%(m*2)//2+1 if k%2==1: s='L' else: s='R' print(r,d,s)
Title: Santa Claus and a Place in a Class Time Limit: None seconds Memory Limit: None megabytes Problem Description: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane are numbered from 1 to *m* starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture). The organizers numbered all the working places from 1 to 2*nm*. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. Santa Clause knows that his place has number *k*. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right! Input Specification: The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. Output Specification: Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. Demo Input: ['4 3 9\n', '4 3 24\n', '2 4 4\n'] Demo Output: ['2 2 L\n', '4 3 R\n', '1 2 R\n'] Note: The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example. In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.
```python n,m,k=map(int,input().split()) r=(k-1)//(m*2)+1 d=(k-1)%(m*2)//2+1 if k%2==1: s='L' else: s='R' print(r,d,s) ```
3
3
A
Shortest path of the king
PROGRAMMING
1,000
[ "greedy", "shortest paths" ]
A. Shortest path of the king
1
64
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).
The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.
In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.
[ "a8\nh1\n" ]
[ "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n" ]
none
0
[ { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "b2\nb4", "output": "2\nU\nU" }, { "input": "a5\na5", "output": "0" }, { "input": "h1\nb2", "output": "6\nLU\nL\nL\nL\nL\nL" }, { "input": "c5\nh2", "output": "5\nRD\nRD\nRD\nR\nR" }, { "input": "e1\nf2", "output": "1\nRU" }, { "input": "g4\nd2", "output": "3\nLD\nLD\nL" }, { "input": "a8\nb2", "output": "6\nRD\nD\nD\nD\nD\nD" }, { "input": "d4\nh2", "output": "4\nRD\nRD\nR\nR" }, { "input": "c5\na2", "output": "3\nLD\nLD\nD" }, { "input": "h5\nf8", "output": "3\nLU\nLU\nU" }, { "input": "e6\nb6", "output": "3\nL\nL\nL" }, { "input": "a6\ng4", "output": "6\nRD\nRD\nR\nR\nR\nR" }, { "input": "f7\nc2", "output": "5\nLD\nLD\nLD\nD\nD" }, { "input": "b7\nh8", "output": "6\nRU\nR\nR\nR\nR\nR" }, { "input": "g7\nd6", "output": "3\nLD\nL\nL" }, { "input": "c8\na3", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "h8\nf1", "output": "7\nLD\nLD\nD\nD\nD\nD\nD" }, { "input": "d1\nb7", "output": "6\nLU\nLU\nU\nU\nU\nU" }, { "input": "a7\ne5", "output": "4\nRD\nRD\nR\nR" }, { "input": "d6\nb1", "output": "5\nLD\nLD\nD\nD\nD" }, { "input": "f5\ng5", "output": "1\nR" }, { "input": "h4\nd1", "output": "4\nLD\nLD\nLD\nL" }, { "input": "b3\na5", "output": "2\nLU\nU" }, { "input": "d2\nf1", "output": "2\nRD\nR" }, { "input": "f1\nc5", "output": "4\nLU\nLU\nLU\nU" }, { "input": "a8\nh1", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD" }, { "input": "c7\ne5", "output": "2\nRD\nRD" }, { "input": "e7\nb1", "output": "6\nLD\nLD\nLD\nD\nD\nD" }, { "input": "g8\na8", "output": "6\nL\nL\nL\nL\nL\nL" }, { "input": "g6\nf2", "output": "4\nLD\nD\nD\nD" }, { "input": "g4\nc4", "output": "4\nL\nL\nL\nL" }, { "input": "g2\na6", "output": "6\nLU\nLU\nLU\nLU\nL\nL" }, { "input": "f8\nf8", "output": "0" }, { "input": "f5\nd2", "output": "3\nLD\nLD\nD" } ]
1,691,068,058
2,147,483,647
Python 3
OK
TESTS
35
92
0
# LUOGU_RID: 118875845 a = input() + input() a, b = (ord(a[i]) - ord(a[i + 2]) for i in (0, 1)) print(max(a, -a, b, -b)) while a != 0 or b != 0: r = '' if a < 0: r = 'R';a += 1 if a > 0: r = 'L';a -= 1 if b < 0: r += 'U';b += 1 if b > 0: r += 'D';b -= 1 print(r)
Title: Shortest path of the king Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to). Input Specification: The first line contains the chessboard coordinates of square *s*, the second line — of square *t*. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. Output Specification: In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. Demo Input: ['a8\nh1\n'] Demo Output: ['7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n'] Note: none
```python # LUOGU_RID: 118875845 a = input() + input() a, b = (ord(a[i]) - ord(a[i + 2]) for i in (0, 1)) print(max(a, -a, b, -b)) while a != 0 or b != 0: r = '' if a < 0: r = 'R';a += 1 if a > 0: r = 'L';a -= 1 if b < 0: r += 'U';b += 1 if b > 0: r += 'D';b -= 1 print(r) ```
3.954
604
B
More Cowbell
PROGRAMMING
1,400
[ "binary search", "greedy" ]
null
null
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=&gt;<=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*.
The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively. The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order.
Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*.
[ "2 1\n2 5\n", "4 3\n2 3 5 9\n", "3 2\n3 5 7\n" ]
[ "7\n", "9\n", "8\n" ]
In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}. In the third sample, the optimal solution is {3, 5} and {7}.
1,000
[ { "input": "2 1\n2 5", "output": "7" }, { "input": "4 3\n2 3 5 9", "output": "9" }, { "input": "3 2\n3 5 7", "output": "8" }, { "input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10 10\n3 15 31 61 63 63 68 94 98 100", "output": "100" }, { "input": "100 97\n340 402 415 466 559 565 649 689 727 771 774 776 789 795 973 1088 1212 1293 1429 1514 1587 1599 1929 1997 2278 2529 2656 2677 2839 2894 2951 3079 3237 3250 3556 3568 3569 3578 3615 3641 3673 3892 4142 4418 4515 4766 4846 4916 5225 5269 5352 5460 5472 5635 5732 5886 5941 5976 5984 6104 6113 6402 6409 6460 6550 6563 6925 7006 7289 7401 7441 7451 7709 7731 7742 7750 7752 7827 8101 8154 8376 8379 8432 8534 8578 8630 8706 8814 8882 8972 9041 9053 9109 9173 9473 9524 9547 9775 9791 9983", "output": "9983" }, { "input": "10 9\n7 29 35 38 41 47 54 56 73 74", "output": "74" }, { "input": "1 2342\n12345", "output": "12345" }, { "input": "10 5\n15 15 20 28 38 44 46 52 69 94", "output": "109" }, { "input": "10 9\n6 10 10 32 36 38 69 80 82 93", "output": "93" }, { "input": "10 10\n4 19 22 24 25 43 49 56 78 88", "output": "88" }, { "input": "100 89\n474 532 759 772 803 965 1043 1325 1342 1401 1411 1452 1531 1707 1906 1928 2034 2222 2335 2606 2757 2968 2978 3211 3513 3734 3772 3778 3842 3948 3976 4038 4055 4113 4182 4267 4390 4408 4478 4595 4668 4792 4919 5133 5184 5255 5312 5341 5476 5628 5683 5738 5767 5806 5973 6051 6134 6254 6266 6279 6314 6342 6599 6676 6747 6777 6827 6842 7057 7097 7259 7340 7378 7405 7510 7520 7698 7796 8148 8351 8507 8601 8805 8814 8826 8978 9116 9140 9174 9338 9394 9403 9407 9423 9429 9519 9764 9784 9838 9946", "output": "9946" }, { "input": "100 74\n10 211 323 458 490 592 979 981 1143 1376 1443 1499 1539 1612 1657 1874 2001 2064 2123 2274 2346 2471 2522 2589 2879 2918 2933 2952 3160 3164 3167 3270 3382 3404 3501 3522 3616 3802 3868 3985 4007 4036 4101 4580 4687 4713 4714 4817 4955 5257 5280 5343 5428 5461 5566 5633 5727 5874 5925 6233 6309 6389 6500 6701 6731 6847 6916 7088 7088 7278 7296 7328 7564 7611 7646 7887 7887 8065 8075 8160 8300 8304 8316 8355 8404 8587 8758 8794 8890 9038 9163 9235 9243 9339 9410 9587 9868 9916 9923 9986", "output": "9986" }, { "input": "100 61\n82 167 233 425 432 456 494 507 562 681 683 921 1218 1323 1395 1531 1586 1591 1675 1766 1802 1842 2116 2625 2697 2735 2739 3337 3349 3395 3406 3596 3610 3721 4059 4078 4305 4330 4357 4379 4558 4648 4651 4784 4819 4920 5049 5312 5361 5418 5440 5463 5547 5594 5821 5951 5972 6141 6193 6230 6797 6842 6853 6854 7017 7026 7145 7322 7391 7460 7599 7697 7756 7768 7872 7889 8094 8215 8408 8440 8462 8714 8756 8760 8881 9063 9111 9184 9281 9373 9406 9417 9430 9511 9563 9634 9660 9788 9883 9927", "output": "9927" }, { "input": "100 84\n53 139 150 233 423 570 786 861 995 1017 1072 1196 1276 1331 1680 1692 1739 1748 1826 2067 2280 2324 2368 2389 2607 2633 2760 2782 2855 2996 3030 3093 3513 3536 3557 3594 3692 3707 3823 3832 4009 4047 4088 4095 4408 4537 4565 4601 4784 4878 4935 5029 5252 5322 5389 5407 5511 5567 5857 6182 6186 6198 6280 6290 6353 6454 6458 6567 6843 7166 7216 7257 7261 7375 7378 7539 7542 7762 7771 7797 7980 8363 8606 8612 8663 8801 8808 8823 8918 8975 8997 9240 9245 9259 9356 9755 9759 9760 9927 9970", "output": "9970" }, { "input": "100 50\n130 248 312 312 334 589 702 916 921 1034 1047 1346 1445 1500 1585 1744 1951 2123 2273 2362 2400 2455 2496 2530 2532 2944 3074 3093 3094 3134 3698 3967 4047 4102 4109 4260 4355 4466 4617 4701 4852 4892 4915 4917 4936 4981 4999 5106 5152 5203 5214 5282 5412 5486 5525 5648 5897 5933 5969 6251 6400 6421 6422 6558 6805 6832 6908 6924 6943 6980 7092 7206 7374 7417 7479 7546 7672 7756 7973 8020 8028 8079 8084 8085 8137 8153 8178 8239 8639 8667 8829 9263 9333 9370 9420 9579 9723 9784 9841 9993", "output": "11103" }, { "input": "100 50\n156 182 208 409 496 515 659 761 772 794 827 912 1003 1236 1305 1388 1412 1422 1428 1465 1613 2160 2411 2440 2495 2684 2724 2925 3033 3035 3155 3260 3378 3442 3483 3921 4031 4037 4091 4113 4119 4254 4257 4442 4559 4614 4687 4839 4896 5054 5246 5316 5346 5859 5928 5981 6148 6250 6422 6433 6448 6471 6473 6485 6503 6779 6812 7050 7064 7074 7141 7378 7424 7511 7574 7651 7808 7858 8286 8291 8446 8536 8599 8628 8636 8768 8900 8981 9042 9055 9114 9146 9186 9411 9480 9590 9681 9749 9757 9983", "output": "10676" }, { "input": "100 50\n145 195 228 411 577 606 629 775 1040 1040 1058 1187 1307 1514 1784 1867 1891 2042 2042 2236 2549 2555 2560 2617 2766 2807 2829 2917 3070 3072 3078 3095 3138 3147 3149 3196 3285 3287 3309 3435 3531 3560 3563 3769 3830 3967 4081 4158 4315 4387 4590 4632 4897 4914 5128 5190 5224 5302 5402 5416 5420 5467 5517 5653 5820 5862 5941 6053 6082 6275 6292 6316 6490 6530 6619 6632 6895 7071 7234 7323 7334 7412 7626 7743 8098 8098 8136 8158 8264 8616 8701 8718 8770 8803 8809 8983 9422 9530 9811 9866", "output": "10011" }, { "input": "100 50\n56 298 387 456 518 532 589 792 870 1041 1055 1122 1141 1166 1310 1329 1523 1548 1626 1730 1780 1833 1850 1911 2006 2157 2303 2377 2403 2442 2450 2522 2573 2822 2994 3200 3238 3252 3280 3311 3345 3422 3429 3506 3526 3617 3686 3791 4134 4467 4525 4614 4633 4792 5017 5220 5243 5338 5445 5536 5639 5675 5763 5875 6129 6220 6228 6287 6385 6616 6789 6822 6940 6959 6985 7297 7304 7391 7443 7580 7824 7884 7981 8055 8063 8223 8280 8322 8346 8473 8688 8986 9087 9323 9477 9489 9518 9621 9699 9804", "output": "10009" }, { "input": "100 49990\n221 257 543 613 818 855 884 1195 1233 1293 1327 1474 1567 1568 1728 1789 1809 1957 1994 2198 2217 2289 2298 2360 2441 2454 2517 2519 2597 2652 2909 2958 2970 3271 3310 3409 3450 3646 3950 3965 4016 4116 4134 4159 4462 4624 4631 4783 4804 5031 5276 5538 5729 5845 5880 5894 5959 5961 6028 6105 6184 6335 6370 6523 6532 6677 6762 6868 6998 7066 7245 7360 7490 7492 7645 7677 7786 7804 8038 8131 8207 8400 8507 8556 8575 8599 8673 8676 8712 8816 9123 9158 9216 9369 9628 9707 9768 9800 9876 9934", "output": "9934" }, { "input": "1 50000\n2", "output": "2" }, { "input": "1 40000\n23456", "output": "23456" }, { "input": "1 2\n10", "output": "10" }, { "input": "1 1\n1", "output": "1" }, { "input": "2 2\n2 3", "output": "3" }, { "input": "4 2\n1 2 8 9", "output": "10" } ]
1,677,816,501
2,147,483,647
PyPy 3-64
OK
TESTS
54
77
13,516,800
n,k = map(int, input().split()) l = list(map(int, input().split())) x = 2*k - n ans = l[-1] for i in range(n-x): j = n-x-1-i if i==j: ans = max(ans,l[i]) break elif i>j: break else: ans = max(ans,l[i]+l[j]) print(ans)
Title: More Cowbell Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. Kevin is a meticulous cowbell collector and knows that the size of his *i*-th (1<=≤<=*i*<=≤<=*n*) cowbell is an integer *s**i*. In fact, he keeps his cowbells sorted by size, so *s**i*<=-<=1<=≤<=*s**i* for any *i*<=&gt;<=1. Also an expert packer, Kevin can fit one or two cowbells into a box of size *s* if and only if the sum of their sizes does not exceed *s*. Given this information, help Kevin determine the smallest *s* for which it is possible to put all of his cowbells into *k* boxes of size *s*. Input Specification: The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively. The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000), the sizes of Kevin's cowbells. It is guaranteed that the sizes *s**i* are given in non-decreasing order. Output Specification: Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. Demo Input: ['2 1\n2 5\n', '4 3\n2 3 5 9\n', '3 2\n3 5 7\n'] Demo Output: ['7\n', '9\n', '8\n'] Note: In the first sample, Kevin must pack his two cowbells into the same box. In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}. In the third sample, the optimal solution is {3, 5} and {7}.
```python n,k = map(int, input().split()) l = list(map(int, input().split())) x = 2*k - n ans = l[-1] for i in range(n-x): j = n-x-1-i if i==j: ans = max(ans,l[i]) break elif i>j: break else: ans = max(ans,l[i]+l[j]) print(ans) ```
3
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,698,612,086
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
// "COURTESY TO ALMIGHTY ALLAH" #include<bits/stdc++.h> using namespace std ; bool islucky(int n){ string s = to_string(n) ; for (int i=0 ; i<s.size();i++){ if (s[i] != '4' && s[i] != '7') return false ; } return true ; } bool isdiv(int n){ vector<int> v = {4,7,44,77,47,74,777,444,774,747,477,447,474,744} ; for(int i:v){ if (n%i == 0) return true ; } return false ; } int main(){ int n ; cin >> n ; if (islucky(n) || isdiv(n)) cout << "YES" ; else cout << "NO" ; return 0 ; }
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 // "COURTESY TO ALMIGHTY ALLAH" #include<bits/stdc++.h> using namespace std ; bool islucky(int n){ string s = to_string(n) ; for (int i=0 ; i<s.size();i++){ if (s[i] != '4' && s[i] != '7') return false ; } return true ; } bool isdiv(int n){ vector<int> v = {4,7,44,77,47,74,777,444,774,747,477,447,474,744} ; for(int i:v){ if (n%i == 0) return true ; } return false ; } int main(){ int n ; cin >> n ; if (islucky(n) || isdiv(n)) cout << "YES" ; else cout << "NO" ; return 0 ; } ```
-1
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,619,947,859
2,147,483,647
Python 3
OK
TESTS
81
124
204,800
n = int(input()) arr = [list(map(int,input().split())) for _ in range(n)] sum,sum1,sum2 = 0,0,0 for i in range(len(arr)): sum += arr[i][0] sum1 += arr[i][1] sum2 += arr[i][2] if (sum == 0) and (sum1 == 0) and (sum2 == 0) : print("YES") else : print("NO")
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) arr = [list(map(int,input().split())) for _ in range(n)] sum,sum1,sum2 = 0,0,0 for i in range(len(arr)): sum += arr[i][0] sum1 += arr[i][1] sum2 += arr[i][2] if (sum == 0) and (sum1 == 0) and (sum2 == 0) : print("YES") else : print("NO") ```
3.968619
610
A
Pasha and Stick
PROGRAMMING
1,000
[ "combinatorics", "math" ]
null
null
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick.
The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square.
[ "6\n", "20\n" ]
[ "1\n", "4\n" ]
There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
500
[ { "input": "6", "output": "1" }, { "input": "20", "output": "4" }, { "input": "1", "output": "0" }, { "input": "2", "output": "0" }, { "input": "3", "output": "0" }, { "input": "4", "output": "0" }, { "input": "2000000000", "output": "499999999" }, { "input": "1924704072", "output": "481176017" }, { "input": "73740586", "output": "18435146" }, { "input": "1925088820", "output": "481272204" }, { "input": "593070992", "output": "148267747" }, { "input": "1925473570", "output": "481368392" }, { "input": "629490186", "output": "157372546" }, { "input": "1980649112", "output": "495162277" }, { "input": "36661322", "output": "9165330" }, { "input": "1943590793", "output": "0" }, { "input": "71207034", "output": "17801758" }, { "input": "1757577394", "output": "439394348" }, { "input": "168305294", "output": "42076323" }, { "input": "1934896224", "output": "483724055" }, { "input": "297149088", "output": "74287271" }, { "input": "1898001634", "output": "474500408" }, { "input": "176409698", "output": "44102424" }, { "input": "1873025522", "output": "468256380" }, { "input": "5714762", "output": "1428690" }, { "input": "1829551192", "output": "457387797" }, { "input": "16269438", "output": "4067359" }, { "input": "1663283390", "output": "415820847" }, { "input": "42549941", "output": "0" }, { "input": "1967345604", "output": "491836400" }, { "input": "854000", "output": "213499" }, { "input": "1995886626", "output": "498971656" }, { "input": "10330019", "output": "0" }, { "input": "1996193634", "output": "499048408" }, { "input": "9605180", "output": "2401294" }, { "input": "1996459740", "output": "499114934" }, { "input": "32691948", "output": "8172986" }, { "input": "1975903308", "output": "493975826" }, { "input": "1976637136", "output": "494159283" }, { "input": "29803038", "output": "7450759" }, { "input": "1977979692", "output": "494494922" }, { "input": "1978595336", "output": "494648833" }, { "input": "27379344", "output": "6844835" }, { "input": "1979729912", "output": "494932477" }, { "input": "1980253780", "output": "495063444" }, { "input": "1980751584", "output": "495187895" }, { "input": "53224878", "output": "13306219" }, { "input": "5", "output": "0" }, { "input": "7", "output": "0" }, { "input": "8", "output": "1" }, { "input": "9", "output": "0" }, { "input": "10", "output": "2" }, { "input": "11", "output": "0" }, { "input": "12", "output": "2" }, { "input": "13", "output": "0" }, { "input": "14", "output": "3" }, { "input": "15", "output": "0" }, { "input": "16", "output": "3" }, { "input": "17", "output": "0" }, { "input": "18", "output": "4" }, { "input": "19", "output": "0" }, { "input": "21", "output": "0" }, { "input": "22", "output": "5" }, { "input": "23", "output": "0" }, { "input": "24", "output": "5" }, { "input": "25", "output": "0" }, { "input": "26", "output": "6" }, { "input": "27", "output": "0" }, { "input": "28", "output": "6" }, { "input": "29", "output": "0" }, { "input": "30", "output": "7" }, { "input": "111", "output": "0" }, { "input": "55", "output": "0" }, { "input": "105", "output": "0" }, { "input": "199", "output": "0" }, { "input": "151", "output": "0" } ]
1,609,515,468
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
15
139
0
n=int(input()) print(n//4-(not n%4))
Title: Pasha and Stick Time Limit: None seconds Memory Limit: None megabytes Problem Description: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=2·109) — the length of Pasha's stick. Output Specification: The output should contain a single integer — the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Demo Input: ['6\n', '20\n'] Demo Output: ['1\n', '4\n'] Note: There is only one way to divide the stick in the first sample {1, 1, 2, 2}. Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work.
```python n=int(input()) print(n//4-(not n%4)) ```
0
851
B
Arpa and an exam about geometry
PROGRAMMING
1,400
[ "geometry", "math" ]
null
null
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct.
Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower).
[ "0 1 1 1 1 0\n", "1 1 0 0 1000 1000\n" ]
[ "Yes\n", "No\n" ]
In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
1,000
[ { "input": "0 1 1 1 1 0", "output": "Yes" }, { "input": "1 1 0 0 1000 1000", "output": "No" }, { "input": "1 0 2 0 3 0", "output": "No" }, { "input": "3 4 0 0 4 3", "output": "Yes" }, { "input": "-1000000000 1 0 0 1000000000 1", "output": "Yes" }, { "input": "49152 0 0 0 0 81920", "output": "No" }, { "input": "1 -1 4 4 2 -3", "output": "No" }, { "input": "-2 -2 1 4 -2 0", "output": "No" }, { "input": "5 0 4 -2 0 1", "output": "No" }, { "input": "-4 -3 2 -1 -3 4", "output": "No" }, { "input": "-3 -3 5 2 3 -1", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 999999999", "output": "No" }, { "input": "-1000000000 -1000000000 0 0 1000000000 1000000000", "output": "No" }, { "input": "-357531221 381512519 -761132895 -224448284 328888775 -237692564", "output": "No" }, { "input": "264193194 -448876521 736684426 -633906160 -328597212 -47935734", "output": "No" }, { "input": "419578772 -125025887 169314071 89851312 961404059 21419450", "output": "No" }, { "input": "-607353321 -620687860 248029390 477864359 728255275 -264646027", "output": "No" }, { "input": "299948862 -648908808 338174789 841279400 -850322448 350263551", "output": "No" }, { "input": "48517753 416240699 7672672 272460100 -917845051 199790781", "output": "No" }, { "input": "-947393823 -495674431 211535284 -877153626 -522763219 -778236665", "output": "No" }, { "input": "-685673792 -488079395 909733355 385950193 -705890324 256550506", "output": "No" }, { "input": "-326038504 547872194 49630307 713863100 303770000 -556852524", "output": "No" }, { "input": "-706921242 -758563024 -588592101 -443440080 858751713 238854303", "output": "No" }, { "input": "-1000000000 -1000000000 0 1000000000 1000000000 -1000000000", "output": "Yes" }, { "input": "1000000000 1000000000 0 -1000000000 -1000000000 1000000000", "output": "Yes" }, { "input": "-999999999 -1000000000 0 0 1000000000 999999999", "output": "Yes" }, { "input": "-1000000000 -999999999 0 0 1000000000 999999999", "output": "No" }, { "input": "-1 -1000000000 0 1000000000 1 -1000000000", "output": "Yes" }, { "input": "0 1000000000 1 0 0 -1000000000", "output": "Yes" }, { "input": "0 1000000000 0 0 0 -1000000000", "output": "No" }, { "input": "0 1 1 2 2 3", "output": "No" }, { "input": "999999999 1000000000 0 0 -1000000000 -999999999", "output": "Yes" }, { "input": "0 0 1 1 2 0", "output": "Yes" }, { "input": "0 0 1 1 2 2", "output": "No" }, { "input": "1 1 2 2 3 3", "output": "No" }, { "input": "0 2 0 3 0 4", "output": "No" }, { "input": "1 1 1 2 1 3", "output": "No" }, { "input": "0 0 3 4 3 9", "output": "Yes" }, { "input": "589824 196608 262144 196608 0 0", "output": "Yes" }, { "input": "0 0 1000000000 1 1000000000 -999999999", "output": "No" }, { "input": "0 0 2 45 0 90", "output": "Yes" }, { "input": "0 0 0 2 0 1", "output": "No" }, { "input": "0 2 4 5 4 0", "output": "Yes" }, { "input": "0 0 2 0 4 0", "output": "No" }, { "input": "1 1 3 3 5 5", "output": "No" }, { "input": "1 1 2 2 3 1", "output": "Yes" } ]
1,504,540,461
4,761
Python 3
WRONG_ANSWER
PRETESTS
3
46
0
ax, ay, bx, by, cx, cy = map(int, input().split()) a = ax + ay b = bx + by c = cx + cy if a + c == b: print('Yes') elif a == b and ax == cx: print('Yes') else: print('No')
Title: Arpa and an exam about geometry Time Limit: None seconds Memory Limit: None megabytes Problem Description: Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points *a*,<=*b*,<=*c*. Find a point and an angle such that if we rotate the page around the point by the angle, the new position of *a* is the same as the old position of *b*, and the new position of *b* is the same as the old position of *c*. Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not. Input Specification: The only line contains six integers *a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*c**x*,<=*c**y* (|*a**x*|,<=|*a**y*|,<=|*b**x*|,<=|*b**y*|,<=|*c**x*|,<=|*c**y*|<=≤<=109). It's guaranteed that the points are distinct. Output Specification: Print "Yes" if the problem has a solution, "No" otherwise. You can print each letter in any case (upper or lower). Demo Input: ['0 1 1 1 1 0\n', '1 1 0 0 1000 1000\n'] Demo Output: ['Yes\n', 'No\n'] Note: In the first sample test, rotate the page around (0.5, 0.5) by <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/9d845923f4d356a48d8ede337db0303821311f0c.png" style="max-width: 100.0%;max-height: 100.0%;"/>. In the second sample test, you can't find any solution.
```python ax, ay, bx, by, cx, cy = map(int, input().split()) a = ax + ay b = bx + by c = cx + cy if a + c == b: print('Yes') elif a == b and ax == cx: print('Yes') else: print('No') ```
0
276
C
Little Girl and Maximum Sum
PROGRAMMING
1,500
[ "data structures", "greedy", "implementation", "sortings" ]
null
null
The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.
The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query.
In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
[ "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n" ]
[ "25\n", "33\n" ]
none
1,500
[ { "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25" }, { "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33" }, { "input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\n12 30\n11 30\n9 21\n1 14\n15 22\n4 11\n5 24\n8 20\n17 33\n6 9\n3 14\n25 34\n10 17", "output": "9382" }, { "input": "16 13\n40 32 15 16 35 36 45 23 30 42 25 8 29 21 39 23\n2 9\n3 11\n8 9\n4 14\n1 6\n5 10\n5 14\n5 11\n13 13\n2 8\n9 16\n6 10\n7 8", "output": "2838" }, { "input": "31 48\n45 19 16 42 38 18 50 7 28 40 39 25 45 14 36 18 27 30 16 4 22 6 1 23 16 47 14 35 27 47 2\n6 16\n11 28\n4 30\n25 26\n11 30\n5 9\n4 17\n15 17\n10 25\n15 26\n1 3\n9 26\n8 29\n16 30\n5 24\n27 30\n9 10\n22 29\n2 6\n15 24\n6 21\n19 21\n4 28\n1 7\n18 21\n10 22\n6 15\n14 28\n4 29\n12 13\n19 29\n5 6\n13 31\n21 27\n9 25\n6 18\n6 8\n28 30\n2 4\n15 21\n1 1\n8 30\n3 31\n11 27\n28 29\n6 22\n20 22\n9 25", "output": "17471" }, { "input": "22 7\n44 41 40 41 37 42 46 16 50 47 30 7 32 6 20 14 47 25 11 1 35 12\n1 10\n10 20\n4 5\n1 8\n2 12\n8 8\n2 16", "output": "2202" }, { "input": "3 2\n1 2 3\n2 3\n1 2", "output": "9" } ]
1,689,794,579
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
26,112,000
n,m=map(int,input().split()) v=list(map(int,input().split())) v.sort(reverse=True) freq=[] for i in range(n+1): freq.append(0) for i in range(m): l,r=map(int,input().split()) freq[l-1]+=1 freq[r]-=1 for i in range(1,n+1): freq[i]+=freq[i-1] freq.sort(reverse=True) ans=0 for i in range(n): ans+=(freq[i]*v[i]) print(ans)
Title: Little Girl and Maximum Sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. Input Specification: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the $i$-th query. Output Specification: In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Demo Input: ['3 3\n5 3 2\n1 2\n2 3\n1 3\n', '5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n'] Demo Output: ['25\n', '33\n'] Note: none
```python n,m=map(int,input().split()) v=list(map(int,input().split())) v.sort(reverse=True) freq=[] for i in range(n+1): freq.append(0) for i in range(m): l,r=map(int,input().split()) freq[l-1]+=1 freq[r]-=1 for i in range(1,n+1): freq[i]+=freq[i-1] freq.sort(reverse=True) ans=0 for i in range(n): ans+=(freq[i]*v[i]) print(ans) ```
0
114
A
Cifera
PROGRAMMING
1,000
[ "math" ]
null
null
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.
The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1).
You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*.
[ "5\n25\n", "3\n8\n" ]
[ "YES\n1\n", "NO\n" ]
none
500
[ { "input": "5\n25", "output": "YES\n1" }, { "input": "3\n8", "output": "NO" }, { "input": "123\n123", "output": "YES\n0" }, { "input": "99\n970300", "output": "NO" }, { "input": "1000\n6666666", "output": "NO" }, { "input": "59\n3571", "output": "NO" }, { "input": "256\n16777217", "output": "NO" }, { "input": "4638\n21511044", "output": "YES\n1" }, { "input": "24\n191102976", "output": "YES\n5" }, { "input": "52010\n557556453", "output": "NO" }, { "input": "61703211\n1750753082", "output": "NO" }, { "input": "137\n2571353", "output": "YES\n2" }, { "input": "8758\n1746157336", "output": "NO" }, { "input": "2\n64", "output": "YES\n5" }, { "input": "96\n884736", "output": "YES\n2" }, { "input": "1094841453\n1656354409", "output": "NO" }, { "input": "1154413\n1229512809", "output": "NO" }, { "input": "2442144\n505226241", "output": "NO" }, { "input": "11548057\n1033418098", "output": "NO" }, { "input": "581\n196122941", "output": "YES\n2" }, { "input": "146\n1913781536", "output": "NO" }, { "input": "945916\n1403881488", "output": "NO" }, { "input": "68269\n365689065", "output": "NO" }, { "input": "30\n900", "output": "YES\n1" }, { "input": "6\n1296", "output": "YES\n3" }, { "input": "1470193122\n1420950405", "output": "NO" }, { "input": "90750\n1793111557", "output": "NO" }, { "input": "1950054\n1664545956", "output": "NO" }, { "input": "6767692\n123762320", "output": "NO" }, { "input": "1437134\n1622348229", "output": "NO" }, { "input": "444103\n1806462642", "output": "NO" }, { "input": "2592\n6718464", "output": "YES\n1" }, { "input": "50141\n366636234", "output": "NO" }, { "input": "835\n582182875", "output": "YES\n2" }, { "input": "156604\n902492689", "output": "NO" }, { "input": "27385965\n1742270058", "output": "NO" }, { "input": "3\n9", "output": "YES\n1" }, { "input": "35\n1838265625", "output": "YES\n5" }, { "input": "8\n4096", "output": "YES\n3" }, { "input": "85955\n945811082", "output": "NO" }, { "input": "54958832\n956670209", "output": "NO" }, { "input": "1475381\n1348159738", "output": "NO" }, { "input": "7313241\n413670642", "output": "NO" }, { "input": "582470\n2116368165", "output": "NO" }, { "input": "26859739\n595086170", "output": "NO" }, { "input": "249766393\n1582130", "output": "NO" }, { "input": "11734\n137686756", "output": "YES\n1" }, { "input": "925093\n1098566745", "output": "NO" }, { "input": "40\n1600", "output": "YES\n1" }, { "input": "2147483647\n2147483647", "output": "YES\n0" }, { "input": "2147483646\n2147483647", "output": "NO" }, { "input": "2147483647\n2147483646", "output": "NO" }, { "input": "2\n2147483647", "output": "NO" }, { "input": "2\n1073741825", "output": "NO" }, { "input": "2\n1073741824", "output": "YES\n29" }, { "input": "10000\n10", "output": "NO" }, { "input": "10\n10000", "output": "YES\n3" }, { "input": "10\n2000000000", "output": "NO" }, { "input": "10\n1000000000", "output": "YES\n8" }, { "input": "5\n1808548329", "output": "NO" }, { "input": "2\n2147483646", "output": "NO" }, { "input": "25\n125", "output": "NO" }, { "input": "6\n18", "output": "NO" }, { "input": "5\n30", "output": "NO" } ]
1,438,377,615
2,147,483,647
Python 3
OK
TESTS
64
124
0
k = int(input()) m = int(input()) left = 1 right = 50 while right-left > 1: middle = (left+right) // 2 if k**middle <= m: left = middle else: right = middle if k**left == m: print('YES\n{}'.format(left-1)) else: print('NO')
Title: Cifera Time Limit: None seconds Memory Limit: None megabytes Problem Description: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. Input Specification: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). Output Specification: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Demo Input: ['5\n25\n', '3\n8\n'] Demo Output: ['YES\n1\n', 'NO\n'] Note: none
```python k = int(input()) m = int(input()) left = 1 right = 50 while right-left > 1: middle = (left+right) // 2 if k**middle <= m: left = middle else: right = middle if k**left == m: print('YES\n{}'.format(left-1)) else: print('NO') ```
3
550
A
Two Substrings
PROGRAMMING
1,500
[ "brute force", "dp", "greedy", "implementation", "strings" ]
null
null
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters.
Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
[ "ABA\n", "BACFAB\n", "AXBYBXA\n" ]
[ "NO\n", "YES\n", "NO\n" ]
In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
1,000
[ { "input": "ABA", "output": "NO" }, { "input": "BACFAB", "output": "YES" }, { "input": "AXBYBXA", "output": "NO" }, { "input": "ABABAB", "output": "YES" }, { "input": "BBBBBBBBBB", "output": "NO" }, { "input": "ABBA", "output": "YES" }, { "input": "ABAXXXAB", "output": "YES" }, { "input": "TESTABAXXABTEST", "output": "YES" }, { "input": "A", "output": "NO" }, { "input": "B", "output": "NO" }, { "input": "X", "output": "NO" }, { "input": "BA", "output": "NO" }, { "input": "AB", "output": "NO" }, { "input": "AA", "output": "NO" }, { "input": "BB", "output": "NO" }, { "input": "BAB", "output": "NO" }, { "input": "AAB", "output": "NO" }, { "input": "BAA", "output": "NO" }, { "input": "ABB", "output": "NO" }, { "input": "BBA", "output": "NO" }, { "input": "AAA", "output": "NO" }, { "input": "BBB", "output": "NO" }, { "input": "AXBXBXA", "output": "NO" }, { "input": "SKDSKDJABSDBADKFJDK", "output": "YES" }, { "input": "ABAXXBBXXAA", "output": "NO" }, { "input": "ABAB", "output": "NO" }, { "input": "BABA", "output": "NO" }, { "input": "AAAB", "output": "NO" }, { "input": "AAAA", "output": "NO" }, { "input": "AABA", "output": "NO" }, { "input": "ABAA", "output": "NO" }, { "input": "BAAA", "output": "NO" }, { "input": "AABB", "output": "NO" }, { "input": "BAAB", "output": "YES" }, { "input": "BBAA", "output": "NO" }, { "input": "BBBA", "output": "NO" }, { "input": "BBAB", "output": "NO" }, { "input": "BABB", "output": "NO" }, { "input": "ABBB", "output": "NO" }, { "input": "BBBB", "output": "NO" }, { "input": "BABAB", "output": "YES" }, { "input": "ABABA", "output": "YES" }, { "input": "AAABAAACBBBC", "output": "NO" }, { "input": "AABBBACBBBBBBAACBCCACBBAABBBBBCAACABAACABCACCBCBCCCBCBCABCBBCCBCBBAACBACAABACBBCACCBCCACCABBCBABBAAC", "output": "YES" }, { "input": "CBBABDDBBADAC", "output": "YES" }, { "input": "ABYFAB", "output": "NO" }, { "input": "BABXXAB", "output": "YES" }, { "input": "ABAXAB", "output": "YES" }, { "input": "ABABXAB", "output": "YES" }, { "input": "ABXABXABXABXABXBAXBAXBAXBA", "output": "YES" }, { "input": "QQQQQQQQQABABQQQQQQQQ", "output": "NO" } ]
1,691,255,158
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
46
0
x=str(input()) b=x.split("AB") # print(b) if len(b)==1: print("NO") else: check=0 if b[0]=="": #take the second check=+1 elif b[1]=="": #take the first check+=2 if check==1: strings="" strings+=b[1] BA_split=strings.split("BA") if len(BA_split)>1: print("YES") else: print("NO") if check==2: strings="" strings+=b[0] BA_split=strings.split("BA") if len(BA_split)>1: print("YES") else: print("NO")
Title: Two Substrings Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). Input Specification: The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. Output Specification: Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. Demo Input: ['ABA\n', 'BACFAB\n', 'AXBYBXA\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
```python x=str(input()) b=x.split("AB") # print(b) if len(b)==1: print("NO") else: check=0 if b[0]=="": #take the second check=+1 elif b[1]=="": #take the first check+=2 if check==1: strings="" strings+=b[1] BA_split=strings.split("BA") if len(BA_split)>1: print("YES") else: print("NO") if check==2: strings="" strings+=b[0] BA_split=strings.split("BA") if len(BA_split)>1: print("YES") else: print("NO") ```
0
133
A
HQ9+
PROGRAMMING
900
[ "implementation" ]
null
null
HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.
The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive.
Output "YES", if executing the program will produce any output, and "NO" otherwise.
[ "Hi!\n", "Codeforces\n" ]
[ "YES\n", "NO\n" ]
In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
500
[ { "input": "Hi!", "output": "YES" }, { "input": "Codeforces", "output": "NO" }, { "input": "a+b=c", "output": "NO" }, { "input": "hq-lowercase", "output": "NO" }, { "input": "Q", "output": "YES" }, { "input": "9", "output": "YES" }, { "input": "H", "output": "YES" }, { "input": "+", "output": "NO" }, { "input": "~", "output": "NO" }, { "input": "dEHsbM'gS[\\brZ_dpjXw8f?L[4E\"s4Zc9*(,j:>p$}m7HD[_9nOWQ\\uvq2mHWR", "output": "YES" }, { "input": "tt6l=RHOfStm.;Qd$-}zDes*E,.F7qn5-b%HC", "output": "YES" }, { "input": "@F%K2=%RyL/", "output": "NO" }, { "input": "juq)k(FT.^G=G\\zcqnO\"uJIE1_]KFH9S=1c\"mJ;F9F)%>&.WOdp09+k`Yc6}\"6xw,Aos:M\\_^^:xBb[CcsHm?J", "output": "YES" }, { "input": "6G_\"Fq#<AWyHG=Rci1t%#Jc#x<Fpg'N@t%F=``YO7\\Zd;6PkMe<#91YgzTC)", "output": "YES" }, { "input": "Fvg_~wC>SO4lF}*c`Q;mII9E{4.QodbqN]C", "output": "YES" }, { "input": "p-UXsbd&f", "output": "NO" }, { "input": "<]D7NMA)yZe=`?RbP5lsa.l_Mg^V:\"-0x+$3c,q&L%18Ku<HcA\\s!^OQblk^x{35S'>yz8cKgVHWZ]kV0>_", "output": "YES" }, { "input": "f.20)8b+.R}Gy!DbHU3v(.(=Q^`z[_BaQ}eO=C1IK;b2GkD\\{\\Bf\"!#qh]", "output": "YES" }, { "input": "}do5RU<(w<q[\"-NR)IAH_HyiD{", "output": "YES" }, { "input": "Iy^.,Aw*,5+f;l@Q;jLK'G5H-r1Pfmx?ei~`CjMmUe{K:lS9cu4ay8rqRh-W?Gqv!e-j*U)!Mzn{E8B6%~aSZ~iQ_QwlC9_cX(o8", "output": "YES" }, { "input": "sKLje,:q>-D,;NvQ3,qN3-N&tPx0nL/,>Ca|z\"k2S{NF7btLa3_TyXG4XZ:`(t&\"'^M|@qObZxv", "output": "YES" }, { "input": "%z:c@1ZsQ@\\6U/NQ+M9R>,$bwG`U1+C\\18^:S},;kw!&4r|z`", "output": "YES" }, { "input": "OKBB5z7ud81[Tn@P\"nDUd,>@", "output": "NO" }, { "input": "y{0;neX]w0IenPvPx0iXp+X|IzLZZaRzBJ>q~LhMhD$x-^GDwl;,a'<bAqH8QrFwbK@oi?I'W.bZ]MlIQ/x(0YzbTH^l.)]0Bv", "output": "YES" }, { "input": "EL|xIP5_+Caon1hPpQ0[8+r@LX4;b?gMy>;/WH)pf@Ur*TiXu*e}b-*%acUA~A?>MDz#!\\Uh", "output": "YES" }, { "input": "UbkW=UVb>;z6)p@Phr;^Dn.|5O{_i||:Rv|KJ_ay~V(S&Jp", "output": "NO" }, { "input": "!3YPv@2JQ44@)R2O_4`GO", "output": "YES" }, { "input": "Kba/Q,SL~FMd)3hOWU'Jum{9\"$Ld4:GW}D]%tr@G{hpG:PV5-c'VIZ~m/6|3I?_4*1luKnOp`%p|0H{[|Y1A~4-ZdX,Rw2[\\", "output": "YES" }, { "input": "NRN*=v>;oU7[acMIJn*n^bWm!cm3#E7Efr>{g-8bl\"DN4~_=f?[T;~Fq#&)aXq%</GcTJD^e$@Extm[e\"C)q_L", "output": "NO" }, { "input": "y#<fv{_=$MP!{D%I\\1OqjaqKh[pqE$KvYL<9@*V'j8uH0/gQdA'G;&y4Cv6&", "output": "YES" }, { "input": "+SE_Pg<?7Fh,z&uITQut2a-mk8X8La`c2A}", "output": "YES" }, { "input": "Uh3>ER](J", "output": "NO" }, { "input": "!:!{~=9*\\P;Z6F?HC5GadFz)>k*=u|+\"Cm]ICTmB!`L{&oS/z6b~#Snbp/^\\Q>XWU-vY+/dP.7S=-#&whS@,", "output": "YES" }, { "input": "KimtYBZp+ISeO(uH;UldoE6eAcp|9u?SzGZd6j-e}[}u#e[Cx8.qgY]$2!", "output": "YES" }, { "input": "[:[SN-{r>[l+OggH3v3g{EPC*@YBATT@", "output": "YES" }, { "input": "'jdL(vX", "output": "NO" }, { "input": "Q;R+aay]cL?Zh*uG\"YcmO*@Dts*Gjp}D~M7Z96+<4?9I3aH~0qNdO(RmyRy=ci,s8qD_kwj;QHFzD|5,5", "output": "YES" }, { "input": "{Q@#<LU_v^qdh%gGxz*pu)Y\"]k-l-N30WAxvp2IE3:jD0Wi4H/xWPH&s", "output": "YES" }, { "input": "~@Gb(S&N$mBuBUMAky-z^{5VwLNTzYg|ZUZncL@ahS?K*As<$iNUARM3r43J'jJB)$ujfPAq\"G<S9flGyakZg!2Z.-NJ|2{F>]", "output": "YES" }, { "input": "Jp5Aa>aP6fZ!\\6%A}<S}j{O4`C6y$8|i3IW,WHy&\"ioE&7zP\"'xHAY;:x%@SnS]Mr{R|})gU", "output": "YES" }, { "input": "ZA#:U)$RI^sE\\vuAt]x\"2zipI!}YEu2<j$:H0_9/~eB?#->", "output": "YES" }, { "input": "&ppw0._:\\p-PuWM@l}%%=", "output": "NO" }, { "input": "P(^pix\"=oiEZu8?@d@J(I`Xp5TN^T3\\Z7P5\"ZrvZ{2Fwz3g-8`U!)(1$a<g+9Q|COhDoH;HwFY02Pa|ZGp$/WZBR=>6Jg!yr", "output": "YES" }, { "input": "`WfODc\\?#ax~1xu@[ao+o_rN|L7%v,p,nDv>3+6cy.]q3)+A6b!q*Hc+#.t4f~vhUa~$^q", "output": "YES" }, { "input": ",)TH9N}'6t2+0Yg?S#6/{_.,!)9d}h'wG|sY&'Ul4D0l0", "output": "YES" }, { "input": "VXB&r9Z)IlKOJ:??KDA", "output": "YES" }, { "input": "\")1cL>{o\\dcYJzu?CefyN^bGRviOH&P7rJS3PT4:0V3F)%\\}L=AJouYsj_>j2|7^1NWu*%NbOP>ngv-ls<;b-4Sd3Na0R", "output": "YES" }, { "input": "2Y}\\A)>row{~c[g>:'.|ZC8%UTQ/jcdhK%6O)QRC.kd@%y}LJYk=V{G5pQK/yKJ%{G3C", "output": "YES" }, { "input": "O.&=qt(`z(", "output": "NO" }, { "input": "_^r6fyIc/~~;>l%9?aVEi7-{=,[<aMiB'-scSg$$|\"jAzY0N>QkHHGBZj2c\"=fhRlWd5;5K|GgU?7h]!;wl@", "output": "YES" }, { "input": "+/`sAd&eB29E=Nu87${.u6GY@$^a$,}s^!p!F}B-z8<<wORb<S7;HM1a,gp", "output": "YES" }, { "input": "U_ilyOGMT+QiW/M8/D(1=6a7)_FA,h4`8", "output": "YES" }, { "input": "!0WKT:$O", "output": "NO" }, { "input": "1EE*I%EQz6$~pPu7|(r7nyPQt4uGU@]~H'4uII?b1_Wn)K?ZRHrr0z&Kr;}aO3<mN=3:{}QgPxI|Ncm4#)", "output": "YES" }, { "input": "[u3\"$+!:/.<Dp1M7tH}:zxjt],^kv}qP;y12\"`^'/u*h%AFmPJ>e1#Yly", "output": "YES" }, { "input": "'F!_]tB<A&UO+p?7liE>(x&RFgG2~\\(", "output": "NO" }, { "input": "Qv)X8", "output": "YES" }, { "input": "aGv7,J@&g1(}E3g6[LuDZwZl2<v7IwQA%\"R(?ouBD>_=y\"3Kf%^>vON<a^T\\G^ootgE@whWmZo=[ex|F", "output": "YES" }, { "input": "e{}2vQ+/r@p0}cLKNe4MCk", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnkH", "output": "YES" }, { "input": "Qzbmweyydiadtlcouegmdbyfwurpwbpuvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "mzbmweyydiadtlcouegmdbyfwurpwb9uvhifnuapwyndmhtqvkgkbhtytszotwflegsjzzszfwtzfpnscguemwrczqxycivdqnky", "output": "YES" }, { "input": "1H1", "output": "YES" }, { "input": "+Q", "output": "YES" }, { "input": "1ab", "output": "NO" }, { "input": "!", "output": "NO" }, { "input": "0+", "output": "NO" }, { "input": "+H", "output": "YES" }, { "input": "cH", "output": "YES" }, { "input": "+8", "output": "NO" }, { "input": "8+", "output": "NO" }, { "input": "++++++++++++++++++++++++++", "output": "NO" }, { "input": "(+)", "output": "NO" }, { "input": "H+", "output": "YES" }, { "input": "a!", "output": "NO" }, { "input": "++++++++++++++", "output": "NO" }, { "input": "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++", "output": "NO" }, { "input": "8", "output": "NO" }, { "input": "3", "output": "NO" }, { "input": "HQ9", "output": "YES" }, { "input": "+++H", "output": "YES" }, { "input": "++++++++++", "output": "NO" }, { "input": "HHHHHHH", "output": "YES" }, { "input": "abacabaH", "output": "YES" }, { "input": "+G", "output": "NO" } ]
1,690,277,171
2,147,483,647
Python 3
OK
TESTS
85
92
0
a = input() if any(i in 'HQ9' for i in a): print("YES") else: print("NO")
Title: HQ9+ Time Limit: None seconds Memory Limit: None megabytes Problem Description: HQ9+ is a joke programming language which has only four one-character instructions: - "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator. Instructions "H" and "Q" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored. You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output. Input Specification: The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. Output Specification: Output "YES", if executing the program will produce any output, and "NO" otherwise. Demo Input: ['Hi!\n', 'Codeforces\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first case the program contains only one instruction — "H", which prints "Hello, World!". In the second case none of the program characters are language instructions.
```python a = input() if any(i in 'HQ9' for i in a): print("YES") else: print("NO") ```
3
41
A
Translation
PROGRAMMING
800
[ "implementation", "strings" ]
A. Translation
2
256
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. 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,661,110,519
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a = input() b = input() c = a[::-1] if c == b: print('Yes') elif a != b: 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 a = input() b = input() c = a[::-1] if c == b: print('Yes') elif a != b: print('No') ```
0
315
A
Sereja and Bottles
PROGRAMMING
1,400
[ "brute force" ]
null
null
Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle.
In a single line print a single integer — the answer to the problem.
[ "4\n1 1\n2 2\n3 3\n4 4\n", "4\n1 2\n2 3\n3 4\n4 1\n" ]
[ "4\n", "0\n" ]
none
500
[ { "input": "4\n1 1\n2 2\n3 3\n4 4", "output": "4" }, { "input": "4\n1 2\n2 3\n3 4\n4 1", "output": "0" }, { "input": "3\n2 828\n4 392\n4 903", "output": "3" }, { "input": "4\n2 3\n1 772\n3 870\n3 668", "output": "2" }, { "input": "5\n1 4\n6 6\n4 3\n3 4\n4 758", "output": "2" }, { "input": "6\n4 843\n2 107\n10 943\n9 649\n7 806\n6 730", "output": "6" }, { "input": "7\n351 955\n7 841\n102 377\n394 102\n549 440\n630 324\n624 624", "output": "6" }, { "input": "8\n83 978\n930 674\n542 22\n834 116\n116 271\n640 930\n659 930\n705 987", "output": "6" }, { "input": "9\n162 942\n637 967\n356 108\n768 53\n656 656\n575 32\n32 575\n53 53\n351 222", "output": "6" }, { "input": "10\n423 360\n947 538\n507 484\n31 947\n414 351\n169 901\n901 21\n592 22\n763 200\n656 485", "output": "8" }, { "input": "1\n1000 1000", "output": "1" }, { "input": "1\n500 1000", "output": "1" }, { "input": "11\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11", "output": "11" }, { "input": "49\n1 758\n5 3\n5 3\n4 2\n4 36\n3 843\n5 107\n1 943\n1 649\n2 806\n3 730\n2 351\n2 102\n1 4\n3 4\n3 955\n2 841\n2 377\n5 2\n3 440\n4 324\n3 3\n3 83\n2 2\n2 1\n4 1\n1 931\n3 4\n2 5\n2 5\n4 73\n5 830\n3 4\n3 5\n5 291\n1 2\n5 3\n4 4\n2 3\n3 151\n4 2\n4 431\n5 1\n2 5\n2 4\n4 2\n4 4\n3 1\n5 2", "output": "0" }, { "input": "50\n507 31\n31 250\n414 763\n169 304\n901 9\n592 610\n763 414\n656 789\n411 422\n360 468\n625 504\n538 201\n549 619\n484 797\n596 282\n42 310\n603 656\n351 623\n292 293\n837 180\n375 658\n21 192\n597 729\n22 512\n349 635\n200 56\n669 647\n485 887\n282 939\n735 808\n54 417\n1000 310\n419 652\n939 617\n901 669\n789 390\n128 549\n468 511\n729 837\n894 729\n649 894\n484 22\n808 586\n422 286\n311 427\n618 656\n814 933\n515 901\n310 894\n617 330", "output": "30" }, { "input": "2\n7 7\n5 359", "output": "2" }, { "input": "2\n465 706\n706 706", "output": "1" }, { "input": "2\n1 1\n1 1", "output": "0" }, { "input": "3\n1 1\n1 1\n2 2", "output": "1" }, { "input": "5\n1 1\n1 2\n2 3\n3 4\n4 3", "output": "1" }, { "input": "3\n1 2\n1 2\n1 1", "output": "1" } ]
1,575,105,914
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
3
310
0
MOD = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n=ii() l1, l2 = [], [] lvis=[1]*n for _ in range(n): a, b = f() l1.append(a) l2.append(b) for i in range(n): for j in range(n): if l2[i]==l1[j] and i!=j: lvis[i]=0 print(sum(lvis))
Title: Sereja and Bottles Time Limit: None seconds Memory Limit: None megabytes Problem Description: Sereja and his friends went to a picnic. The guys had *n* soda bottles just for it. Sereja forgot the bottle opener as usual, so the guys had to come up with another way to open bottles. Sereja knows that the *i*-th bottle is from brand *a**i*, besides, you can use it to open other bottles of brand *b**i*. You can use one bottle to open multiple other bottles. Sereja can open bottle with opened bottle or closed bottle. Knowing this, Sereja wants to find out the number of bottles they've got that they won't be able to open in any way. Help him and find this number. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of bottles. The next *n* lines contain the bottles' description. The *i*-th line contains two integers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the description of the *i*-th bottle. Output Specification: In a single line print a single integer — the answer to the problem. Demo Input: ['4\n1 1\n2 2\n3 3\n4 4\n', '4\n1 2\n2 3\n3 4\n4 1\n'] Demo Output: ['4\n', '0\n'] Note: none
```python MOD = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n=ii() l1, l2 = [], [] lvis=[1]*n for _ in range(n): a, b = f() l1.append(a) l2.append(b) for i in range(n): for j in range(n): if l2[i]==l1[j] and i!=j: lvis[i]=0 print(sum(lvis)) ```
0
742
B
Arpa’s obvious problem and Mehrdad’s terrible solution
PROGRAMMING
1,500
[ "brute force", "math", "number theory" ]
null
null
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer: the answer to the problem.
[ "2 3\n1 2\n", "6 1\n5 1 2 3 4 1\n" ]
[ "1", "2" ]
In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1. In the second sample the only two pairs are *i* = 3, *j* = 4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i* = 1, *j* = 5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>). A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
1,000
[ { "input": "2 3\n1 2", "output": "1" }, { "input": "6 1\n5 1 2 3 4 1", "output": "2" }, { "input": "38 101\n395 5 339 366 409 150 400 180 348 200 409 20 182 409 208 74 176 401 459 158 282 207 241 406 33 484 65 245 363 337 204 197 445 445 72 435 126 423", "output": "0" }, { "input": "47 117\n77 57 535 240 250 321 51 29 42 582 390 525 149 195 119 465 198 494 456 313 497 205 115 256 513 413 15 423 568 135 519 174 147 201 564 182 359 41 465 162 125 378 342 144 549 363 309", "output": "1" }, { "input": "27 41\n156 148 86 161 113 80 185 15 204 185 205 95 147 146 133 187 114 8 11 120 117 167 100 171 140 102 174", "output": "1" }, { "input": "10 208\n399 912 747 631 510 622 234 707 483 496", "output": "0" }, { "input": "64 43\n78 90 211 205 198 4 172 43 163 21 58 145 28 66 210 68 79 90 155 123 9 119 188 151 180 157 44 163 20 71 28 120 163 141 170 206 31 34 21 195 72 194 83 163 140 40 182 208 127 128 110 72 184 157 128 189 146 35 51 206 62 8 117 61", "output": "8" }, { "input": "69 25\n68 26 8 121 96 101 106 87 103 14 86 26 76 85 70 50 4 4 97 89 44 98 33 65 76 64 98 95 30 5 93 121 97 85 47 50 66 2 46 79 46 22 68 59 75 94 104 105 91 97 121 6 32 94 101 125 32 91 76 57 110 31 27 97 91 49 45 37 92", "output": "21" }, { "input": "64 118\n361 547 410 294 448 377 482 490 13 116 346 50 251 330 443 128 543 580 370 489 337 509 414 291 228 71 245 308 319 314 154 39 317 288 145 248 547 152 262 278 89 108 522 238 128 575 112 469 86 230 310 492 127 270 475 25 179 72 345 444 17 332 544 338", "output": "3" }, { "input": "52 231\n229 492 1005 498 786 274 773 573 316 774 977 110 709 49 131 81 1146 1028 451 451 776 470 996 363 581 484 1023 858 1115 273 1105 4 445 509 428 125 432 131 360 404 280 808 649 4 499 1097 831 512 208 996 430 1010", "output": "0" }, { "input": "4 0\n1 2 3 4", "output": "0" }, { "input": "3 0\n2 2 2", "output": "3" }, { "input": "5 0\n1 1 1 1 1", "output": "10" }, { "input": "3 0\n1 1 1", "output": "3" }, { "input": "4 0\n2 2 2 2", "output": "6" }, { "input": "3 0\n10 10 10", "output": "3" }, { "input": "3 0\n3 3 3", "output": "3" }, { "input": "4 0\n1 1 1 1", "output": "6" }, { "input": "3 0\n4 4 4", "output": "3" }, { "input": "2 0\n2 2", "output": "1" }, { "input": "2 0\n2 3", "output": "0" }, { "input": "2 0\n1 2", "output": "0" }, { "input": "5 0\n5 5 5 5 5", "output": "10" }, { "input": "6 0\n1 1 1 1 1 1", "output": "15" }, { "input": "2 0\n1 1", "output": "1" }, { "input": "4 0\n1 1 3 3", "output": "2" }, { "input": "2 0\n10 10", "output": "1" }, { "input": "4 0\n3 3 3 3", "output": "6" }, { "input": "5 0\n1 1 1 2 2", "output": "4" }, { "input": "5 0\n1 1 2 2 3", "output": "2" }, { "input": "10 0\n1 1 1 1 1 1 1 1 1 1", "output": "45" }, { "input": "2 0\n3 3", "output": "1" } ]
1,673,609,242
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
1,000
0
n, x = map(int, input().split()) s = input().split() counter = 0 for i in range(n): for j in range(i + 1, n): if int(s[i]) ^ int(s[j]) == x: counter += 1 print(counter)
Title: Arpa’s obvious problem and Mehrdad’s terrible solution Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number *x*, count the number of pairs of indices *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) such that , where is bitwise xor operation (see notes for explanation). Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem. Input Specification: First line contains two integers *n* and *x* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*x*<=≤<=105) — the number of elements in the array and the integer *x*. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the elements of the array. Output Specification: Print a single integer: the answer to the problem. Demo Input: ['2 3\n1 2\n', '6 1\n5 1 2 3 4 1\n'] Demo Output: ['1', '2'] Note: In the first sample there is only one pair of *i* = 1 and *j* = 2. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/bec9071ce5b1039982fe0ae476cd31528ddfa2f3.png" style="max-width: 100.0%;max-height: 100.0%;"/> so the answer is 1. In the second sample the only two pairs are *i* = 3, *j* = 4 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3701990d023d19c5da0b315b5057d572ec11e4fd.png" style="max-width: 100.0%;max-height: 100.0%;"/>) and *i* = 1, *j* = 5 (since <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/8c96223ca88621240a5ee6e1498acb7e4ce0eb44.png" style="max-width: 100.0%;max-height: 100.0%;"/>). A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: [https://en.wikipedia.org/wiki/Bitwise_operation#XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
```python n, x = map(int, input().split()) s = input().split() counter = 0 for i in range(n): for j in range(i + 1, n): if int(s[i]) ^ int(s[j]) == x: counter += 1 print(counter) ```
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
1,695,045,617
2,147,483,647
Python 3
OK
TESTS
44
92
0
def change(x): y = {} for i in range(n): if i < n-1 and x[i] == 'B' and x[i+1] == 'G': y[i] = 'G' y[i+1] = 'B' elif i > 0 and x[i-1] == 'B' and x[i] == 'G': continue else: y[i] = x[i] return y n,t = map(int,input().split()) st = input() dic = {} for i in range(n): dic[i] = st[i] for i in range(t): dic = change(dic) out = '' for i in range(n): out += dic[i] print(out)
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". Output Specification: Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". Demo Input: ['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n'] Demo Output: ['GBGGB\n', 'GGBGB\n', 'GGGB\n'] Note: none
```python def change(x): y = {} for i in range(n): if i < n-1 and x[i] == 'B' and x[i+1] == 'G': y[i] = 'G' y[i+1] = 'B' elif i > 0 and x[i-1] == 'B' and x[i] == 'G': continue else: y[i] = x[i] return y n,t = map(int,input().split()) st = input() dic = {} for i in range(n): dic[i] = st[i] for i in range(t): dic = change(dic) out = '' for i in range(n): out += dic[i] print(out) ```
3
540
C
Ice Cave
PROGRAMMING
2,000
[ "dfs and similar" ]
null
null
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of *n* rows and *m* columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked. Let's number the rows with integers from 1 to *n* from top to bottom and the columns with integers from 1 to *m* from left to right. Let's denote a cell on the intersection of the *r*-th row and the *c*-th column as (*r*,<=*c*). You are staying in the cell (*r*1,<=*c*1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (*r*2,<=*c*2) since the exit to the next level is there. Can you do this?
The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500) — the number of rows and columns in the cave description. Each of the next *n* lines describes the initial state of the level of the cave, each line consists of *m* characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, *r*1 and *c*1 (1<=≤<=*r*1<=≤<=*n*,<=1<=≤<=*c*1<=≤<=*m*) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (*r*1,<=*c*1), that is, the ice on the starting cell is initially cracked. The next line contains two integers *r*2 and *c*2 (1<=≤<=*r*2<=≤<=*n*,<=1<=≤<=*c*2<=≤<=*m*) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.
If you can reach the destination, print 'YES', otherwise print 'NO'.
[ "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2\n", "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1\n", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6\n" ]
[ "YES\n", "NO\n", "YES\n" ]
In the first sample test one possible path is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c61f56de718beea14935ccdc85ae2c4ad45c1454.png" style="max-width: 100.0%;max-height: 100.0%;"/> After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
1,500
[ { "input": "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2", "output": "YES" }, { "input": "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1", "output": "NO" }, { "input": "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6", "output": "YES" }, { "input": "5 3\n.XX\n...\n.X.\n.X.\n...\n1 3\n4 1", "output": "YES" }, { "input": "1 1\nX\n1 1\n1 1", "output": "NO" }, { "input": "1 6\n.X...X\n1 2\n1 5", "output": "NO" }, { "input": "7 1\nX\n.\n.\n.\nX\n.\n.\n5 1\n3 1", "output": "YES" }, { "input": "1 2\nXX\n1 1\n1 1", "output": "NO" }, { "input": "2 1\n.\nX\n2 1\n2 1", "output": "YES" }, { "input": "3 4\n.X..\n..XX\n..X.\n1 2\n3 4", "output": "NO" }, { "input": "3 5\n.X.XX\nX...X\nX.X..\n2 1\n1 5", "output": "NO" }, { "input": "3 2\n..\nX.\n.X\n3 2\n3 1", "output": "NO" }, { "input": "3 4\nXX.X\nX...\n.X.X\n1 2\n1 1", "output": "YES" }, { "input": "1 2\nX.\n1 1\n1 2", "output": "NO" }, { "input": "2 1\nX\nX\n2 1\n1 1", "output": "YES" }, { "input": "2 2\nXX\nXX\n1 1\n2 2", "output": "NO" }, { "input": "2 2\n..\n.X\n2 2\n1 1", "output": "YES" }, { "input": "2 2\n.X\n.X\n1 2\n2 2", "output": "YES" }, { "input": "2 2\n..\nXX\n2 1\n1 1", "output": "YES" }, { "input": "4 2\nX.\n.X\n.X\nXX\n2 2\n3 1", "output": "NO" }, { "input": "2 4\nX.XX\n.X..\n2 2\n2 3", "output": "YES" }, { "input": "6 4\nX..X\n..X.\n.X..\n..X.\n.X..\nX..X\n1 1\n6 4", "output": "NO" }, { "input": "5 4\nX...\n..X.\n.X..\nX..X\n....\n4 4\n3 1", "output": "NO" }, { "input": "3 4\nX..X\n..XX\n.X..\n2 3\n3 1", "output": "NO" }, { "input": "20 20\n....................\n.......X...........X\n............X......X\n.X...XX..X....X.....\n....X.....X.........\nX..........X........\n......X........X....\n....................\n...................X\n......X.............\n..............X.....\n......X.X...........\n.X.........X.X......\n.........X......X..X\n..................X.\n...X........X.......\n....................\n....................\n..X.....X...........\n........X......X.X..\n20 16\n5 20", "output": "YES" }, { "input": "21 21\n.....X...X.........X.\n...X...XX......X.....\n..X........X.X...XX..\n.........X....X...X..\nX...X...........XX...\n...X...X....XX...XXX.\n.X............X......\n......X.X............\n.X...X.........X.X...\n......XX......X.X....\n....X.......X.XXX....\n.X.......X..XXX.X..X.\n..X........X....X...X\n.........X..........X\n.....XX.....X........\n...XX......X.........\n.....X...XX...X......\n..X.X....XX..XX.X....\nX........X.X..XX..X..\nX..X......X...X.X....\nX.....X.....X.X......\n20 4\n21 5", "output": "YES" }, { "input": "2 1\nX\nX\n2 1\n2 1", "output": "NO" }, { "input": "2 2\nXX\nX.\n1 1\n2 2", "output": "NO" }, { "input": "2 1\nX\nX\n1 1\n1 1", "output": "NO" }, { "input": "1 2\nXX\n1 2\n1 2", "output": "NO" }, { "input": "1 2\nXX\n1 1\n1 2", "output": "YES" }, { "input": "1 2\nXX\n1 2\n1 1", "output": "YES" }, { "input": "2 1\nX\nX\n1 1\n2 1", "output": "YES" }, { "input": "2 1\n.\nX\n2 1\n1 1", "output": "NO" }, { "input": "2 1\nX\n.\n1 1\n2 1", "output": "NO" }, { "input": "1 2\n.X\n1 2\n1 1", "output": "NO" }, { "input": "2 1\nX\n.\n1 1\n1 1", "output": "YES" }, { "input": "1 2\nX.\n1 1\n1 1", "output": "YES" }, { "input": "1 2\n.X\n1 2\n1 2", "output": "YES" }, { "input": "2 2\nX.\n..\n1 1\n2 2", "output": "YES" }, { "input": "2 2\n..\nX.\n2 1\n1 1", "output": "YES" }, { "input": "4 3\n..X\n..X\n.XX\n.XX\n4 2\n2 2", "output": "YES" }, { "input": "3 3\nXXX\nX..\nXXX\n2 1\n2 2", "output": "YES" }, { "input": "5 4\nXXXX\nX..X\nX..X\nXXXX\nXXXX\n4 2\n3 3", "output": "YES" } ]
1,656,231,855
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
3
93
19,865,600
from collections import deque n,m=map(int,input().split()) cave=[[] for i in range(n+1)] for i in range(1,n+1): cave[i]=[0]+list(input()) r1,c1=map(int,input().split()) r2,c2=map(int,input().split()) q=deque([[r1,c1]]) ans=False move=[(-1,0),(0,-1),(1,0),(0,1)] visited=[[False]*(m+1) for i in range(n+1)] while q: u,v=q.popleft() visited[u][v] = True for x,y in move: if (u+x,v+y)==(r2,c2): ans=True break if 1<=u+x<=n and 1<=v+y<=m and cave[u+x][v+y]=='.' and not visited[u+x][v+y]: q.append([u+x,v+y]) if ans: if cave[r2][c2]=='X': print('YES') exit() else: count=0 for x,y in move: if 1<=r2+x<=n and 1<=c2+y<=m and (cave[c2+x][c2+y]=='.' or (r2+x,c2+y)==(r1,c1)): count+=1 if count>=2: print('YES') exit() else: print('NO') exit() else: print('NO') exit()
Title: Ice Cave Time Limit: None seconds Memory Limit: None megabytes Problem Description: You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of *n* rows and *m* columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked. Let's number the rows with integers from 1 to *n* from top to bottom and the columns with integers from 1 to *m* from left to right. Let's denote a cell on the intersection of the *r*-th row and the *c*-th column as (*r*,<=*c*). You are staying in the cell (*r*1,<=*c*1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (*r*2,<=*c*2) since the exit to the next level is there. Can you do this? Input Specification: The first line contains two integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=500) — the number of rows and columns in the cave description. Each of the next *n* lines describes the initial state of the level of the cave, each line consists of *m* characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, *r*1 and *c*1 (1<=≤<=*r*1<=≤<=*n*,<=1<=≤<=*c*1<=≤<=*m*) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (*r*1,<=*c*1), that is, the ice on the starting cell is initially cracked. The next line contains two integers *r*2 and *c*2 (1<=≤<=*r*2<=≤<=*n*,<=1<=≤<=*c*2<=≤<=*m*) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one. Output Specification: If you can reach the destination, print 'YES', otherwise print 'NO'. Demo Input: ['4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2\n', '5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1\n', '4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: In the first sample test one possible path is: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c61f56de718beea14935ccdc85ae2c4ad45c1454.png" style="max-width: 100.0%;max-height: 100.0%;"/> After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.
```python from collections import deque n,m=map(int,input().split()) cave=[[] for i in range(n+1)] for i in range(1,n+1): cave[i]=[0]+list(input()) r1,c1=map(int,input().split()) r2,c2=map(int,input().split()) q=deque([[r1,c1]]) ans=False move=[(-1,0),(0,-1),(1,0),(0,1)] visited=[[False]*(m+1) for i in range(n+1)] while q: u,v=q.popleft() visited[u][v] = True for x,y in move: if (u+x,v+y)==(r2,c2): ans=True break if 1<=u+x<=n and 1<=v+y<=m and cave[u+x][v+y]=='.' and not visited[u+x][v+y]: q.append([u+x,v+y]) if ans: if cave[r2][c2]=='X': print('YES') exit() else: count=0 for x,y in move: if 1<=r2+x<=n and 1<=c2+y<=m and (cave[c2+x][c2+y]=='.' or (r2+x,c2+y)==(r1,c1)): count+=1 if count>=2: print('YES') exit() else: print('NO') exit() else: print('NO') exit() ```
-1
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,690,830,723
2,147,483,647
Python 3
OK
TESTS
35
92
0
m,n = map(int, input().split()) product = m*n if product < 2: print(0) else: print(product//2)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python m,n = map(int, input().split()) product = m*n if product < 2: print(0) else: print(product//2) ```
3.977
922
C
Cave Painting
PROGRAMMING
1,600
[ "brute force", "number theory" ]
null
null
Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that: - 1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*.
The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018).
Print "Yes", if all the remainders are distinct, and "No" otherwise. You can print each letter in arbitrary case (lower or upper).
[ "4 4\n", "5 3\n" ]
[ "No\n", "Yes\n" ]
In the first sample remainders modulo 1 and 4 coincide.
1,250
[ { "input": "4 4", "output": "No" }, { "input": "5 3", "output": "Yes" }, { "input": "1 1", "output": "Yes" }, { "input": "744 18", "output": "No" }, { "input": "47879 10", "output": "Yes" }, { "input": "1000000000000000000 1000000000000000000", "output": "No" }, { "input": "657180569218773599 42", "output": "Yes" }, { "input": "442762254977842799 30", "output": "Yes" }, { "input": "474158606260730555 1", "output": "Yes" }, { "input": "807873101233533988 39", "output": "No" }, { "input": "423 7", "output": "No" }, { "input": "264306177888923090 5", "output": "No" }, { "input": "998857801526481788 87", "output": "No" }, { "input": "999684044704565212 28", "output": "No" }, { "input": "319575605003866172 71", "output": "No" }, { "input": "755804560577415016 17", "output": "No" }, { "input": "72712630136142067 356370939", "output": "No" }, { "input": "807264258068668062 33080422", "output": "No" }, { "input": "808090496951784190 311661970", "output": "No" }, { "input": "808916740129867614 180178111", "output": "No" }, { "input": "1 2", "output": "Yes" }, { "input": "2 1", "output": "Yes" }, { "input": "57334064998850639 19", "output": "Yes" }, { "input": "144353716412182199 11", "output": "Yes" }, { "input": "411002215096001759 11", "output": "Yes" }, { "input": "347116374613371527 3", "output": "Yes" }, { "input": "518264351335130399 37", "output": "Yes" }, { "input": "192435891235905239 11", "output": "Yes" }, { "input": "491802505049361659 7", "output": "Yes" }, { "input": "310113769227703889 3", "output": "Yes" }, { "input": "876240758958364799 41", "output": "Yes" }, { "input": "173284263472319999 33", "output": "Yes" }, { "input": "334366426725130799 29", "output": "Yes" }, { "input": "415543470272330399 26", "output": "Yes" }, { "input": "631689521541558479 22", "output": "Yes" }, { "input": "581859366558790319 14", "output": "Yes" }, { "input": "224113913709159599 10", "output": "Yes" }, { "input": "740368848764104559 21", "output": "Yes" }, { "input": "895803074828822159 17", "output": "Yes" }, { "input": "400349974997012039 13", "output": "Yes" }, { "input": "205439024252247599 5", "output": "Yes" }, { "input": "197688463911338399 39", "output": "Yes" }, { "input": "283175367224349599 39", "output": "Yes" }, { "input": "893208176423362799 31", "output": "Yes" }, { "input": "440681012669897999 27", "output": "Yes" }, { "input": "947403664618451039 19", "output": "Yes" }, { "input": "232435556779345919 19", "output": "Yes" }, { "input": "504428493840551279 23", "output": "Yes" }, { "input": "30019549241681999 20", "output": "Yes" }, { "input": "648000813924303839 16", "output": "Yes" }, { "input": "763169499725761451 488954176053755860", "output": "No" }, { "input": "199398459594277592 452260924647536414", "output": "No" }, { "input": "635627415167826436 192195636386541160", "output": "No" }, { "input": "71856370741375281 155502380685354417", "output": "No" }, { "input": "731457367464667229 118809129279134971", "output": "No" }, { "input": "167686318743248777 858743836723172421", "output": "No" }, { "input": "603915274316797622 822050585316952974", "output": "No" }, { "input": "647896534275160623 65689274138731296", "output": "No" }, { "input": "648722777453244047 501918229712280140", "output": "No" }, { "input": "649549020631327471 41923378183538525", "output": "No" }, { "input": "650375259514443599 597748177714153637", "output": "No" }, { "input": "651201506987494319 33977137582669778", "output": "No" }, { "input": "652027745870610447 470206093156218622", "output": "No" }, { "input": "652853989048693871 906435048729767466", "output": "No" }, { "input": "653680227931809999 342664004303316311", "output": "No" }, { "input": "654506475404860719 375019787446735639", "output": "No" }, { "input": "655332714287976847 438493956600157103", "output": "No" }, { "input": "166512305365727033 900267947832156186", "output": "No" }, { "input": "167338548543810457 336496907700672326", "output": "No" }, { "input": "168164787426926585 772725863274221171", "output": "No" }, { "input": "523 3", "output": "No" }, { "input": "39211 6", "output": "No" }, { "input": "22151 9", "output": "No" }, { "input": "1 3", "output": "No" }, { "input": "47 5", "output": "No" }, { "input": "999999998999999999 1000000000", "output": "No" }, { "input": "11 6", "output": "No" }, { "input": "7 4", "output": "No" }, { "input": "1 10", "output": "No" }, { "input": "9 5", "output": "No" }, { "input": "2519 20", "output": "No" }, { "input": "700001 3", "output": "Yes" }, { "input": "13 7", "output": "No" }, { "input": "999999 10000", "output": "No" }, { "input": "1 4", "output": "No" }, { "input": "232792559 30", "output": "No" }, { "input": "1 5", "output": "No" }, { "input": "5 4", "output": "No" }, { "input": "5 8", "output": "No" }, { "input": "55 4", "output": "No" } ]
1,676,306,579
2,147,483,647
PyPy 3-64
OK
TESTS
90
62
0
import sys input = sys.stdin.readline n, k = map(int, input().split()) s = set() for i in range(1, k+1): if n%i in s: print('No') break else: s.add(n%i) else: print('Yes')
Title: Cave Painting Time Limit: None seconds Memory Limit: None megabytes Problem Description: Imp is watching a documentary about cave painting. Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number *n* by all integers *i* from 1 to *k*. Unfortunately, there are too many integers to analyze for Imp. Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all , 1<=≤<=*i*<=≤<=*k*, are distinct, i. e. there is no such pair (*i*,<=*j*) that: - 1<=≤<=*i*<=&lt;<=*j*<=≤<=*k*, - , where is the remainder of division *x* by *y*. Input Specification: The only line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1018). Output Specification: Print "Yes", if all the remainders are distinct, and "No" otherwise. You can print each letter in arbitrary case (lower or upper). Demo Input: ['4 4\n', '5 3\n'] Demo Output: ['No\n', 'Yes\n'] Note: In the first sample remainders modulo 1 and 4 coincide.
```python import sys input = sys.stdin.readline n, k = map(int, input().split()) s = set() for i in range(1, k+1): if n%i in s: print('No') break else: s.add(n%i) else: print('Yes') ```
3
681
A
A Good Contest
PROGRAMMING
800
[ "implementation" ]
null
null
Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.
Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.
[ "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n", "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n" ]
[ "YES", "NO" ]
In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
500
[ { "input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "NO" }, { "input": "1\nDb -3373 3591", "output": "NO" }, { "input": "5\nQ2bz 960 2342\nhmX 2710 -1348\ngbAe -1969 -963\nE -160 196\npsi 2665 -3155", "output": "NO" }, { "input": "9\nmwAz9lQ 1786 -1631\nnYgYFXZQfY -1849 -1775\nKU4jF -1773 -3376\nopR 3752 2931\nGl -1481 -1002\nR -1111 3778\n0i9B21DC 3650 289\nQ8L2dS0 358 -3305\ng -2662 3968", "output": "NO" }, { "input": "5\nzMSBcOUf -2883 -2238\nYN -3314 -1480\nfHpuccQn06 -1433 -589\naM1NVEPQi 399 3462\n_L 2516 -3290", "output": "NO" }, { "input": "1\na 2400 2401", "output": "YES" }, { "input": "1\nfucker 4000 4000", "output": "NO" }, { "input": "1\nJora 2400 2401", "output": "YES" }, { "input": "1\nACA 2400 2420", "output": "YES" }, { "input": "1\nAca 2400 2420", "output": "YES" }, { "input": "1\nSub_d 2401 2402", "output": "YES" }, { "input": "2\nHack 2400 2401\nDum 1243 555", "output": "YES" }, { "input": "1\nXXX 2400 2500", "output": "YES" }, { "input": "1\nfucker 2400 2401", "output": "YES" }, { "input": "1\nX 2400 2500", "output": "YES" }, { "input": "1\nvineet 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2500", "output": "YES" }, { "input": "1\naaaaa 2400 2401", "output": "YES" }, { "input": "1\nhoge 2400 2401", "output": "YES" }, { "input": "1\nInfinity 2400 2468", "output": "YES" }, { "input": "1\nBurunduk1 2400 2401", "output": "YES" }, { "input": "1\nFuck 2400 2401", "output": "YES" }, { "input": "1\nfuck 2400 2401", "output": "YES" }, { "input": "3\nApplejack 2400 2401\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450", "output": "YES" }, { "input": "1\nalex 2400 2401", "output": "YES" }, { "input": "1\nA 2400 2401", "output": "YES" }, { "input": "1\na 2400 2455", "output": "YES" }, { "input": "1\nlol 2400 2401", "output": "YES" }, { "input": "2\nBurunduk1 2400 2537\nBudAlNik 2084 2214", "output": "YES" }, { "input": "1\naaaaaa 2400 2401", "output": "YES" }, { "input": "1\nBurunduk1 2400 2500", "output": "YES" }, { "input": "1\nds 2400 2410", "output": "YES" }, { "input": "1\nas 2400 2401", "output": "YES" }, { "input": "1\nabc 2400 2401", "output": "YES" }, { "input": "3\nBudAlNik 2084 2214\nsubscriber 2833 2749\nBurunduk1 2526 2537", "output": "YES" }, { "input": "1\ncaonima 2400 2401", "output": "YES" }, { "input": "1\narr 2400 2500", "output": "YES" }, { "input": "1\nx 2400 2401", "output": "YES" }, { "input": "1\narrr 2400 2500", "output": "YES" }, { "input": "1\nabc 2400 2405", "output": "YES" }, { "input": "3\nBurunduk1 2400 2420\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nBurunduk1 2400 2537", "output": "YES" }, { "input": "1\nHELLO 2400 2401", "output": "YES" }, { "input": "1\neatmore 2400 2500", "output": "YES" }, { "input": "1\nb 2400 2401", "output": "YES" }, { "input": "3\nBurunduk1 2400 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES" }, { "input": "1\nApplejack 2400 2410", "output": "YES" }, { "input": "1\nabacaba 2400 2451", "output": "YES" }, { "input": "1\nrekt_n00b 2500 2600", "output": "YES" } ]
1,612,314,288
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
124
2,048,000
n = int(input()) for i in range(n): # list prefer to have same data type #to stor names x= list(input().split(' ')) #to store before y= list(input().split(' ')) #to store after z=list(input().split(' ')) #to store y in int to can compare the number y=int(y) z=int(z) # if x>2400 that mean he is red if x>=2400 and y>z: print("yes") else: print("n")
Title: A Good Contest Time Limit: None seconds Memory Limit: None megabytes Problem Description: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct. Output Specification: Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. Demo Input: ['3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n', '3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n'] Demo Output: ['YES', 'NO'] Note: In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest. In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.
```python n = int(input()) for i in range(n): # list prefer to have same data type #to stor names x= list(input().split(' ')) #to store before y= list(input().split(' ')) #to store after z=list(input().split(' ')) #to store y in int to can compare the number y=int(y) z=int(z) # if x>2400 that mean he is red if x>=2400 and y>z: print("yes") else: print("n") ```
-1
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,412,070,153
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
6
2,000
6,144,000
n = int(input()) s = [ int(x) for x in input().split() ] pts = 0 while n > 0 : pts += sum(s) m = min(s) if n >= 2 : pts += m s.remove(m) else : s.remove(m) n -= 1 print(pts)
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()) s = [ int(x) for x in input().split() ] pts = 0 while n > 0 : pts += sum(s) m = min(s) if n >= 2 : pts += m s.remove(m) else : s.remove(m) n -= 1 print(pts) ```
0
672
B
Different is Good
PROGRAMMING
1,000
[ "constructive algorithms", "implementation", "strings" ]
null
null
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible.
The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters.
If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes.
[ "2\naa\n", "4\nkoko\n", "5\nmurat\n" ]
[ "1\n", "2\n", "0\n" ]
In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
1,000
[ { "input": "2\naa", "output": "1" }, { "input": "4\nkoko", "output": "2" }, { "input": "5\nmurat", "output": "0" }, { "input": "6\nacbead", "output": "1" }, { "input": "7\ncdaadad", "output": "4" }, { "input": "25\npeoaicnbisdocqofsqdpgobpn", "output": "12" }, { "input": "25\ntcqpchnqskqjacruoaqilgebu", "output": "7" }, { "input": "13\naebaecedabbee", "output": "8" }, { "input": "27\naaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "-1" }, { "input": "10\nbababbdaee", "output": "6" }, { "input": "11\ndbadcdbdbca", "output": "7" }, { "input": "12\nacceaabddaaa", "output": "7" }, { "input": "13\nabddfbfaeecfa", "output": "7" }, { "input": "14\neeceecacdbcbbb", "output": "9" }, { "input": "15\ndcbceaaggabaheb", "output": "8" }, { "input": "16\nhgiegfbadgcicbhd", "output": "7" }, { "input": "17\nabhfibbdddfghgfdi", "output": "10" }, { "input": "26\nbbbbbabbaababaaabaaababbaa", "output": "24" }, { "input": "26\nahnxdnbfbcrirerssyzydihuee", "output": "11" }, { "input": "26\nhwqeqhkpxwulbsiwmnlfyhgknc", "output": "8" }, { "input": "26\nrvxmulriorilidecqwmfaemifj", "output": "10" }, { "input": "26\naowpmreooavnmamogdoopuisge", "output": "12" }, { "input": "26\ninimevtuefhvuefirdehmmfudh", "output": "15" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "27\nqdcfjtblgglnilgassirrjekcjt", "output": "-1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyza", "output": "-1" }, { "input": "26\nqwertyuiopasdfghjklzxcvbnm", "output": "0" }, { "input": "5\nzzzzz", "output": "4" }, { "input": "27\naaaaaaaaaaaaaaaaabaaaaaaaaa", "output": "-1" }, { "input": "1\nq", "output": "0" }, { "input": "27\nqwertyuioplkjhgfdsazxcvbnmm", "output": "-1" }, { "input": "9\nxxxyyyzzz", "output": "6" }, { "input": "45\naaabbbcccdddeeefffgghhiijjkkkkkkkkkkkkkkkkkkk", "output": "-1" }, { "input": "27\nqwertyuiopasdfghjklzxcvbnmm", "output": "-1" }, { "input": "26\nabcdefghijklmnopqrstuvwxyz", "output": "0" }, { "input": "26\nabcdefghijklmnopqrstuvwxya", "output": "1" }, { "input": "27\nabcdefghijklmnopqrstuvwxyzz", "output": "-1" }, { "input": "26\naaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "25" }, { "input": "26\nqwertyuioplkjhgfdsazxcvbnm", "output": "0" }, { "input": "10\nzzzzzzzzzz", "output": "9" }, { "input": "1\na", "output": "0" }, { "input": "30\nabcdefghtyabcdefghtyabcdefghty", "output": "-1" } ]
1,567,411,729
2,147,483,647
Python 3
OK
TESTS
47
124
716,800
from collections import OrderedDict n=int(input()) s=str(input()) l=len(s) f="".join(OrderedDict.fromkeys(s)) if(len(s)>26): print('-1') else: print(len(s)-len(f))
Title: Different is Good Time Limit: None seconds Memory Limit: None megabytes Problem Description: A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different. Kerem recently got a string *s* consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his string *s* to be distinct. Substring is a string formed by some number of consecutive characters of the string. For example, string "aba" has substrings "" (empty substring), "a", "b", "a", "ab", "ba", "aba". If string *s* has at least two equal substrings then Kerem will change characters at some positions to some other lowercase English letters. Changing characters is a very tiring job, so Kerem want to perform as few changes as possible. Your task is to find the minimum number of changes needed to make all the substrings of the given string distinct, or determine that it is impossible. Input Specification: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the length of the string *s*. The second line contains the string *s* of length *n* consisting of only lowercase English letters. Output Specification: If it's impossible to change the string *s* such that all its substring are distinct print -1. Otherwise print the minimum required number of changes. Demo Input: ['2\naa\n', '4\nkoko\n', '5\nmurat\n'] Demo Output: ['1\n', '2\n', '0\n'] Note: In the first sample one of the possible solutions is to change the first character to 'b'. In the second sample, one may change the first character to 'a' and second character to 'b', so the string becomes "abko".
```python from collections import OrderedDict n=int(input()) s=str(input()) l=len(s) f="".join(OrderedDict.fromkeys(s)) if(len(s)>26): print('-1') else: print(len(s)-len(f)) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,630,465,419
2,147,483,647
Python 3
OK
TESTS
59
62
6,758,400
def FindSmaller(x, y): if x < y: return x return y def FindFactorial(a, b): number = FindSmaller(a, b) fact = 1 while(number > 0): fact *= number number -= 1 return fact k = input().split() a, b = int(k[0]), int(k[1]) print(FindFactorial(a, b))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python def FindSmaller(x, y): if x < y: return x return y def FindFactorial(a, b): number = FindSmaller(a, b) fact = 1 while(number > 0): fact *= number number -= 1 return fact k = input().split() a, b = int(k[0]), int(k[1]) print(FindFactorial(a, b)) ```
3
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,642,471,039
2,147,483,647
PyPy 3-64
OK
TESTS
30
216
0
n=input() upper=0 lower=0 for i in n: if i.isupper(): upper+=1 else: lower+=1 if upper==lower or lower>upper: print(n.lower()) else: print(n.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python n=input() upper=0 lower=0 for i in n: if i.isupper(): upper+=1 else: lower+=1 if upper==lower or lower>upper: print(n.lower()) else: print(n.upper()) ```
3.946
992
A
Nastya and an Array
PROGRAMMING
800
[ "implementation", "sortings" ]
null
null
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array.
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
[ "5\n1 1 1 1 1\n", "3\n2 0 -1\n", "4\n5 -6 -5 1\n" ]
[ "1\n", "2\n", "4\n" ]
In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
500
[ { "input": "5\n1 1 1 1 1", "output": "1" }, { "input": "3\n2 0 -1", "output": "2" }, { "input": "4\n5 -6 -5 1", "output": "4" }, { "input": "1\n0", "output": "0" }, { "input": "2\n21794 -79194", "output": "2" }, { "input": "3\n-63526 95085 -5239", "output": "3" }, { "input": "3\n0 53372 -20572", "output": "2" }, { "input": "13\n-2075 -32242 27034 -37618 -96962 82203 64846 48249 -71761 28908 -21222 -61370 46899", "output": "13" }, { "input": "5\n806 0 1308 1954 683", "output": "4" }, { "input": "8\n-26 0 -249 -289 -126 -206 288 -11", "output": "7" }, { "input": "10\n2 2 2 1 2 -1 0 2 -1 1", "output": "3" }, { "input": "1\n8", "output": "1" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "5\n2 0 -1 0 0", "output": "2" }, { "input": "2\n0 0", "output": "0" }, { "input": "5\n0 0 0 0 0", "output": "0" }, { "input": "2\n1 0", "output": "1" }, { "input": "2\n-1 0", "output": "1" }, { "input": "4\n0 0 0 0", "output": "0" }, { "input": "8\n10 9 -1 0 0 3 2 3", "output": "5" }, { "input": "5\n5 0 1 2 3", "output": "4" }, { "input": "3\n1 1 0", "output": "1" }, { "input": "1\n-1", "output": "1" }, { "input": "5\n1 2 0 0 0", "output": "2" }, { "input": "5\n1 0 0 0 0", "output": "1" }, { "input": "5\n4 5 6 0 0", "output": "3" }, { "input": "4\n-1 0 0 1", "output": "2" }, { "input": "5\n3 0 0 4 5", "output": "3" }, { "input": "3\n0 0 2", "output": "1" }, { "input": "3\n1 0 0", "output": "1" }, { "input": "4\n0 0 0 4", "output": "1" }, { "input": "5\n-1 0 0 0 0", "output": "1" }, { "input": "2\n0 1", "output": "1" }, { "input": "3\n1 2 3", "output": "3" }, { "input": "1\n5", "output": "1" }, { "input": "10\n0 0 0 0 0 1 2 3 0 0", "output": "3" }, { "input": "4\n0 1 2 3", "output": "3" }, { "input": "3\n0 1 2", "output": "2" }, { "input": "4\n2 0 0 -1", "output": "2" } ]
1,585,472,076
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
93
0
l=list(map(int,input().split())) l=list(set(l)) if(0 in l): l.remove(0) print(len(l))
Title: Nastya and an Array Time Limit: None seconds Memory Limit: None megabytes Problem Description: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. Output Specification: Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. Demo Input: ['5\n1 1 1 1 1\n', '3\n2 0 -1\n', '4\n5 -6 -5 1\n'] Demo Output: ['1\n', '2\n', '4\n'] Note: In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero. In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.
```python l=list(map(int,input().split())) l=list(set(l)) if(0 in l): l.remove(0) print(len(l)) ```
0
707
C
Pythagorean Triples
PROGRAMMING
1,500
[ "math", "number theory" ]
null
null
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples. Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse. Katya had no problems with completing this task. Will you do the same?
The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle.
Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them.
[ "3\n", "6\n", "1\n", "17\n", "67\n" ]
[ "4 5", "8 10", "-1", "144 145", "2244 2245" ]
Illustration for the first sample.
1,500
[ { "input": "3", "output": "4 5" }, { "input": "6", "output": "8 10" }, { "input": "1", "output": "-1" }, { "input": "17", "output": "144 145" }, { "input": "67", "output": "2244 2245" }, { "input": "10", "output": "24 26" }, { "input": "14", "output": "48 50" }, { "input": "22", "output": "120 122" }, { "input": "23", "output": "264 265" }, { "input": "246", "output": "15128 15130" }, { "input": "902", "output": "203400 203402" }, { "input": "1000000000", "output": "1250000000 750000000" }, { "input": "1998", "output": "998000 998002" }, { "input": "2222222", "output": "1234567654320 1234567654322" }, { "input": "2222226", "output": "1234572098768 1234572098770" }, { "input": "1111110", "output": "308641358024 308641358026" }, { "input": "9999998", "output": "24999990000000 24999990000002" }, { "input": "1024", "output": "1280 768" }, { "input": "8388608", "output": "10485760 6291456" }, { "input": "4", "output": "5 3" }, { "input": "8", "output": "10 6" }, { "input": "16", "output": "20 12" }, { "input": "492", "output": "615 369" }, { "input": "493824", "output": "617280 370368" }, { "input": "493804", "output": "617255 370353" }, { "input": "493800", "output": "617250 370350" }, { "input": "2048", "output": "2560 1536" }, { "input": "8388612", "output": "10485765 6291459" }, { "input": "44", "output": "55 33" }, { "input": "444", "output": "555 333" }, { "input": "4444", "output": "5555 3333" }, { "input": "44444", "output": "55555 33333" }, { "input": "444444", "output": "555555 333333" }, { "input": "4444444", "output": "5555555 3333333" }, { "input": "100000000", "output": "125000000 75000000" }, { "input": "2", "output": "-1" }, { "input": "3", "output": "4 5" }, { "input": "5", "output": "12 13" }, { "input": "7", "output": "24 25" }, { "input": "9", "output": "40 41" }, { "input": "11", "output": "60 61" }, { "input": "13", "output": "84 85" }, { "input": "15", "output": "112 113" }, { "input": "19", "output": "180 181" }, { "input": "111", "output": "6160 6161" }, { "input": "113", "output": "6384 6385" }, { "input": "115", "output": "6612 6613" }, { "input": "117", "output": "6844 6845" }, { "input": "119", "output": "7080 7081" }, { "input": "111111", "output": "6172827160 6172827161" }, { "input": "111113", "output": "6173049384 6173049385" }, { "input": "111115", "output": "6173271612 6173271613" }, { "input": "111117", "output": "6173493844 6173493845" }, { "input": "111119", "output": "6173716080 6173716081" }, { "input": "9999993", "output": "49999930000024 49999930000025" }, { "input": "9999979", "output": "49999790000220 49999790000221" }, { "input": "9999990", "output": "24999950000024 24999950000026" }, { "input": "9999991", "output": "49999910000040 49999910000041" }, { "input": "9999992", "output": "12499990 7499994" }, { "input": "9999973", "output": "49999730000364 49999730000365" }, { "input": "9999994", "output": "24999970000008 24999970000010" }, { "input": "9999995", "output": "49999950000012 49999950000013" }, { "input": "9999996", "output": "12499995 7499997" }, { "input": "9999997", "output": "49999970000004 49999970000005" }, { "input": "9999978", "output": "24999890000120 24999890000122" }, { "input": "99999993", "output": "4999999300000024 4999999300000025" }, { "input": "99999979", "output": "4999997900000220 4999997900000221" }, { "input": "99999990", "output": "2499999500000024 2499999500000026" }, { "input": "99999991", "output": "4999999100000040 4999999100000041" }, { "input": "99999992", "output": "124999990 74999994" }, { "input": "99999973", "output": "4999997300000364 4999997300000365" }, { "input": "99999994", "output": "2499999700000008 2499999700000010" }, { "input": "99999995", "output": "4999999500000012 4999999500000013" }, { "input": "99999996", "output": "124999995 74999997" }, { "input": "99999997", "output": "4999999700000004 4999999700000005" }, { "input": "99999978", "output": "2499998900000120 2499998900000122" }, { "input": "987654323", "output": "487730530870294164 487730530870294165" }, { "input": "2", "output": "-1" }, { "input": "4", "output": "5 3" }, { "input": "8", "output": "10 6" }, { "input": "64", "output": "80 48" }, { "input": "999999999", "output": "499999999000000000 499999999000000001" }, { "input": "16", "output": "20 12" }, { "input": "999999937", "output": "499999937000001984 499999937000001985" }, { "input": "999999998", "output": "249999999000000000 249999999000000002" }, { "input": "433494437", "output": "93958713454973484 93958713454973485" }, { "input": "484916147", "output": "117571834810662804 117571834810662805" }, { "input": "999999929", "output": "499999929000002520 499999929000002521" }, { "input": "982451653", "output": "482605625241216204 482605625241216205" }, { "input": "2048", "output": "2560 1536" } ]
1,689,901,259
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
2
1,000
1,536,000
a = int(input()) for i in range(1, int(1e9)): x = pow(a * a + i * i, 0.5) if x == int(x): print(i, int(x)) exit() print(-1)
Title: Pythagorean Triples Time Limit: None seconds Memory Limit: None megabytes Problem Description: Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, triples (3,<=4,<=5), (5,<=12,<=13) and (6,<=8,<=10) are Pythagorean triples. Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse. Katya had no problems with completing this task. Will you do the same? Input Specification: The only line of the input contains single integer *n* (1<=≤<=*n*<=≤<=109) — the length of some side of a right triangle. Output Specification: Print two integers *m* and *k* (1<=≤<=*m*,<=*k*<=≤<=1018), such that *n*, *m* and *k* form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer *n*, print <=-<=1 in the only line. If there are many answers, print any of them. Demo Input: ['3\n', '6\n', '1\n', '17\n', '67\n'] Demo Output: ['4 5', '8 10', '-1', '144 145', '2244 2245'] Note: Illustration for the first sample.
```python a = int(input()) for i in range(1, int(1e9)): x = pow(a * a + i * i, 0.5) if x == int(x): print(i, int(x)) exit() print(-1) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\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", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,670,075,718
2,147,483,647
Python 3
OK
TESTS
18
92
0
nm = input().split() nm = [int(x) for x in nm] n = nm[0] m = nm[1] array = input().split() array = [int(x) for x in array] def task(n,m,array): results = [] result = 0 array.sort() for i in range(m): try: result = array[i+n-1] - array[i] results.append(result) except: pass return min(results) print(task(n,m,array))
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python nm = input().split() nm = [int(x) for x in nm] n = nm[0] m = nm[1] array = input().split() array = [int(x) for x in array] def task(n,m,array): results = [] result = 0 array.sort() for i in range(m): try: result = array[i+n-1] - array[i] results.append(result) except: pass return min(results) print(task(n,m,array)) ```
3